/// <summary> /// Export process to code folder in vs project /// </summary> /// <param name="fi"></param> /// <param name="mapedFile"></param> private void Export_Process(FileInfo fi) { #region Mapped process template file FileInfo f_prc_template = new DirectoryInfo(SYS_MAPS_PATH).GetFiles(dGLOBALS.MAPS_PROCESS)[0]; String prc_template = File.ReadAllText(f_prc_template.FullName); #endregion #region Loop into processes JSonFile jProcess = new JSonFile(fi.FullName); if ((jProcess.jActiveObj[dPROCESS.PROCESSES] != null) && (fi.Name != "base_process.json")) { String functions = ""; String base_processes = ""; #region create path to code // export code to String code_path = (system_app) ? System_code_path : dEXPORTCODE.VS_CODE_PATH; String codeMapPath = Path.Combine(APP_VSPROJECT_PATH, code_path); String processes_path = DAPP_PRC.FullName; String file_path = fi.FullName.Replace(processes_path, ""); String relative_path = ""; String filename = ""; foreach (String dir in file_path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries)) { if (!dir.Contains(".json")) { relative_path = Path.Combine(relative_path, dir); if (!Directory.Exists(Path.Combine(codeMapPath, relative_path))) { Directory.CreateDirectory(Path.Combine(codeMapPath, relative_path)); } } else { filename = dir.Replace(".json", ".cs"); } } #endregion #region Get code from logic and insert into process file foreach (JToken Jnode in jProcess.jActiveObj[dPROCESS.PROCESSES] as JArray) { // Get code from logic String Guid = Jnode[dPROCESS.GUID].ToString(); String Name = (Jnode[dPROCESS.NAME] != null) ? Jnode[dPROCESS.NAME].ToString() : ""; String Desciption = (Jnode[dPROCESS.DESCRIPTION] != null) ? Jnode[dPROCESS.DESCRIPTION].ToString() : ""; String prc_code = CLogicEditor.get_Code_from_logic(ARQODE_PATH, Guid); if ((prc_code == "") && (Jnode[dPROCESS.CODE] != null) && (Jnode[dPROCESS.CODE].ToString() != "")) { prc_code = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(Jnode[dPROCESS.CODE].ToString())); } if (prc_code != "") { // Save into current process Jnode[dPROCESS.CODE] = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(prc_code)); // write replaced template file to mapped folder. Renaming guid to valid function name functions += dEXPORTCODE.F_TEMPLATE. Replace(dEXPORTCODE.F_NAME, Name). Replace(dEXPORTCODE.F_DESCRIPTION, Desciption). Replace(dEXPORTCODE.F_FUNCTION_NAME, Utils.escape_sc(Guid)). Replace(dEXPORTCODE.F_CODE, prc_code); } #region Save base process string JToken base_prc = Jnode.DeepClone(); if (Jnode[dPROCESS.CODE] != null) { ((JObject)base_prc).Property(dPROCESS.CODE).Remove(); } base_processes += "public static string BP_" + Utils.escape_sc(Guid) + " { get { return \"" + Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(base_prc.ToString())) + "\"; } } \r\n"; #endregion } jProcess.Write(); #endregion if (functions != "") { #region Save process file prc_template = prc_template .Replace(dEXPORTCODE.F_FUNCTIONS, functions) // Replace functions .Replace(dEXPORTCODE.F_BASE_PROCESSES, base_processes); // Replace base processs strings File.WriteAllText(Path.Combine(codeMapPath, Path.Combine(relative_path, filename)), prc_template); #endregion #region Insert into VS project file // Add node if not founded else remove from pj_compile list if (!pj_compile_items.ContainsKey(Path.Combine(code_path, Path.Combine(relative_path, filename)))) { XmlNode xnode = x_pj.CreateNode(XmlNodeType.Element, dEXPORTCODE.VS_PJ_ITEM_COMPILE, null); XmlAttribute xatt = x_pj.CreateAttribute(dEXPORTCODE.VS_PJ_ATT_INCLUDE); xatt.Value = Path.Combine(code_path, Path.Combine(relative_path, filename)); xnode.Attributes.Append(xatt); x_item_group.AppendChild(xnode); changes_in_pj = true; } else { pj_compile_items.Remove(Path.Combine(code_path, Path.Combine(relative_path, filename))); } #endregion } } #endregion }
/// <summary> /// Find in processes process all words in find_str /// </summary> /// <param name="fi"></param> /// <param name="find_str"></param> /// <param name="findedProcesses"></param> private void find_in_processes(FileInfo fi, ArrayList find_str, ref List <KeyValuePair <JToken, int> > findedProcesses) { JSonFile jProcess = new JSonFile(fi.FullName); int max_founded = 0; int founded = 0; // Search in calls if (jProcess.jActiveObj["processes"] != null) { foreach (JToken Jnode in jProcess.jActiveObj["processes"] as JArray) { String Guid = Jnode["Guid"].ToString(); Jnode["Guid"] = ""; founded = 0; String cad_bus = ""; if (find_str.Count > 2) { foreach (string find in find_str) { cad_bus += find + " "; } if (Jnode.ToString().ToLower().Contains(cad_bus)) { founded += 2; } cad_bus = ""; } for (int i = 1; i < find_str.Count && find_str.Count > 1; i++) { cad_bus = find_str[i - 1] + " " + find_str[i]; if (Jnode.ToString().ToLower().Contains(cad_bus)) { founded += 1; } } foreach (string find in find_str) { if (Jnode.ToString().ToLower().Contains(find.ToLower())) { founded++; } } if (founded >= find_str.Count) { if (max_founded < founded) { max_founded = founded; } JObject jfind = new JObject(); jfind["Process"] = fi.FullName; jfind["Process guid"] = Guid; jfind["Process name"] = (Jnode["Name"] != null) ? Jnode["Name"] : Guid; findedProcesses.Add(new KeyValuePair <JToken, int>(jfind, founded)); } } } #region find in path founded = 0; foreach (string find in find_str) { if (fi.FullName.ToLower().Contains(find.ToLower())) { founded++; } } if (founded >= find_str.Count - 1) { JObject jfind = new JObject(); jfind["Process"] = fi.FullName; jfind["Process guid"] = ""; jfind["Process name"] = ""; if (max_founded < founded) { max_founded = founded; } findedProcesses.Add(new KeyValuePair <JToken, int>(jfind, max_founded + (founded - find_str.Count))); } #endregion }