コード例 #1
0
        private void buttonExtLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.InitialDirectory = System.IO.Path.Combine(Tools.GetAppDataDirectory(), "Actions");

            if (!System.IO.Directory.Exists(dlg.InitialDirectory))
            {
                System.IO.Directory.CreateDirectory(dlg.InitialDirectory);
            }

            dlg.DefaultExt   = "atf";
            dlg.AddExtension = true;
            dlg.Filter       = "Action Text Files (*.atf)|*.atf|All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader(dlg.FileName))
                {
                    string        err;
                    ActionProgram ap = ActionProgram.FromFile(dlg.FileName, out err);

                    if (ap == null)
                    {
                        Forms.MessageBoxTheme.Show(this, "Failed to load text file" + Environment.NewLine + err);
                    }
                    else
                    {
                        LoadProgram(ap);
                    }
                }
            }
        }
コード例 #2
0
        public ActionProgramRun(ActionFile af,                      // associated file
                                ActionProgram r,                    // the program
                                ConditionVariables iparas,          // input variables to the program only.. not globals
                                ActionRun runner,                   // who is running it..
                                ActionController ed) : base(r.Name) // allow a pause
        {
            actionfile           = af;
            actionrun            = runner;
            actioncontroller     = ed;
            execlevel            = 0;
            execstate[execlevel] = ExecState.On;
            nextstepnumber       = 0;

            System.Diagnostics.Debug.WriteLine("Run " + actionfile.name + "::" + r.Name);
            //ActionData.DumpVars(gvars, " Func Var:");

            inputvars = iparas;             // current vars is set up by ActionRun at the point of invokation to have the latests globals

            List <Action> psteps = new List <Action>();
            Action        ac;

            for (int i = 0; (ac = r.GetStep(i)) != null; i++)
            {
                psteps.Add(Action.CreateCopy(ac));
            }

            programsteps = psteps;
        }
コード例 #3
0
        public string FromJSONObject(JObject jo)
        {
            string errlist = "";

            try
            {
                Clear();

                JArray jf = (JArray)jo["ProgramSet"];

                foreach (JObject j in jf)
                {
                    ActionProgram ap;
                    string        err = ActionProgram.FromJSON(j, out ap);

                    if (err.Length == 0 && ap != null)         // if can't load, we can't trust the pack, so indicate error so we can let the user manually sort it out
                    {
                        programs.Add(ap);
                    }
                    else
                    {
                        errlist += err;
                    }
                }

                return(errlist);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Dump:" + ex.StackTrace);
                errlist = "Exception bad JSON";
            }

            return(errlist);
        }
コード例 #4
0
        void LoadProgram(ActionProgram prog)
        {
            foreach (Group g in groups)
            {
                g.panel.Controls.Clear();
                panelVScroll.Controls.Remove(g.panel);
            }

            groups.Clear();

            curprog = new ActionProgram(prog.Name);

            initialprogname = textBoxBorderName.Text = prog.Name;

            SuspendLayout();
            panelVScroll.SuspendLayout();

            Action ac;
            int    step = 0;

            while ((ac = prog.GetStep(step)) != null)
            {
                Action ca = Action.CreateCopy(ac);// COPY it.. so we can modify without altering current
                curprog.Add(ca);
                CreateStep(-1, ca);
                step++;
            }

            RepositionGroups();
            panelVScroll.ResumeLayout();
            ResumeLayout();
        }
コード例 #5
0
        static public string FromJSON(JObject j, out ActionProgram ap)          // Read from JSON the program
        {
            ap = null;
            string errlist = "";

            string progname = (string)j["Name"];
            JArray steps    = (JArray)j["Steps"];

            if (steps != null)
            {
                ap = new ActionProgram(progname);

                int lineno = 1;

                foreach (JObject js in steps)
                {
                    string stepname   = (string)js["StepName"];
                    string stepUC     = (string)js["StepUC"];
                    int    stepLU     = JSONHelper.GetInt(js["StepLevelUp"], 0);        // optional
                    int    whitespace = JSONHelper.GetInt(js["StepWhitespace"], 0);     // was not in earlier version, optional
                    string comment    = JSONHelper.GetStringDef(js["StepComment"], ""); // was not in earlier version, optional

                    Action cmd = Action.CreateAction(stepname, stepUC, comment, stepLU, whitespace);

                    if (cmd != null && cmd.VerifyActionCorrect() == null)                  // throw away ones with bad names
                    {
                        cmd.LineNumber = lineno++;
                        lineno        += cmd.Whitespace;
                        ap.programsteps.Add(cmd);
                    }
                    else
                    {
                        errlist += "Failed to create " + progname + " step: " + stepname + ":" + stepUC + Environment.NewLine;
                    }
                }
            }
            else
            {
                string file = (string)j["Filename"];

                if (file != null)
                {
                    ap = FromFile(file, out errlist);
                    if (ap != null)
                    {
                        ap.StoredInFile = file;
                        ap.Name         = progname; // override, we have priority
                    }
                }
            }

            return(errlist);
        }
コード例 #6
0
        public void AddOrChange(ActionProgram ap)
        {
            int existing = programs.FindIndex(x => x.Name.Equals(ap.Name));

            if (existing >= 0)
            {
                programs[existing] = ap;
            }
            else
            {
                programs.Add(ap);
            }
        }
コード例 #7
0
        public bool EditInEditor(string file = null)           // edit in editor, swap to this
        {
            try
            {
                if (file == null)                               // if not associated directly with a file, save to a temp one
                {
                    string filename = Name.Length > 0 ? Name : "Default";
                    file = System.IO.Path.Combine(System.IO.Path.GetTempPath(), filename.SafeFileString() + ".atf");

                    if (!SaveText(file))
                    {
                        return(false);
                    }
                }

                while (true)
                {
                    System.Diagnostics.Process p = new System.Diagnostics.Process();
                    p.StartInfo.FileName  = Tools.AssocQueryString(Tools.AssocStr.Executable, ".txt");
                    p.StartInfo.Arguments = file.QuoteString();
                    p.Start();
                    p.WaitForExit();

                    string        err;
                    ActionProgram apin = ActionProgram.FromFile(file, out err);

                    if (apin == null)
                    {
                        DialogResult dr = Forms.MessageBoxTheme.Show("Editing produced the following errors" + Environment.NewLine + Environment.NewLine + err + Environment.NewLine +
                                                                     "Click Retry to correct errors, Cancel to abort editing",
                                                                     "Warning", MessageBoxButtons.RetryCancel);

                        if (dr == DialogResult.Cancel)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        programsteps = apin.programsteps;
                        Name         = apin.Name;
                        StoredInFile = apin.StoredInFile;
                        return(true);
                    }
                }
            }
            catch { }

            Forms.MessageBoxTheme.Show("Unable to run text editor - check association for .txt files");
            return(false);
        }
コード例 #8
0
        public Tuple <ActionFile, ActionProgram> FindProgram(string packname, string progname)
        {
            ActionFile f = actionfiles.Find(x => x.name.Equals(packname));

            if (f != null)
            {
                ActionProgram ap = f.actionprogramlist.Get(progname);   // get in local program list first

                if (ap != null)
                {
                    return(new Tuple <ActionFile, ActionProgram>(f, ap));
                }
            }

            return(null);
        }
コード例 #9
0
        public ActionProgram GetProgram()      // call only when OK returned
        {
            ActionProgram ap = new ActionProgram(curprog.Name, curprog.StoredInFile);

            Action ac;
            int    step = 0;

            while ((ac = curprog.GetStep(step++)) != null)
            {
                if (ac != null)
                {
                    ap.Add(ac);
                }
            }

            return(ap);
        }
コード例 #10
0
        public void Init(string t, EDDiscoveryForm form,
                         List <string> vbs,                                  // list any variables you want in condition statements - passed to config menu, passed back up to condition, not null
                         string pfilesetname,                                // file set name
                         ActionProgram prog   = null,                        // give the program to display
                         string[] defprogs    = null,                        // list any default program names
                         string suggestedname = null, bool edittext = false) // give a suggested name, if prog is null
        {
            discoveryform = form;

            startvarlist   = vbs;
            currentvarlist = new List <string>(startvarlist);

            bool winborder = discoveryform.theme.ApplyToForm(this, SystemFonts.DefaultFont);

            statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder;
            this.Text = label_index.Text = t;

            filesetname   = pfilesetname;
            labelSet.Text = filesetname + "::";
            textBoxBorderName.Location = new Point(labelSet.Location.X + labelSet.Width + 8, textBoxBorderName.Location.Y);

            if (defprogs != null)
            {
                definedprograms = defprogs;
            }

            if (suggestedname != null)
            {
                textBoxBorderName.Text = suggestedname;
            }

            if (prog != null)
            {
                LoadProgram(prog);
            }

            panelVScroll.ContextMenuStrip = contextMenuStrip1;
            panelVScroll.MouseDown       += panelVScroll_MouseDown;

            editastextimmediately = edittext;

#if !DEBUG
            buttonExtDisk.Visible = false;
#endif
        }
コード例 #11
0
ファイル: ActionRun.cs プロジェクト: caiodias/EDDiscovery
        // now = true, run it immediately, else run at end of queue.  Optionally pass in handles and dialogs in case its a sub prog

        public void Run(bool now, ActionFile fileset, ActionProgram r, ConditionVariables inputparas,
                        ConditionFileHandles fh = null, Dictionary <string, Forms.ConfigurableForm> d = null, bool closeatend = true)
        {
            if (now)
            {
                if (progcurrent != null)                    // if running, push the current one back onto the queue to be picked up
                {
                    progqueue.Insert(0, progcurrent);
                }

                progcurrent = new ActionProgramRun(fileset, r, inputparas, this, actioncontroller);   // now we run this.. no need to push to stack

                progcurrent.PrepareToRun(new ConditionVariables(progcurrent.inputvariables, actioncontroller.Globals),
                                         fh == null ? new ConditionFileHandles() : fh, d == null ? new Dictionary <string, Forms.ConfigurableForm>() : d, closeatend);              // if no filehandles, make them and close at end
            }
            else
            {
                progqueue.Add(new ActionProgramRun(fileset, r, inputparas, this, actioncontroller));
            }
        }