/// <summary> /// Save the logger /// </summary> /// <returns></returns> public bool Save() { IoC.Logger.Log($"Saving ini file to {Filename}..."); try { ResultClassInstance.ToIniFile(); } catch (Exception ex) { HandleExceptions(this, ex); return(false); } IoC.Logger.Log($"Ini file saved."); return(true); }
/// <summary> /// Save the logger /// </summary> /// <returns></returns> public bool Save() { IoC.Logger.Log($"Saving Text file to {Filename}..."); try { // First convert to a data table, and then save it as text file foreach (DataTable t in ResultClassInstance.ToDataset().Tables) { t.SaveToTextFile($"{Filename}-{t.TableName}{_fileExtension}", _displayColumnNames); } } catch (Exception ex) { HandleExceptions(this, ex); return(false); } IoC.Logger.Log($"File saved."); return(true); }
/// <summary> /// Save the result logger file /// </summary> /// <returns></returns> public bool Save() { IoC.Logger.Log($"Saving ods file to {Filename}..."); string newTemplate = ""; try { // The style dataset DataSet styleDataset = null; // Convert the class to a dataset DataSet data = ResultClassInstance.ToDataset(); #region Prepare for style Dictionary <string, CellStyle> styleDictionary; // Get all the defined styles var styles = (DefineStyleAttribute[])ResultClassInstance.GetType().GetCustomAttributes(typeof(DefineStyleAttribute), false); if (styles != null) { styleDictionary = new Dictionary <string, CellStyle>(); foreach (var style in styles) { styleDictionary.Add(style.StyleName, new CellStyle() { ForegroundColor = style.ForegroundColor != "" ? Color.FromName(style.ForegroundColor) : Color.Empty, BackgroundColor = style.BackgroundColor != "" ? Color.FromName(style.BackgroundColor) : Color.Empty }); IoC.Logger.Log($"New style added: {style.StyleName} = (Foreground {style.ForegroundColor}, Background {style.BackgroundColor})"); } // Remove the existing styled template if (File.Exists(styledTemplate)) { File.Delete(styledTemplate); } // Create a new one if (LibreOfficeHelper.CreateStyleTemplate(styleDictionary, TemplateFilename, styledTemplate)) { // If successfully created newTemplate = styledTemplate; // Log it IoC.Logger.Log($"Style tempate created."); // Create style dataset styleDataset = ResultClassInstance.ToDatasetStyle(new HashSet <string>(styleDictionary.Keys)); // Debug //LibreOfficeHelper.WriteToOdsFile(styleDataset, ".\\StyleDataset.ods", newTemplate); } ; } #endregion string template = newTemplate == "" ? TemplateFilename : newTemplate; // Save as ods file LibreOfficeHelper.WriteToOdsFile(data, Filename, template, styleDataset); // Remove the style template if (File.Exists(styledTemplate)) { File.Delete(styledTemplate); } } catch (Exception ex) { HandleExceptions(this, ex); return(false); } IoC.Logger.Log($"Ods file saved."); return(true); }