using System; using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Sockets; using Gestor.Common.Validation; namespace Gestor.Common.Helpers; public class Functions { public static Stopwatch Stopwatch; public static DateTime? StartTime; public static int Compare(string original, string modified) { if (original == null) { original = ""; } if (modified == null) { modified = ""; } string text = original.ToLongNullable().ToString(); if (!string.IsNullOrWhiteSpace(text)) { original = text; } text = modified.ToLongNullable().ToString(); if (!string.IsNullOrWhiteSpace(text)) { modified = text; } int length = original.Length; int length2 = modified.Length; int[,] array = new int[length + 1, length2 + 1]; for (int i = 0; i <= length; i++) { array[i, 0] = i; } for (int j = 0; j <= length2; j++) { array[0, j] = j; } for (int k = 1; k <= length; k++) { for (int l = 1; l <= length2; l++) { int num = ((modified[l - 1] != original[k - 1]) ? 1 : 0); int[] source = new int[3] { array[k - 1, l] + 1, array[k, l - 1] + 1, array[k - 1, l - 1] + num }; array[k, l] = source.Min(); if (k > 1 && l > 1 && original[k - 1] == modified[l - 2] && original[k - 2] == modified[l - 1]) { array[k, l] = Math.Min(array[k, l], array[k - 2, l - 2] + num); } } } return array[length, length2]; } public static DateTime GetNetworkTime() { try { if (StartTime.HasValue) { return StartTime.Value.AddMilliseconds(Stopwatch.ElapsedMilliseconds); } byte[] array = new byte[48]; array[0] = 27; IPEndPoint remoteEP = new IPEndPoint(Dns.GetHostEntry("time.google.com").AddressList.First((IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork), 123); using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { socket.Connect(remoteEP); socket.ReceiveTimeout = 3000; socket.Send(array); socket.Receive(array); socket.Close(); } ulong num = ((ulong)array[40] << 24) | ((ulong)array[41] << 16) | ((ulong)array[42] << 8) | array[43]; ulong num2 = ((ulong)array[44] << 24) | ((ulong)array[45] << 16) | ((ulong)array[46] << 8) | array[47]; ulong num3 = num * 1000 + num2 * 1000 / 4294967296L; DateTime value = new DateTime(1900, 1, 1).AddMilliseconds((long)num3).ToLocalTime(); StartTime = value; Stopwatch = Stopwatch.StartNew(); return StartTime.Value; } catch (Exception) { StartTime = DateTime.Now; Stopwatch = Stopwatch.StartNew(); return StartTime.Value; } } }