private void FileMenu_SaveCurrent_Click(object sender, RoutedEventArgs e) { if (GlobalState.CurrentExportFormatName == null) { GlobalState.CurrentExportFormatName = "TrackMaker.ExportXMLv2"; } Type EXType = Type.GetType(GlobalState.CurrentExportFormatName); IExportFormat IEXF = (IExportFormat)Activator.CreateInstance(EXType); IEXF.Export(CurrentProject); //refactoring probably needed string CurrentlyOpenFile = GlobalState.GetCurrentOpenFile(); if (CurrentlyOpenFile == null || CurrentlyOpenFile == "") { Error.Throw("Error!", "Failed to set currently open file!", ErrorSeverity.Error, 231); return; } Title = $"Track Maker 2.1 - [{GlobalState.GetCurrentOpenFile()}]"; }
private void Export_Init(FormatType FType, IExportFormat ExportFormat) { Logging.Log("ExportUI Initialising..."); Logging.Log($"Format type: {FType}, export format: {ExportFormat.GetName()}"); ExpFormat = ExportFormat; StormsToExport = MnWindow.CurrentProject.SelectedBasin.GetFlatListOfStorms(); // feature pushed back to Dano, maybe even 3.0/"Aurora" Type = FType; if (ExportFormat is IImageExportFormat) { IImageExportFormat ExpFI = (IImageExportFormat)ExportFormat; if (!ExpFI.DisplayQualityControl) { HideQualityControl(); } } else // not an IImageExportFormat { HideQualityControl(); } if (!GeneratePreview()) { Error.Throw("Error!", "Error generating preview", ErrorSeverity.FatalError, 283); } }
public ExportUI(FormatType FType, IExportFormat ExportFormat) { //if (!Export_PreInit(FType, ExportFormat)) return; // do not initialise if preinit failed MnWindow = (MainWindow)Application.Current.MainWindow; InitializeComponent(); Export_Init(FType, ExportFormat); }
private static async Task ExportFile(string FileName, IExportFormat Output) { using (FileStream fs = File.OpenRead(FileName)) { if (FileName.StartsWith(Gateway.RootFolder)) { FileName = FileName.Substring(Gateway.RootFolder.Length); } await Output.ExportFile(FileName, fs); } await Output.UpdateClient(false); }
public DataExporter(int index) { this.index = index; if (Enum.IsDefined(typeof(ExportType), index)) { switch ((ExportType)index) { case ExportType.Excel: ex = new ExportExcel(); break; case ExportType.HTML: ex = new ExportHTML(); break; case ExportType.OldHTML: ex = new ExportOldHTML(); break; case ExportType.CSV: ex = new ExportCSV(); break; case ExportType.TXT: ex = new ExportTXT(); break; case ExportType.JPG: ex = new ExportJPG(); break; default: break; } } }
/// <summary> /// Exports gateway data /// </summary> /// <param name="Output">Export Output</param> /// <param name="Database">If the contents of the database is to be exported.</param> /// <param name="WebContent">If web content is to be exported.</param> /// <param name="Folders">Root subfolders to export.</param> public static async Task DoExport(IExportFormat Output, bool Database, bool WebContent, string[] Folders) { try { List <KeyValuePair <string, object> > Tags = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("Database", Database) }; foreach (string Folder in Folders) { Tags.Add(new KeyValuePair <string, object>(Folder, true)); } Log.Informational("Starting export.", Output.FileName, Tags.ToArray()); await Output.Start(); if (Database) { StringBuilder Temp = new StringBuilder(); using (XmlWriter w = XmlWriter.Create(Temp, XML.WriterSettings(false, true))) { await Persistence.Database.Analyze(w, string.Empty, Path.Combine(Gateway.RootFolder, "Data"), false, true); } await Persistence.Database.Export(Output); } if (WebContent || Folders.Length > 0) { await Output.StartFiles(); try { string[] FileNames; string Folder2; if (WebContent) { FileNames = Directory.GetFiles(Gateway.RootFolder, "*.*", SearchOption.TopDirectoryOnly); foreach (string FileName in FileNames) { await ExportFile(FileName, Output); } Export.FolderCategory[] ExportFolders = Export.GetRegisteredFolders(); foreach (string Folder in Directory.GetDirectories(Gateway.RootFolder, "*.*", SearchOption.TopDirectoryOnly)) { bool IsWebContent = true; foreach (Export.FolderCategory FolderCategory in ExportFolders) { foreach (string Folder3 in FolderCategory.Folders) { if (string.Compare(Folder3, Folder, true) == 0) { IsWebContent = false; break; } } if (!IsWebContent) { break; } } if (IsWebContent) { FileNames = Directory.GetFiles(Folder, "*.*", SearchOption.AllDirectories); foreach (string FileName in FileNames) { await ExportFile(FileName, Output); } } } } foreach (string Folder in Folders) { if (Directory.Exists(Folder2 = Path.Combine(Gateway.RootFolder, Folder))) { FileNames = Directory.GetFiles(Folder2, "*.*", SearchOption.AllDirectories); foreach (string FileName in FileNames) { await ExportFile(FileName, Output); } } } } finally { await Output.EndFiles(); } } Log.Informational("Export successfully completed.", Output.FileName); } catch (Exception ex) { Log.Critical(ex); string[] Tabs = ClientEvents.GetTabIDsForLocation("/Backup.md"); ClientEvents.PushEvent(Tabs, "BackupFailed", "{\"fileName\":\"" + CommonTypes.JsonStringEncode(Output.FileName) + "\", \"message\": \"" + CommonTypes.JsonStringEncode(ex.Message) + "\"}", true, "User"); } finally { try { await Output.End(); Output.Dispose(); } catch (Exception ex) { Log.Critical(ex); } lock (synchObject) { exporting = false; } } }