static void Import(string file, string folder) { ErpFile erp = new ErpFile(); erp.Read(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)); erp.ProgressStatus = new Progress <string>(status => { _stringBuilder.Append(status); }); Task.Run(() => erp.Import(Directory.GetFiles(folder, "*", SearchOption.AllDirectories))).Wait(); Task.Run(() => erp.Write(File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read))).Wait(); }
static void Import(string file, string folder) { ErpFile erp = new ErpFile(); using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) erp.Read(fs); var progressStatus = new Progress <string>(status => { _stringBuilder.Append(status); }); var resourceExporter = new ErpResourceExporter(); resourceExporter.Import(erp, Directory.GetFiles(folder, "*", SearchOption.AllDirectories), progressStatus, null); using (var fs = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read)) erp.Write(fs); }
private void SaveCommand_Execute(object parameter) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Erp files|*.erp|All files|*.*"; saveFileDialog.FilterIndex = 1; saveFileDialog.FileName = Path.GetFileNameWithoutExtension(filePath); saveFileDialog.InitialDirectory = Path.GetDirectoryName(filePath); if (saveFileDialog.ShowDialog() == true) { try { Task.Run(() => file.Write(File.Open(saveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.Read))).Wait(); filePath = saveFileDialog.FileName; DisplayName = Properties.Resources.AppTitleShort + " - " + Path.GetFileName(filePath); } catch (Exception ex) { MessageBox.Show("The program could not save this file! The error is displayed below:" + Environment.NewLine + Environment.NewLine + ex.Message, Properties.Resources.AppTitleLong, MessageBoxButton.OK, MessageBoxImage.Error); } } }