Esempio n. 1
0
        private ConditionVariables ReadVarsFromFile(string file, out bool?enable)
        {
            using (StreamReader sr = new StreamReader(file))         // read directly from file..
            {
                string json = sr.ReadToEnd();

                JObject jo = (JObject)JObject.Parse(json);

                enable = null;
                if (!JSONHelper.IsNullOrEmptyT(jo["Enabled"]))      // if this has an enabled, note it
                {
                    enable = (bool)jo["Enabled"];
                }

                JArray ivarja = (JArray)jo["Install"];

                if (!JSONHelper.IsNullOrEmptyT(ivarja))
                {
                    ConditionVariables cv = new ConditionVariables();
                    cv.FromJSONObject(ivarja);
                    return(cv);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public static string ReadFile(string filename, out ActionFile af)
        {
            af = null;
            string errlist = "";

            using (StreamReader sr = new StreamReader(filename))         // read directly from file..
            {
                string json = sr.ReadToEnd();
                sr.Close();

                try
                {
                    JObject jo = (JObject)JObject.Parse(json);

                    JObject jcond = (JObject)jo["Conditions"];
                    JObject jprog = (JObject)jo["Programs"];
                    bool    en    = (bool)jo["Enabled"];

                    JArray ivarja = (JArray)jo["Install"];

                    ConditionVariables ivars = new ConditionVariables();
                    if (!JSONHelper.IsNullOrEmptyT(ivarja))
                    {
                        ivars.FromJSONObject(ivarja);
                    }

                    ConditionLists    cond = new ConditionLists();
                    ActionProgramList prog = new ActionProgramList();

                    if (cond.FromJSON(jcond))
                    {
                        errlist = prog.FromJSONObject(jprog);

                        if (errlist.Length == 0)
                        {
                            af = new ActionFile(cond, prog, filename, Path.GetFileNameWithoutExtension(filename), en, ivars);
                        }
                    }
                    else
                    {
                        errlist = "Bad JSON in conditions";
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Dump:" + ex.StackTrace);
                    errlist = "Bad JSON in File";
                }

                return(errlist);
            }
        }