public void OutputHtmlFileTest() { List <Node> nodeList = new List <Node>(); Dictionary <string, string> shellItemProperties = new Dictionary <string, string>(); shellItemProperties.Add("Size", "0"); shellItemProperties.Add("Type", "31"); shellItemProperties.Add("TypeName", "Some Type Name"); shellItemProperties.Add("Name", "Some Name"); shellItemProperties.Add("ModifiedDate", "1/1/0001 12:00:00 AM"); shellItemProperties.Add("AccessedDate", "1/1/0001 12:00:00 AM"); shellItemProperties.Add("CreationDate", "1/1/0001 12:00:00 AM"); CsvParsedShellItem ShellItem = new CsvParsedShellItem(shellItemProperties); Event aEvent = new Event("item1", DateTime.Now, ShellItem, "Access"); InfoBlock block = new InfoBlock(); Node aNode = new Node(aEvent, block); nodeList.Add(aNode); if (File.Exists("timeline.html")) { File.Delete("timeline.html"); } HtmlIO.OutputHtmlFile(nodeList, "timeline.html"); Assert.IsTrue(File.Exists("timeline.html")); }
public async Task EncipherAsync(ICommandContext context, string content, bool parseKeys) { var msg = context.Message; RotorKeys rotorKeys = (parseKeys ? ReadRotorKeys(ref content) : this.rotorKeys); Machine machine = new Machine(new SetupArgs { LetterSet = letterSet, Steckering = steckering, RotorKeys = rotorKeys, }); if (content.Length > 1024) { content = $"{content.Substring(0, 1021)}..."; } else if (content.Length == 0) { throw new Exception("No content was specified!"); } string deciphered = content; string enciphered = machine.Encipher(content); /*if (msg.Attachments.Any()) { * string htmlUrl = msg.Attachments.First().Url; * using (HttpClient client = new HttpClient()) { * string html = await client.GetStringAsync(htmlUrl).ConfigureAwait(false); * } * }*/ EmbedBuilder embed = new EmbedBuilder { Color = configParser.EmbedColor, Title = EncipheredTitle, Timestamp = DateTime.UtcNow, Description = Format.Sanitize(enciphered), }; embed.WithAuthorName(context.User, context.Guild); embed.AddField(RotorKeysTitle, string.Join(" ", rotorKeys)); using (MemoryStream stream = new MemoryStream()) using (StreamWriter writer = new StreamWriter(stream)) { string html = HtmlIO.WriteText(enciphered, HtmlTemplateFile); await writer.WriteAsync(html).ConfigureAwait(false); await writer.FlushAsync().ConfigureAwait(false); stream.Position = 0; await context.Channel.SendFileAsync(stream, "Message.html").ConfigureAwait(false); var message = await context.Channel.SendMessageAsync(embed : embed.Build()).ConfigureAwait(false); await message.AddReactionAsync(EnigmaReactions.ViewMessage).ConfigureAwait(false); } }
/// <summary> /// This checks when the download button is hit, whether the HTML and/or the CSV checkbox is checked or not and calls the creation of HtmlOutput. /// </summary> private void DownloadClick(object sender, RoutedEventArgs e) { if (htmlCheckBox.IsChecked ?? false) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.DefaultExt = ".html"; saveFileDialog1.Filter = "Html File (*.html)| *.html"; saveFileDialog1.AddExtension = true; saveFileDialog1.ShowDialog(); string name = saveFileDialog1.FileName; if (name != string.Empty) { List <Node.Node> visibleNodes = App.nodeCollection.nodeList .Where(node => node.Visibility == Visibility.Visible).ToList(); HtmlIO.OutputHtmlFile(visibleNodes, name); } } if (csvCheckBox.IsChecked ?? false) { SaveFileDialog saveFileDialog2 = new SaveFileDialog(); saveFileDialog2.DefaultExt = ".csv"; saveFileDialog2.Filter = "CSV File (*.csv)| *.csv"; saveFileDialog2.AddExtension = true; saveFileDialog2.ShowDialog(); string name2 = saveFileDialog2.FileName; if (name2 != string.Empty) { var file = new FileInfo(name2); if (file.Exists) { try // Check if the file is locked { using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None)) { stream.Close(); } } catch (IOException ex) { System.Windows.MessageBox.Show("The file: \"" + name2 + "\" is being used by another process.\n" + "Select a different file name or close the process to save the CSV.", "Cannot save file", MessageBoxButton.OK, MessageBoxImage.Exclamation); logger.Info(ex, "The file: \"" + name2 + "\" is being used by another process.\n" + ex.ToString()); return; } } CsvIO.OutputCSVFile(App.ShellItems, name2); } } }
public async Task DecipherAsync(ICommandContext context, string content, bool parseKeys) { var msg = context.Message; RotorKeys rotorKeys = (parseKeys ? ReadRotorKeys(ref content) : this.rotorKeys); Machine machine = new Machine(new SetupArgs { LetterSet = letterSet, Steckering = steckering, RotorKeys = rotorKeys, }); if (content.Length > 1024) { content = $"{content.Substring(0, 1021)}..."; } string enciphered = content; if (msg.Attachments.Any()) { string htmlUrl = msg.Attachments.First().Url; using (HttpClient client = new HttpClient()) { string html = await client.GetStringAsync(htmlUrl).ConfigureAwait(false); enciphered = HtmlIO.ReadText(html); } } else if (content.Length == 0) { throw new Exception("No content was specified!"); } string deciphered = machine.Decipher(enciphered); EmbedBuilder embed = new EmbedBuilder { Color = configParser.EmbedColor, Title = DecipheredTitle, Timestamp = DateTime.UtcNow, Description = Format.Sanitize(deciphered), }; embed.WithAuthorName(context.User, context.Guild); embed.AddField(RotorKeysTitle, string.Join(" ", rotorKeys)); await context.Channel.SendMessageAsync(embed : embed.Build()).ConfigureAwait(false); }
/// <summary> /// Runs the Enigma Machine decipherer. /// </summary> /// <returns>The decipherer string.</returns> public void RunDecipherer(EnterMode mode) { try { if (!machineConfig.IsSetup) { PrintError("The Enigma Machine has not been fully configured!"); return; } string line = string.Empty; switch (mode) { case EnterMode.Input: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enciphered: "); line = Console.ReadLine(); break; case EnterMode.Paste: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enciphered: "); line = TextCopy.Clipboard.GetText(); if (string.IsNullOrEmpty(line)) { PrintError("Clipboard has no text!"); return; } Console.WriteLine(line); break; case EnterMode.File: Console.ForegroundColor = ConsoleColor.DarkYellow; //Console.WriteLine($"Default: \"{DefaultHtmlFile}\""); Console.Write("Enter the input Enciphered HTML file path: "); PrintWatermark(DefaultHtmlFile); string path = PrepareHtmlPath(Console.ReadLine()); try { line = HtmlIO.Read(path); } catch (Exception ex) { PrintError(ex.Message); return; } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enciphered: "); Console.WriteLine(line); break; } line = line.Replace("\t", " "); if (string.IsNullOrEmpty(line)) { Console.WriteLine(); return; } string deciphered = encipherer.Decipher(machineConfig.Machine, line); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Deciphered: "); Console.WriteLine(deciphered); Console.ResetColor(); Console.WriteLine(); TextCopy.Clipboard.SetText(deciphered); Console.Write("Copied Deciphered Text! "); } finally { Console.ResetColor(); } }