Esempio n. 1
0
        private void newDialog_DialogClosed(object sender, EventArgs e)
        {
            inputDialog.DialogClosed -= newDialog_DialogClosed;
            if (inputDialog.DialogResult)
            {
                if (!string.IsNullOrEmpty(inputDialog.InputText))
                {
                    string s = inputDialog.InputText.Trim();
                    if (s.Length > 0)
                    {
                        if ((from a in Manager.Instance.ActionFlows where string.Compare(a.Name, s, true) == 0 select a).Count() == 0)
                        {
                            ActionFlow af = new ActionFlow();
                            af.Name = inputDialog.InputText;
                            Core.Settings.Default.ActionBuilderFlowID++;
                            af.ID      = string.Format("actbuildf{0}", Core.Settings.Default.ActionBuilderFlowID);
                            af.Actions = new List <ActionImplementation>();
                            var obj = new ActionStart();
                            obj.ID = Guid.NewGuid().ToString("N");
                            af.Actions.Add(obj);
                            Manager.Instance.ActionFlows.Add(af);
                            ActiveActionFlow = af;

                            SaveData();
                            Manager.Instance.AddFlowToMenu(af);
                        }
                        else
                        {
                            Core.ApplicationData.Instance.Logger.AddLog(this, new Exception(string.Format("Flow with name {0} already exists.", s)));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void AddFlowToMenu(ActionFlow af)
        {
            MenuItem mi = new MenuItem();

            mi.Header           = af.Name;
            mi.Name             = af.ID;
            mi.Command          = ExecuteFlowCommand;
            mi.CommandParameter = af;
            Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items.Add(mi);
        }
Esempio n. 3
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     if (ActiveActionFlow != null)
     {
         Manager.Instance.RemoveFlowFromMenu(ActiveActionFlow);
         ActionFlow af = ActiveActionFlow;
         ActiveActionFlow = null;
         Manager.Instance.ActionFlows.Remove(af);
         SaveData();
     }
 }
Esempio n. 4
0
 public async Task RunActionFow(ActionFlow af)
 {
     if (Core.ApplicationData.Instance.ActiveDatabase != null)
     {
         using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
         {
             await Task.Run(() =>
             {
                 runFlow(af);
             });
         }
     }
 }
Esempio n. 5
0
        public void RemoveFlowFromMenu(ActionFlow af)
        {
            MenuItem mi;

            for (int i = 0; i < Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items.Count; i++)
            {
                mi = Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items[i] as MenuItem;
                if (mi != null && mi.Name == af.ID)
                {
                    Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items.RemoveAt(i);
                    break;
                }
            }
        }
Esempio n. 6
0
        public void RenameFlow(ActionFlow af, string newName)
        {
            af.Name = newName;
            MenuItem mi;

            for (int i = 0; i < Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items.Count; i++)
            {
                mi = Core.ApplicationData.Instance.MainWindow.actbuildermnu.Items[i] as MenuItem;
                if (mi != null && mi.Name == af.ID)
                {
                    mi.Header = newName;
                    break;
                }
            }
        }
Esempio n. 7
0
        private void runFlow(ActionFlow flow)
        {
            try
            {
                foreach (ActionImplementation ai in flow.Actions)
                {
                    ai.PrepareRun();
                }
                //find start and run
                ActionStart startAction          = (from a in flow.Actions where a is ActionStart select a).FirstOrDefault() as ActionStart;
                List <Core.Data.Geocache> gcList = startAction.PrepareFlow();

                DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                int      index      = 0;
                bool     canceled   = false;
                using (Utils.ProgressBlock prog = new Utils.ProgressBlock("ActionBuilder", "Executing", gcList.Count, 0, true))
                {
                    foreach (Core.Data.Geocache gc in gcList)
                    {
                        startAction.Run(gc);
                        index++;
                        if (DateTime.Now >= nextUpdate)
                        {
                            if (!prog.Update("Executing", gcList.Count, index))
                            {
                                canceled = true;
                                break;
                            }
                            nextUpdate = DateTime.Now.AddSeconds(1);
                        }
                    }
                }

                if (!canceled)
                {
                    //wrap up
                    foreach (ActionImplementation ai in flow.Actions)
                    {
                        ai.FinalizeRun();
                    }
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(this, e);
            }
        }
Esempio n. 8
0
        private void getActionFlowsFromXml(XmlDocument doc)
        {
            List <ActionImplementation> allActionImpl = new List <ActionImplementation>();

            XmlNodeList nl = doc.SelectNodes("/flows/flow");

            foreach (XmlNode n in nl)
            {
                ActionFlow af = new ActionFlow();
                af.Name    = n.Attributes["name"].Value;
                af.ID      = n.Attributes["id"].Value;
                af.Actions = new List <ActionImplementation>();

                XmlNodeList al = n.SelectNodes("action");
                foreach (XmlNode a in al)
                {
                    Type                 t           = Type.GetType(a.Attributes["type"].Value);
                    ConstructorInfo      constructor = t.GetConstructor(Type.EmptyTypes);
                    ActionImplementation obj         = (ActionImplementation)constructor.Invoke(null);
                    obj.ID       = a.Attributes["id"].Value;
                    obj.Location = new System.Windows.Point((double)int.Parse(a.Attributes["x"].Value), (double)int.Parse(a.Attributes["y"].Value));

                    af.Actions.Add(obj);
                    allActionImpl.Add(obj);

                    XmlNodeList vl = a.SelectNodes("values/value");
                    foreach (XmlNode v in vl)
                    {
                        obj.Values.Add(v.InnerText);
                    }
                }

                ActionFlows.Add(af);
            }

            //all actions are created, now we can match the ID's for the connections.
            nl = doc.SelectNodes("/flows/flow/action");
            foreach (XmlNode n in nl)
            {
                ActionImplementation          ai = (from ac in allActionImpl where ac.ID == n.Attributes["id"].Value select ac).FirstOrDefault();
                XmlNodeList                   conl;
                ActionImplementation.Operator op = ai.AllowOperators;
                if ((op & ActionImplementation.Operator.Equal) != 0)
                {
                    conl = n.SelectNodes("Equal/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.Equal);
                    }
                }
                if ((op & ActionImplementation.Operator.Larger) != 0)
                {
                    conl = n.SelectNodes("Larger/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.Larger);
                    }
                }
                if ((op & ActionImplementation.Operator.LargerOrEqual) != 0)
                {
                    conl = n.SelectNodes("LargerOrEqual/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.LargerOrEqual);
                    }
                }
                if ((op & ActionImplementation.Operator.Less) != 0)
                {
                    conl = n.SelectNodes("Less/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.Less);
                    }
                }
                if ((op & ActionImplementation.Operator.LessOrEqual) != 0)
                {
                    conl = n.SelectNodes("LessOrEqual/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.LessOrEqual);
                    }
                }
                if ((op & ActionImplementation.Operator.NotEqual) != 0)
                {
                    conl = n.SelectNodes("NotEqual/ID");
                    foreach (XmlNode con in conl)
                    {
                        ai.ConnectToOutput((from ac in allActionImpl where ac.ID == con.InnerText select ac).FirstOrDefault(), ActionImplementation.Operator.NotEqual);
                    }
                }
            }
        }