private void AssertFileIsNotReadOnly([NotNull] BaseEntry entry, [NotNull] AbsolutePath absolutePath) { if (entry is FileEntry file && file.Attributes.HasFlag(FileAttributes.ReadOnly)) { throw ErrorFactory.System.UnauthorizedAccess(absolutePath.GetText()); } }
private void AddToPlaylistExecute(BaseEntry item) { try { List <Song> addToPlaylistSongs = null; if (item is Artist) { var artist = item as Artist; if (artist.Songs.Count > 0) { addToPlaylistSongs = artist.Songs.Where(p => (!p.IsTemp)).ToList(); } } else if (item is Album) { var album = item as Album; if (album.Songs.Count > 0) { addToPlaylistSongs = album.Songs.Where(p => (!p.IsTemp)).ToList(); } } if (addToPlaylistSongs != null && addToPlaylistSongs.Count > 0) { AddToPlaylistPage.songs = addToPlaylistSongs; SheetUtility.OpenAddToPlaylistPage(); } } catch (Exception) { } }
public async Task InsertAsync(BaseEntry entry) { try { await Task.Run(() => { using (var custstmt = DbConnection.Prepare(EasySql.CreateInsert(entry.GetType()))) { EasySql.FillInsert(custstmt, entry); var res = custstmt.Step(); if (res != SQLiteResult.DONE) { throw new Exception(); } } } ); } catch (Exception ex) { Debug.WriteLine(ex.Message); return; } using (var idstmt = DbConnection.Prepare("SELECT last_insert_rowid()")) { idstmt.Step(); { entry.Id = (long)idstmt[0]; } } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); BaseEntry entry = (BaseEntry)this.Element; if (this.Control != null) { Control?.SetBackgroundColor(Android.Graphics.Color.Transparent); Control.SetHintTextColor(Color.FromHex("#B9B9B9").ToAndroid()); Control.Gravity = GravityFlags.CenterVertical; //this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions); if (string.IsNullOrWhiteSpace(Control.Text)) { Control.SetCursorVisible(true); } if (entry != null) { SetReturnType(entry); // Editor Action is called when the return button is pressed Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) => { if (entry.ReturnType != ReturnType.Next) { entry.Unfocus(); } // Call all the methods attached to base_entry event handler Completed entry.InvokeCompleted(); }; } } }
private async void EntryPlayClickExecute(BaseEntry item) { try { List <Song> queueSongs = null; if (item is Artist) { var artist = item as Artist; queueSongs = artist.Songs.ToList(); } else if (item is Album) { var album = item as Album; queueSongs = album.Songs.ToList(); } else if (item is Playlist) { var playlist = item as Playlist; queueSongs = playlist.Songs.Select(p => p.Song).ToList(); } if (queueSongs != null && queueSongs.Count > 0) { await PlayAndQueueHelper.PlaySongsAsync(queueSongs[0], queueSongs, true); } } catch (Exception) { } }
public override DateTime Handle(FileGetTimeArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); var resolver = new EntryResolver(Root); BaseEntry entry = resolver.SafeResolveEntry(arguments.Path); if (entry == null) { return(arguments.IsInUtc ? PathFacts.ZeroFileTimeUtc : PathFacts.ZeroFileTime); } switch (arguments.Kind) { case FileTimeKind.CreationTime: return(arguments.IsInUtc ? entry.CreationTimeUtc : entry.CreationTime); case FileTimeKind.LastWriteTime: return(arguments.IsInUtc ? entry.LastWriteTimeUtc : entry.LastWriteTime); case FileTimeKind.LastAccessTime: return(arguments.IsInUtc ? entry.LastAccessTimeUtc : entry.LastAccessTime); default: throw new NotSupportedException($"Unsupported kind of file time '{arguments.Kind}'."); } }
public override Missing Handle(FileCryptoArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); AssertIsEncryptingOnNtFsVolume(arguments); BaseEntry entry = ResolveEntry(arguments); if (entry is FileEntry fileEntry) { AssertFileIsNotExternallyEncrypted(fileEntry, arguments.Path); AssertHasExclusiveAccess(fileEntry, arguments.Path); AssertFileIsNotReadOnly(fileEntry); } if (arguments.IsEncrypt) { HandleEncrypt(entry); } else { HandleDecrypt(entry); } return(Missing.Value); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (this.Control != null) { GradientDrawable gd = new GradientDrawable(); gd.SetCornerRadius(10); gd.SetColor(Color.White.ToAndroid()); this.Control.SetBackground(gd); } BaseEntry base_entry = (BaseEntry)this.Element; this.SetReturnType(base_entry); this.Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) => { if (base_entry.ReturnType != ReturnType.Next) { base_entry.Unfocus(); } base_entry.InvokeCompleted(); }; }
internal BaseVirtualEntity(InternalFileSystem fileSystem, BaseEntry entry) { _entry = entry; FileSystem = fileSystem; Id = entry.Id; CreatedAt = entry.CreationTime; }
private void SetReturnType(BaseEntry base_entry) { ReturnType type = base_entry.ReturnType; switch (type) { case ReturnType.Go: this.Control.ImeOptions = ImeAction.Go; this.Control.SetImeActionLabel("Go", ImeAction.Go); break; case ReturnType.Next: this.Control.ImeOptions = ImeAction.Next; this.Control.SetImeActionLabel("Next", ImeAction.Next); break; case ReturnType.Send: this.Control.ImeOptions = ImeAction.Send; this.Control.SetImeActionLabel("Send", ImeAction.Send); break; case ReturnType.Search: this.Control.ImeOptions = ImeAction.Search; this.Control.SetImeActionLabel("Search", ImeAction.Search); break; default: this.Control.ImeOptions = ImeAction.Done; this.Control.SetImeActionLabel("Done", ImeAction.Done); break; } }
private static void AssertIsNotExternallyEncrypted([NotNull] BaseEntry entry, [NotNull] AbsolutePath absolutePath) { if (entry.IsExternallyEncrypted) { throw ErrorFactory.System.UnauthorizedAccess(absolutePath.GetText()); } }
public override System.CodeDom.CodeMemberMethod GetDeserializerMethod() { CodeMemberMethod method = base.GetDeserializerMethod(); CodeTypeReference listType = CodeGen.CreateGenericType(typeof(List <>), BaseEntry.GetTypeReference()); method.Statements.Add(CodeGen.MakeVariable(listType, "ret", CodeGen.CreateObject(listType))); if (TrailingLength.IsValid) { int length; // If not a primitive expression or the length is not 0 if (!TrailingLength.ParseInt(out length) || (length != 0)) { method.Statements.Add(CodeGen.GetAssign(CodeGen.GetReader(), CodeGen.CreateObject(typeof(DataReader), CodeGen.CallMethod(CodeGen.GetReader(), "ReadToEndTrail", CodeGen.GetLength(TrailingLength))))); } } List <CodeStatement> loopStatements = new List <CodeStatement>(); loopStatements.Add(CodeGen.GetStatement(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "Add", _memberEntry.GetReaderExpression(CodeGen.GetReader())))); method.Statements.Add( CodeGen.GetTryCatch(new CodeStatement[] { CodeGen.GetInfLoop(loopStatements.ToArray()) }, typeof(EndOfStreamException))); method.Statements.Add(CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray"))); return(method); }
public CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression ret = null; IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter; if (_reference.IsValid()) { string name = _isByteLength ? "SAB" : "SA"; List <CodeExpression> parameters = new List <CodeExpression>(); parameters.Add(reader); EvalExpression lengthRead = LengthReadExpression; parameters.Add(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames())); if (lengthRead.IsValid) { parameters.Add(CodeGen.GetPrimitive(lengthRead.Expression)); } else { parameters.Add(CodeGen.GetPrimitive(_adjustment)); } ret = CodeGen.CallMethod(CodeGen.GetThis(), name, BaseEntry.GetTypeReference(), parameters.ToArray()); } else { ret = CodeGen.CreateArray(GetTypeReference(), 0); } return(ret); }
public static async Task DeleteFromDevice(BaseEntry item) { if (item == null) { return; } try { var song = item as Song; string filename = song.Name.CleanForFileName("Invalid Song Name"); if (song.ArtistName != song.Album.PrimaryArtist.Name) { filename = song.ArtistName.CleanForFileName("Invalid Artist Name") + "-" + filename; } string path = string.Format( AppConstant.SongPath, song.Album.PrimaryArtist.Name.CleanForFileName("Invalid Artist Name"), song.Album.Name.CleanForFileName("Invalid Album Name"), filename); await WinRtStorageHelper.DeleteFileAsync(path, KnownFolders.MusicLibrary); } catch (Exception) { } }
private void SetReturnType(BaseEntry entry) { ReturnType type = entry.ReturnType; switch (type) { case ReturnType.Go: Control.ReturnKeyType = UIReturnKeyType.Go; break; case ReturnType.Next: Control.ReturnKeyType = UIReturnKeyType.Next; break; case ReturnType.Send: Control.ReturnKeyType = UIReturnKeyType.Send; break; case ReturnType.Search: Control.ReturnKeyType = UIReturnKeyType.Search; break; case ReturnType.Done: Control.ReturnKeyType = UIReturnKeyType.Done; break; default: Control.ReturnKeyType = UIReturnKeyType.Default; break; } }
public override DateTime Handle(FileGetTimeArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); var resolver = new EntryResolver(Container); BaseEntry entry = resolver.SafeResolveEntry(arguments.Path); if (entry == null) { return(arguments.IsInUtc ? PathFacts.ZeroFileTimeUtc : PathFacts.ZeroFileTime); } switch (arguments.Kind) { case FileTimeKind.CreationTime: { return(arguments.IsInUtc ? entry.CreationTimeUtc : entry.CreationTime); } case FileTimeKind.LastWriteTime: { return(arguments.IsInUtc ? entry.LastWriteTimeUtc : entry.LastWriteTime); } case FileTimeKind.LastAccessTime: { return(arguments.IsInUtc ? entry.LastAccessTimeUtc : entry.LastAccessTime); } default: { throw ErrorFactory.Internal.EnumValueUnsupported(arguments.Kind); } } }
public override object Handle(EntryMoveArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); AssertMovingToDifferentDirectoryOnSameVolume(arguments); AssertSourceIsNotVolumeRoot(arguments.SourcePath); BaseEntry sourceFileOrDirectory = ResolveSourceFileOrDirectory(arguments.SourcePath); if (sourceFileOrDirectory is DirectoryEntry sourceDirectory) { AssertNoConflictWithCurrentDirectory(sourceDirectory); AssertDirectoryContainsNoOpenFiles(sourceDirectory, arguments.SourcePath); DirectoryEntry destinationDirectory = ResolveDestinationDirectory(arguments.DestinationPath); AssertDestinationIsNotDescendantOfSource(destinationDirectory, sourceDirectory); string newDirectoryName = arguments.DestinationPath.Components.Last(); MoveDirectory(sourceDirectory, destinationDirectory, newDirectoryName); } else if (sourceFileOrDirectory is FileEntry sourceFile) { AssertHasExclusiveAccess(sourceFile); DirectoryEntry destinationDirectory = ResolveDestinationDirectory(arguments.DestinationPath); string newFileName = arguments.DestinationPath.Components.Last(); MoveFile(sourceFile, destinationDirectory, newFileName); } return(Missing.Value); }
private async void EntryPlayClickExecute(BaseEntry item) { List <Song> queueSongs = null; if (item is Artist) { var artist = item as Artist; queueSongs = artist.Songs.ToList(); } else if (item is Album) { var album = item as Album; queueSongs = album.Songs.ToList(); } else if (item is Playlist) { var playlist = item as Playlist; queueSongs = playlist.Songs.Select(p => p.Song).ToList(); } if (queueSongs != null) { await CollectionHelper.PlaySongsAsync(queueSongs, forceClear : true); } }
private void SetReturnType(BaseEntry entry) { ReturnType type = entry.ReturnType; switch (type) { case ReturnType.Go: Control.ImeOptions = ImeAction.Go; Control.SetImeActionLabel("Ir", ImeAction.Go); break; case ReturnType.Next: Control.ImeOptions = ImeAction.Next; Control.SetImeActionLabel("Próximo", ImeAction.Next); break; case ReturnType.Send: Control.ImeOptions = ImeAction.Send; Control.SetImeActionLabel("Enviar", ImeAction.Send); break; case ReturnType.Search: Control.ImeOptions = ImeAction.Search; Control.SetImeActionLabel("Procurar", ImeAction.Search); break; default: Control.ImeOptions = ImeAction.Done; Control.SetImeActionLabel("Feito", ImeAction.Done); break; } }
private static void AssertHasExclusiveAccessToFile([NotNull] BaseEntry entry, [NotNull] AbsolutePath absolutePath) { if (entry is FileEntry file && file.IsOpen()) { throw ErrorFactory.System.FileIsInUse(absolutePath.GetText()); } }
private int CompareData(BaseEntry <T> state1, BaseEntry <T> state2) { if (state1.IsText && state2.IsText) { return(string.Compare((string)(object)state1.EntryData !, (string)(object)state2.EntryData !, StringComparison.InvariantCulture)); } if (state1.IsBinary && state2.IsBinary) { var data1 = (byte[])(object)state1.EntryData !; var data2 = (byte[])(object)state2.EntryData !; if (data1.Length == data2.Length) { for (int idx = 0; idx < data1.Length; ++idx) { if (data1[idx] != data2[idx]) { return(1); } } return(0); } return(1); } return(1); }
private void saveButton_Click(object sender, EventArgs e) { if (_mirType == 0) { _entry = new CrystalCredentials { FilePath = clientDirBox.Text, IsDebug = debugBox.Checked, ServerName = serverNameBox.Text, UserName = userNameBox.Text, Password = passwordBox.Text }; EntryAdded?.Invoke(this, _entry); } else if (_mirType == 1) { _entry = new ZirconCredentials { FilePath = clientDirBox.Text, IsDebug = debugBox.Checked, ServerName = serverNameBox.Text, UserName = userNameBox.Text, Password = passwordBox.Text }; EntryAdded?.Invoke(this, _entry); } }
private void AssertIsNotDirectory([NotNull] BaseEntry entry, [NotNull] AbsolutePath path) { if (entry is DirectoryEntry) { throw ErrorFactory.System.DirectoryNotFound(path.GetText()); } }
public override int GetHashCode() { var hashCode = -1264449780; hashCode = hashCode * -1521134295 + BaseEntry.GetHashCode(); hashCode = hashCode * -1521134295 + BaseType.GetHashCode(); return(hashCode); }
public PlaylistPicker(BaseEntry song) { InitializeComponent(); var playlists = App.Locator.CollectionService.Playlists.Where(p => p.Songs.Count(pp => pp.SongId == song.Id) == 0); PlaylistPickerListView.ItemsSource = playlists; }
public System.CodeDom.CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression ret = OnlyCalculated ? reader : _memberEntry.GetReaderExpression(reader); ret = CodeGen.GetCalc(ReadExpression, BaseEntry.GetTypeReference(), ret); return(ret); }
public override FileAttributes Handle(FileGetAttributesArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); var resolver = new EntryResolver(Root); BaseEntry entry = resolver.ResolveEntry(arguments.Path); return(entry.Attributes); }
/// <inheritdoc /> public override void SaveChanges(Boolean forceDelete) { BaseEntry.Properties["cACertificate"].Clear(); foreach (DsCertificateEntry cert in DsList["NTAuth"]) { BaseEntry.Properties["cACertificate"].Add(cert.Certificate.RawData); } BaseEntry.CommitChanges(); CleanupSave(); }
public BaseEntry Merge(BaseEntry main, BaseEntry addition) { var e = main.Clone() as BaseEntry; if (string.IsNullOrWhiteSpace(main.Translation)) { e.Translation = addition.Translation; } return(e); }
public override object Handle(EntrySetTimeArguments arguments) { Guard.NotNull(arguments, nameof(arguments)); AssertTimeValueIsInRange(arguments); AssertIsNotVolumeRoot(arguments.Path); var resolver = new EntryResolver(Root); BaseEntry entry = resolver.ResolveEntry(arguments.Path); AssertIsNotDirectory(entry, arguments.Path); AssertFileIsNotReadOnly(entry, arguments.Path); AssertHasExclusiveAccessToFile(entry, arguments.Path); switch (arguments.Kind) { case FileTimeKind.CreationTime: if (arguments.IsInUtc) { entry.CreationTimeUtc = arguments.TimeValue; } else { entry.CreationTime = arguments.TimeValue; } break; case FileTimeKind.LastWriteTime: if (arguments.IsInUtc) { entry.LastWriteTimeUtc = arguments.TimeValue; } else { entry.LastWriteTime = arguments.TimeValue; } break; case FileTimeKind.LastAccessTime: if (arguments.IsInUtc) { entry.LastAccessTimeUtc = arguments.TimeValue; } else { entry.LastAccessTime = arguments.TimeValue; } break; default: throw ErrorFactory.Internal.EnumValueUnsupported(arguments.Kind); } return(Missing.Value); }
public void FormatMethodExitForSingleLineOutput_NestedMethodCalls_CallsAreInCorrectOrder() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new BaseEntry[] { new MethodEntry(1, "FirstMethod", null, startDateTime), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null) }; var expectedText = (new string[] { string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime), string.Format("SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format("ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)) } ).ToList(); List<String> output = new List<string>(); var filters = this.GetDefaultFilters(); var lineNo = 0; // Act foreach (var entry in entries) { if (entry is MethodEntry) formatter.FormatMethodEntry(22, (entry as MethodEntry).StackLevel, ++lineNo, (MethodEntry)entry, filters, true); else if (entry is MethodExit) { var result = formatter.FormatMethodExitForSingleLineOutput(22, (entry as MethodExit).StackLevel, lineNo, (MethodExit)entry, filters, true); if (result != null) output.AddRange(result.Select(oo => oo.FormattedLine).ToArray()); lineNo--; } } // Assert Assert.That(output.Count, Is.EqualTo(3), "Expected only three lines to be returned"); for (int index = 0; index < 3; index++) { Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}", index + 1); } }
public void DelimitedValuesFormatter_NestedMethodCalls_ReportHasCorrectFormatting() { // Arrange var tempFilePath = Path.ChangeExtension(Path.GetTempFileName(), ".txt"); var startDateTime = DateTime.Now; var entries = new BaseEntry[] { new ThreadData(22, null, null), new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80)), new MethodExit(3, "FourthMethod", 57, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var expectedText = (new string[] { string.Format("Yalf,Method,TopLevelMethod,blackSheep,{0:HH:mm:ss.fff},233,0,22", startDateTime), string.Format("Yalf,Method,FirstMethod,,{0:HH:mm:ss.fff},200,0,22", startDateTime.AddSeconds(12)), string.Format("Yalf,Method,SecondMethod,,{0:HH:mm:ss.fff},178,1,22", startDateTime.AddSeconds(45)), string.Format("Yalf,Log,Information log message here,,{0:HH:mm:ss.fff},0,2,22", startDateTime.AddSeconds(47)), string.Format("Yalf,Exception,Test the log Parameter name: lineNo,,{0:HH:mm:ss.fff},0,2,22", startDateTime.AddSeconds(53)), string.Format("Yalf,Method,ThirdMethod,,{0:HH:mm:ss.fff},100,2,22", startDateTime.AddSeconds(75)), string.Format("Yalf,Method,FourthMethod,,{0:HH:mm:ss.fff},57,2,22", startDateTime.AddSeconds(80)), string.Format("Yalf,Method,TopLevelMethod2,whiteSheep,{0:HH:mm:ss.fff},488,0,22", startDateTime.AddSeconds(99)) } ).ToList(); var formatter = new DelimitedValuesFormatter(); var filters = this.GetDefaultFilters(); var indentLevel = 0; // Act var outputter = new CsvFileOutputHandler(filters, formatter, tempFilePath); outputter.Initialise(); foreach (var entry in entries) { if (entry is ThreadData) { outputter.HandleThread((ThreadData)entry); } else if (entry is MethodEntry) { outputter.HandleMethodEntry((entry as MethodEntry), indentLevel, true); ++indentLevel; } else if (entry is MethodExit) { --indentLevel; outputter.HandleMethodExit((entry as MethodExit), indentLevel, true); } else if (entry is LogEvent) { outputter.HandleLogEvent((entry as LogEvent), indentLevel, true); } else if (entry is ExceptionTrace) { outputter.HandleException((entry as ExceptionTrace), indentLevel); } } outputter.Complete(); var reportText = File.ReadAllText(tempFilePath); // Assert Console.WriteLine("Output data to '{0}'", tempFilePath); Console.WriteLine(reportText); List<String> output = reportText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}", expectedText.Count, output.Count); Assert.That(reportText, Is.Not.Empty, "Expected report text to be returned."); for (int index = 0; index < expectedText.Count; index++) { Console.WriteLine("Checking actual\r\n\"{0}\" with expected\r\n\"{1}\"", output[index], expectedText[index]); Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}", index + 1); } }
public void SingleLineFormatter_NestedMethodCalls_ReportHasCorrectIndenting() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new BaseEntry[] { new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80)), new MethodExit(3, "FourthMethod", 57, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format(" SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format(" [Log] [Info] Information log message here"), string.Format(" [Exception] {0:HH:mm:ss.fff} Test the log", startDateTime.AddSeconds(53)), string.Format("Parameter name: lineNo"), string.Format(" ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format(" FourthMethod() started {0:HH:mm:ss.fff} duration 57ms", startDateTime.AddSeconds(80)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var filters = this.GetDefaultFilters(); var indentLevel = 0; // Act var outputter = new DefaultOutputHandler(filters, formatter); outputter.Initialise(); foreach (var entry in entries) { if (entry is MethodEntry) { outputter.HandleMethodEntry((entry as MethodEntry), indentLevel, true); ++indentLevel; } else if (entry is MethodExit) { --indentLevel; outputter.HandleMethodExit((entry as MethodExit), indentLevel, true); } else if (entry is LogEvent) { outputter.HandleLogEvent((entry as LogEvent), indentLevel, true); } else if (entry is ExceptionTrace) { outputter.HandleException((entry as ExceptionTrace), indentLevel); } } outputter.Complete(); var reportText = outputter.GetReport(); // Assert Console.WriteLine(reportText); List<String> output = reportText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}", expectedText.Count, output.Count); Assert.That(reportText, Is.Not.Empty, "Expected report text to be returned."); for (int index = 0; index < expectedText.Count; index++) { Console.WriteLine("Checking actual\r\n\"{0}\" with expected\r\n\"{1}\"", output[index], expectedText[index]); Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}", index + 1); } }
public void FormatMethodExit_MixedNestting_ExpectedTextIsReturned() { // Arrange var filters = LogFiltersBuilder.Create().Build(); var formatter = new DelimitedValuesFormatter(); var startDateTime = DateTime.Now; int threadId = 22; int lineNo = 0; int indentLevel = 0; var expectedText = (new string[] { string.Format("Yalf,Method,TopLevelMethod,blackSheep,{0:HH:mm:ss.fff},233,1,22", startDateTime), string.Format("Yalf,Method,FirstMethod,,{0:HH:mm:ss.fff},200,1,22", startDateTime.AddSeconds(12)), string.Format("Yalf,Method,SecondMethod,,{0:HH:mm:ss.fff},178,2,22", startDateTime.AddSeconds(45)), string.Format("Yalf,Log,Information log message here,,{0:HH:mm:ss.fff},0,2,22", startDateTime.AddSeconds(47)), string.Format("Yalf,Exception,Test the log Parameter name: lineNo,,{0:HH:mm:ss.fff},0,2,22", startDateTime.AddSeconds(53)), string.Format("Yalf,Method,ThirdMethod,,{0:HH:mm:ss.fff},100,3,22", startDateTime.AddSeconds(75)), string.Format("Yalf,Method,TopLevelMethod2,whiteSheep,{0:HH:mm:ss.fff},488,1,22", startDateTime.AddSeconds(99)) } ).ToList(); var entries = new BaseEntry[] { new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var actualText = new List<String>(); // Act foreach (var entry in entries) { if (entry is MethodEntry) formatter.FormatMethodEntry(threadId, indentLevel++, ++lineNo, (entry as MethodEntry), filters, true); else if (entry is MethodExit) { var result = formatter.FormatMethodExitForSingleLineOutput(threadId, indentLevel--, lineNo++, (entry as MethodExit), filters, true); if (result != null) actualText.AddRange(result.Select(oo => oo.FormattedLine).ToList()); } else if (entry is LogEvent) { var result = formatter.FormatLogEvent(threadId, indentLevel, lineNo++, (entry as LogEvent), filters, true); if (result != null) actualText.Add(result); } else if (entry is ExceptionTrace) { var result = formatter.FormatException(threadId, indentLevel, lineNo++, (entry as ExceptionTrace), filters); if (result != null) actualText.Add(result); } } // Assert Console.WriteLine(String.Join(Environment.NewLine, actualText.ToArray())); Assert.That(actualText.Count, Is.EqualTo(expectedText.Count), "Expected {0} lines to be returned overall, but have {1}.", expectedText.Count, actualText.Count); for (int logLine = 0; logLine < actualText.Count - 1; logLine++) { Assert.That(actualText[logLine], Is.EqualTo(expectedText[logLine]), "Text does not match on line {0}", logLine); } //var misMatchedResults = actualText.Where((at, i) => (at != expectedText[i])); //Assert.That(misMatchedResults.Count(), Is.EqualTo(0), "{0} of the lines do not match.\nExpected:\n{1}\n\nActual:\n{2}" // , misMatchedResults.Count() // , String.Join(Environment.NewLine, expectedText.ToArray()) // , String.Join(Environment.NewLine, actualText.ToArray()) // ); }
public void SingleLineFormatter_NestedMethodCalls_ReportHasCorrectIndenting() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new BaseEntry[] { new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80)), new MethodExit(3, "FourthMethod", 57, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format(" SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format(" [Log] [Info] Information log message here"), string.Format(" [Exception] {0:HH:mm:ss.fff} Test the log\r\nParameter name: lineNo", startDateTime.AddSeconds(53)), string.Format(" ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format(" FourthMethod() started {0:HH:mm:ss.fff} duration 57ms", startDateTime.AddSeconds(80)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var filters = this.GetDefaultFilters(); var indentLevel = 0; int threadId = 22; var threadData = new ThreadData(threadId, "cotton", null); var outputter = new ThreadCollectionOutputHandler(filters, formatter); outputter.Initialise(); outputter.HandleThread(threadData); // Act foreach (var entry in entries) { if (entry is MethodEntry) { outputter.HandleMethodEntry((entry as MethodEntry), indentLevel, true); ++indentLevel; } else if (entry is MethodExit) { --indentLevel; outputter.HandleMethodExit((entry as MethodExit), indentLevel, true); } else if (entry is LogEvent) { outputter.HandleLogEvent((entry as LogEvent), indentLevel, true); } else if (entry is ExceptionTrace) { outputter.HandleException((entry as ExceptionTrace), indentLevel); } } outputter.Complete(); // Assert var reportText = outputter.GetThreadEntries(); Assert.That(reportText.Count, Is.EqualTo(1), "Expected one thread collection"); var output = reportText[threadId]; Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}\n{2}", expectedText.Count, output.Count, this.CreateComparisonReport(output, expectedText)); for (int index = 0; index < expectedText.Count; index++) { Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}\n\n{1}", index + 1, this.CreateComparisonReport(output, expectedText)); } }
public void FormatMethodExit_MixedNestting_ExpectedTextIsReturned() { // Arrange var filters = LogFiltersBuilder.Create().Build(); var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; int threadId = 22; int lineNo = 0; int indentLevel = 0; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format("SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format("[Log] [Info] Information log message here"), string.Format("[Exception] {0:HH:mm:ss.fff} Test the log\r\nParameter name: lineNo", startDateTime.AddSeconds(53)), string.Format("ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var entries = new BaseEntry[] { new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var actualText = new List<String>(); // Act foreach (var entry in entries) { if (entry is MethodEntry) formatter.FormatMethodEntry(threadId, indentLevel++, ++lineNo, (entry as MethodEntry), filters, true); else if (entry is MethodExit) { var result = formatter.FormatMethodExitForSingleLineOutput(threadId, indentLevel--, lineNo++, (entry as MethodExit), filters, true); if (result != null) actualText.AddRange(result.Select(oo => oo.FormattedLine).ToList()); } else if (entry is LogEvent) { var result = formatter.FormatLogEvent(threadId, indentLevel, lineNo++, (entry as LogEvent), filters, true); if (result != null) actualText.Add(result); } else if (entry is ExceptionTrace) { var result = formatter.FormatException(threadId, indentLevel, lineNo++, (entry as ExceptionTrace), filters); if (result != null) actualText.Add(result); } } // Assert Assert.That(actualText.Count, Is.EqualTo(expectedText.Count), "Expected {0} lines to be returned overall, but have {1}.", expectedText.Count, actualText.Count); var misMatchedResults = actualText.Where((at, i) => (at != expectedText[i])); Assert.That(misMatchedResults.Count(), Is.EqualTo(0), "{0} of the lines do not match.\nExpected:\n{1}\n\nActual:\n{2}" , misMatchedResults.Count() , String.Join(Environment.NewLine, expectedText.ToArray()) , String.Join(Environment.NewLine, actualText.ToArray()) ); }
public ThreadData(int threadId, string threadName, BaseEntry[] entries) { ThreadId = threadId; ThreadName = threadName; Entries = entries; }