Skip to content

Commit

Permalink
VS2022 Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkoshevoi committed Oct 5, 2022
1 parent ede63a8 commit 3d184e7
Show file tree
Hide file tree
Showing 146 changed files with 10,957 additions and 11,100 deletions.
9 changes: 6 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dotnet_sort_system_directives_first = false
csharp_indent_case_contents_when_block = false

# var preferences
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_for_built_in_types = false:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
Expand All @@ -33,7 +33,10 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_prefer_switch_expression = true:warning

# Namespace preferences
csharp_style_namespace_declarations = block_scoped:warning
csharp_style_namespace_declarations = file_scoped:warning

# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = suggestion
dotnet_remove_unnecessary_suppression_exclusions = suggestion

# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = suggestion
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<LangVersion>preview</LangVersion><NoWarn>CS0105</NoWarn> <!--Needed for VS2019-->
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors Condition="'$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
125 changes: 62 additions & 63 deletions NureTimetable.Core/BL/ExceptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,87 @@
using System.Net;
using Xamarin.Essentials;

namespace NureTimetable.Core.BL
namespace NureTimetable.Core.BL;

public static class ExceptionService
{
public static class ExceptionService
public delegate void ExceptionHandler(Exception exception);
public static event ExceptionHandler? ExceptionLogged;

public static void LogException(Exception ex)
{
public delegate void ExceptionHandler(Exception exception);
public static event ExceptionHandler? ExceptionLogged;
ExceptionLogged?.Invoke(ex);

public static void LogException(Exception ex)
// Getting exception Data
Dictionary<string, string?> properties = new();
List<ErrorAttachmentLog> attachments = new();
foreach (DictionaryEntry de in ex.Data)
{
ExceptionLogged?.Invoke(ex);

// Getting exception Data
Dictionary<string, string?> properties = new();
List<ErrorAttachmentLog> attachments = new();
foreach (DictionaryEntry de in ex.Data)
if (de.Value is ErrorAttachmentLog attachment)
{
if (de.Value is ErrorAttachmentLog attachment)
{
attachments.Add(attachment);
continue;
}
properties.Add(de.Key.ToString()!, de.Value?.ToString());
}
if (ex.InnerException != null)
{
attachments.Add(ErrorAttachmentLog.AttachmentWithText(ex.InnerException.ToString(), "InnerException.txt"));
attachments.Add(attachment);
continue;
}
properties.Add(de.Key.ToString()!, de.Value?.ToString());
}
if (ex.InnerException != null)
{
attachments.Add(ErrorAttachmentLog.AttachmentWithText(ex.InnerException.ToString(), "InnerException.txt"));
}

// Special cases for certain exception types
if (ex is WebException webEx)
// Special cases for certain exception types
if (ex is WebException webEx)
{
if (Connectivity.NetworkAccess == NetworkAccess.None)
{
if (Connectivity.NetworkAccess == NetworkAccess.None)
{
// No Internet caused WebException, nothing to log here
return;
}

// WebException happens for external reasons, and shouldn't be treated as an exception.
// But just in case it is logged as Event

if (webEx.Status != 0 && webEx.Status != WebExceptionStatus.UnknownError)
{
properties.Add("Status", webEx.Status.ToString());
}
if (webEx.InnerException != null)
{
properties.Add("InnerException", webEx.InnerException.GetType().FullName);
}
properties.Add("Message", ex.Message);

Analytics.TrackEvent("WebException", properties);
// No Internet caused WebException, nothing to log here
return;
}
else if (ex is CistException cistEx)
{
// CistException happens for external reasons, and shouldn't be treated as an exception

if (!properties.ContainsKey("Status"))
{
properties.Add("Status", cistEx.Status.ToString());
}
// WebException happens for external reasons, and shouldn't be treated as an exception.
// But just in case it is logged as Event

Analytics.TrackEvent("CistException", properties);
return;
if (webEx.Status != 0 && webEx.Status != WebExceptionStatus.UnknownError)
{
properties.Add("Status", webEx.Status.ToString());
}
else if (ex is MoodleException moodleEx)
if (webEx.InnerException != null)
{
// MoodleException happens for external reasons, and shouldn't be treated as an exception
properties.Add("InnerException", webEx.InnerException.GetType().FullName);
}
properties.Add("Message", ex.Message);

properties.Add("ErrorCode", moodleEx.ErrorCode);
properties.Add("Message", moodleEx.Message);
Analytics.TrackEvent("WebException", properties);
return;
}
else if (ex is CistException cistEx)
{
// CistException happens for external reasons, and shouldn't be treated as an exception

Analytics.TrackEvent("MoodleException", properties);
return;
}
else if (ex is IOException && ex.Message.StartsWith("Disk full."))
if (!properties.ContainsKey("Status"))
{
return;
properties.Add("Status", cistEx.Status.ToString());
}

// Logging exception
Crashes.TrackError(ex, properties, attachments.ToArray());
Analytics.TrackEvent("CistException", properties);
return;
}
else if (ex is MoodleException moodleEx)
{
// MoodleException happens for external reasons, and shouldn't be treated as an exception

properties.Add("ErrorCode", moodleEx.ErrorCode);
properties.Add("Message", moodleEx.Message);

Analytics.TrackEvent("MoodleException", properties);
return;
}
else if (ex is IOException && ex.Message.StartsWith("Disk full."))
{
return;
}

// Logging exception
Crashes.TrackError(ex, properties, attachments.ToArray());
}
}
41 changes: 20 additions & 21 deletions NureTimetable.Core/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
namespace NureTimetable.Core.Extensions
namespace NureTimetable.Core.Extensions;

public static class EnumExtensions
{
public static class EnumExtensions
public static T AddFlag<T>(this Enum value, T flag)
{
public static T AddFlag<T>(this Enum value, T flag)
if (!value.GetType().IsEquivalentTo(typeof(T)))
{
if (!value.GetType().IsEquivalentTo(typeof(T)))
{
throw new ArgumentException("Enum value and flags types don't match.");
}

return (T)Enum.ToObject(typeof(T), Convert.ToUInt64(value) | Convert.ToUInt64(flag));
throw new ArgumentException("Enum value and flags types don't match.");
}

public static T RemoveFlag<T>(this Enum value, T flag)
{
if (!value.GetType().IsEquivalentTo(typeof(T)))
{
throw new ArgumentException("Enum value and flags types don't match.");
}

return (T)Enum.ToObject(typeof(T), Convert.ToUInt64(value) & ~Convert.ToUInt64(flag));
}
return (T)Enum.ToObject(typeof(T), Convert.ToUInt64(value) | Convert.ToUInt64(flag));
}

public static int FlagCount(this Enum value)
public static T RemoveFlag<T>(this Enum value, T flag)
{
if (!value.GetType().IsEquivalentTo(typeof(T)))
{
string binary = Convert.ToString(int.Parse(value.ToString("D")), 2);
return binary.Count(x => x == '1');
throw new ArgumentException("Enum value and flags types don't match.");
}

return (T)Enum.ToObject(typeof(T), Convert.ToUInt64(value) & ~Convert.ToUInt64(flag));
}

public static int FlagCount(this Enum value)
{
string binary = Convert.ToString(int.Parse(value.ToString("D")), 2);
return binary.Count(x => x == '1');
}
}
Loading

0 comments on commit 3d184e7

Please sign in to comment.