public void Base36EncodeTest() { // positive number long inputNumber = 512344131333132; long result = 0; string base36 = ""; base36 = StringUtils.Base36Encode(inputNumber); Assert.IsTrue(!string.IsNullOrEmpty(base36), "Base36 number resulted in empty or null"); result = StringUtils.Base36Decode(base36); Assert.AreEqual(inputNumber, result, "Base36 conversion failed."); // negative number inputNumber = -512344131333132; base36 = StringUtils.Base36Encode(inputNumber); Assert.IsTrue(!string.IsNullOrEmpty(base36), "Base36 number resulted in empty or null"); result = StringUtils.Base36Decode(base36); Assert.AreEqual(inputNumber, result, "Base36 conversion failed."); inputNumber = 0; base36 = StringUtils.Base36Encode(inputNumber); Assert.IsTrue(!string.IsNullOrEmpty(base36), "Base36 number resulted in empty or null"); result = StringUtils.Base36Decode(base36); Assert.AreEqual(inputNumber, result, "Base36 conversion failed."); }
private string getOutputCacheTimestamp() { // -- if authoring, always force cache to bust. Otherwise base the timestamp from when the assembly was created. long ticks = DateTime.Now.Ticks; if (this._page.currentUserCanWrite) { ticks = DateTime.Now.Ticks; } else { try { System.IO.FileInfo fi = new System.IO.FileInfo(typeof(CmsContext).Assembly.Location); ticks = fi.CreationTime.Ticks; } catch { } } string ret = StringUtils.Base36Encode(ticks); return(ret); }
protected static string getImageCacheKey(string FullSizeImageFilenameOnDisk, int displayBoxWidth, int displayBoxHeight) { //-- algorithm note: nothing called here should access the disk or database; everything should be memory based. string PathUnderAppRoot = PathUtils.RelativePathTo(System.Web.Hosting.HostingEnvironment.MapPath("~/"), FullSizeImageFilenameOnDisk); string ret = PathUnderAppRoot; byte[] bytes = System.Text.Encoding.UTF32.GetBytes(ret); long val = long.MaxValue; foreach (byte b in bytes) { val = val - b; } ret = StringUtils.Base36Encode(val); string fn = Path.GetFileNameWithoutExtension(PathUnderAppRoot); ret = ret + fn; foreach (char c in Path.GetInvalidPathChars()) { ret = ret.Replace(c, '.'); } ret = ret.Replace(Path.DirectorySeparatorChar.ToString(), ""); ret = ret.Replace(Path.AltDirectorySeparatorChar.ToString(), ""); ret = ret.Replace(Path.VolumeSeparatorChar.ToString(), ""); ret = ret.Replace(Path.PathSeparator.ToString(), ""); ret = ret.Replace("#", ""); ret = ret.Replace("%", ""); ret = ret.Replace(" ", "."); ret = ret.Replace("~", "."); // -- note: when using mono/linux, ~ has special significance // -- HTTrack has problems with unicode characters in filenames // logged here: http://forum.httrack.com/readmsg/18923/index.html // let's replace some common chars, but leave the rest to the for loop before. // We could use the list of Unicode chars: http://en.wikipedia.org/wiki/List_of_Unicode_characters ret = ret.Replace("ä", "a"); ret = ret.Replace("á", "a"); ret = ret.Replace("á", "a"); ret = ret.Replace("Ä", "A"); ret = ret.Replace("Ã", "A"); ret = ret.Replace("ç", "c"); ret = ret.Replace("Č", "C"); ret = ret.Replace("č", "c"); ret = ret.Replace("ě", "e"); ret = ret.Replace("é", "e"); ret = ret.Replace("í", "i"); ret = ret.Replace("ñ", "n"); ret = ret.Replace("Ñ", "N"); ret = ret.Replace("ř", "r"); ret = ret.Replace("ß", "ss"); ret = ret.Replace("ö", "o"); ret = ret.Replace("Ö", "O"); ret = ret.Replace("Ó", "O"); ret = ret.Replace("ó", "o"); ret = ret.Replace("ü", "u"); ret = ret.Replace("Ü", "U"); ret = ret.Replace("ý", "y"); ret = ret.Replace("ž", "z"); string noUnicode = ret; foreach (char c in ret) { if (c > '\u0080') { noUnicode = noUnicode.Replace(c.ToString(), Convert.ToInt32(c).ToString()); } } // foreach ret = noUnicode; // -- check the length of the string to ensure it will fit on the file system. if (ret.Length >= 245) { ret = ret.Substring(ret.Length - 245); } // -- add the displayBoxHeight and displayBoxWidth if (displayBoxHeight <= 0) { displayBoxHeight = -1; } if (displayBoxWidth <= 0) { displayBoxWidth = -1; } ret = ret + "." + displayBoxWidth.ToString() + "." + displayBoxHeight.ToString() + "."; return(ret); }