/// <summary>
 /// Check integrity in program processes
 /// </summary>
 /// <param name="fi"></param>
 /// <param name="FindedPrograms"></param>
 /// <returns></returns>
 private bool check_integrity_in_process(FileInfo fi, ref ArrayList FindedPrograms)
 {
     try
     {
         JSonFile jProgram     = new JSonFile(fi.FullName);
         String   program_path = fi.FullName.Replace(Globals.AppDataSection(dPATH.PROGRAM).FullName + "\\", "").Replace("\\", ".").Replace(".json", "");
         TErrors  er           = new TErrors(Globals, program_path);
         foreach (JObject prc_node in jProgram.jActiveObj["Logic"] as JArray)
         {
             if (prc_node.Properties().Count() > 0)
             {
                 TProcess prc = new TProcess(sys, Globals, prc_node);
                 if (!CDataIntegrity.CheckAllVariables(prc, ref er))
                 {
                     FindedPrograms.Add(String.Format("Program: {0}: \r\n   -> Process: {1} \r\n   -> {2}",
                                                      program_path, prc.Name, er.getErrors().ToString()));
                 }
             }
         }
     }
     catch (Exception exc)
     {
         FindedPrograms.Add(exc.Message);
     }
     return(false);
 }
Exemple #2
0
        /// <summary>
        /// Execute process by program process object
        /// </summary>
        /// <param name="prc_node"></param>
        /// <returns></returns>
        private TProcess execute_process(JObject prc_node)
        {
            // Get process base
            TProcess proc = new TProcess(sys, ref vars, prc_node);

            // set active process to errors
            sys.ProgramErrors.Active_Process = proc;

            // run recursive processes in inputs
            //for (int i = 0; i < proc.Inputs.Count(); i++)
            //{
            //    JToken jActiveInput = proc.Inputs.ElementAt(i);
            //    if ((jActiveInput != null) && (jActiveInput is JObject) && (jActiveInput[dPROCESS.GUID.ToString()] != null))
            //    {
            //        TProcess act_prc = execute_process(jActiveInput as JObject);
            //    }
            //}

            if (!sys.ProgramErrors.hasErrors())
            {
                // run current proccess
                if (ExecuteProcess != null)
                {
                    ExecuteProcess(proc);
                }

                debug.Processes.Add(proc.Data);
                return(proc);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Prepare for execute process
        /// </summary>
        /// <param name="prc"></param>
        /// <returns></returns>
        public void Run(TProcess proc)
        {
            prc = proc;

            // Check inputs first
            if (CDataIntegrity.CheckAllVariables(prc, ref errors))
            {
                // init timer
                DateTime prcInitTime = DateTime.Now;

                // Execute process
                debug.cprint(String.Format("Running process: '{0}', from program {1} and view {2}",
                                           (prc.Name != null) ? prc.Name.ToString() : prc.Guid, event_desc.Program, event_desc.View_Name));

                try
                {
                    Type       t  = this.GetType();
                    MethodInfo mi = t.GetMethod("f_" + TLogic.Utils.escape_sc(prc.Guid));
                    mi.Invoke(this, null);
                }
                catch (Exception exc)
                {
                    errors.unhandledError = exc.Message;
                }

                // set process time
                prc.Total_time = Math.Round((DateTime.Now - prcInitTime).TotalSeconds, 2);
            }
        }
Exemple #4
0
        /// <summary>
        /// Prepare for execute process
        /// </summary>
        /// <param name="prc"></param>
        /// <returns></returns>
        public void Run(TProcess proc)
        {
            prc_error = false;
            prc       = proc;

            // Check inputs first
            if (CDataIntegrity.CheckAllVariables(prc, ref errors))
            {
                if ((Globals.is_system) && (!App_globals.is_system))
                {
                    try
                    {
                        Type       t  = this.GetType();
                        MethodInfo mi = t.GetMethod("f_" + escape_sc(prc.Guid));
                        mi.Invoke(this, null);
                    }
                    catch (Exception exc)
                    {
                        errors.unhandledError = exc.Message;
                    }
                }
                else
                {
                    // init timer
                    DateTime prcInitTime = DateTime.Now;

                    // Execute process
                    debug.cprint(String.Format("Running process: '{0}', from program {1} and view {2}",
                                               (prc.Name != null) ? prc.Name.ToString() : prc.Guid, event_desc.Program, event_desc.View_Name));

                    if (prc.Edit_code == "1")
                    {
                        SendToEditor();
                    }
                    else
                    {
                        if (execute_process(prc.Guid))
                        {
                            //si no se encuentra el proceso enviar a código la ejecución
                            SendToEditor();
                        }
                    }

                    // set process time
                    prc.Total_time = Math.Round((DateTime.Now - prcInitTime).TotalSeconds, 2);

                    if (prc_error)
                    {
                        // if error send process to editor
                        SendToEditor();
                    }
                }
            }
        }
Exemple #5
0
        /// #NAME#: #DESCRIPTION#
        public void f_f59c1ab8_4979_49af_9503_26fcf239135b()
        {
            //INI CODE PRCGUID: f59c1ab8-4979-49af-9503-26fcf239135b

            ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);

            if (CVentanaProgramas.Proceso_de_programa_activo != null)
            {
                TProcess tempPrc = prc;
                prc = new TProcess(sys, App_globals, CVentanaProgramas.Proceso_de_programa_activo as JObject);
                SendToEditor();
                //CLogicEditor.SaveCode(Globals.ARQODE_APP);
                prc = tempPrc;
            }


//END CODE PRCGUID: f59c1ab8-4979-49af-9503-26fcf239135b
        }
Exemple #6
0
        /// <summary>
        /// Check all inputs in process
        /// </summary>
        /// <returns></returns>
        public static bool CheckAllVariables(TProcess prc, ref TErrors errors)
        {
            bool no_Input_errors = true;

            foreach (JToken input in prc.BaseInputs)
            {
                if ((!input.ToString().StartsWith("-")) && ((prc.Inputs.Count() == 0) || (prc.Inputs[input.ToString()].ToString() == "")))
                {
                    no_Input_errors = false;
                    errors.noInputs = String.Format("Error: no input '{0}' found in current program.", input.ToString());
                }
            }
            bool no_configs_errors = true;

            foreach (JToken conf in prc.BaseConfiguration)
            {
                if ((!conf.ToString().StartsWith("-")) && ((prc.Configuration.Count() == 0) || (prc.Configuration[conf.ToString()].ToString() == "")))
                {
                    no_configs_errors      = false;
                    errors.noConfiguration = String.Format("Error: no configuration '{0}' found in current program.", conf.ToString());
                }
            }

            bool no_outputs_errors = true;

            foreach (JToken output in prc.BaseOutputs)
            {
                if ((!output.ToString().StartsWith("-")) && ((prc.Outputs.Count() == 0) || (prc.Outputs[output.ToString()].ToString() == "")))
                {
                    no_outputs_errors = false;
                    errors.noOutputs  = String.Format("Error: no output '{0}' found out current program.", output.ToString());
                }
            }

            return(no_Input_errors && no_configs_errors && no_outputs_errors);
        }
Exemple #7
0
        /// #NAME#: #DESCRIPTION#
        public void f_9af9d8c3_c621_460b_96a7_fa53cde549dd()
        {
            //INI CODE PRCGUID: 9af9d8c3-c621-460b-96a7-fa53cde549dd


            #region Variables

            ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);
            TProcess tempprc = new TProcess(sys, App_globals, (JObject)CVentanaProgramas.Proceso_de_programa_activo);


            String codigo_prc = CLogicEditor.get_Code_from_logic(Globals.ARQODE_APP, tempprc.Guid);
            if ((codigo_prc == "") && (tempprc.Code != null) && (tempprc.Code.ToString() != ""))
            {
                codigo_prc = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(tempprc.Code.ToString()));
            }
            // Outputs vars
            Outputs("Código del proceso", codigo_prc);
            #endregion



            //END CODE PRCGUID: 9af9d8c3-c621-460b-96a7-fa53cde549dd
        }
Exemple #8
0
        /// #NAME#: #DESCRIPTION#
        public void f_Cargar_subprogramas()
        {
            //INI CODE PRCGUID: Cargar subprogramas

            ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);
            TreeNode ActiveNode = CVentanaProgramas.ArbolProgramas.SelectedNode;
            int      row_index  = 0;
            int      col_index  = 0;

            if ((ActiveNode != null) && (ActiveNode.Text.EndsWith(".json")))
            {
                CProgram CurrentProg = new CProgram(sys, App_globals, ActiveNode.FullPath.Replace(dPROGRAM.FOLDER + "\\", "").Replace(".json", "").Replace("\\", "."));
                CVentanaProgramas.Namespace_programa_activo = CurrentProg.Program_namespace;

                #region Guardar namespace actual en histórico
                DataTable dt = null;
                if (CVentanaProgramas.Historico_de_programas == null)
                {
                    dt = new DataTable();
                    dt.Columns.Add("Path");
                    dt.Columns.Add("Program name");
                    CVentanaProgramas.Historico_de_programas = dt;
                }
                else
                {
                    dt = (DataTable)CVentanaProgramas.Historico_de_programas;
                }
                if (!((dt.Rows.Count > 0) && (dt.Rows[0][0].ToString() == CurrentProg.Program_namespace)))
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = dPROGRAM.FOLDER + "." + CurrentProg.Program_namespace;
                    dr[1] = CurrentProg.Program_namespace;
                    dt.Rows.InsertAt(dr, 0);
                }

                Outputs("Histórico de programas", dt);
                #endregion

                if (CurrentProg.Logic != null)
                {
                    if ((CVentanaProgramas.ListaProcesos.RowCount > 0) && (CVentanaProgramas.ListaProcesos.SelectedCells.Count > 0))
                    {
                        row_index = CVentanaProgramas.ListaProcesos.SelectedCells[0].RowIndex;
                        col_index = CVentanaProgramas.ListaProcesos.SelectedCells[0].ColumnIndex;
                    }

                    JArray JProcess_array = new JArray();
                    foreach (JObject prc_node in CurrentProg.Logic)
                    {
                        if (prc_node.Count > 0)
                        {
                            TProcess CurrentProc = new TProcess(sys, App_globals, prc_node);

                            JObject JRow = new JObject();
                            JRow.Add("Editor", CurrentProc.Edit_code == "1");
                            JRow.Add("Guid", CurrentProc.Guid.ToString());
                            String Name = (CurrentProc.Name != null) ? CurrentProc.Name.ToString() : CurrentProc.Guid.ToString();
                            JRow.Add("Name", Name);

                            if (Name.EndsWith("Call"))
                            {
                                String call_at_end = "";
                                if (CurrentProc.Configuration["program"].ToString().StartsWith("&"))
                                {
                                    call_at_end = "(Execute at end). ";
                                }

                                JRow.Add("Description", call_at_end + CurrentProc.Configuration["program"].ToString());
                            }
                            else
                            {
                                JRow.Add("Description", (CurrentProc.Description != null) ? CurrentProc.Description.ToString() : "");
                            }

                            JProcess_array.Add(JRow);
                        }
                    }
                    CVentanaProgramas.Procesos_programa_activo = CurrentProg.Logic;

                    DataGridViewCheckBoxColumn c1 = new DataGridViewCheckBoxColumn()
                    {
                        ValueType = typeof(bool),
                        Name      = "Editor"
                    };

                    DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn();
                    c2.ValueType = typeof(string);
                    c2.Name      = "Guid";
                    DataGridViewTextBoxColumn c3 = new DataGridViewTextBoxColumn();
                    c3.ValueType = typeof(string);
                    c3.Name      = "Name";
                    DataGridViewTextBoxColumn c4 = new DataGridViewTextBoxColumn();
                    c4.ValueType = typeof(string);
                    c4.Name      = "Description";
                    CVentanaProgramas.ListaProcesos.Columns.Clear();
                    CVentanaProgramas.ListaProcesos.Columns.Add(c1);
                    CVentanaProgramas.ListaProcesos.Columns.Add(c2);
                    CVentanaProgramas.ListaProcesos.Columns.Add(c3);
                    CVentanaProgramas.ListaProcesos.Columns.Add(c4);
                    CVentanaProgramas.ListaProcesos.DataSource = null;

                    CVentanaProgramas.ListaProcesos.Rows.Clear();
                    foreach (JToken Jpro in JProcess_array)
                    {
                        CVentanaProgramas.ListaProcesos.Rows.Add(Jpro["Editor"], Jpro["Guid"], Jpro["Name"], Jpro["Description"]);
                    }
                    CVentanaProgramas.ListaProcesos.AllowUserToAddRows  = false;
                    CVentanaProgramas.ListaProcesos.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

                    if (CVentanaProgramas.ListaProcesos.RowCount > 0)
                    {
                        if ((CVentanaProgramas.ListaProcesos.Rows.Count > row_index) && (CVentanaProgramas.ListaProcesos.Columns.Count > col_index))
                        {
                            CVentanaProgramas.ListaProcesos[col_index, row_index].Selected = true;
                            CVentanaProgramas.ListaProcesos[0, 0].Selected = false;
                        }
                    }
                    CVentanaProgramas.ListaProcesos.Columns[0].Width = 40;
                    CVentanaProgramas.ListaProcesos.Columns[1].Width = 200;
                }
                else
                {
                    MessageBox.Show("El programa seleccionado contiene errores, revisar formato del json.");
                }
            }
            else
            {
                CVentanaProgramas.ListaProcesos.Rows.Clear();
            }
            //END CODE PRCGUID: Cargar subprogramas
        }
Exemple #9
0
 /// <summary>
 /// Event program run
 /// </summary>
 /// <param name="prc"></param>
 private void Program_ExecuteProcess(TProcess prc)
 {
     logic.Run(prc);
 }
Exemple #10
0
        /// <summary>
        /// Send code to editor
        /// </summary>
        /// <param name="arqode_path"></param>
        /// <param name="sys_app_path"></param>
        /// <param name="app_path"></param>
        /// <param name="app_name"></param>
        /// <param name="p_guid"></param>
        /// <param name="prc"></param>
        public static void SendCodeToEditor(String app_path, String app_name, String p_guid, TProcess prc)
        {
            CGlobals sys_globals  = new CGlobals();
            String   sys_app_path = sys_globals.App_path.FullName;
            String   arqode_path  = sys_globals.ARQODE_APP;

            // Save code in editor
            String editor_prc_guid = SaveCode(arqode_path, prc.Guid);

            if (prc.Guid != editor_prc_guid)
            {
                // get map vars code
                CMap cmap = new CMap(sys_app_path, app_path, arqode_path, app_name);

                // Map changes in views
                cmap.MapViews();

                // Map all vars
                String varsregion = cmap.MapVars(prc.BaseInputs as JArray, prc.BaseOutputs as JArray, prc.BaseConfiguration as JArray, prc.vars);

                // Get code file
                String codefile_path = Path.Combine(arqode_path, dEXPORTCODE.P_CODER_CS);
                String codefile      = File.ReadAllText(codefile_path);

                // get code from logic or from process json file
                String codigo_prc = get_Code_from_logic(arqode_path, p_guid);
                if ((codigo_prc == "") && (prc.Code != null) && (prc.Code.ToString() != ""))
                {
                    codigo_prc = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(prc.Code.ToString()));
                }

                if (codigo_prc != "")
                {
                    if (((dEXPORTCODE.P_Ini_code_process_mark + p_guid) == codigo_prc.Split('\n')[0].Replace("\r", "")) && (codefile.Contains(dEXPORTCODE.P_Begin_editor_code_mark)))
                    {
                        int write_code_index = write_code_index = codefile.IndexOf(dEXPORTCODE.P_Begin_editor_code_mark) + dEXPORTCODE.P_Begin_editor_code_mark.Length;

                        codefile = codefile.Insert(write_code_index, "\n\n" + codigo_prc);
                        File.WriteAllText(codefile_path, codefile);
                    }
                }
                else
                {
                    String prc_name = "//" + prc.Name.ToString();
                    codigo_prc = dEXPORTCODE.P_Ini_code_process_mark + p_guid + "\n" + prc_name + "\n\n" + varsregion + "\n\n" + dEXPORTCODE.P_End_code_process_mark + p_guid;
                    int write_code_index = write_code_index = codefile.IndexOf(dEXPORTCODE.P_Begin_editor_code_mark) + dEXPORTCODE.P_Begin_editor_code_mark.Length;
                    codefile = codefile.Insert(write_code_index, "\n\n" + codigo_prc);

                    File.WriteAllText(codefile_path, codefile);
                }
            }
        }
Exemple #11
0
        /// #NAME#: #DESCRIPTION#
        public void f_17250dd1_6cd2_4b1b_a7cd_58ec52297bb8()
        {
            //INI CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8

            String fichero_de_salida = Input_str("Fichero de salida");

            if (fichero_de_salida != "")
            {
                // current program
                ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);
                String ns_programa = CVentanaProgramas.Namespace_programa_activo.ToString();

                // program stack for recursive exploration
                Stack <KeyValuePair <int, CProgram> > s_prog = new Stack <KeyValuePair <int, CProgram> >();

                // Progs and procs dictionarys
                Dictionary <String, JToken> exp_programs  = new Dictionary <string, JToken>();
                Dictionary <String, JToken> exp_processes = new Dictionary <String, JToken>();

                CProgram cprog = new CProgram(sys, App_globals, ns_programa);
                while ((ns_programa != "") || (s_prog.Count > 0))
                {
                    int i = 0;

                    // Restore program from stack
                    if (cprog == null)
                    {
                        KeyValuePair <int, CProgram> k_prog = s_prog.Pop();
                        i     = k_prog.Key;
                        cprog = k_prog.Value;
                    }
                    int  n_prcs     = ((JArray)cprog.Logic).Count;
                    bool force_exit = false;

                    // Save program and inner processes
                    while ((!force_exit) && (i < n_prcs))
                    {
                        TProcess proc = new TProcess(sys, App_globals, (JObject)((JArray)cprog.Logic).ElementAt(i));
                        if (!exp_programs.ContainsKey(cprog.Program_namespace))
                        {
                            // add program only once
                            exp_programs.Add(cprog.Program_namespace, cprog.get_json.DeepClone());
                        }

                        i++;
                        if (proc.Guid == "Call")
                        {
                            // Add current program to stack and atach the new one for explore recursively
                            s_prog.Push(new KeyValuePair <int, CProgram>(i, cprog));
                            cprog       = new CProgram(sys, App_globals, proc.Configuration["program"].ToString());
                            ns_programa = cprog.Program_namespace;
                            force_exit  = true;
                        }
                        else if (!exp_processes.ContainsKey(proc.Guid))
                        {
                            // add process only once
                            exp_processes.Add(proc.Guid, proc.get_json.DeepClone());
                        }
                    }
                    if ((i == n_prcs) && (!force_exit))
                    {
                        // set null program only if previous bucle ends
                        cprog       = null;
                        ns_programa = "";
                    }
                }

                #region Create zip

                Ionic.Zip.ZipFile exp_file = null;
                if (File.Exists(fichero_de_salida))
                {
                    exp_file = Ionic.Zip.ZipFile.Read(fichero_de_salida);
                }
                else
                {
                    exp_file = new Ionic.Zip.ZipFile(fichero_de_salida);
                }

                #region add programs & ns conversions to zip file

                String entry_path     = "";
                String base_file_path = "";
                JArray jConversion    = new JArray();

                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    Ionic.Zip.ZipEntry ze = exp_file.Entries.Where(entry => entry.FileName == dEXPORTCODE.STR_IMPORT_CONVS).FirstOrDefault();

                    MemoryStream ms = new MemoryStream();
                    ze.Extract(ms);
                    byte[] entry_data   = ms.ToArray();
                    String file_content = System.Text.Encoding.Default.GetString(entry_data);
                    ms.Close();
                    jConversion = JArray.Parse(file_content);
                }
                foreach (String sprog in exp_programs.Keys)
                {
                    base_file_path = escape_sc(sprog);

                    // Conversions
                    String  new_ns = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path;
                    JObject jconv  = new JObject(new JProperty(sprog, new_ns));
                    jConversion.Add(jconv);

                    // Add program
                    entry_path = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path + ".json";
                    if (!exp_file.ContainsEntry(entry_path))
                    {
                        exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(exp_programs[sprog].ToString()));
                    }
                }
                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    exp_file.UpdateEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                else
                {
                    exp_file.AddEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                #endregion

                #region Create processes file

                JSonFile jfTemplate = new JSonFile(Globals.AppDataSection(dPATH.PROCESSES), dGLOBALS.PROCESS_TEMPLATE.Replace(".json", ""));
                foreach (JToken jproc in exp_processes.Values)
                {
                    ((JArray)jfTemplate.get(dPROCESS.PROCESSES)).Add(jproc);
                }
                #endregion

                #region add processes file

                base_file_path = escape_sc(CVentanaProgramas.Namespace_programa_activo.ToString());
                entry_path     = dPROCESS.FOLDER + "\\Imports\\" + base_file_path + ".json";
                if (!exp_file.ContainsEntry(entry_path))
                {
                    exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(jfTemplate.jActiveObj.ToString()));
                }
                #endregion

                exp_file.Save();

                #endregion

                MessageBox.Show(String.Format("Program exported {0}", CVentanaProgramas.Namespace_programa_activo.ToString()));
            }

            //END CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8
        }