From 772ecf8a90a7f86b2080d72af84f0badf6ed5fbf Mon Sep 17 00:00:00 2001 From: olivier HERGAULT Date: Thu, 23 Jun 2022 16:49:00 +0200 Subject: [PATCH] ticksFrom2022base36 pour shortGUID --- .../ApplicationLogEntity.cs | 4 +- .../ApplicationLogEntityManager.cs | 4 +- Source/SerialLabs.Logging/LogEntry.cs | 1 + Source/SerialLabs/CoolTools.cs | 69 ++++++++++++------- .../Properties/Resources.Designer.cs | 44 ++++++------ Source/SerialLabs/SerialLabs.csproj | 7 +- Source/SerialLabs/packages.config | 2 +- 7 files changed, 79 insertions(+), 52 deletions(-) diff --git a/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntity.cs b/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntity.cs index 2b4d0d2..976b239 100644 --- a/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntity.cs +++ b/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntity.cs @@ -30,8 +30,8 @@ public class ApplicationLogEntity : TableEntity [DataMemberAttribute] public string MachineName { get; set; } - [DataMemberAttribute] - public string AppDomainName { get; set; } + //[DataMemberAttribute] + //public string AppDomainName { get; set; } [DataMemberAttribute] public string ProcessId { get; set; } diff --git a/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntityManager.cs b/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntityManager.cs index b2a57ab..8de55dd 100644 --- a/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntityManager.cs +++ b/Source/SerialLabs.Logging.AzureTable/ApplicationLogEntityManager.cs @@ -90,7 +90,7 @@ public static ApplicationLogEntity CreateFromLogEntry(LogEntry logEntry, ILogFor Guard.ArgumentNotNull(logEntry, "logEntry"); ApplicationLogEntity entity = new ApplicationLogEntity { - AppDomainName = logEntry.AppDomainName, + //AppDomainName = logEntry.AppDomainName, //not an interesting value to store ApplicationName = logEntry.ApplicationName, Category = logEntry.Categories.Join(","), EventId = logEntry.EventId, @@ -118,7 +118,7 @@ public static ApplicationLogEntity Create(string title, string rawMessage, strin { return new ApplicationLogEntity { - AppDomainName = "Unknown AppDomain", + //AppDomainName = "Unknown AppDomain", ApplicationName = applicationName, Category = category, EventId = eventId, diff --git a/Source/SerialLabs.Logging/LogEntry.cs b/Source/SerialLabs.Logging/LogEntry.cs index db4e865..3393dc5 100644 --- a/Source/SerialLabs.Logging/LogEntry.cs +++ b/Source/SerialLabs.Logging/LogEntry.cs @@ -384,6 +384,7 @@ private void InitializeProcessName() Properties.Resources.IntrinsicPropertyError, Properties.Resources.LogEntryIntrinsicPropertyNoUnmanagedCodePermissionError); } + if (this.ProcessName == @"c:\windows\system32\inetsrv\w3wp.exe") this.ProcessName = "..w3wp"; } private void InitializeThreadName() diff --git a/Source/SerialLabs/CoolTools.cs b/Source/SerialLabs/CoolTools.cs index ecea956..ac7db8b 100644 --- a/Source/SerialLabs/CoolTools.cs +++ b/Source/SerialLabs/CoolTools.cs @@ -270,7 +270,7 @@ public static int userInputLikeTimespan2sec(string myTimespan) userInput = userInput.Replace(" ", "");//remove spaces inside the string // \/ ! the longest words first, to not replace just one letter and after find no match string[,] replacementArray = { { "hours", "h", "minutes", "min", "m", "seconds", "sec", "s" }, - { ":", ":", ":", ":", ":", "", "", "" } }; + { ":", ":", ":", ":", ":", "", "", "" } }; for (int i = 2; i < 8; i++) userInput = userInput.Replace(replacementArray[0, i], replacementArray[1, i]); @@ -614,7 +614,7 @@ public static int EditDistance(IEnumerable x, IEnumerable y, bool allow int d3 = first[i - 1].Equals(second[j - 1]) ? 0 : 1; if (allowForSubstitutions) // then may reduce d3 if substitution detected, else leave unchanged if (d3 == 1) if (i < n && j < m) - if (first[i].Equals(second[j - 1]) && first[i - 1].Equals(second[j])) d3 = 0; + if (first[i].Equals(second[j - 1]) && first[i - 1].Equals(second[j])) d3 = 0; if (allowPlaceHolder) if (typeof(T) == typeof(char)) if (d3 == 1) if (first[i - 1].Equals('?') || first[i - 2 < 0 ? 0 : i - 2].Equals('?')) d3 = 0; @@ -1035,11 +1035,11 @@ public static string HtmlStripTags(string htmlContent, bool replaceNamedEntities endIdx = bodyEndTagIdx; bool insideTag = false, - insideAttributeValue = false, - insideHtmlComment = false, - insideScriptBlock = false, - insideNoScriptBlock = false, - insideStyleBlock = false; + insideAttributeValue = false, + insideHtmlComment = false, + insideScriptBlock = false, + insideNoScriptBlock = false, + insideStyleBlock = false; char attributeValueDelimiter = '"'; StringBuilder sb = new StringBuilder(htmlContent.Length); @@ -1311,7 +1311,7 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } public static IEnumerable GetPrimeFactors( -int value, Eratosthenes eratosthenes) + int value, Eratosthenes eratosthenes) { List factors = new List(); @@ -1700,10 +1700,10 @@ public static class ConvertNumFromBaseToBase { public static readonly char[] BaseChars = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray(); + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray(); private static readonly Dictionary CharValues = BaseChars - .Select((c, i) => new { Char = c, Index = i }) - .ToDictionary(c => c.Char, c => c.Index); + .Select((c, i) => new { Char = c, Index = i }) + .ToDictionary(c => c.Char, c => c.Index); public static readonly char[] BaseChars36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); @@ -1721,7 +1721,7 @@ public static string LongToBase(long value, char[] alphabet) long targetBase = alphabet.Length; // Determine exact number of characters to use. char[] buffer = new char[Math.Max( - (int)Math.Ceiling(Math.Log(value + 1, targetBase)), 1)]; + (int)Math.Ceiling(Math.Log(value + 1, targetBase)), 1)]; var i = buffer.Length; do @@ -1755,13 +1755,13 @@ public static long BaseToLong(string number) // convert to hexadecimal static string hex = IntToString(42, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F'}); + 'A', 'B', 'C', 'D', 'E', 'F'}); // convert to sexagesimal static string xx = IntToString(42, new char[] { '0','1','2','3','4','5','6','7','8','9', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', - 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'}); + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'}); public static string IntToString(int value, char[] baseChars) @@ -1805,7 +1805,7 @@ public static string IntToStringFast(int value, char[] baseChars) } } - /// + /// /// to create shorter GUID /// FROM https://jopinblog.wordpress.com/2009/02/04/a-shorter-friendlier-guiduuid-in-net/ /// @@ -1874,18 +1874,42 @@ public string GetBase32UniqueId(byte[] basis, int numDigits) var ret = new string(chars, 26 - numDigits, numDigits); return ret; } - - public static string ticksTo2080base36() + + + /// + /// Calculate the numbers of ticks between now and 01/01/2080 and convert the number to base 36 + /// Add '0' padding to 7 char (optional) + /// + /// 2022-05-20T17:00:09 => 8cp7k5f + /// 2079-12-01T00:00:00 => 000iio0 + /// add leading 0 to get a 7 char string + /// + public static string ticksTo2080base36(bool withPaddingTo7Char=true) { - return CoolTools.ConvertNumFromBaseToBase.LongToBase( + string s= CoolTools.ConvertNumFromBaseToBase.LongToBase( (new DateTime(2080, 01, 01).Ticks - DateTime.Now.Ticks) / 1000000, ConvertNumFromBaseToBase.BaseChars36minus); + if (withPaddingTo7Char) + if (s.Length < 7) + s = s.PadLeft(7 - s.Length, '0'); + return s; } - public static string ticksFrom2022base36() + + /// + /// Calculate the numbers of ticks between 01/01/2022 and Now convert the number to base 36 + /// Add '0' padding to 7 char (optional) + /// + /// add leading 0 to get a 7 char string + /// + public static string ticksFrom2022base36(bool withPaddingTo7Char=true) { - return CoolTools.ConvertNumFromBaseToBase.LongToBase( + string s= CoolTools.ConvertNumFromBaseToBase.LongToBase( (DateTime.Now.Ticks- new DateTime(2022, 01, 01).Ticks ) / 1000000, ConvertNumFromBaseToBase.BaseChars36minus); + if (withPaddingTo7Char) + if (s.Length < 7) + s = s.PadLeft(7 - s.Length, '0'); + return s; } @@ -2640,5 +2664,4 @@ public static List cancelShuffleSecure(this IList list, List oldIn } -} - +} \ No newline at end of file diff --git a/Source/SerialLabs/Properties/Resources.Designer.cs b/Source/SerialLabs/Properties/Resources.Designer.cs index a52feda..9960fd3 100644 --- a/Source/SerialLabs/Properties/Resources.Designer.cs +++ b/Source/SerialLabs/Properties/Resources.Designer.cs @@ -1,25 +1,25 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.34011 +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. // //------------------------------------------------------------------------------ -namespace SerialLabs.Properties -{ - - +namespace SerialLabs.Properties { + using System; + + /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { @@ -61,7 +61,7 @@ internal Resources() { } /// - /// Looks up a localized string similar to The provided string argument must not be empty.. + /// Recherche une chaîne localisée semblable à The provided string argument must not be empty.. /// internal static string ArgumentMustNotBeEmpty { get { @@ -70,7 +70,7 @@ internal static string ArgumentMustNotBeEmpty { } /// - /// Looks up a localized string similar to The provided string argument contains only whitespace.. + /// Recherche une chaîne localisée semblable à The provided string argument contains only whitespace.. /// internal static string ArgumentMustNotBeWhiteSpace { get { @@ -79,7 +79,7 @@ internal static string ArgumentMustNotBeWhiteSpace { } /// - /// Looks up a localized string similar to The given parameter is not an instance of type {0}.. + /// Recherche une chaîne localisée semblable à The given parameter is not an instance of type {0}.. /// internal static string IsNotInstanceOfType { get { @@ -88,7 +88,7 @@ internal static string IsNotInstanceOfType { } /// - /// Looks up a localized string similar to The type {1} cannot be assigned to variables of type {0}.. + /// Recherche une chaîne localisée semblable à The type {1} cannot be assigned to variables of type {0}.. /// internal static string TypesAreNotAssignable { get { @@ -97,7 +97,7 @@ internal static string TypesAreNotAssignable { } /// - /// Looks up a localized string similar to <unknown>. + /// Recherche une chaîne localisée semblable à <unknown>. /// internal static string UnknownType { get { diff --git a/Source/SerialLabs/SerialLabs.csproj b/Source/SerialLabs/SerialLabs.csproj index fe17665..0139704 100644 --- a/Source/SerialLabs/SerialLabs.csproj +++ b/Source/SerialLabs/SerialLabs.csproj @@ -51,9 +51,12 @@ ..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll - ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + ..\..\..\MyBlazonTools\MyBlasonCreatorTestAppli\packages\Newtonsoft.Json.13.0.2-beta1\lib\net45\Newtonsoft.Json.dll + True + + + ..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll - diff --git a/Source/SerialLabs/packages.config b/Source/SerialLabs/packages.config index 376abb5..d0828b6 100644 --- a/Source/SerialLabs/packages.config +++ b/Source/SerialLabs/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file