public bool ExportCSV(string path, List <NoteModel> noteMaster) { if (!Path.IsPathFullyQualified(path)) { return(false); } if (!Path.HasExtension(path)) { return(false); } string extension = Path.GetExtension(path); if (extension != ".csv") { return(false); } if (!CheckPathExists.PathExists(path)) { FileFolderGenerator.EvaluatePath(path); } using StreamWriter sw = new StreamWriter(path, false, new UTF8Encoding(true)); using (var csv = new CsvWriter(sw, CultureInfo.InvariantCulture)) { csv.Configuration.RegisterClassMap <NoteMapper>(); csv.WriteRecords(noteMaster); } return(true); }
public void Check(int number1, int number2, bool expected) { var nodes = CreateNodes(); var node1 = nodes[number1 - 1]; var node2 = nodes[number2 - 1]; var solution = new CheckPathExists(); var actual = solution.Check(node1, node2); Assert.Equal(expected, actual); }
public CsvParserServiceService() { if (!CheckPathExists.PathExists(Constants.Paths.path)) { using StreamWriter sw = new StreamWriter(Constants.Paths.path, false, new UTF8Encoding(true)); using (var csv = new CsvWriter(sw, CultureInfo.InvariantCulture)) { csv.WriteHeader <NoteModel>(); } } }
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } try { if (!string.IsNullOrEmpty(initialDirectory) && !initialDirectory.Contains("\\")) { Enum.TryParse(initialDirectory, out Environment.SpecialFolder specialfolder); initialDirectory = Environment.GetFolderPath(specialfolder); } } catch (Exception) { throw; } if (!string.IsNullOrEmpty(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }