Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 public ActionFile(ConditionLists c, ActionProgramList p, string f, string n, bool e, ConditionVariables ivar = null)
 {
     actionfieldfilter = c;
     actionprogramlist = p;
     filepath          = f;
     name    = n;
     enabled = e;
     installationvariables = new ConditionVariables();
     if (ivar != null)
     {
         installationvariables.Add(ivar);
     }
 }