Skip to content

Commit

Permalink
ticksFrom2022base36 pour shortGUID
Browse files Browse the repository at this point in the history
  • Loading branch information
oldbrazil committed Jun 23, 2022
1 parent b00a43b commit 772ecf8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Source/SerialLabs.Logging.AzureTable/ApplicationLogEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static ApplicationLogEntity CreateFromLogEntry(LogEntry logEntry, ILogFor
Guard.ArgumentNotNull<PlatformException>(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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Source/SerialLabs.Logging/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
69 changes: 46 additions & 23 deletions Source/SerialLabs/CoolTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -614,7 +614,7 @@ public static int EditDistance<T>(IEnumerable<T> x, IEnumerable<T> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1311,7 +1311,7 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
public static IEnumerable<int> GetPrimeFactors(
int value, Eratosthenes eratosthenes)
int value, Eratosthenes eratosthenes)
{
List<int> factors = new List<int>();

Expand Down Expand Up @@ -1700,10 +1700,10 @@ public static class ConvertNumFromBaseToBase
{

public static readonly char[] BaseChars =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
private static readonly Dictionary<char, int> 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();
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1805,7 +1805,7 @@ public static string IntToStringFast(int value, char[] baseChars)
}
}

/// <summary>
/// <summary>
/// to create shorter GUID
/// FROM https://jopinblog.wordpress.com/2009/02/04/a-shorter-friendlier-guiduuid-in-net/
/// </summary>
Expand Down Expand Up @@ -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()


/// <summary>
/// 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)
/// </summary>
/// <example>2022-05-20T17:00:09 => 8cp7k5f</example>
/// <example>2079-12-01T00:00:00 => 000iio0</example>
/// <param name="withPaddingTo7Char">add leading 0 to get a 7 char string</param>
/// <returns></returns>
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()

/// <summary>
/// Calculate the numbers of ticks between 01/01/2022 and Now convert the number to base 36
/// Add '0' padding to 7 char (optional)
/// </summary>
/// <param name="withPaddingTo7Char">add leading 0 to get a 7 char string</param>
/// <returns></returns>
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;
}


Expand Down Expand Up @@ -2640,5 +2664,4 @@ public static List<T> cancelShuffleSecure<T>(this IList<T> list, List<int> oldIn


}
}

}
44 changes: 22 additions & 22 deletions Source/SerialLabs/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Source/SerialLabs/SerialLabs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\..\MyBlazonTools\MyBlasonCreatorTestAppli\packages\Newtonsoft.Json.13.0.2-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down
2 changes: 1 addition & 1 deletion Source/SerialLabs/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net451" />
<package id="Newtonsoft.Json" version="13.0.2-beta1" targetFramework="net451" />
</packages>

0 comments on commit 772ecf8

Please sign in to comment.