Пример #1
0
        private async void button5_Click(object sender, EventArgs e)
        {
            //restore button
            List <bool> enable_states = new List <bool>();

            foreach (Control c in Controls)
            {
                enable_states.Add(c.Enabled);
                c.Enabled = false;
            }

            var cfg = MCv2Persistance.Instance.Config;

            ProgressDialog pgd = new ProgressDialog("Database Restore");

            pgd.Show();
            pgd.SetMarqueeStyle();

            var backup_filename = backups.Keys.ElementAt(dataGridView1.SelectedRows[0].Index);

            pgd.LabelText = "Restoring from " + new FileInfo(backup_filename).Name;

            await DBBackupAndRestore.Restore(backup_filename);

            pgd.Dispose();

            for (int i = 0; i < enable_states.Count; i++)
            {
                Controls[i].Enabled = enable_states[i];
            }
        }
Пример #2
0
        private async Task LoadBackupInfo()
        {
            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "backups\\");

            backups.Clear();
            foreach (var file in files)
            {
                backups.Add(file, await DBBackupAndRestore.GetBackupProperties(file));
            }

            backups = backups.OrderBy(x => x.Value.Timestamp).Reverse().ToDictionary(x => x.Key, x => x.Value);
        }
Пример #3
0
        private async void databaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dbconnprop = DatabaseConnectionProperties.FromArray(GetTextBoxStrings());

            MCv2Persistance.Instance.Config.DatabaseConfiguration.DatabaseConnectionProperties = dbconnprop;

            List <string> files_to_import = new List <string>();

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Multiselect      = true;
                ofd.Filter           = "Supported Extentions (*.db2bak)|*.db2bak";
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                ofd.FileName         = "";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    files_to_import.AddRange(ofd.FileNames);
                }
            }

            if (files_to_import.Count() == 0)
            {
                return;
            }

            ProgressDialog pgd = new ProgressDialog("Restoring Database");

            pgd.Show();
            pgd.SetMarqueeStyle();

            foreach (var file in files_to_import)
            {
                pgd.LabelText = "Processing " + file;

                try
                {
                    await DBBackupAndRestore.Restore(file, DatabaseConnectionProperties.FromArray(GetTextBoxStrings()));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occured while restoring from " + file + ".");
                }
            }

            pgd.Dispose();
        }
Пример #4
0
        private async void button4_Click(object sender, EventArgs e)
        {
            //create button
            button4.Enabled = false;
            button5.Enabled = false;

            var cfg = MCv2Persistance.Instance.Config;

            ProgressDialog pgd = new ProgressDialog("Database Backup");

            pgd.Show();
            pgd.SetMarqueeStyle();

            var now_is          = DateTime.Now;
            var backup_filename = cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString();

            pgd.LabelText = "Saving backup to " + backup_filename + ".db2bak";

            await DBBackupAndRestore.Backup("./backups/" + backup_filename + ".db2bak");

            pgd.Dispose();

            await RefreshUI();
        }
Пример #5
0
        public MCIv2Form()
        {
            var cfg  = MCv2Persistance.Instance.Config;
            var bcfg = cfg.BackupConfiguration;

            if (bcfg.EnableAutoBackup)
            {
                ProgressDialog pgd = new ProgressDialog("Database Backup");
                pgd.Show();
                pgd.SetMarqueeStyle();

                var now_is          = DateTime.Now;
                var backup_filename = "auto_backup_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString();

                pgd.LabelText = "Saving backup to " + backup_filename + ".db2bak";

                DBBackupAndRestore.Backup("./backups/" + backup_filename + ".db2bak").Wait();

                pgd.Dispose();

                bcfg.LastAutoBackupTimestamp = DateTime.Now;
            }

            if (bcfg.EnableBackupNag && (DateTime.Now - bcfg.LastNagBackupTimestamp) > bcfg.BackupNagInterval)
            {
                var res = MessageBox.Show(this, "It's been " + (DateTime.Now - bcfg.LastNagBackupTimestamp).TotalDays + " days since the last local database backup." + Environment.NewLine
                                          + "Would you like to perform a backup now?", "Warning", MessageBoxButtons.YesNo);

                if (res == DialogResult.Yes)
                {
                    //backup database
                    string file_name = null;

                    using (SaveFileDialog sfd = new SaveFileDialog())
                    {
                        sfd.Filter           = "Supported Extentions (*.db2bak)|*.db2bak";
                        sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        var now_is = DateTime.Now;
                        sfd.FileName = cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString();

                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            file_name = sfd.FileName;
                        }
                    }

                    if (file_name != null)
                    {
                        ProgressDialog pgd = new ProgressDialog("Database Backup");
                        pgd.Show();
                        pgd.SetMarqueeStyle();

                        pgd.LabelText = "Saving backup to " + file_name;
                        DBBackupAndRestore.Backup(file_name).Wait();

                        pgd.Dispose();

                        bcfg.LastNagBackupTimestamp = DateTime.Now;
                    }
                }
            }

            MCv2Persistance.Instance.Config = cfg;

            InitializeComponent();

            //context menu
            toolStripMenuItem2.Click += (a, b) => {
                Clipboard.SetText(new Func <string>(() =>
                {
                    var str   = "";
                    var items = listBox2.Items.Cast <string>();
                    foreach (var item in items)
                    {
                        str += item + Environment.NewLine;
                    }
                    return(str);
                }).Invoke());
            };

            DoubleBuffered = true;

            var version_strings = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.');
            var version_string  = "MCI v" + version_strings[0] + "." + version_strings[1] + " Prerelease " + version_strings[2] + "." + version_strings[3];

            Text = version_string;

            //Set double buffering on the gridview using reflection and the bindingflags enum.
            typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic |
                                              BindingFlags.Instance | BindingFlags.SetProperty, null,
                                              dataGridView1, new object[] { true });

            card_lookup_controls.Add(listBox1);
            card_lookup_controls.Add(textBox3);
            card_lookup_controls.Add(button1);
            card_lookup_controls.Add(listBox2);
            card_lookup_controls.Add(button2);
            card_lookup_controls.Add(button22);

            update_holdoff_timer.Elapsed += async(s, ea) =>
            {
                rct = new CancellationTokenSource();

                update_holdoff_timer.Stop();

                //try
                //{
                await Task.Run(async() =>
                {
                    string tb0 = "", tb1 = "";

                    Invoke((MethodInvoker)(() =>
                    {
                        tb0 = textBox1.Text.Trim();
                        tb1 = textBox3.Text.Trim();

                        textBox3.Text = "";

                        textBox1.BackColor = Color.LightCyan;

                        Refresh();
                    }));

                    //RemoveDataGridView1Events();
                    await UserLookupAndDisplay(tb0, true, rct);
                    //RestoreDataGridView1Events();

                    //if there are rows displayed then refresh card lookup and display

                    //var selected_users = ULAD_GetSelectedUsers();
                    //if(selected_users.Count() > 0)
                    //{
                    //await CardLookupAndDisplay(selected_user, tb1, true);
                    //}

                    Invoke((MethodInvoker)(() =>
                    {
                        textBox1.BackColor = SystemColors.Window;

                        Refresh();
                    }));
                }, rct.Token);

                //}
                //catch (Exception ex) { }

                rct.Dispose();
                rct = null;
            };

            V2LE_ResetAll();
        }