Beispiel #1
0
        public async void ExportFile(string name)
        {
            SaveFileDialog dlg     = new SaveFileDialog();
            string         newName = string.Empty;

            if (name.EndsWith("ViewModel", StringComparison.OrdinalIgnoreCase))
            {
                newName = name.Remove(name.Length - 9, 9);
            }
            if (string.IsNullOrEmpty(newName))
            {
                newName = name;
            }

            dlg.FileName   = $"{newName}Chart_{DateTime.Now.ToString("yyyy_dd_MM_HH_mm_ss")}";
            dlg.DefaultExt = ".csv";
            dlg.Filter     = "Csv documents (.csv)|*.csv";
            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                DataToCsv.SaveChartReportToCsv(DataCollection, dlg.FileName);
                await DialogHelper.Instance.ShowDialog(new CustomDialogEntryData()
                {
                    MetroWindow     = StaticServiceProvider.MetroWindowInstance,
                    DialogTitle     = this.GetLocalizedString("Information"),
                    DialogMessage   = this.GetLocalizedString("ExportMessage"),
                    OkButtonMessage = "Ok",
                    InformationType = InformationType.Information
                });
            }
        }
        public void CheckIfFilePathIsCorrect()
        {
            const string fileName = @"Output.csv";
            var          filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;

            Assert.True(filePath.Equals(DataToCsv.GetFilePath()));
        }
        public async void ExportFile()
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName   = "CommitsFile";
            dlg.DefaultExt = ".csv";
            dlg.Filter     = "Csv documents (.csv)|*.csv";
            // Show save file dialog box
            bool?result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string        filename = dlg.FileName;
                List <Commit> tempList = CommitsCollection.ToList();
                DataToCsv.CreateCSVFromGitCommitsList(tempList, filename);

                await DialogHelper.Instance.ShowDialog(new CustomDialogEntryData()
                {
                    MetroWindow     = StaticServiceProvider.MetroWindowInstance,
                    DialogTitle     = this.GetLocalizedString("Information"),
                    DialogMessage   = this.GetLocalizedString("ExportMessage"),
                    OkButtonMessage = "Ok",
                    InformationType = InformationType.Information
                });
            }
        }
Beispiel #4
0
        private static void SaveCountryRanges(string csvDatabasePath, IEnumerable<IPRangeCountry> ranges)
        {
            var csv = new DataToCsv<IPRangeCountry>(ranges, new List<HeaderBase<IPRangeCountry>>
            {
                new CustomHeader<IPRangeCountry>("StartIP", item => item.StartIP),
                new CustomHeader<IPRangeCountry>("EndIP", item => item.EndIP),
                new CustomHeader<IPRangeCountry>("ISO_Code_2", item => item.ISO_Code_2)
            }, offsetValue: ",", useOffsetBeforeNewLine: false).Csv;
            var fileStream = new FileStream(csvDatabasePath, FileMode.CreateNew);
            csv.WriteTo(fileStream);
            fileStream.Close();
            csv.Close();

            //Using CsvWriter causes a strange behaviour of adding a random integer ("3" or "37") at the end of the csv values, thus making the file not usable for loading of the cache.
            //Updating the CsvHelper didn't help either.
            //var csv = new CsvWriter(File.CreateText(csvDatabasePath));
            //csv.WriteRecords(ranges);
        }
        public void CheckFileSystem()
        {
            var ret = DataToCsv.WriteToCsv("Hello world");

            Assert.True(ret == 1);
        }