/// <summary> /// Returns path with filename specified. Optionally, sets <c>fileDescription</c> for directory readme generator /// </summary> /// <param name="filename">The filename.</param> /// <param name="mode">The mode.</param> /// <param name="fileDescription">The file description - if not specified, it will try to improvize :)</param> /// <param name="updateExisting">if set to <c>true</c> it will force update if any existing file description was found. <see cref="RegisterFile(string, string, bool)"/></param> /// <returns>The path</returns> public string pathFor(string filename, getWritableFileMode mode = getWritableFileMode.none, String fileDescription = "", Boolean updateExisting = false) { filename = filename.getCleanFilepath(""); //filename = filename.getCleanFileName(false); if (Path.IsPathRooted(filename)) { filename = Path.GetFileName(filename); } else if (filename.StartsWith(path)) { filename = imbSciStringExtensions.removeStartsWith(filename, path); } string output = imbSciStringExtensions.add(path, filename, Path.DirectorySeparatorChar); output = output.Replace("\\\\", Path.DirectorySeparatorChar.ToString()); output = output.Replace("\\\\", Path.DirectorySeparatorChar.ToString()); if (mode != getWritableFileMode.none) { output = output.getWritableFile(mode).FullName; } RegisterFile(filename, fileDescription, updateExisting); return(output); }
#pragma warning disable CS1574 // XML comment has cref attribute 'getWritableFileMode' that could not be resolved /// <summary> /// Saves the table on specified path. According to <see cref="aceCommonTypes.enums.getWritableFileMode"/> mode selected /// </summary> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> /// <returns></returns> public virtual bool SaveAs(string path, getWritableFileMode mode = getWritableFileMode.newOrExisting) #pragma warning restore CS1574 // XML comment has cref attribute 'getWritableFileMode' that could not be resolved { info = path.getWritableFile(mode); return(Save()); }
/// <summary> /// Saves the slits. /// </summary> /// <param name="pathPrefix">The path prefix.</param> /// <param name="mode">The mode.</param> public void saveSlits(String pathPrefix = "", getWritableFileMode mode = getWritableFileMode.overwrite) { foreach (fileTextSearchResult splitRes in this) { splitRes.saveLineContent(pathPrefix.add(splitRes.filePath, "\\"), mode); } }
/// <summary> /// Saves content of DataTable to CSV file on supplied path /// </summary> /// <param name="table"></param> /// <param name="path"></param> /// <param name="mode"></param> /// <param name="separator"></param> /// <param name="newlineSeparator"></param> /// <returns></returns> public static bool toCsvFileFromTable(this DataTable table, string path, getWritableFileMode mode = getWritableFileMode.overwrite, string separator = ",", string newlineSeparator = "\n") { if (newlineSeparator == "\n") { newlineSeparator = Environment.NewLine; } string output = ""; foreach (DataColumn dc in table.Columns) { output = output.add(dc.Caption, separator); } foreach (DataRow dr in table.Rows) { foreach (DataColumn dc in table.Columns) { string content = stringToCSVCell(dr[dc].toStringSafe("")); output = output.add(content, separator).add(newlineSeparator); } } FileInfo fi = path.getWritableFile(mode); try { var wr = fi.CreateText(); wr.Write(output); } catch (Exception ex) { throw new dataException("CSV file write failed at [" + path + "]", ex); } return(true); }
/// <summary> /// Saves the content of the line. /// </summary> /// <param name="filepath">The filepath.</param> /// <param name="mode">The mode.</param> /// <returns>reference to file just saved</returns> public FileInfo saveLineContent(String filepath, getWritableFileMode mode = getWritableFileMode.overwrite) { FileInfo fi = filepath.getWritableFile(mode); saveBase.saveToFile(fi.FullName, getLineContentList()); return(fi); }
public object addPage(string name, bool scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameThis, reportOutputFormatName format = reportOutputFormatName.none) { String c = "<!-- wp:nextpage --><!--nextpage--><!-- /wp:nextpage -->"; _AppendLine(c); return(c); }
/// <summary> /// Saves the specified filepath. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="graph">The graph.</param> /// <param name="filepath">The filepath.</param> /// <param name="mode">The mode.</param> public static void Save <T>(this T graph, String filepath, getWritableFileMode mode = getWritableFileMode.overwrite) where T : freeGraph, new() { if (!Path.HasExtension(filepath)) { filepath = filepath + ".xml"; } var fi = filepath.getWritableFile(mode); graph.OnBeforeSave(fi.Directory); graph.saveObjectToXML(fi.FullName); }
/// <summary> /// Saves the <c>content</c> string as text file. Returns path with filename specified. Optionally, sets <c>fileDescription</c> for directory readme generator /// </summary> /// <remarks> /// This method calls: <see cref="pathFor(string, getWritableFileMode, string, bool)"/> and then uses <see cref="File.WriteAllText(string, string)"/> to save the file. /// </remarks> /// <param name="content">The textual content to be saved</param> /// <param name="filename">The filename, if has no extension it will set .txt</param> /// <param name="mode">The mode.</param> /// <param name="fileDescription">The file description - if not specified, it will try to improvize :)</param> /// <param name="updateExistingDesc">if set to <c>true</c> it will force update if any existing file description was found. <see cref="RegisterFile(string, string, bool)" /></param> /// <returns> /// The path /// </returns> public String SaveText(String content, String filename, getWritableFileMode mode = getWritableFileMode.none, String fileDescription = "", Boolean updateExistingDesc = false) { if (!Path.HasExtension(filename)) { filename = filename + ".txt"; } String p = pathFor(filename, mode, fileDescription, updateExistingDesc); File.WriteAllText(p, content); return(p); }
/// <summary> /// New instance of <see cref="builderForLog"/> /// </summary> /// <param name="__filename">The log output filename with extension .md. It will automatically set .md extension</param> /// <param name="autoSave">if set to <c>true</c> if will do automatic save on each log call.</param> public builderForLog(String __filename, Boolean autoSave, getWritableFileMode mode = getWritableFileMode.autoRenameExistingOnOtherDate) : base() { immediateSaveOn = autoSave; filename = imbSciStringExtensions.ensureEndsWith(__filename, ".md"); if (autoSave) { String fileheader = "*AUTO SAVE LOG FILE*"; FileInfo fi = outputPath.getWritableFile(mode); //fileheader.saveStringToFile(outputPath, getWritableFileMode.autoRenameExistingOnOtherDate); outputPath = fi.FullName; } }
#pragma warning disable CS1574 // XML comment has cref attribute 'dataException' that could not be resolved /// <summary> /// Saves this instance. Returns <c>true</c> on success /// </summary> /// <returns>TRUE if saved sucessfully</returns> /// <exception cref="aceCommonTypes.core.exceptions.dataException">Can't just call Save() when no FileInfo instance ever set - null - Save() failed, call SaveAs() first</exception> public virtual bool Save(getWritableFileMode mode = getWritableFileMode.newOrExisting) #pragma warning restore CS1574 // XML comment has cref attribute 'dataException' that could not be resolved { if (info != null) { if (!ReadOnlyMode) { Monitor.Enter(SaveLinkedLock); } try { //if (IsInstanceLinkActive) //{ // foreach (var pair in instanceRegistry) // { // UpdateBase(pair.Value, pair.Key); // } //} table.AcceptChanges(); info = info.FullName.getWritableFile(mode); if (table.TableName.isNullOrEmpty()) { table.TableName = name; } if (table.TableName.isNullOrEmpty()) { table.TableName = info.Name.Replace(".", ""); } objectSerialization.saveObjectToXML(table, info.FullName); } finally { if (!ReadOnlyMode) { Monitor.Exit(SaveLinkedLock); } } return(true); } else { throw new dataException("Can't just call Save() when no FileInfo instance ever set", null, this, "Save() failed, call SaveAs() first"); return(false); } }
public FileInfo getFileInfo(string basename, getWritableFileMode mode, reportOutputFormatName format) { if (format == reportOutputFormatName.none) { format = builder.format; } string output = formats.getFilename(basename, format); output = directoryScope.FullName.add(output, "\\"); FileInfo fi = output.getWritableFile(mode); return(fi); }
/// <summary> /// Saves complete string into path /// </summary> /// <param name="data"></param> /// <param name="path"></param> /// <param name="mode"></param> /// <param name="encoding"></param> /// <returns></returns> public static FileInfo saveStringToFile(this String data, String path, getWritableFileMode mode = getWritableFileMode.overwrite, Encoding encoding = null) { lock (saveStringToFileLock) { if (encoding == null) { encoding = UnicodeEncoding.Unicode; } FileInfo fi = path.getWritableFile(mode); Directory.CreateDirectory(fi.DirectoryName); File.WriteAllText(fi.FullName, data, encoding); return(fi); } }
/// <summary> /// Saves the specified path. /// </summary> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> public void Save(String path, getWritableFileMode mode = getWritableFileMode.overwrite) { if (!path.EndsWith(".dgml")) { path = path + ".dgml"; } FileInfo fi = path.getWritableFile(mode); objectSerialization.saveObjectToXML(this, fi.FullName); if (ConversionErrors.Any()) { String errFileName = Path.GetFileNameWithoutExtension(path) + "_conversionErrors.txt"; folderNode fl = fi.Directory; String errFilePath = fl.pathFor(errFileName, getWritableFileMode.overwrite); File.WriteAllLines(errFilePath, ConversionErrors); } }
/// <summary> /// Saves the index to default location /// </summary> public void Save() { lock (saveLock) { lastIndexSave = DateTime.Now; getWritableFileMode mode = getWritableFileMode.newOrExisting; if (imbWEMManager.settings.indexEngine.doIndexBackupOnEachSave) { mode = getWritableFileMode.autoRenameExistingToOld; } pageIndexTable.Save(mode); domainIndexTable.Save(mode); indexSessionRecords.Save(mode); experimentManager.Save(mode); } wRecordsDeployed = 0; }
public override FileInfo saveDocument(string name, getWritableFileMode mode, reportOutputFormatName format = reportOutputFormatName.none) { if (format == reportOutputFormatName.none) { format = reportOutputFormatName.textMdFile; } String str_output = ContentToString(false, format); String filename = name; if (!Path.HasExtension(name)) { filename = formats.getFilename(name, format); } FileInfo fi = filename.getWritableFile(getWritableFileMode.newOrExisting); return(str_output.saveStringToFile(fi.FullName, getWritableFileMode.overwrite, System.Text.Encoding.UTF8)); //if (format == reportOutputFormatName.htmlViaMD) //{ // FileInfo fi = filename.getWritableFile(getWritableFileMode.newOrExisting); // getLastLine(); // //String markdown = //contentElements.ToDelimitedString(Environment.NewLine); // String html = markdown.markdigMD2HTML(); // saveBase.saveToFile(fi.FullName, html); // return fi; //} //else //{ // return base.saveDocument(name, mode, format); //} }
/// <summary> /// 2017: Saves CSV to file from path /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collection">Typed IList to write CSV for. For properties with Display Name attribute it will use the attribute value</param> /// <param name="path">Relative or apsolute path where to store the file</param> /// <returns></returns> public static bool toCsvFile <T>(this IEnumerable <T> collection, string path, getWritableFileMode mode = getWritableFileMode.overwrite) where T : class, new() { if (imbSciStringExtensions.isNullOrEmptyString(path)) { throw new ArgumentNullException("path", "File path can't be null nor empty"); return(false); } var fi = path.getWritableFile(mode); if (collection == null) { collection = new List <T>(); } try { StreamWriter sw; if (mode == getWritableFileMode.appendFile) { sw = File.AppendText(path); } else { sw = File.CreateText(path); } throw new NotImplementedException(); //var csv = new CsvHelper.CsvWriter(sw); //csv.WriteRecords(collection); } catch (Exception ex) { throw new ArgumentException("path", "CSV file writing failed [" + path + "].", ex); return(false); } return(true); }
/// <summary> /// Gets fileinfo /// </summary> /// <param name="filenameBase">Filename base - automatically trims any existing extension</param> /// <param name="dir">directorium to put file into</param> /// <param name="format">Targeted output format</param> /// <returns></returns> public FileInfo getFileInfo(String filenameBase, DirectoryInfo dir, reportOutputFormatName format = reportOutputFormatName.none, getWritableFileMode mode = getWritableFileMode.autoRenameExistingOnOtherDate) { //String filename = getFilename(filenameBase, format); String filepath = getFilename(filenameBase, dir, format); return(filepath.getWritableFile(mode)); //new FileInfo(filepath); }
public object addDocument(string name, bool scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameExistingOnOtherDate, reportOutputFormatName format = reportOutputFormatName.none) { return(null); }
///// <summary> ///// Builds plain (no format) workbook inside provided excel object and adds it into workbook set ///// </summary> ///// <param name="data">DataTable with rows and columns</param> ///// <param name="doInsertCaptions">if TRUE the first row will be DataColumn.Caption</param> ///// <param name="excel">ExcelPackage or ExcelWorkbook object. If null it will create new</param> ///// <returns>ExcelPackage - from parameter or newly instatiated</returns> //public static ExcelPackage buildPlainWorkbook(this IDocumentRender builder, DataTable data, PropertyCollection dataMeta, ExcelPackage excel = null) //{ // if (excel == null) // { // excel = new ExcelPackage(); // } // //cursor cur = data.buildCursorAndZone(0, 1, 0, 0); // String wkn = excel.Workbook.Worksheets.getUniqueName(data.TableName); // ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(wkn); // worksheet.DefaultColWidth = 50.toExcelWidth(); // cur.switchToZone(textCursorZone.outterZone, textCursorZoneCorner.UpLeft); // worksheet.SetValue(cur, meta.header.description, true); // worksheet.SetValues(cur, meta.header.content, true, textCursorZoneCorner.Bottom); // cur.setMarginHere(textCursorZoneCorner.Top); // cur.switchToZone(textCursorZone.innerZone, textCursorZoneCorner.UpLeft); // if (meta.doInsertCaptions) // { // foreach (DataColumn dc in data.Columns) // { // worksheet.SetValue(cur, dc.Caption, false, textCursorZoneCorner.Right); // } // cur.enter(); // } // foreach (DataRow rw in data.Rows) // { // foreach (DataColumn dc in data.Columns) // { // worksheet.SetValue(cur, rw[dc], false, textCursorZoneCorner.Right); // } // cur.enter(); // } // cur.switchToZone(textCursorZone.outterZone, textCursorZoneCorner.default_corner); // worksheet.SetValues(cur, meta.footer.content, true); // if (meta.keywords.content.Any()) // { // cur.enter(); // worksheet.SetValue(cur, "Keywords:", false, textCursorZoneCorner.Right); // worksheet.SetValues(cur, meta.keywords.content, true, textCursorZoneCorner.Right); // } // cur.enter(); // worksheet.SetValue(cur, meta.footer.bottomLine, true); // return excel; //} //public static ExcelPackage createExcel(this String filename_base) //{ // ExcelPackage output = new ExcelPackage(); //} public static ExcelPackage saveOutput(this ExcelPackage excel, DirectoryInfo di, string filename_base, getWritableFileMode mode = getWritableFileMode.overwrite, params reportOutputFormatName[] formats) { object output = ""; reportOutputSupport support = reportOutputSupport.getFormatSupportFor(reportAPI.EEPlus, filename_base); var supported = support.checkSupport(true, formats); string filename = ""; FileInfo fi = null; output = excel; foreach (reportOutputFormatName format in supported) { filename_base.add(support[format].toStringSafe(), "."); fi = support[format].toStringSafe().getWritableFile(mode); // File file = fi.OpenWrite(); switch (format) { case reportOutputFormatName.sheetCsv: byte[] by = EpplusCsvConverter.ConvertToCsv(excel); File.WriteAllBytes(fi.FullName, by); break; case reportOutputFormatName.sheetExcel: excel.File = fi; excel.Save(); break; case reportOutputFormatName.sheetHtml: //excel.Workbook.Worksheets[0] break; case reportOutputFormatName.sheetXML: excel.Workbook.WorkbookXml.OuterXml.saveStringToFile(fi.FullName, mode); // File.WriteAllText(fi.FullName, excel.Workbook.WorkbookXml.OuterXml); break; case reportOutputFormatName.sheetPDF: break; } } return(excel); }
/// <summary> /// Creates new document both in filesytem and internal memory. Location for new file is current directory. /// </summary> /// <param name="name">Name of new document. It will transform it to filename version and add proper file extension. No problem if you put extension alone.</param> /// <param name="mode">How any existing file should be handled</param> /// <returns>Newly created document</returns> /// \ingroup_disabled renderapi_service public abstract Object addDocument(String name, Boolean scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameExistingOnOtherDate, reportOutputFormatName format = reportOutputFormatName.none);
/// <summary> /// Gets writable file based on selected mode. By default it will do overwrite. Autorename calls <see cref="addUniqueSufix(string, string)" /> extension that counts existing files and sets proper number. /// </summary> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> /// <param name="logger">The logger.</param> /// <returns></returns> /// <exception cref="imbFileException">getWritableFile [" + mode.ToString() + "] failed when directory should be created from [" + dir.toStringSafe() + "]. " /// + ex.Message - null - null</exception> public static FileInfo getWritableFile(this String path, getWritableFileMode mode = getWritableFileMode.overwrite, ILogBuilder logger = null) { String output = path; String existing = path; if (path.Length > 200) { if (logger != null) { logger.log("Path length critical: " + path.Length); } } String dir = Path.GetDirectoryName(path); if (!imbSciStringExtensions.isNullOrEmpty(dir)) { try { if (!Directory.Exists(dir)) { lock (CreateDirLock) { if (!Directory.Exists(dir)) { var di = Directory.CreateDirectory(dir); } } } } catch (Exception ex) { // throw new imbFileException("getWritableFile [" + mode.ToString() + "] failed when directory should be created from [" + dir.toStringSafe() + "]. " // + ex.Message, ex, null, path, null); } } Int32 retryCount = 5; Boolean jobDone = true; while (retryCount > 0) { jobDone = true; if (File.Exists(output)) { switch (mode) { case getWritableFileMode.appendFile: break; case getWritableFileMode.newOrExisting: // do nothing break; case getWritableFileMode.existing: break; case getWritableFileMode.overwrite: try { File.Delete(output); } catch (Exception ex) { if (logger != null) { logger.log("The file [" + path + "] is blocked by another application. " + ex.Message); } jobDone = false; } break; case getWritableFileMode.autoRenameExistingOnOtherDate: FileInfo exfi = new FileInfo(output); if (exfi.CreationTime.Date != DateTime.Now.Date) { existing = existing + "_" + exfi.CreationTime.ToString("MM-dd"); File.Delete(existing); File.Copy(output, existing); try { File.Delete(output); } catch (Exception ex) { existing = output.addUniqueSufix("_" + DateTime.Now.ToString("MM-dd")); if (logger != null) { logger.log("The log file was used by another process. Saving to: " + existing); } } } else { } break; case getWritableFileMode.autoRenameThis: output = output.addUniqueSufix(); break; case getWritableFileMode.autoRenameExistingToNextPage: output = output.addUniqueSufix("_page_"); break; case getWritableFileMode.autoRenameExistingToBack: existing = existing.addUniqueSufix("backup"); File.Copy(output, existing); break; case getWritableFileMode.autoRenameExistingToOld: existing = existing.addUniqueSufix("old"); File.Copy(output, existing); break; case getWritableFileMode.autoRenameExistingToOldOnce: existing = existing.add("_old"); if (File.Exists(existing)) { File.Delete(existing); } File.Copy(output, existing); break; } } if (jobDone) { retryCount = 0; } if (retryCount > 0) { if (logger != null) { logger.log(retryCount.ToString() + " retry [" + mode + "] file [" + existing + "]"); } Thread.Sleep(RETRY_DELAY); retryCount--; } } FileInfo fi = new FileInfo(output); return(fi); }
public object addPage(string name, bool scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameThis, reportOutputFormatName format = reportOutputFormatName.none) { throw new NotImplementedException(); }
public object addDocument(string name, bool scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameExistingOnOtherDate, reportOutputFormatName format = reportOutputFormatName.none) { throw new NotImplementedException(); }
/// <summary> /// Saves to new path /// </summary> /// <param name="newPath">The new path.</param> /// <param name="mode">The mode.</param> /// <param name="loger">The loger.</param> public void SaveAs(String newPath, getWritableFileMode mode, ILogBuilder loger) { info = newPath.getWritableFile(mode); Save(loger); }
public FileInfo GetTFIDF_Master_File(getWritableFileMode mode = getWritableFileMode.newOrExisting) { return(TFIDF_ConstructFolder.pathFor("master_tf-idf.xml").getWritableFile(mode)); }
/// <summary> /// Adds new page, drives cursor to upper-left corner /// </summary> /// <param name="name">The name of newly created page.</param> /// <param name="mode">In case page with the same name already exists</param> /// <returns>Page object - usually not directly used</returns> /// \ingroup_disabled renderapi_service public abstract TPage addPage(String name, Boolean scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameThis, reportOutputFormatName format = reportOutputFormatName.none);
/// <summary> /// Saves the current document, returns <c>FileInfo</c> pointing to it /// </summary> /// <param name="name">The name without extension</param> /// <param name="mode">Existing file mode</param> /// <returns>File info pointing to</returns> /// \ingroup_disabled renderapi_service public abstract FileInfo saveDocument(String name, getWritableFileMode mode, reportOutputFormatName format = reportOutputFormatName.none);
public object addPage(string name, bool scopeToNew = true, getWritableFileMode mode = getWritableFileMode.autoRenameThis, reportOutputFormatName format = reportOutputFormatName.none) { return(saveDocument(name, mode, format)); }
#pragma warning disable CS1066 // The default value specified for parameter 'format' will have no effect because it applies to a member that is used in contexts that do not allow optional arguments /// <summary> /// Adds new page, drives cursor to upper-left corner /// </summary> /// <param name="name">The name of newly created page.</param> /// <param name="scopeToNew"></param> /// <param name="mode">In case page with the same name already exists</param> /// <returns> /// Page object - usually not directly used /// </returns> /// \ingroup_disabled renderapi_service object ITextRender.addPage(string name, bool scopeToNew, getWritableFileMode mode, reportOutputFormatName format = reportOutputFormatName.none) #pragma warning restore CS1066 // The default value specified for parameter 'format' will have no effect because it applies to a member that is used in contexts that do not allow optional arguments { return(addPage(name, scopeToNew, mode)); }
public weightTableCompiled GetTFIDF_DLC(indexDomain idomain, getWritableFileMode mode = getWritableFileMode.newOrExisting) { FileInfo fi = new FileInfo(TFIDF_ConstructFolder.pathFor("dlc_" + idomain.HashCode + ".xml")); //.getWritableFile(mode); return(new weightTableCompiled(fi.FullName, true, idomain.domain)); }