Ejemplo n.º 1
0
        public static void LoadConfiguration()
        {
            //check
            if (!File.Exists(_path_name_config))
            {
                SaveConfiguration();
                return;
            }

            //load
            string configJson = string.Empty;

            using (StreamReader reader = new StreamReader(_path_name_config, Encoding.Unicode)) {
                while (!reader.EndOfStream)
                {
                    configJson += reader.ReadLine();
                }
                reader.Close();
            }
            var d = new Devices();

            Convert.ChangeType(d, typeof(string));

            var i = 0;

            var r = i.;

            var db = new SqLite();

            db.Open();
            db.Select("configuration", "c", "where c.is_last=1").Apply(typeof(Configuration));
            db.Close();

            //foreach (System.Data.DataRow row in dt.Rows)
            //{
            //    time_interval = Convert.ToInt32(row["time_interval"]);
            //    enable_interval = Convert.ToBoolean(row["enable_interval"]);
            //    enable_server = Convert.ToBoolean(row["enable_server"]);

            //    path_save_video = Convert.ToString(row["path_save_video"]);
            //    frame_rate = Convert.ToInt32(row["frame_rate"]);
            //    bit_rate = Convert.ToInt32(row["bit_rate"]);
            //    compress_video = Convert.ToBoolean(row["compress_video"]);
            //    show_date_time = Convert.ToBoolean(row["show_date_time"]);
            //    legend_align = (LegendAlign)Convert.ToInt32(row["legend_align"]);
            //    font = new Font(
            //                Convert.ToString(row["font_family"]),
            //                Convert.ToInt32(row["font_size"])
            //            );

            //    devices_config = JsonConvert.DeserializeObject<Dictionary<string, Size>>(Convert.ToString(row["devices_config"]));

            //    start_window = Convert.ToBoolean(row["start_window"]);
            //    start_window_minimized = Convert.ToBoolean(row["start_window_minimized"]);

            //}
            //db.Close();

            //restore
            try
            {
            }catch (System.Exception) {
                MessageBox.Show("Falha ao carregar as configurações!", "Aviso",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        public static void SaveConfiguration()
        {
            try
            {
                var config = new
                {
                    time_interval,
                    enable_interval,
                    enable_server,
                    path_save_video,
                    frame_rate,
                    bit_rate,
                    compress_video,
                    show_date_time,
                    legend_align = (int)legend_align,
                    font_family  = font.FontFamily.Name,
                    font_size    = font.Size,

                    //devices
                    devices_config = JsonConvert.SerializeObject(DeviceController.BindDeviceConfiguration()),

                    start_window,
                    start_window_minimized,
                    date_time = DateTime.Now,
                    is_last   = true
                };

                var db = new SqLite();
                db.Open();
                db.Update(new SqlLiteData(new { is_last = false }, _table_name));
                db.Save(new SqlLiteData(config, _table_name));
                db.Close();

                string configJson = JsonConvert.SerializeObject(new
                {
                    time_interval,
                    enable_interval,
                    enable_server,
                    path_save_video,
                    frame_rate,
                    bit_rate,
                    compress_video,
                    show_date_time,
                    legend_align,
                    font_family = font.FontFamily.Name,
                    font_size   = font.Size,

                    //devices
                    devices_config = DeviceController.BindDeviceConfiguration(),

                    start_window,
                    start_window_minimized,
                    date_time = DateTime.Now,
                    is_last   = true
                });

                using (StreamWriter file = new StreamWriter(_path_name_config, false, Encoding.Unicode))
                {
                    file.WriteLine(configJson);
                    file.Close();
                }
            }
            catch (System.Exception ex) {
                MessageBox.Show("Falha ao salvar configurações!", "Aviso",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
        }