public ProfileItemControl(ProfileConfigModel profile, int index)
        {
            InitializeComponent();

            this.profile = profile;
            this.index = index;

            SetState();
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            Boolean isValid = ValidateProfile();

            ProfileConfigModel pcm = new ProfileConfigModel();
            pcm.name = nameTextBox.Text;

            MainWindow.AddProfile(pcm);
        }
示例#3
0
        public JsonConfigModel ParseVersionOne(JObject jsconfig)
        {
            JsonConfigModel json = new JsonConfigModel();

            try
            {
                json.version = (String)jsconfig.GetValue("version");
                json.defaultProfile = (int)jsconfig.GetValue("defaultProfile");
                IList<JToken> processes = jsconfig["profiles"].Children().ToList();

                ProfileConfigModel p = new ProfileConfigModel();
                
                foreach (JToken conf in processes)
                {
                    Config c = JsonConvert.DeserializeObject<Config>(conf.ToString());
                    Console.WriteLine("getting config is ok");

                    if (c.uid == null || c.uid == "")
                    {
                        c.uid = Guid.NewGuid().ToString();
                    }

                    //json.processes.Add(c);
                    p.processes.Add(c);
                }

                json.profiles.Add(p);

                Save(json); // update to the new format
            }
            catch (Exception ex)
            {
                Console.WriteLine("File read problem: " + ex.Data.ToString());
                json = new JsonConfigModel();
                json.version = "1.1";
                json.defaultProfile = 0;
                json.profiles = new List<ProfileConfigModel>();
                ProfileConfigModel profile = new ProfileConfigModel();
                profile.name = "Default";
                profile.processes = new List<Config>();
                json.profiles.Add(profile);
            }

            return json;
        }
示例#4
0
        public JsonConfigModel Load()
        {
            Console.WriteLine(Application.UserAppDataPath + "\\process.json");
            JsonConfigModel json;

            try
            {
                StreamReader configReader = File.OpenText(Application.UserAppDataPath + "\\processes.json");

                JObject jsconfig = (JObject)JToken.ReadFrom(new JsonTextReader(configReader));
                String version = (String)jsconfig.GetValue("version");

                if (version == "1.0")
                {
                    json = ParseVersionOne(jsconfig);
                }
                else if (version == "1.1")
                {
                    json = ParseVersionOneOne(jsconfig);
                }
                else
                {
                    throw new Exception("No config version, falling back to 1.1");
                }

                configReader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("File read problem: " + ex.Data.ToString());
                json = new JsonConfigModel();
                json.version = "1.1";
                json.defaultProfile = 0;
                json.profiles = new List<ProfileConfigModel>();
                ProfileConfigModel profile = new ProfileConfigModel();
                profile.name = "Default";
                profile.processes = new List<Config>();
                json.profiles.Add(profile);
                //json.profiles
                //json.processes = new List<Config>();
            }

            return json;
        }
        public static void AddProfile(ProfileConfigModel pcm)
        {
            json.profiles.Add(pcm);

            SwitchProfile(json.profiles.Count);
        }
示例#6
0
        public JsonConfigModel ParseVersionOneOne(JObject jsconfig)
        {
            JsonConfigModel json = new JsonConfigModel();

            try
            {
                json.version = (String)jsconfig.GetValue("version");
                json.defaultProfile = (int)jsconfig.GetValue("defaultProfile");
                IList<JToken> profiles = jsconfig["profiles"].Children().ToList();

                json.profiles = new List<ProfileConfigModel>();

                foreach (JToken profile in profiles)
                {
                    ProfileConfigModel p = JsonConvert.DeserializeObject<ProfileConfigModel>(profile.ToString());

                    json.profiles.Add(p);
                }

                Console.WriteLine("---- CORRECTLY LOADED CONFIG ----");
            }
            catch (Exception ex)
            {
                json = new JsonConfigModel();
                json.version = "1.1";
                json.defaultProfile = 0;
                json.profiles = new List<ProfileConfigModel>();
                ProfileConfigModel profile = new ProfileConfigModel();
                profile.name = "Default";
                profile.processes = new List<Config>();
                json.profiles.Add(profile);
            }

            return json;
        }