} // for testing /// <summary> /// Initializes a new instance of the <see cref="BlobItem"/> class. /// </summary> /// <param name="item">The <see cref="IListBlobItem"/> to build properties from.</param> public BlobItem([NotNull] IListBlobItem item) { Tag = item; RootFolder = item.Container.Name; Path = item.Uri.AbsolutePath; UniqueLeaseName = Guid.NewGuid().ToString(); var index = Path.LastIndexOf("/", StringComparison.InvariantCulture); FileName = Path.Substring(index + 1, Path.Length - index - 1); FileNameWithoutExtension = FileName; index = Path.LastIndexOf(".", StringComparison.InvariantCulture) + 1; if (index > 0) { FileExtension = Path.Substring(index, Path.Length - index).ToLower(CultureInfo.InvariantCulture); FileNameWithoutExtension = FileName.Replace(FileExtension, string.Empty); var extIndex = FileNameWithoutExtension.LastIndexOf(".", StringComparison.InvariantCulture); FileNameWithoutExtension = extIndex > 0 ? FileNameWithoutExtension.Substring(0, extIndex) : FileNameWithoutExtension; } Path = $"{RootFolder}/{FileName}"; }
/// <summary> /// Initializes a new instance of the <see cref="BlobItem"/> class. /// </summary> /// <param name="item">The <see cref="CloudBlockBlob"/> to build properties from.</param> public BlobItem([NotNull] CloudBlockBlob item) { Tag = item; RootFolder = item.Container.Name; Path = item.Uri.AbsolutePath; UniqueLeaseName = Guid.NewGuid().ToString(); var index = Path.LastIndexOf("/", StringComparison.InvariantCulture); FileName = Path.Substring(index + 1, Path.Length - index - 1); FileNameWithoutExtension = FileName; index = Path.LastIndexOf(".", StringComparison.InvariantCulture) + 1; if (index > 0) { FileExtension = Path.Substring(index, Path.Length - index).ToLower(CultureInfo.InvariantCulture); FileNameWithoutExtension = FileName.Replace(FileExtension, string.Empty); var extIndex = FileNameWithoutExtension.LastIndexOf(".", StringComparison.InvariantCulture); FileNameWithoutExtension = extIndex > 0 ? FileNameWithoutExtension.Substring(0, extIndex) : FileNameWithoutExtension; } Metadata = (Dictionary <string, string>)item.Metadata; if (item.Properties != null && item.Properties.Length != -1) { FileSize = item.Properties.Length; // Set content hash if it exists. if (item.Properties.ContentMD5 != null) { ContentHash = ConvertContentHash(item.Properties.ContentMD5); } // Set LastWriteTime if it exists. if (item.Properties.LastModified != null) { LastWriteTime = item.Properties.LastModified.Value.UtcDateTime; } } // We need to get the LastWriteTime for the blob, a custom metadata property. // We are including a fallback to the built in last modified date of the blob should the custom property not exist. // Instantiating the property to DateTime.MinValue just in case something really weird has happened and the fallback property isn't set. if (item.Metadata.ContainsKey("LastWriteTimeUtc")) { var encodedLastWrite = item.Metadata["LastWriteTimeUtc"]; LastWriteTime = DateTime.Parse(HttpUtility.UrlDecode(encodedLastWrite)); } Path = $"{RootFolder}/{FileName}"; }
/// <summary> /// Log a message to the log file. /// </summary> /// <param name="message">content to log</param> /// <param name="category">the priority of the message</param> public override void WriteLine(string message, string category) { if (String.IsNullOrEmpty(message)) { return; } if (RollingLogs) { // Create or append to log file. string shortDate = DateTime.Now.ToString("yyyyMMdd"); FileNameWithoutExtension = FileNameWithoutExtension.Substring(0, FileNameWithoutExtension.LastIndexOf('_')) + "_" + shortDate; } string fullPath = Path.Combine(logLocation, FileNameWithoutExtension, LogExtension); string dateTime = DateTime.Now.ToString("MM-dd-yyyy h:mm:ss tt"); //Get calling method name StackTrace stackTrace = new StackTrace(); string methodName = ""; int methodNum = 1; MethodBase mb = stackTrace.GetFrame(methodNum).GetMethod(); string className = ""; while (mb.Name.ToLowerInvariant() == "writeline" || mb.Name.ToLowerInvariant() == "handleexception") { methodNum++; mb = stackTrace.GetFrame(methodNum).GetMethod(); string[] fullName = mb.ReflectedType.FullName.Split('.'); className = fullName[fullName.Length - 1]; } if (mb != null) { if (!String.IsNullOrEmpty(className)) { methodName = className + ">"; } methodName += mb.Name; } // Create or append to log file. fullPath = Path.Combine(LogLocation, FileNameWithoutExtension + LogExtension); //remove extra line breaks if (message.EndsWith(Environment.NewLine)) { message = message.Substring(0, message.LastIndexOf(Environment.NewLine)); } for (int i = 0; i < 10; i++) { try { File.AppendAllText(fullPath, String.Format("{0} [{1}] [{2}] [{3}] {4}", dateTime, category.ToUpperInvariant(), Environment.MachineName, methodName, message + Environment.NewLine)); break; } catch (System.IO.IOException) { System.Threading.Thread.Sleep(100); } } }