static string FindUniqueTimedFileOrFolder(string pathPrefix, string fileSuffix, DateTime time, int maxTryBeforeGuid, Func <string, bool> tester) { if (pathPrefix == null) { throw new ArgumentNullException("pathPrefix"); } if (fileSuffix == null) { throw new ArgumentNullException("fileSuffix"); } if (maxTryBeforeGuid < 0) { throw new ArgumentOutOfRangeException("maxTryBeforeGuid"); } DateTimeStamp timeStamp = new DateTimeStamp(time); int counter = 0; string result = pathPrefix + timeStamp.ToString() + fileSuffix; for ( ; ;) { if (tester(result)) { break; } if (counter < maxTryBeforeGuid) { timeStamp = new DateTimeStamp(timeStamp, timeStamp); result = pathPrefix + timeStamp.ToString() + fileSuffix; } else { if (counter == maxTryBeforeGuid + 1) { throw new Exception(Impl.CoreResources.FileUtilUnableToCreateUniqueTimedFileOrFolder); } if (counter == maxTryBeforeGuid) { result = pathPrefix + FormatTimedUniqueFilePart(time) + fileSuffix; } } ++counter; } return(result); }
static StringBuilder CreateHeader(DateTimeStamp logTime, string text, LogLevel level, CKTrait tags) { StringBuilder buffer = new StringBuilder(); buffer.Append('<').Append(level.ToString()).Append('>').Append('@').Append(logTime.ToString()); if (tags != null && !tags.IsEmpty) { buffer.Append(" - ").Append(tags.ToString()); } buffer.AppendLine(); if (text != null && text.Length > 0) { buffer.Append(text).AppendLine(); } return(buffer); }