77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using Xamarin.Essentials;
|
|
|
|
namespace Billing
|
|
{
|
|
internal static class Helper
|
|
{
|
|
#if DEBUG
|
|
public static void Debug(string message)
|
|
{
|
|
var time = DateTime.Now.ToString("HH:mm:ss.fff");
|
|
System.Diagnostics.Debug.WriteLine($"[{time}] - {message}");
|
|
}
|
|
|
|
public static void Error(string category, Exception ex)
|
|
{
|
|
Error(category, ex?.Message ?? "unknown error");
|
|
}
|
|
|
|
public static void Error(string category, string message)
|
|
{
|
|
var time = DateTime.Now.ToString("HH:mm:ss.fff");
|
|
System.Diagnostics.Debug.Fail($"[{time}] - {category}", message);
|
|
}
|
|
#else
|
|
#pragma warning disable IDE0060 // Remove unused parameter
|
|
public static void Debug(string message)
|
|
{
|
|
}
|
|
|
|
public static void Error(string category, Exception ex)
|
|
{
|
|
}
|
|
|
|
public static void Error(string category, string message)
|
|
{
|
|
}
|
|
#pragma warning restore IDE0060 // Remove unused parameter
|
|
#endif
|
|
|
|
public static bool NetworkAvailable
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
return Connectivity.NetworkAccess == NetworkAccess.Internet
|
|
|| Connectivity.NetworkAccess == NetworkAccess.ConstrainedInternet;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public const string DEFAULT_COLOR = "#183153";
|
|
|
|
public static string WrapColorString(string color)
|
|
{
|
|
if (color == null)
|
|
{
|
|
return DEFAULT_COLOR;
|
|
}
|
|
if (color.Length > 7)
|
|
{
|
|
var alpha = color[1..3];
|
|
if (int.TryParse(alpha, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int a) && a == 255)
|
|
{
|
|
return "#" + color[3..];
|
|
}
|
|
}
|
|
return color;
|
|
}
|
|
}
|
|
} |