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..
                                ActionCoreController 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 <ActionBase> psteps = new List <ActionBase>();
            ActionBase        ac;

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

            programsteps = psteps;
        }
        public void CreateSet(string s, string appfolder)
        {
            ActionFile af = new ActionFile(appfolder + "\\\\" + s + ".act", s);

            af.WriteFile();
            actionfiles.Add(af);
        }
 public void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile file, ActionPackEditorForm.AdditionalNames func)
 {
     onAdditionalNames = func;
     cd                   = new Condition(cond); // full clone, we can now modify it.
     actionfile           = file;
     actioncorecontroller = cp;
     applicationfolder    = appfolder;
     InitSub(events);
 }
        public string LoadAllActionFiles(string appfolder)              // loads or reloads the actions, dep on if present in list
        {
            if (!Directory.Exists(appfolder))
            {
                Directory.CreateDirectory(appfolder);
            }

            FileInfo[] allFiles = Directory.EnumerateFiles(appfolder, "*.act", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

            string errlist = "";

            foreach (FileInfo f in allFiles)
            {
                int indexof = actionfiles.FindIndex(x => x.filepath.Equals(f.FullName));

                ActionFile af;

                if (indexof == -1)                  // if we don't have it, new it.. else overwrite it
                {
                    af = new ActionFile();
                }
                else
                {
                    af = actionfiles[indexof];      // overwriting keeps any dynamic data action files have
                }
                bool   readenable;
                string err = af.ReadFile(f.FullName, out readenable);       // re-read it in.  Note it does not kill the fileaveriables

                if (err.Length == 0)
                {
                    if (indexof == -1)
                    {
                        System.Diagnostics.Debug.WriteLine("Add pack " + af.name);
                        actionfiles.Add(af);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Update Pack " + af.name);
                    }
                }
                else
                {
                    errlist += "File " + f.FullName + " failed to load: " + Environment.NewLine + err;
                    if (indexof != -1)
                    {
                        actionfiles.RemoveAt(indexof);          // remove dead packs
                        System.Diagnostics.Debug.WriteLine("Delete Pack " + af.name);
                    }
                }
            }

            return(errlist);
        }
        public void Init(string title, Icon ic, ActionCoreController cp, string appfolder, ActionFile file, List <ActionEvent> evlist, string collapsestate)       // here, change to using events
        {
            this.Icon            = ic;
            actioncorecontroller = cp;
            applicationfolder    = appfolder;
            actionfile           = file;
            events = evlist;

            var enumlist = new Enum[] { AFIDs.ActionPackEditPackForm_buttonInstallationVars, AFIDs.ActionPackEditPackForm_labelEditProg };

            BaseUtils.Translator.Instance.TranslateControls(this, enumlist);

            grouptypenames = (from e in events select e.UIClass).ToList().Distinct().ToList();      // here we extract from events relevant data
            groupeventlist = new Dictionary <string, List <string> >();
            foreach (string s in grouptypenames)
            {
                groupeventlist.Add(s, (from e in events where e.UIClass == s select e.TriggerName).ToList());
            }

            bool winborder = ExtendedControls.Theme.Current.ApplyDialog(this);    // scale to font

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

            ConditionLists clist = actionfile.FileEventList;    // now load the initial conditions from the action file

            string eventname = null;

            for (int i = 0; i < clist.Count; i++)       // for ever event, find the condition, create the group, theme
            {
                string gname = clist[i].GroupName;
                if (gname != eventname)
                {
                    eventname = gname;
                    Group gg = CreateGroup(false, null, gname);
                    gg.collapsed = collapsestate.Contains("<" + gname + ";");
                    groups.Add(gg);
                }

                Condition cd = clist[i];
                Group     g  = CreateGroup(true, cd, null);
                groups.Add(g);
            }

            foreach (Group g in groups)     // add the groups to the vscroller
            {
                panelVScroll.Controls.Add(g.panel);
            }

            PositionGroups(true);       //repositions all items

            Usercontrol_RefreshEvent();
        }
        public Tuple <ActionFile, ActionProgram> FindProgram(string req, ActionFile preferred = null)        // find a program
        {
            ActionProgram ap = null;

            string file = null, prog;
            int    colon = req.IndexOf("::");

            if (colon != -1)
            {
                file = req.Substring(0, colon);
                prog = req.Substring(colon + 2);
            }
            else
            {
                prog = req;
            }

            if (file != null)                             // if file given, only search that
            {
                ActionFile f = actionfiles.Find(x => x.name.Equals(file));

                if (f != null)      // found file..
                {
                    ap = f.actionprogramlist.Get(prog);

                    return((ap != null) ? new Tuple <ActionFile, ActionProgram>(f, ap) : null);
                }
            }
            else
            {
                if (preferred != null)                          // if no file stated, and we have a preferred
                {
                    ap = preferred.actionprogramlist.Get(prog); // get in local program list first

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

                foreach (ActionFile f in actionfiles)
                {
                    ap = f.actionprogramlist.Get(prog);

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

            return(null);
        }
        public void Init(string t, Icon ic, ActionCoreController cp, string appfolder, ActionFile file, List <ActionEvent> evlist, string collapsestate)       // here, change to using events
        {
            this.Icon            = ic;
            actioncorecontroller = cp;
            applicationfolder    = appfolder;
            actionfile           = file;
            events = evlist;

            grouptypenames = (from e in events select e.UIClass).ToList().Distinct().ToList();      // here we extract from events relevant data
            groupeventlist = new Dictionary <string, List <string> >();
            foreach (string s in grouptypenames)
            {
                groupeventlist.Add(s, (from e in events where e.UIClass == s select e.TriggerName).ToList());
            }

            bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont);

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

            ConditionLists clist = actionfile.actioneventlist;          // now load the initial conditions from the action file


            string eventname = null;

            for (int i = 0; i < clist.Count; i++)       // for ever event, find the condition, create the group, theme
            {
                string gname = clist.GetGroupName(i);
                if (gname != eventname)
                {
                    eventname = gname;
                    Group gg = CreateGroup(false, null, gname);
                    gg.collapsed = collapsestate.Contains("<" + gname + ";");
                    groups.Add(gg);
                }

                Condition cd = clist.Get(i);
                Group     g  = CreateGroup(true, cd, null);
                groups.Add(g);
            }

            foreach (Group g in groups)     // add the groups to the vscroller
            {
                panelVScroll.Controls.Add(g.panel);
            }

            PositionGroups(true);       //repositions all items

            Usercontrol_RefreshEvent();
        }
        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);
        }
Exemple #9
0
        // 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, Variables inputparas,
                                FunctionPersistentData fh = null, Dictionary<string, ExtendedControls.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 Variables(progcurrent.inputvariables, actioncontroller.Globals, fileset.filevariables),
                                                fh == null ? new FunctionPersistentData() : fh, d == null ? new Dictionary<string, ExtendedControls.ConfigurableForm>() : d, closeatend);        // if no filehandles, make them and close at end
            }
            else
            {
                progqueue.Add(new ActionProgramRun(fileset, r, inputparas, this, actioncontroller));
            }
        }
        public void Init(string t, Icon ic, ActionCoreController cp, string appfolder, ActionFile file, List <ActionEvent> evlist)       // here, change to using events
        {
            this.Icon            = ic;
            actioncorecontroller = cp;
            applicationfolder    = appfolder;
            actionfile           = file;
            events = evlist;

            grouptypenames = (from e in events select e.uiclass).ToList().Distinct().ToList();      // here we extract from events relevant data
            groupeventlist = new Dictionary <string, List <string> >();
            foreach (string s in grouptypenames)
            {
                groupeventlist.Add(s, (from e in events where e.uiclass == s select e.triggername).ToList());
            }

            bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont);

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

            ConditionLists clist = actionfile.actioneventlist;          // now load the initial conditions from the action file

            groups = new List <Group>();

            for (int i = 0; i < clist.Count; i++)       // for ever event, find the condition, create the group, theme
            {
                Condition cd = clist.Get(i);
                Group     g  = CreateGroup(cd);
                groups.Add(g);
                ExtendedControls.ThemeableFormsInstance.Instance.ApplyToControls(g.panel, SystemFonts.DefaultFont);
            }

            foreach (Group g in groups)     // add the groups to the vscroller
            {
                panelVScroll.Controls.Add(g.panel);
            }

            PositionGroups(true);       //repositions all items

            this.Text = label_index.Text = initialtitle + " (" + groups.Count.ToString() + " conditions)";

            Usercontrol_RefreshEvent();
        }
Exemple #11
0
        static public bool SetEnableFlag(string file, bool enable)              // change the enable flag. Read in,write out.
        {                                                                       // true if managed to change it..
            try
            {
                ActionFile f = new ActionFile();

                bool readenable;
                if (f.ReadFile(file, out readenable).Length == 0)        // read it in..
                {
                    f.enabled = enable;
                    f.WriteFile();                                // write it out.
                    //  System.Diagnostics.Debug.WriteLine("Set Enable " + file + " " + enable );
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
        public event AdditionalNames onAdditionalNames;             // must set this, provide extra names

        public void Init(string t, ActionCoreController cp, string appfolder, ActionFile file, List <Tuple <string, string> > ev)
        {
            actioncorecontroller = cp;
            applicationfolder    = appfolder;
            actionfile           = file;
            events = ev;

            grouptypenames = (from e in events select e.Item2).ToList().Distinct().ToList();
            groupeventlist = new Dictionary <string, List <string> >();
            foreach (string s in grouptypenames)
            {
                groupeventlist.Add(s, (from e in events where e.Item2 == s select e.Item1).ToList());
            }

            bool winborder = BaseUtils.ThemeAbleFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont);

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

            LoadConditions();
        }
Exemple #13
0
        static public ConditionVariables ReadVarsAndEnableFromFile(string file, out bool?enable)
        {
            ActionFile f = new ActionFile();

            enable = null;

            bool readenable;

            if (f.ReadFile(file, out readenable).Length == 0)        // read it in..
            {
                if (readenable)
                {
                    enable = f.enabled;
                }
                //System.Diagnostics.Debug.WriteLine("Enable vars read " + file + " " + enable);
                return(f.installationvariables);
            }
            else
            {
                return(null);
            }
        }
Exemple #14
0
        public void Init(ActionFile af, Condition c, ActionCoreController ac, string apf, Icon i, ToolTip toolTip,
                         ActionProgram.ProgramConditionClass cls)
        {
            cd                   = c; // point at common condition, we never new it, just update action data/action
            actionfile           = af;
            actioncorecontroller = ac;
            applicationfolder    = apf;
            Icon                 = i;
            classifier           = cls;

            progmajortype = new ExtendedControls.PanelSelectionList();
            progmajortype.Items.AddRange(new string[] { "Key", "Say", "Key+Say", "Full Program" });
            indextoclassifier = new ActionProgram.ProgramConditionClass[] { ActionProgram.ProgramConditionClass.Key, ActionProgram.ProgramConditionClass.Say,
                                                                            ActionProgram.ProgramConditionClass.KeySay, ActionProgram.ProgramConditionClass.Full };
            progmajortype.Location              = new Point(0, 0);
            progmajortype.Size                  = new Size(this.Width, this.Height); // outer panel aligns with this UC
            progmajortype.SelectedIndexChanged += PanelType_SelectedIndexChanged;
            toolTip.SetToolTip(progmajortype, "Use the selector (click on bottom right arrow) to select program class type");

            proglist = new ExtendedControls.ComboBoxCustom();
            proglist.Items.Add("New");
            proglist.Items.AddRange(actionfile.actionprogramlist.GetActionProgramList());
            proglist.Location              = new Point(panelxmargin, panelymargin);
            proglist.Size                  = new Size((this.Width - 24 - 8 - 8 - 8 - panelxmargin * 2) / 2, 24); // 24 button, 8+8 gaps, 8 for selector
            proglist.DropDownHeight        = 400;
            proglist.DropDownWidth         = proglist.Width * 3 / 2;
            proglist.SelectedIndexChanged += Proglist_SelectedIndexChanged;
            proglist.SetTipDynamically(toolTip, "Select program to associate with this event");

            progedit          = new ExtendedControls.ButtonExt();
            progedit.Text     = "P";
            progedit.Location = new Point(proglist.Right + 8, panelymargin);
            progedit.Size     = new Size(24, 24);
            progedit.Click   += Progedit_Click;
            toolTip.SetToolTip(progedit, "Edit associated program");

            paras          = new ExtendedControls.TextBoxBorder();
            paras.Text     = (cd.actiondata != null) ? cd.actiondata : "";
            paras.Location = new Point(progedit.Right + 8, panelymargin + 2);
            paras.Size     = proglist.Size;
            paras.ReadOnly = true;
            paras.Click   += Paras_Click;
            paras.SetTipDynamically(toolTip, "Click to enter parameters to pass to program");

            buttonKeys          = new ExtendedControls.ButtonExt();
            buttonKeys.Location = proglist.Location;
            buttonKeys.Size     = new Size((this.Width - 8 - 8 - panelxmargin * 2) / 2, 24);
            buttonKeys.Click   += Keypress_Click;
            toolTip.SetToolTip(buttonKeys, "Click to define keystrokes to send");

            buttonSay          = new ExtendedControls.ButtonExt();
            buttonSay.Location = new Point(buttonKeys.Right + 8, buttonKeys.Top);
            buttonSay.Size     = buttonKeys.Size;
            buttonSay.Click   += Saypress_Click;
            toolTip.SetToolTip(buttonSay, "Click to set speech to say");

            SuspendLayout();
            progmajortype.Controls.Add(proglist);
            progmajortype.Controls.Add(progedit);
            progmajortype.Controls.Add(paras);
            progmajortype.Controls.Add(buttonKeys);
            progmajortype.Controls.Add(buttonSay);
            Controls.Add(progmajortype);

            UpdateControls();

            ResumeLayout();
        }
Exemple #15
0
        public Condition cd;    // which is a copy of the Program condition, so it can edited

        public virtual void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile file,
                                 System.Func <string, List <TypeHelpers.PropertyNameInfo> > func, Icon ic, ToolTip toolTip)
        {
        }
Exemple #16
0
        public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile,
                                  System.Func <string, List <BaseUtils.TypeHelpers.PropertyNameInfo> > func, Icon ic, ToolTip toolTip)
        {
            cd = cond;

            //this.BackColor = Color.Red; // for debug

            // layed out for 12 point.  UC below require 28 point area

            eventtype = new ExtendedControls.ExtComboBox();
            eventtype.Items.AddRange(events);
            eventtype.Location = new Point(panelxmargin, panelymargin);
            eventtype.Size     = new Size(140, 24);
            if (cd.EventName != null)
            {
                eventtype.SelectedItem = cd.EventName;
            }
            eventtype.SelectedIndexChanged += Eventtype_SelectedIndexChanged;

            Controls.Add(eventtype);

            uccond          = new ActionPackEditCondition();
            uccond.Location = new Point(eventtype.Right + 16, 0);
            uccond.Size     = new Size(200, 28);   // init all the panels to 0/this height, select widths
            uccond.Init(cond, ic, toolTip);
            uccond.onAdditionalNames += () => { return(func(eventtype.Text)); };

            Controls.Add(uccond);

            ActionProgram p = cond.Action.HasChars() ? actionfile.ProgramList.Get(cond.Action) : null;

            ActionProgram.ProgramConditionClass classifier = p != null ? p.ProgramClass : ActionProgram.ProgramConditionClass.Full;
            ucprog          = new ActionPackEditProgram();
            ucprog.Location = new Point(uccond.Right + 16, 0);
            ucprog.Size     = new Size(400, 28);   // init all the panels to 0/this height, select widths
            ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier);
            ucprog.onEditKeys         = onEditKeys;
            ucprog.onEditSay          = onEditSay;
            ucprog.onAdditionalNames += () => { return(func(eventtype.Text)); };
            ucprog.SuggestedName     += () => { return(eventtype.Text); };
            ucprog.RefreshEvent      += () => { RefreshIt(); };
            Controls.Add(ucprog);
        }
Exemple #17
0
        public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile,
                                  System.Func <string, List <BaseUtils.TypeHelpers.PropertyNameInfo> > func, Icon ic, ToolTip toolTip)
        {
            cd = cond;      // on creation, the cond with be set to onVoice with one condition, checked in ActionController.cs:SetPackEditor..

            textBoxInput              = new ExtendedControls.ExtTextBox();
            textBoxInput.Location     = new Point(panelxmargin, panelymargin);
            textBoxInput.Size         = new Size(356, 24); // manually matched to size of eventprogramcondition bits
            textBoxInput.Text         = cd.fields[0].matchstring;
            textBoxInput.TextChanged += TextBoxInput_TextChanged;
            textBoxInput.SetTipDynamically(toolTip, "Enter the voice input to recognise.  Multiple phrases seperate with semicolons");

            Controls.Add(textBoxInput);

            ActionProgram p = cond.action.HasChars() ? actionfile.actionprogramlist.Get(cond.action) : null;

            ActionProgram.ProgramConditionClass classifier = p != null ? p.progclass : ActionProgram.ProgramConditionClass.KeySay;

            ucprog          = new ActionPackEditProgram();
            ucprog.Location = new Point(textBoxInput.Right + 16, 0);
            ucprog.Size     = new Size(400, this.Height);   // init all the panels to 0/this height, select widths
            ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier);
            ucprog.onEditKeys         = onEditKeys;
            ucprog.onEditSay          = onEditSay;
            ucprog.onAdditionalNames += () => { return(func(cd.eventname)); };
            ucprog.SuggestedName     += () =>
            {
                string textparse = (textBoxInput.Text.Length > 0 && !textBoxInput.Text.Equals("?")) ? ("_" + textBoxInput.Text.Split(';')[0].SafeVariableString()) : "";
                return("VoiceInput" + textparse);
            };

            ucprog.RefreshEvent += () => { RefreshIt(); };
            Controls.Add(ucprog);
        }
Exemple #18
0
        public override void Init(Condition cond, List <string> events, ActionCoreController cp, string appfolder, ActionFile actionfile,
                                  System.Func <string, List <string> > func, Icon ic, ToolTip toolTip)
        {
            cd     = cond;
            anfunc = func;

            eventtype = new ExtendedControls.ComboBoxCustom();
            eventtype.Items.AddRange(events);
            eventtype.Location       = new Point(panelxmargin, panelymargin);
            eventtype.Size           = new Size(140, 24);
            eventtype.DropDownHeight = 400;
            eventtype.DropDownWidth  = eventtype.Width * 3 / 2;
            if (cd.eventname != null)
            {
                eventtype.SelectedItem = cd.eventname;
            }
            eventtype.SelectedIndexChanged += Eventtype_SelectedIndexChanged;

            Controls.Add(eventtype);

            uccond          = new ActionPackEditCondition();
            uccond.Location = new Point(eventtype.Right + 16, 0);
            uccond.Size     = new Size(200, this.Height);   // init all the panels to 0/this height, select widths
            uccond.Init(cond, ic, toolTip);
            uccond.onAdditionalNames += () => { return(anfunc(eventtype.Text)); };

            Controls.Add(uccond);

            ActionProgram p = cond.action.HasChars() ? actionfile.actionprogramlist.Get(cond.action) : null;

            ActionProgram.ProgramConditionClass classifier = p != null ? p.progclass : ActionProgram.ProgramConditionClass.Full;
            ucprog          = new ActionPackEditProgram();
            ucprog.Location = new Point(uccond.Right + 16, 0);
            ucprog.Size     = new Size(400, this.Height);   // init all the panels to 0/this height, select widths
            ucprog.Init(actionfile, cond, cp, appfolder, ic, toolTip, classifier);
            ucprog.onEditKeys         = onEditKeys;
            ucprog.onEditSay          = onEditSay;
            ucprog.onAdditionalNames += () => { return(anfunc(eventtype.Text)); };
            ucprog.SuggestedName     += () => { return(eventtype.Text); };
            ucprog.RefreshEvent      += () => { RefreshIt(); };
            Controls.Add(ucprog);
        }