Exemplo 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;
                            Settings.Settings.Default.ActionBuilderFlowID++;
                            af.ID      = string.Format("actbuildf{0}", Settings.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();
                        }
                        else
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void RunFlow(ActionFlow flow, Database.DBCon db)
        {
            List <ActionImplementation> orderedActions = null;

            try
            {
                ApplicationData.Instance.StatusText = string.Format("{0} {1}", Localization.TranslationManager.Instance.Translate("StartingFlow"), flow.Name);
                orderedActions = flow.Actions.OrderByDescending(x => x.Priority).ToList();
                int id = 0;
                foreach (ActionImplementation ai in orderedActions)
                {
                    id++;
                    ApplicationData.Instance.StatusText = string.Format("{0} {1}", Localization.TranslationManager.Instance.Translate("PreparingAction"), Localization.TranslationManager.Instance.Translate(ai.Name));
                    ai.PrepareRun(db, string.Format("gskwrp{0}", id));
                }

                //find start and run
                ActionStart startAction = (from a in flow.Actions where a is ActionStart select a).FirstOrDefault() as ActionStart;

                startAction.Run(null);
            }
            finally
            {
                foreach (ActionImplementation ai in orderedActions)
                {
                    ApplicationData.Instance.StatusText = string.Format("{0} {1}", Localization.TranslationManager.Instance.Translate("FinishingAction"), Localization.TranslationManager.Instance.Translate(ai.Name));
                    ai.FinalizeRun();
                }
            }
            ApplicationData.Instance.StatusText = string.Format("{0} {1}", Localization.TranslationManager.Instance.Translate("FinishedFlow"), flow.Name);
        }
Exemplo n.º 3
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     if (ActiveActionFlow != null)
     {
         if (System.Windows.MessageBox.Show(string.Format(Localization.TranslationManager.Instance.Translate("Delete_flow_") as string, ActiveActionFlow.Name), "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             ActionFlow af = ActiveActionFlow;
             ActiveActionFlow = null;
             Manager.Instance.ActionFlows.Remove(af);
             SaveData();
         }
     }
 }
Exemplo n.º 4
0
        public async Task RunActionFow(ActionFlow af)
        {
            SqlStatementsOfLastExecutedFlow = "";
            await Task.Run(() =>
            {
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                try
                {
                    var fn = System.IO.Path.Combine(Settings.Settings.Default.DatabaseFolderPath, Settings.Settings.Default.SelectedDatabase, "sqlite.db3");
                    if (System.IO.File.Exists(fn))
                    {
                        using (var db = new Database.DBConSqlite(fn))
                        {
                            try
                            {
                                RunFlow(af, db);
                            }
                            finally
                            {
                                SqlStatementsOfLastExecutedFlow = string.Join("\r\n", db.ExecutedSqlQueries);
                            }
                        }
                    }
                    sw.Stop();
                    ApplicationData.Instance.StatusText = string.Format(Localization.TranslationManager.Instance.Translate("FlowFinishedIn") as string, af.Name, sw.Elapsed.TotalSeconds.ToString("0.0"));
                }
                catch (Exception e)
                {
                    sw.Stop();
                    ApplicationData.Instance.StatusText = string.Format("{0}: {1}", Localization.TranslationManager.Instance.Translate("Error"), e.Message);
                }
            });

#if DEBUG
            System.IO.File.WriteAllText(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GSAKWrapper", "sqlstatements.log"), SqlStatementsOfLastExecutedFlow);
#endif
        }
Exemplo n.º 5
0
        public string GetFlowXml(ActionFlow flow)
        {
            string result = null;

            try
            {
                XmlDocument doc = createFlowXml(new List <ActionFlow>()
                {
                    flow
                });
                StringBuilder        sb = new StringBuilder();
                System.IO.TextWriter tr = new System.IO.StringWriter(sb);
                XmlTextWriter        wr = new XmlTextWriter(tr);
                wr.Formatting = Formatting.None;
                doc.Save(wr);
                wr.Close();
                result = sb.ToString();
            }
            catch
            {
            }
            return(result);
        }
Exemplo n.º 6
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "";                               // Default file name
            dlg.DefaultExt = ".gwf";                           // Default file extension
            dlg.Filter     = "GSAKWrapper Flows (.gwf)|*.gwf"; // Filter files by extension

            // Show open file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                try
                {
                    var aflws = Manager.Instance.GetActionFlows(System.IO.File.ReadAllText(dlg.FileName));
                    foreach (var naf in aflws)
                    {
                        //check if ID is already in list
                        //check for ID and name
                        ActionImplementation startAction = (from sa in naf.Actions where sa is ActionStart select sa).FirstOrDefault();
                        if (startAction != null)
                        {
                            ActionFlow found = null;
                            bool       doAdd = false;
                            foreach (var af in Manager.Instance.ActionFlows)
                            {
                                ActionImplementation startAct = (from sa in af.Actions where sa is ActionStart select sa).FirstOrDefault();
                                if (startAct != null)
                                {
                                    if (startAct.ID == startAction.ID)
                                    {
                                        found = af;
                                        break;
                                    }
                                }
                            }
                            if (found != null)
                            {
                                if (System.Windows.MessageBox.Show(string.Format(Localization.TranslationManager.Instance.Translate("Overwrite_flow_") as string, found.Name), "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                {
                                    if (ActiveActionFlow == found)
                                    {
                                        ActiveActionFlow = null;
                                    }
                                    Manager.Instance.ActionFlows.Remove(found);
                                    doAdd = true;
                                }
                            }
                            else
                            {
                                doAdd = true;
                            }
                            if (doAdd)
                            {
                                //insert new
                                //but first check name
                                int index = 0;
                                while ((from a in Manager.Instance.ActionFlows where a.Name.ToLower() == naf.Name.ToLower() select a).Count() > 0)
                                {
                                    index++;
                                    naf.Name = string.Format("{0}{1}", naf.Name, index);
                                }

                                Manager.Instance.ActionFlows.Add(naf);
                            }
                        }
                    }
                    SaveData();
                }
                catch
                {
                    System.Windows.MessageBox.Show("Unable to load the file.", "Error");
                }
            }
        }
Exemplo n.º 7
0
        public List <ActionFlow> GetActionFlows(XmlDocument doc)
        {
            var result = new List <ActionFlow>();
            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);
                    }
                }

                result.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);
                    }
                }
            }
            return(result);
        }