private void btn_Save_Click(object sender, EventArgs e) { string path = GetXmlPath(); if (File.Exists(path)) { File.Move(path, string.Format("{0}_{1}.bak", path, DateTime.Now.ToString().Replace(":", "_").Replace("-", "_").Replace("/", "_"))); } NDirectory.Serialize(path); string mapPath = GetMapPath(); if (File.Exists(mapPath)) { File.Move(mapPath, string.Format("{0}_{1}.bak", mapPath, DateTime.Now.ToString().Replace(":", "_").Replace("-", "_").Replace("/", "_"))); } mapperInfos.Clear(); foreach (ListViewItem item in lv_groups.Items) { MappInfo info = item.Tag as MappInfo; if (info.Key != info.Value) { mapperInfos.Add(info); } } MappInfo.Serialize(mapPath, mapperInfos); MessageBox.Show("操作完成"); }
public void Constructor_Path_DirectoryExist() { using (var t = new NDirectory(folderName)) { Assert.That(Directory.Exists(t.FullPath), Is.True); } }
private async Task AddDirectory(Vault vault, IProgress <ProgressReport> progress) { var allFiles = NDirectory.GetAllFilesRecursive(ToAddPath); var report = new ProgressReport(allFiles.Count); await allFiles.ParallelForEachAsync(async file => { var pathToFile = NPath.GetRelativePathToFile(ToAddPath, file); try { await vault.AddFileAsync(file, pathToFile); } catch (Exception e) { report.IncrementFailedFiles(); Log.Error(string.Format(Strings.AddCommandAsync_AddDirectory_Error_with_file__0____1_, file, e)); } finally { report.IncrementModifiedFiles(); progress.Report(report); } }, 0); Console.WriteLine(); Notifier.Success(string.Format(Strings.AddCommandAsync_AddDirectory_Added_directory__0__to_vault, ToAddPath)); }
private void MergeAndSaveToFolder(string targetPath) { if (NDirectory.Exists(targetPath) == false) { NMessageBox.Show("The entered target path does not exist", "Error", ENMessageBoxButtons.OK, ENMessageBoxIcon.Error); return; } // Clone the rich text view NRichTextView clonedRichTextView = (NRichTextView)m_RichText.DeepClone(); // Switch the mail merge of the cloned rich text view to preview mode NMailMerge mailMerge = clonedRichTextView.Content.MailMerge; mailMerge.PreviewMailMerge = true; // Loop through all mail merge records to save individual documents to file for (int i = 0; i < mailMerge.DataRecordCount; i++) { // Move to the next data source record mailMerge.CurrentDataRecordIndex = i; // Save the merged document to file string fileName = "Document" + i.ToString(CultureInfo.InvariantCulture) + ".docx"; clonedRichTextView.SaveToFile(NPath.Combine(targetPath, fileName)); } NMessageBox.Show("Merged documents saved to \"" + targetPath + "\".", "Mail Merge Complete", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); }
public override async Task Run() { await Task.Run(() => { Log.Debug("Running NewProject with " + $"Name = {Name ?? "null"}, Path = {Path ?? "null"}"); var vaultName = Name ?? GetCurrentDirectoryName(); var vaultPath = GetVaultCtorPath(Path); var folderPath = GetFolderPath(vaultName, Path); Log.Debug($"vaultPath: {folderPath}"); if (!NDirectory.IsDirectoryEmpty(folderPath)) { throw new DirectoryNotEmptyException(Strings.NewCommandAsync_Run_The_directory_vault_is_not_empty); } var key = PasswordPrompt.PromptPasswordWithConfirmationAsHash(); using var vault = Vault.Create(vaultName, key, vaultPath); Notifier.Success(string.Format(Strings.NewCommandAsync_Run_Created_vault__0__as__1__, vaultName, folderPath)); }); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> /// <param name="transferName">Name of the transfer.</param> /// <param name="countFolder">The count folder.</param> /// <param name="imageCount">The image count.</param> /// <param name="imageSuffix">The image suffix.</param> public SimpleTransfer(string transferName, int countFolder, int imageCount = 3, string imageSuffix = null) { _imageCount = imageCount; _imageSuffix = imageSuffix; _rootFolder = DirectoryFactory.New(transferName); AddFolderWithImage(countFolder); }
public void GetPathToFileGivesCorrectPath() { const string testPath = "other/more/stuff/test/mock/file.txt"; const string expected = "other/more/stuff/test/mock/"; var result = NDirectory.GetPathParentDir(testPath); Assert.AreEqual(expected, result); }
public void ConstructorTestParallel_Path_DirectoryExist() { Parallel.For(0, 10, (i) => { using (var t = new NDirectory(folderName)) { Assert.That(Directory.Exists(t.FullPath), Is.True); } }); }
public void CreateFakeFile_Path_EnsureExist() { const string fileName = @"1.jpg"; var directory = new NDirectory(); using (var file = new EmptyFile(directory, fileName)) { file.Create(); Assert.True(File.Exists(file.FullPath)); } }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> /// <param name="directory">The directory.</param> /// <param name="fileName">Name of the file.</param> /// <param name="content">The content.</param> public ContentFile(NDirectory directory, string fileName, byte[] content) : base(directory, fileName) { Contract.Requires<ArgumentNullException>(content != null); _content = content; }
public void EmptyFiles_Dispose_DoesnotThrow() { var d = new NDirectory(folderName); Assert.DoesNotThrow(d.Dispose); }
internal EmptyFile(NDirectory directory, string fileName) : base(directory, fileName) { }
private void Disposing() { _rootFolder.Dispose(); _rootFolder = null; }
private void AddImageToFolder(NDirectory folder, int countImage, string imageSuffix) { var content = new byte[] {0}; for (int i = 0; i < countImage; i++) { folder.Add<NFile>(String.Format("{1}{0}.jpg", i, imageSuffix ?? String.Empty), content); } }