Exemplo n.º 1
0
        public ClockDisplay()
        {
            InitializeComponent();

            if ( !Directory.Exists(genSettings.ProfilePath) )
            {
                Directory.CreateDirectory(genSettings.ProfilePath);
            }

            if (File.Exists(genSettings.ProfilePath + "\\settings.json"))
            {
                string clockSettings = File.ReadAllText(genSettings.ProfilePath + "\\settings.json");
                genSettings = JsonConvert.DeserializeObject<GeneralSettings>(clockSettings);

                // Determine the last used profile and whether it falls in the necessary time period or not
                if (!genSettings.LastProfile.Equals(""))
                {
                    DateTime profileDate = DateTime.Parse(genSettings.LastProfileDate);
                    if (profileDate.ToShortDateString().Equals(DateTime.Now.ToShortDateString()))
                    {
                        if (File.Exists(genSettings.ProfilePath + "\\" + genSettings.LastProfile + ".json"))
                        {
                            clockSettings = File.ReadAllText(@genSettings.ProfilePath + "\\" + genSettings.LastProfile + ".json");
                            clockSettingsBindingSource.Clear();
                            settings = JsonConvert.DeserializeObject<ClockSettings>(clockSettings);
                            clockSettingsBindingSource.Add(settings);

                            clockSettingsBindingSource.ResetBindings(false);
                        }
                    }
                }
            }

            pnlClock.Invalidate();
        }
Exemplo n.º 2
0
        public ClockConfig(ClockDisplay display, BindingSource source, GeneralSettings settings)
        {
            InitializeComponent();

            this.myDisplay = display;
            this.settings = settings;

            if (File.Exists(@settings.ProfilePath + "\\settings.json"))
            {
                string clockSettings = File.ReadAllText(@settings.ProfilePath + "\\settings.json");
                settings = JsonConvert.DeserializeObject<GeneralSettings>(clockSettings);
            }
            else
            {
                settings = new GeneralSettings();
                settings.writeProfile(settings);
            }

            if (!System.IO.Directory.Exists(@settings.ProfilePath))
            {
                System.IO.Directory.CreateDirectory(@settings.ProfilePath);
            }

            PaintListView(@settings.ProfilePath);

            if (source.Current != null)
            {
                loadedClock = (ClockSettings)source.Current;

                clockSettingsBindingSource.Add(source.Current);
                clockSettingsBindingSource.ResetBindings(false);
                populatePresentationList();

                listView1.FindItemWithText(loadedClock.ProfileName).Selected = true;
                listView1.Select();
            }

            settings.PropertyChanged += this.HandleSettingsChanged;
            generalSettingsBindingSource.Add(settings);
        }
Exemplo n.º 3
0
        public void writeProfile(GeneralSettings profile)
        {
            string json = JsonConvert.SerializeObject(profile, Formatting.Indented);

            File.WriteAllText( profilePath + "\\settings.json", json);
        }