private void ImportFiles(string folderPath) { RowCollection rowCollection; Regex regex; Match match; RowCollectionRow objectRow; string[] fileColumns; string[] fileList = Directory.GetFiles(folderPath); regex = new Regex(regexFileMatcher, RegexOptions.IgnoreCase); foreach (string file in fileList) { match = regex.Match(file); if (match.Length > 0) { fileColumns = SplitRow(file, regexSpliterColumn); rowCollection = rowCollectionMenager.GetRowCollectionObjectFromCellNumber(3 + fileColumns.Length, true); objectRow = new RowCollectionRow(rowCollection, Common.MargeTwoStringArray(GetDefaultColumns(file), fileColumns)); rowCollection.Rows.Add(objectRow); } } }
private string ActiveObject(Tag2 active) { string result = null; try { // {=active.fetch.[deep_index].[column_index]} if (active.Child.Name == "counter") { result = this.rowCollectionMenager.ActiveObjectInstance.RowCounter.ToString(); } else { int depth = int.Parse(active.Child.Child.Name); depth--; string objectName = rowCollectionMenager.ActiveObjectInstance[depth]; if (objectName != null) { RowCollection rowCollection = rowCollectionMenager[objectName]; if (active.Child.Name == "fetch") { int columnIndex = int.Parse(active.Child.Child.Child.Name); columnIndex--; RowCollectionRow objectRow = rowCollection.Rows[rowCollection.Rows.Curent]; if (objectRow != null) { result = objectRow[columnIndex].Value; } else { // active object is out of scope result = ""; } } else if (active.Child.Name == "index") { result = (rowCollection.Rows.Curent + 1).ToString();; } else { ModuleLog.Write(new string[] { constError_CommandNotFound, active.InputText }, this, "ActiveObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } else { // active object is out of scope result = ""; } } } catch (Exception ex) { ModuleLog.Write(new string[] { constError_ExecutingBlock, active.InputText }, this, "ActiveObject", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "ActiveObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
/// <summary> /// RowCollection object /// </summary> /// <param name="tag"></param> /// <returns></returns> private string DataObjectGetValue(Tag2 tag) { string result = null; int columntID; RowCollection rowCollection = rowCollectionMenager[tag.Name]; try { // {=objectname.row.column} // {=objectname.column} // Column index is zero base, but user need to treat it like non zero base else it is error if (rowCollection != null) { if (tag.Child.Name == "fetch") { columntID = int.Parse(tag.Child.Child.Name); columntID--; result = rowCollection.Rows.FetchColumn(columntID); } else if (tag.Child.Name == "fetchNext") { columntID = int.Parse(tag.Child.Child.Name); columntID--; result = rowCollection.Rows.FetchNextColumn(columntID); } else if (tag.Child.Name == "search") { // {=object.searchRegex.searchOnColumn.returnColumn."<regex>"} columntID = int.Parse(tag.Child.Child.Name); columntID--; int columnID2 = int.Parse(tag.Child.Child.Child.Name); columnID2--; RowCollectionRow row = rowCollection.Rows.SearchRow(tag.Child.Child.Child.Child.Name, columntID); if (row != null) { result = row[columnID2].Value; } else { result = ""; } } } else { ModuleLog.Write(new string[] { constError_CommandNotFound, tag.InputText }, this, "DataObjectGetValue", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch (Exception ex) { ModuleLog.Write(new string[] { constError_ExecutingBlock, tag.InputText }, this, "DataObjectGetValue", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "DataObjectGetValue", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
private string ReplaceTagsFromInToOut(string text, RowCollectionRow row) { string result = null; string objectName = ""; string objectValue = ""; //string oldText = ""; // Define all regex match with patern //Regex regexMain = new Regex(@"\{=[\w]+\.[^{}]+\}"); // Test regex expresion added for escape function // za right je nije(?!mal) Regex regexMain = new Regex(@"(?<![^\\]\\)\{=[\w]+\.(?!.*(?<![^\\]\\){=.*(?<!\\)}).*?(?<!\\)\}", RegexOptions.Singleline); Regex regex; // Get all matches MatchCollection matchList; // do loop is needed if tags are nested do { matchList = regexMain.Matches(text); foreach (Match match in matchList) { // Define regex string that will extract object name regex = new Regex(@"\{=|\..+\}", RegexOptions.Singleline); // get that object name and save it objectName = regex.Replace(match.Value, ""); // Define regex string that will extract object value //regex = new Regex(@"{=[\w]+\.|}+"); regex = new Regex(@"(?<!\\)\{=[\w]+\.|(?<!\\)\}"); // get that object value objectValue = regex.Replace(match.Value, ""); // Call suported object name and replace tags in text result = this.ReplaceSuportedObject(objectName, objectValue, row); if (result != null) { text = ReplaceOnce(text, match.Value, result); } else { // No suported object found text = text.Replace(match.Value, match.Value.Replace("{=", "(=ubertools_replace_string)")); // dont loog this if (isInitialization == false) { ModuleLog.Write(text, this, "ReplaceTagsFromInToOut", ModuleLog.LogType.DEBUG); } } } } while (matchList.Count > 0); text = text.Replace("(=ubertools_replace_string)", "{="); return(text); }
private void BrowseFolders(string path) { RowCollection rowCollection; RowCollectionRow objectRow; Regex regex; Match match; string[] folderColumns; int counter = 0; string[] folderList = Directory.GetDirectories(path); // define regex matcher regex = new Regex(regexFolderMatcher, RegexOptions.IgnoreCase); foreach (string folder in folderList) { match = regex.Match(folder); if (match.Length > 0) { ModuleLog.Write(new string[] { "Folder: " + path, "Match: yes" }, this, "BrowseFolders", ModuleLog.LogType.DEBUG); folderColumns = FolderParser.SplitRow(folder, regexSpliterColumn); // new rowcollection rowCollection = rowCollectionMenager.GetRowCollectionObjectFromCellNumber(2 + folderColumns.Length, true); objectRow = new RowCollectionRow(rowCollection, Common.MargeTwoStringArray(GetDefaultColumns(folder), folderColumns)); //rowCollectionMenager.AddRow(objectRow); rowCollection.Rows.Add(objectRow); if (subfolders == true) { BrowseFolders(folder); } } else { // dont import folder but browse childs if (subfolders == true) { ModuleLog.Write(new string[] { "Folder: " + path, "Match: no" }, this, "BrowseFolders", ModuleLog.LogType.DEBUG); BrowseFolders(folder); } else { ModuleLog.Write(new string[] { "Folder: " + path, "Match: skip" }, this, "BrowseFolders", ModuleLog.LogType.DEBUG); } } if ((counter++ % 1000) == 0) { System.Windows.Forms.Application.DoEvents(); } } }
private string NumberObject(RowCollectionRow row, string objectValue) { string result = null; Tag tag = new Tag("number", objectValue); try { if (tag.Value == "getvalue") { //{=number.getvalue} result = numberObject_counter.ToString(); } else { if (tag.Tags.Name == "increment") { //{=number.increment.startNumber.incrementBy} if (numberObject_counter == constNumberObject_counter_defaultValue) { ModuleLog.Write(tag.Tags.Tags.Name, this, "NumberObject", ModuleLog.LogType.INFO); numberObject_counter = int.Parse(tag.Tags.Tags.Name); } else { int number_to_increment = 0; number_to_increment = int.Parse(tag.Tags.Tags.Value); numberObject_counter = numberObject_counter + number_to_increment; } result = numberObject_counter.ToString(); } else { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NumberObject", ModuleLog.LogType.WARNING); result = constError_SyntaxError; } } } catch (Exception ex) { ModuleLog.Write(ex, this, "--NumberObject", ModuleLog.LogType.ERROR); ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "--NumberObject", ModuleLog.LogType.DEBUG); result = constError_SyntaxError; } return(result); }
/// <summary> /// Generic method, it will return string value of row object and columnt index /// </summary> /// <param name="row">Row object</param> /// <param name="objectValue">Column index</param> /// <returns></returns> /// private string DataObjectGetValue(RowCollectionRow row, Tag2 tag) { string result = null; int columntID = 0; try { if (tag.Child.Child == null) { columntID = int.Parse(tag.Child.Name); // Column index is zero base, but user need to treat it like non zero base else it is error if (columntID > 0) { // Increment column index to 1, zero index base, user will access it by one base columntID--; result = row[columntID].Value; } else { ModuleLog.Write(new string[] { constError_SyntaxError, tag.InputText }, this, "DataObjectGetValue", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } else { ModuleLog.Write(new string[] { constError_CommandNotFound, tag.InputText }, this, "DataObjectGetValue", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch (Exception ex) { ModuleLog.Write(new string[] { constError_ExecutingBlock, tag.InputText }, this, "DataObjectGetValue", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "DataObjectGetValue", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } //if (result == null) //{ // ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "DataObjectGetValue", ModuleLog.LogType.ERROR); // result = constError_SyntaxError; //} return(result); }
private void ProcessXML(XmlNodeList xmlNodeList, UberTools.Modules.GenericTemplate.RowCollectionNS.RowCollection parentRowCollection) { RowCollection rowCollection = null; RowCollectionRow objectRow; string rowCollectionName = null; foreach (XmlNode node in xmlNodeList) { if (node.NodeType == XmlNodeType.Element) { rowCollectionName = FindXPath(node); rowCollection = rowCollectionMenager[rowCollectionName]; if (rowCollection == null) { rowCollection = rowCollectionMenager.CreateRowCollection(node.Attributes.Count, rowCollectionName); } // check if parent row collection is not null, only first call is null if (parentRowCollection != null) { // add this row collection to parent chilld list parentRowCollection.AddChild(rowCollection); } // make new instance of ObjectRow object objectRow = new RowCollectionRow(rowCollection, GetAllAttribites(node)); // if node have inner text if (node.InnerText != "") { // add extra columnt to objectRow object objectRow.AddColl(new RowCollectionColumn(node.InnerText)); } // add new row to row collection rowCollection.Rows.Add(objectRow); //ModuleLog.Write(GetAllAttribites(node), this, "ProcessXML", ModuleLog.LogType.INFO); // recurse chilld ProcessXML(node.ChildNodes, rowCollection); } } }
private string InputObject(RowCollectionRow row, Tag2 tag) { string result = null; InputBox inputBox; try { if (tag.Child.Name == "repeat") { // // NOTE this need to be like $input.once object // //{=input.repeat.[Value]} inputBox = new InputBox("Write text", tag.Child.Name, "Replace tag with text..."); inputBox.ShowDialog(System.Windows.Forms.Application.OpenForms[0]); result = inputBox.InputTekst; } else if (tag.Child.Name == "once") { result = inputObject.ProcessTag(tag); if (result == null) { result = constError_SyntaxError; } } else { ModuleLog.Write(new string[] { constError_CommandNotFound, tag.InputText }, this, "InputObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch (Exception ex) { ModuleLog.Write(new string[] { constError_ExecutingBlock, tag.InputText }, this, "InputObject", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "InputObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
private string NTHObject(RowCollectionRow row, string objectValue) { string result = null; Tag tag = new Tag("nth", objectValue); try { if (tag.Tags.Name == "swapzarez") { //{=nth.swapzarez.text} result = tag.Tags.Value.Replace(",", "<;>"); } else if (tag.Tags.Name == "max160") { //{=nth.max160.text} if (tag.Tags.Value.Length > 160) { result = "- - - W A R N I N G (text length " + tag.Tags.Value.Length + " ) - - -"; ModuleLog.Write(result, this, "NTHObject", ModuleLog.LogType.WARNING); ModuleLog.Write(tag.Tags.Value, this, "NTHObject", ModuleLog.LogType.DEBUG); } else { result = tag.Tags.Value; } } else { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NTHObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NTHObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
private string StringObject(RowCollectionRow row, Tag2 tag) { string result = null; try { if (tag.Child.Name == "split") { // string.split.[index].[split string].[text] string[] splitList = tag.Child.Child.Child.Child.Name.Split(new string[] { tag.Child.Child.Child.Name }, StringSplitOptions.RemoveEmptyEntries); int index; index = int.Parse(tag.Child.Child.Name); // if index is in range of array if (index < splitList.Length) { result = splitList[index]; } else { // else return empty string and log waring result = ""; ModuleLog.Write("String out of range returning empty string", this, "StringObject", ModuleLog.LogType.WARNING); } } else { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", tag.InputText, ")"), this, "StringObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch (Exception ex) { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", tag.InputText, ")"), this, "StringObject", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "StringObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
private string ReplaceSuportedObject(string objectName, string objectValue, RowCollectionRow row) { // // I N F O - ReplaceTagsFromInToOut will not cut this // Tag2 tag = new Tag2("{=" + objectName + "." + objectValue); if (objectName == "date") { // Call to datetime object return(this.DateObject(objectValue)); } else if (objectName == "string") { // Call to main generic method, other method will call it to get object row value and then format it // this one just return pure text value // // Ovo sa split je privremeno ovdje stavito // if (tag.Child.Name.Equals("split")) { return(StringObject(row, tag)); } else { return(StringObject(row, objectValue)); } } else if (objectName == "nth") { // Call to main generic method, other method will call it to get object row value and then format it // this one just return pure text value return(NTHObject(row, objectValue)); } else if (objectName == "number") { // Call to main generic method, other method will call it to get object row value and then format it // this one just return pure text value return(NumberObject(row, objectValue)); } else if (tag.Name == "input") { // Call to InputObject return(InputObject(row, tag)); } else if (tag.Name == "var") { // Call to VarObject return(VarObject(tag)); } else if (tag.Name == "array") { // Call to ArrayObject ArrayObject arrayObject = new ArrayObject(tag, varObjectList); return(arrayObject.ProcessTag()); } else if (tag.Name == "format") { // Call to FormatObject, get and set method return(FormatObject(tag)); } else if (objectName == "xml") { // Call to FormatObject, get and set method return(XMLObject(row, objectValue)); } else if (objectName.StartsWith("random")) { return(RandomObject(objectName, objectValue)); } else if (objectName.StartsWith("md5")) { return(MD5Object(objectName, objectValue)); } else if (tag.Name == "file") { FileObject fileObject = new FileObject(tag, ref varObjectList); return(fileObject.ProcessTag()); } else if (tag.Name == "dir") { DirObject dirObject = new DirObject(tag, ref varObjectList); return(dirObject.ProcessTag()); } else if (tag.Name == "graphics") { GraphicsObject fileObject = new GraphicsObject(tag); return(fileObject.ProcessTag()); } else if (tag.Name == "math") { MathObject mathObject = new MathObject(tag); return(mathObject.ProcessTag()); } else { // objects that dont need be in initialization proccess if (isInitialization == false) { if (tag.Name == "active") { return(ActiveObject(tag)); } else if (tag.Name == "data") { // Call to main generic method, other method will call it to get object row value and then format it // this one just return pure text value return(DataObjectGetValue(row, tag)); } //else if (objectName.StartsWith("data")) //{ // return DataObjectGetValue(objectName, objectValue); //} else { return(DataObjectGetValue(tag)); } } } return(null); }
//public void AutomaticAddToRowCollectionMenager_ClipboardSource(string regexSpliterColumn, string regexSpliterRow) //{ // int counter = 0; // string[] lineList = TextParser.SplitRow(System.Windows.Forms.Clipboard.GetText(), regexSpliterRow); // if (System.Windows.Forms.Clipboard.ContainsText()) // { // foreach (string line in lineList) // { // rowCollectionMenager.AddRow(new ObjectRow(null, TextParser.SplitRow(line, regexSpliterColumn))); // if ((counter++ % 1000) == 0) // { // System.Windows.Forms.Application.DoEvents(); // } // } // } //} public void AutomaticAddToRowCollectionMenager_ClipboardSource(string regexSpliterColumn, string regexSpliterRow, bool firstRowAsColumnName) { RowCollection rowCollection; RowCollectionRow row; string[] lineList; string[] columnList; int counter = 0; // Get array of rows lineList = TextParser.SplitRow(System.Windows.Forms.Clipboard.GetText(), regexSpliterRow); // If row list is null then exit if (lineList == null) { return; } // Go through all rows foreach (string line in lineList) { // Split row in array of columns columnList = TextParser.SplitRow(line, regexSpliterColumn); // get rowCollection object rowCollection = rowCollectionMenager.GetRowCollectionObjectFromCellNumber(columnList.Length, false); // check if rowCollection is null if (rowCollection == null) { // create new rowCollecion object //rowCollection = new RowCollection(columnList.Length, RowCollection.const_prefix + columnList.Length.ToString()); rowCollection = rowCollectionMenager.CreateRowCollection(columnList.Length); // define column names if (firstRowAsColumnName == true) { for (int i = 0; i < columnList.Length; i++) { rowCollection.Columns[i] = columnList[i]; } } else { // create new row object from column array row = new RowCollectionRow(rowCollection, columnList); // add row to rowCollection rowCollection.Rows.Add(row); } } else { // create new row object from column array row = new RowCollectionRow(rowCollection, columnList); // add row to rowCollection rowCollection.Rows.Add(row); } //rowCollectionMenager.AddRow(new ObjectRow(null, TextParser.SplitRow(line, regexSpliterColumn))); if ((counter++ % 1000) == 0) { System.Windows.Forms.Application.DoEvents(); } } }
private void DestinationObjectData_CompareStrings(string templateHeader, string templateBody, string templateFooter, RowCollectionRow row, int rowID, int rowMax) { TextParser textParser = new TextParser(outputMenagerSettings.rowCollectionMenager); textParser.AutomaticAddToRowCollectionMenager(templateBody, outputMenagerSettings.columnSpliterRegEx, outputMenagerSettings.rowSpliterRegEx); //ObjectRow objectRow = new ObjectRow(new string[] { templateBody }); //outputMenagerSettings.rowCollectionMenager.AddRow(objectRow); }
private string StringObject(RowCollectionRow row, string objectValue) { string result = null; Tag tag = new Tag("string", objectValue); try { if (tag.Tags.Name == "trim") { result = tag.Tags.Value.Trim(); } else if (tag.Tags.Name == "substring") { // {=string.substring.4.2.neki text} int start; int lenght; start = int.Parse(tag.Tags.Tags.Name); lenght = int.Parse(tag.Tags.Tags.Tags.Name); // if index is in range of string length if ((start + lenght) < tag.Tags.Tags.Tags.Value.Length) { result = tag.Tags.Tags.Tags.Value.Substring(start, lenght); } else { // else return empty string and log waring result = ""; ModuleLog.Write("String out of range returning empty string", this, "StringObject", ModuleLog.LogType.WARNING); } } else if (tag.Tags.Name == "indexof") { // {=string.indexof. .damir marijanovic} result = tag.Tags.Tags.Value.IndexOf(tag.Tags.Tags.Name).ToString(); } else if (tag.Tags.Name == "toupper") { result = tag.Tags.Value.ToUpper(); } else if (tag.Tags.Name == "tolower") { result = tag.Tags.Value.ToLower(); } else if (tag.Tags.Name == "replace") { // {=string.replace.old.new.text} result = tag.Tags.Tags.Tags.Value.Replace(tag.Tags.Tags.ToString(), tag.Tags.Tags.Tags.ToString()); } else if (tag.Tags.Name == "split") { // string.split.[index].[split string].[text] string[] splitList = tag.Tags.Tags.Tags.Value.Split(new string[] { tag.Tags.Tags.Tags.Name }, StringSplitOptions.RemoveEmptyEntries); int index; index = int.Parse(tag.Tags.Tags.Name); // if index is in range of array if (index < splitList.Length) { result = splitList[index]; } else { // else return empty string and log waring result = ""; ModuleLog.Write("String out of range returning empty string", this, "StringObject", ModuleLog.LogType.WARNING); } } else { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "StringObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } } catch (Exception ex) { ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "StringObject", ModuleLog.LogType.DEBUG); ModuleLog.Write(ex, this, "StringObject", ModuleLog.LogType.ERROR); result = constError_SyntaxError; } return(result); }
public string ReplaceTags(string text, RowCollectionRow row) { return(ReplaceTags(text, row, false)); }
public string ReplaceTags(string text, RowCollectionRow row, bool isInitialization) { int indexOfFirst = 0; int indexOfLast = 0; int indexOfLastNoTag = 0; int tagCounter = 0; bool tagSearchActive = false; string result = ""; string processedText = ""; this.isInitialization = isInitialization; for (int i = 0; i < text.Length; i++) { // Find first tag, { if (text[i] == '{') { if (!Tag2.IsExcaped(text, i)) { // if start tag is complete, is like {= if ((text.Length > 2 && i < text.Length - 2) && text[i + 1] == '=') { // increment tag counter tagCounter++; // if this is first tag that is find then save indexOf if (tagSearchActive == false) { indexOfFirst = i; // indicate thats tag search is active, from now if tagCounter is 0 then cut tag and call ReplaceTagsFromInToOut(x, x) tagSearchActive = true; // start tag find next for continue; } } } //} } // Find last tag if (text[i] == '}') { // Check if is not excaped if (!Tag2.IsExcaped(text, i)) { // Decrement tag counter and set indexOfLast tagCounter--; indexOfLast = i; } } // if tagCounter is less then zero then throw error if (tagCounter < 0) { throw new Exception("Template syntax error at end of " + Environment.NewLine + text.Substring(indexOfFirst, indexOfLast - indexOfFirst)); } // Check is tag search is active and tagCounter value is zero, if is zero then call ReplaceTagsFromInToOut(x, x) if (tagSearchActive) { // if tagCounter is zero then call ReplaceTagsFromInToOut(x, x) if (tagCounter == 0) { // call function to parse tags extracted result = ReplaceTagsFromInToOut(text.Substring(indexOfFirst, (indexOfLast - indexOfFirst) + 1), row); // copy no tag text processedText += text.Substring(indexOfLastNoTag, indexOfFirst - indexOfLastNoTag); indexOfLastNoTag = indexOfLast + 1; // replace extracted tags block with result from function with 2 (0, 1) (2 - 1) = 1 <= 1 , 1 + 1 = 2, (2 - 1) - 1 1 //processedText += string.Concat(text.Substring(0, indexOfFirst), result, text.Length - 1 >= indexOfLast ? text.Substring(indexOfLast + 1, (text.Length - 1) - indexOfLast) : ""); processedText += result; // reset varables tagSearchActive = false; } } } // Copy text after last tag if (indexOfLastNoTag < text.Length) { processedText += text.Substring(indexOfLastNoTag, text.Length - indexOfLastNoTag); } // if tagCounter is not zero then throw error if (tagCounter > 0) { throw new Exception("Template syntax error at start of " + Environment.NewLine + text.Substring(indexOfFirst, text.Length - indexOfFirst)); } // Do all unexcape //processedText = processedText.Replace("\\\\", "\\"); processedText = Tag2.UnEscape(processedText); // log if change is made if (text != processedText) { ModuleLog.Write(processedText, this, "ReplaceTags", ModuleLog.LogType.DEBUG); } return(processedText); }
private void DestinationFile(string templateHeader, string templateBody, string templateFooter, RowCollectionRow row, int rowID, int rowMax) { string filePath; string folder; string file; bool writeHeader = false; bool writeFooter = false; folder = tagsReplace.ReplaceTags(outputMenagerSettings.sourceFolder, row); file = tagsReplace.ReplaceTags(outputMenagerSettings.sourceFileName, row); folder = Common.SetSlashOnEndOfDirectory(folder); filePath = folder + file; if (!Directory.Exists(folder)) { Common.MakeAllSubFolders(folder); } //fileName = tagsReplace.ReplaceTags(outputMenagerSettings.sourceFileName, row); // Is header text length more then 0 caracther if (templateHeader.Length > 0) { // If append is true then only write header if file dont exist if (outputMenagerSettings.AppendFile) { if (!File.Exists(filePath)) { writeHeader = true; } } else { // Append is false, so write header in each file writeHeader = true; } } // // Is footer text lenght more then 0 charachter if (templateFooter.Length > 0) { // If append is true then only write header if file dont exist if (outputMenagerSettings.AppendFile) { // Ovdje se mora dodati provjera koja ce kad se svi redovi izvrte pogledati gdje nije upisao footer // Ova ispod provjera je samo zakrpa u slucaju da je destinacion name staticno a nije varijabla if (rowID + 1 >= rowMax) { writeFooter = true; } } else { // Append is false, so write header in each file writeFooter = true; } } // If stream writer last file path is not current path make new stream writer object if (!outputMenagerSettings.AppendFile || (sw_filePath != filePath) || sw == null) { // Close last sw object and open new if (sw != null) { sw.Close(); } sw = new StreamWriter(filePath, outputMenagerSettings.AppendFile, outputMenagerSettings.Encoding); sw_filePath = filePath; } if (writeHeader) { // If header is true then write header sw.WriteLine(templateHeader); } // Write body //////////////// TO DO WriteLine bug if (rowID + 1 >= rowMax) { sw.Write(templateBody); //ModuleLog.Write("Write", this, "DestinationFile", ModuleLog.LogType.DEBUG); } else { sw.Write(templateBody); //ModuleLog.Write("WriteLine", this, "DestinationFile", ModuleLog.LogType.DEBUG); } if (writeFooter) { // If header is true then write header sw.WriteLine(templateFooter); } }