Пример #1
0
        private void uxImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Text Files|*.txt";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    qcData = json.Deserialize <QuickCopyData>(new JsonTextReader(new StringReader(File.ReadAllText(ofd.FileName))));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to import QuickCopy data: " + ex.Message);
                }
            }
        }
Пример #2
0
        private void LoadTreeData()
        {
            QuickCopyData sqlData = null, fileData = null;
            string        url          = Properties.Settings.Default.SQLServerURL;
            string        database     = Properties.Settings.Default.SQLServerDatabase;
            string        username     = Properties.Settings.Default.SQLServerUsername;
            string        password     = Properties.Settings.Default.SQLServerPassword;
            string        userUsername = Properties.Settings.Default.QuickCopyUsername;
            string        userPassword = Properties.Settings.Default.QuickCopyPassword;
            string        key          = null;

            try
            {
                key = Encoding.ASCII.GetString(Convert.FromBase64String(Properties.Settings.Default.QuickCopyAesKey));
            }
            catch (FormatException ex)
            {
                MessageBox.Show("AES decryption key is not valid: " + ex.Message);
            }

            // try to load data from sql server
            if (Properties.Settings.Default.RemoteSaveEnabled)
            {
                try
                {
                    sqlSource = new SQLQuickCopySource(url, database, username, password, userUsername, userPassword);
                    sqlData   = json.Deserialize <QuickCopyData>(new JsonTextReader(new StringReader(sqlSource.GetData(key))));
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("Failed to connect to database: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("No QuickCopy data was found in the database.");
                }
                catch (JsonSerializationException ex)
                {
                    MessageBox.Show("Failed to deserialize JSON data: " + ex.Message);
                }
            }

            // try to load data from file
            if (Properties.Settings.Default.LocalSaveEnabled)
            {
                try
                {
                    fileSource = new FileQuickCopySource(Properties.Settings.Default.LocalFilePath);
                    fileData   = json.Deserialize <QuickCopyData>(new JsonTextReader(new StringReader(fileSource.GetData(key))));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to read file: " + ex.Message);
                }
            }

            // see which one is newer and keep that one
            if (sqlData != null)
            {
                if (fileData != null)
                {
                    qcData = sqlData.LastModifiedTime >= fileData.LastModifiedTime ? sqlData : fileData;
                }
                else
                {
                    qcData = sqlData;
                }
            }
            else
            {
                if (fileData != null)
                {
                    qcData = fileData;
                }
                else
                {
                    MessageBox.Show("Neither source of data could be accessed. If you wish to save, you must explicitly save using \"File\" -> \"Save\".");
                    qcData = new QuickCopyData();
                }
            }
        }