Ejemplo n.º 1
0
 /// <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);
         }
     }
 }
Ejemplo n.º 2
0
        public void OutputCSVFileTest()
        {
            List <IShellItem>           shellItems          = new List <IShellItem>();
            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);

            shellItems.Add(ShellItem);

            if (File.Exists("raw.csv"))
            {
                File.Delete("raw.csv");
            }
            CsvIO.OutputCSVFile(shellItems, "raw.csv");
            Assert.IsTrue(File.Exists("raw.csv"));
        }
Ejemplo n.º 3
0
        public void ExportAndImportCSVWithSpecialCharactersTest()
        {
            // Export
            List <IShellItem>           shellItems          = new List <IShellItem>();
            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, \n \"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);

            shellItems.Add(ShellItem);

            if (File.Exists("raw.csv"))
            {
                File.Delete("raw.csv");
            }
            CsvIO.OutputCSVFile(shellItems, "raw.csv");
            Assert.IsTrue(File.Exists("raw.csv"));

            // Import
            List <IShellItem>            importedShellItems = CsvIO.ImportCSVFile("raw.csv");
            IDictionary <string, string> allProperties      = importedShellItems[0].GetAllProperties();

            Assert.IsTrue(allProperties["Size"].Equals("0"));
            Assert.IsTrue(allProperties["Type"].Equals("31"));
            Assert.IsTrue(allProperties["TypeName"].Equals("Some Type Name"));
            Assert.IsTrue(allProperties["Name"].Equals("Some Name, \n \"Name\""));
            Assert.IsTrue(allProperties["ModifiedDate"].Equals("1/1/0001 12:00:00 AM"));
            Assert.IsTrue(allProperties["AccessedDate"].Equals("1/1/0001 12:00:00 AM"));
            Assert.IsTrue(allProperties["CreationDate"].Equals("1/1/0001 12:00:00 AM"));
        }