public bool FromString(string s, out string progname, out ConditionVariables vars, out Dictionary <string, string> altops)
        {
            StringParser p = new StringParser(s);

            vars   = new ConditionVariables();
            altops = new Dictionary <string, string>();

            progname = p.NextWord("( ");        // stop at space or (

            if (progname != null)
            {
                if (p.IsCharMoveOn('('))                                                                                                      // if (, then
                {
                    if (vars.FromString(p, ConditionVariables.FromMode.MultiEntryCommaBracketEnds, altops) && p.IsCharMoveOn(')') && p.IsEOL) // if para list decodes and we finish on a ) and its EOL
                    {
                        return(true);
                    }
                }
                else if (p.IsEOL)   // if EOL, its okay, prog name only
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        protected bool FromString(string ud, out ConditionVariables vars, out Dictionary <string, string> operations)
        {
            vars       = new ConditionVariables();
            operations = new Dictionary <string, string>();
            StringParser p = new StringParser(ud);

            return(vars.FromString(p, ConditionVariables.FromMode.OnePerLine, altops: operations));
        }
        static public bool FromString(string s, out string saying, out ConditionVariables vars)
        {
            vars = new ConditionVariables();

            StringParser p = new StringParser(s);

            saying = p.NextQuotedWord(", ");                                                                                             // stop at space or comma..

            if (saying != null && (p.IsEOL || (p.IsCharMoveOn(',') && vars.FromString(p, ConditionVariables.FromMode.MultiEntryComma)))) // normalise variable names (true)
            {
                return(true);
            }

            saying = "";
            return(false);
        }
        public ActionController(EDDiscoveryForm frm, EDDiscoveryController ctrl)
        {
            discoveryform       = frm;
            discoverycontroller = ctrl;

            persistentglobalvariables = new ConditionVariables();
            persistentglobalvariables.FromString(SQLiteConnectionUser.GetSettingString("UserGlobalActionVars", ""), ConditionVariables.FromMode.MultiEntryComma);

            globalvariables = new ConditionVariables(persistentglobalvariables);        // copy existing user ones into to shared buffer..

            programrunglobalvariables = new ConditionVariables();

            SetInternalGlobal("CurrentCulture", System.Threading.Thread.CurrentThread.CurrentCulture.Name);
            SetInternalGlobal("CurrentCultureInEnglish", System.Threading.Thread.CurrentThread.CurrentCulture.EnglishName);
            SetInternalGlobal("CurrentCultureISO", System.Threading.Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName);

            ReLoad();
        }
Exemple #5
0
        public bool FromString(string s, out string saying, out ConditionVariables vars)
        {
            vars = new ConditionVariables();

            if (s.IndexOf(',') == -1 && s.IndexOf('"') == -1) // no quotes, no commas, just the string, probably typed in..
            {
                saying = s;
                return(true);
            }
            else
            {
                StringParser p = new StringParser(s);
                saying = p.NextQuotedWord(", ");                                                                                             // stop at space or comma..

                if (saying != null && (p.IsEOL || (p.IsCharMoveOn(',') && vars.FromString(p, ConditionVariables.FromMode.MultiEntryComma)))) // normalise variable names (true)
                {
                    return(true);
                }

                saying = "";
                return(false);
            }
        }
Exemple #6
0
        public bool FromString(string s, out string path, out ConditionVariables vars)
        {
            vars = new ConditionVariables();

            if (s.IndexOfAny(",\"'".ToCharArray()) == -1)
            {
                path = s;
                return(true);
            }
            else
            {
                StringParser p = new StringParser(s);
                path = p.NextQuotedWord(", ");                                                                                             // stop at space or comma..

                if (path != null && (p.IsEOL || (p.IsCharMoveOn(',') && vars.FromString(p, ConditionVariables.FromMode.MultiEntryComma)))) // normalise variable names (true)
                {
                    return(true);
                }

                path = "";
                return(false);
            }
        }
Exemple #7
0
        public string ReadFile(string filename, out bool readenable)     // string, empty if no errors
        {
            readenable = false;

            Clear(filename, Path.GetFileNameWithoutExtension(filename));

            try
            {
                var utc8nobom = new UTF8Encoding(false);                        // give it the default UTF8 no BOM encoding, it will detect BOM or UCS-2 automatically

                using (StreamReader sr = new StreamReader(filename, utc8nobom)) // read directly from file.. presume UTF8 no bom
                {
                    string firstline = sr.ReadLine();

                    fileencoding = sr.CurrentEncoding;

                    System.Diagnostics.Debug.WriteLine("File " + filename + " is in " + fileencoding.BodyName + "   is utc8nobom? " + Equals(utc8nobom, fileencoding));

                    if (firstline == "{")
                    {
                        string json = firstline + Environment.NewLine + sr.ReadToEnd();
                        sr.Close();

                        try
                        {
                            JObject jo = JObject.Parse(json);
                            return(Read(jo, out readenable));
                        }
                        catch
                        {
                            return("Invalid JSON" + Environment.NewLine);
                        }
                    }
                    else if (firstline == "ACTIONFILE V4")
                    {
                        string line;
                        int    lineno = 1;  // on actionFILE V4

                        while ((line = sr.ReadLine()) != null)
                        {
                            lineno++;       // on line of read..

                            line.Trim();
                            if (line.StartsWith("ENABLED", StringComparison.InvariantCultureIgnoreCase))
                            {
                                line = line.Substring(7).Trim().ToLower();
                                if (line == "true")
                                {
                                    enabled = true;
                                }
                                else if (line == "false")
                                {
                                    enabled = false;
                                }
                                else
                                {
                                    return(name + " " + lineno + " ENABLED is neither true or false" + Environment.NewLine);
                                }

                                readenable = true;
                            }
                            else if (line.StartsWith("PROGRAM", StringComparison.InvariantCultureIgnoreCase))
                            {
                                ActionProgram ap  = new ActionProgram();
                                string        err = ap.Read(sr, ref lineno);

                                if (err.Length > 0)
                                {
                                    return(name + " " + err);
                                }

                                ap.Rename(line.Substring(7).Trim());        //MUST rename now, after read, as read clears the name expecting PROGRAM
                                actionprogramlist.Add(ap);
                            }
                            else if (line.StartsWith("INCLUDE", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string incfilename = line.Substring(7).Trim();
                                if (!incfilename.Contains("/") && !incfilename.Contains("\\"))
                                {
                                    incfilename = Path.Combine(Path.GetDirectoryName(filename), incfilename);
                                }

                                ActionProgram ap = new ActionProgram("", incfilename);   // NAME will be filled in by PROGRAM statement in file

                                string err = ap.ReadFile(incfilename);

                                if (err.Length > 0)
                                {
                                    return(name + " " + err);
                                }

                                actionprogramlist.Add(ap);
                            }
                            else if (line.StartsWith("EVENT", StringComparison.InvariantCultureIgnoreCase))
                            {
                                Condition c   = new Condition();
                                string    err = c.Read(line.Substring(5).Trim(), true);
                                if (err.Length > 0)
                                {
                                    return(name + " " + lineno + " " + err + Environment.NewLine);
                                }
                                else if (c.action.Length == 0 || c.eventname.Length == 0)
                                {
                                    return(name + " " + lineno + " EVENT Missing event name or action" + Environment.NewLine);
                                }

                                actioneventlist.Add(c);
                            }
                            else if (line.StartsWith("INSTALL", StringComparison.InvariantCultureIgnoreCase))
                            {
                                ConditionVariables c = new ConditionVariables();
                                if (c.FromString(line.Substring(7).Trim(), ConditionVariables.FromMode.OnePerLine) && c.Count == 1)
                                {
                                    installationvariables.Add(c);
                                }
                                else
                                {
                                    return(name + " " + lineno + " Incorrectly formatted INSTALL variable" + Environment.NewLine);
                                }
                            }
                            else if (line.StartsWith("//") || line.StartsWith("REM", StringComparison.InvariantCultureIgnoreCase) || line.Length == 0)
                            {
                            }
                            else
                            {
                                return(name + " " + lineno + " Invalid command" + Environment.NewLine);
                            }
                        }

                        return("");
                    }
                    else
                    {
                        return(name + " Header file type not recognised" + Environment.NewLine);
                    }
                }
            }
            catch (Exception e)
            {
                return(filename + " Not readable" + Environment.NewLine + " " + e.Message);
            }
        }