示例#1
0
        private void MoveJobEntry(UISyncJobEntry entry, int delta)
        {
            int index = SyncJobEntries.IndexOf(entry);
            SyncJobEntries.RemoveAt(index);

            index += delta;

            // Bound index
            if (index < 0) index = (SyncJobEntries.Count + 1) + index;
            if (index > SyncJobEntries.Count) index -= (SyncJobEntries.Count + 1);

            SyncJobEntries.Insert(index, entry);
        }
示例#2
0
        private bool saveSyncJob(UISyncJobEntry entry)
        {
            entry.NewJobName = entry.NewJobName.Trim();
            entry.NewSyncSource = entry.NewSyncSource.Trim();
            entry.NewIntermediaryStoragePath = entry.NewIntermediaryStoragePath.Trim();

            string syncSourceDir = txtSource.Text;
            string intStorageDir = txtIntStorage.Text;

            try
            {
                if (Validator.SyncJobParamsValidated(entry.NewJobName, entry.NewSyncSource, entry.NewIntermediaryStoragePath, jobManager.LoadAllJobs()))
                {
                    BackgroundWorker editJobWorker = new BackgroundWorker();
                    editJobWorker.DoWork += new DoWorkEventHandler(editJobWorker_DoWork);
                    editJobWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(editJobWorker_RunWorkerCompleted);

                    SetControlsEnabledState(false, false);
                    editJobWorker.RunWorkerAsync(entry);
                }
                else
                {
                    showErrorMsg(m_ResourceManager.GetString("err_invalidInput"));
                    entry.EditMode = false;
                    SetControlsEnabledState(false, true);
                }
            }
            catch (SyncJobException syncJobException)
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    showErrorMsg(syncJobException.Message);
                    entry.EditMode = false;
                    SetControlsEnabledState(false, true);
                });
                return false;
            }
            catch (SyncJobNameExistException profileNameExistException)
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    showErrorMsg(profileNameExistException.Message);
                    entry.EditMode = false;
                    SetControlsEnabledState(false, true);
                });
                return false;
            }
            catch (Exception exception)
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    showErrorMsg(exception.Message);
                });
                return false;
            }
            return true;
        }
示例#3
0
        private void btnAddNewJob_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            showErrorMsg("");
            //Check the three required inputs for a new sync job:
            // 1. Sync Job Name;
            // 2. Sync Source Folder Directory;
            // 3. Intermediate Storage Location.
            string syncJobName = txtSyncJobName.Text.Trim();
            string syncSourceDir = txtSource.Text.Trim();
            string intStorageDir = txtIntStorage.Text.Trim();

            //Create new sync job if all three inputs mentioned above are valid.
            try
            {
                if (!Validator.SyncJobParamsValidated(syncJobName, syncSourceDir, intStorageDir, jobManager.LoadAllJobs()))
                {
                    showErrorMsg(m_ResourceManager.GetString("err_invalidInput"));
                    return;
                }

                SyncJob job = jobManager.CreateSyncJob(syncJobName, syncSourceDir, intStorageDir);
                UISyncJobEntry entry = new UISyncJobEntry(job) { IsSelected = true };
                SyncJobEntries.Add(entry);
                txtSyncJobName.Text = "";
                txtSource.Text = "";
                txtIntStorage.Text = "";
            }
            catch (SyncJobNameExistException ex)
            {
                showErrorMsg(ex.Message);
            }
            catch (SyncJobException sje)
            {
                showErrorMsg(sje.Message);
            }
            catch (Exception ex)
            {
                showErrorMsg(ex.Message);
            }
        }
示例#4
0
        private void autoSync(UISyncJobEntry jobEntry)
        {
            Queue<UISyncJobEntry> selectedJobs = new Queue<UISyncJobEntry>();
            selectedJobs.Enqueue(jobEntry);

            this.Dispatcher.Invoke((Action)delegate
            {
                lblJobsNumber.Content = selectedJobs.Count;
            });

            try
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    // Push the sync job to the waiting list while there are jobs now being synced
                    if (syncWorker.IsBusy)
                        toAutoSyncJobs.Enqueue(jobEntry);
                    else
                        Synchronize(selectedJobs);
                });
            }
            catch (SyncJobException syncJobException)
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    showErrorMsg(syncJobException.Message);
                });
            }
            catch (Exception exception)
            {
                try
                {
                    this.Dispatcher.Invoke((Action)delegate
                    {
                        showErrorMsg(exception.Message);
                    });
                }
                catch (Exception) { } //If you don't have .NET 3.5 SP1.
            }
        }
示例#5
0
        public void LoadSyncJobs()
        {
            string syncSourceDir = txtSource.Text.Trim();
            IList<SyncJob> jobs = jobManager.LoadAllJobs();
            sortJobs(jobs);

            foreach (SyncJob job in jobs)
            {
                UISyncJobEntry jobEntry = new UISyncJobEntry(job);
                SyncJobEntries.Add(jobEntry);

                //job.SyncSourceWatcher.Changed += new FileSystemEventHandler((sender, e) => autoSync(jobEntry));
                //job.SyncSourceWatcher.Deleted += new FileSystemEventHandler((sender, e) => autoSync(jobEntry));
                //job.SyncSourceWatcher.Renamed += new RenamedEventHandler((sender, e) => autoSync(jobEntry));
                //job.SyncSourceWatcher.Created += new FileSystemEventHandler((sender, e) => autoSync(jobEntry));
                //job.SyncSourceWatcher.EnableRaisingEvents = true;
            }
        }
示例#6
0
        void syncWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Stop the timers.
            timerDropbox.Stop();
            //timerAutoSync.Stop();

            Queue<UISyncJobEntry> jobEntries = e.Argument as Queue<UISyncJobEntry>;
            if (jobEntries == null || jobEntries.Count <= 0) return;

            UISyncJobEntry entry = jobEntries.Peek();
            if (entry == null) return;

            // Keep track of current entry that is being synchronized
            currentJobEntry = entry;

            // Update UI
            entry.ProgressBarColor = "#FF01D328";
            entry.ProgressBarValue = 0;
            entry.ProgressBarVisibility = Visibility.Visible;
            entry.ProgressBarMessage = m_ResourceManager.GetString("msg_syncing");

            // Add event handler
            AddAgentEventHandler(entry.SyncAgent);

            try
            {
                if (entry.SyncJob.SyncPreviewResult == null)
                    entry.SyncJob.SyncPreviewResult = entry.SyncAgent.GenerateSyncPreview(null);

                entry.SyncAgent.Synchronize(entry.SyncJob.SyncPreviewResult);
                entry.Error = null;
            }
            catch (Community.CsharpSqlite.SQLiteClient.SqliteSyntaxException ex)
            {
                entry.Error = ex;
                entry.ProgressBarValue = 100;
                entry.ProgressBarColor = "Red";

                this.Dispatcher.Invoke((Action)delegate
                {
                    string errorMsg = m_ResourceManager.GetString("err_metadataMissing");
                    entry.ProgressBarMessage = errorMsg;
                    showErrorMsg(errorMsg);
                });
            }
            catch (System.IO.DirectoryNotFoundException ex)
            {
                entry.Error = ex;
                entry.ProgressBarValue = 100;
                entry.ProgressBarColor = "Red";

                this.Dispatcher.Invoke((Action)delegate
                {
                    string errorMsg = String.Format(m_ResourceManager.GetString("err_directoryNotFound"), ex.Message);
                    entry.ProgressBarMessage = errorMsg;
                    showErrorMsg(errorMsg);
                });
            }
            catch (SyncJobException syncJobException)
            {
                entry.Error = syncJobException;
                entry.ProgressBarValue = 100;
                entry.ProgressBarColor = "Red";

                this.Dispatcher.Invoke((Action)delegate
                {
                    string errorMsg = syncJobException.Message;
                    entry.ProgressBarMessage = errorMsg;
                    showErrorMsg(errorMsg);
                });
            }
            catch (OutOfDiskSpaceException ex)
            {
                string errorMsg;
                entry.Error = ex;
                entry.ProgressBarValue = 100;
                errorMsg = String.Format(m_ResourceManager.GetString("err_insufficientSpace"), entry.IntermediaryStoragePath);
                this.Dispatcher.Invoke((Action)delegate
                {
                    entry.ProgressBarMessage = errorMsg;
                    showErrorMsg(errorMsg);
                });
            }
            catch (Exception ex)
            {
                string errorMsg;
                entry.Error = ex;
                entry.ProgressBarValue = 100;
                entry.ProgressBarColor = "Red";
                errorMsg = String.Format(m_ResourceManager.GetString("err_errorReported"), ex.Message);
                this.Dispatcher.Invoke((Action)delegate
                {
                    entry.ProgressBarMessage = errorMsg;
                    showErrorMsg(errorMsg);
                });
            }

            if (syncWorker.CancellationPending)
            {
                UISyncJobEntry currentSyncJobEntry = jobEntries.Peek();
                jobEntries.Clear();
                jobEntries.Enqueue(currentSyncJobEntry);
            }

            e.Result = jobEntries;
        }
示例#7
0
        private void Synchronize(Queue<UISyncJobEntry> selectedEntries)
        {
            if (selectedEntries.Count <= 0) return;

            // Hide all sync job progress bars
            foreach (UISyncJobEntry entry in SyncJobEntries)
                entry.ProgressBarVisibility = Visibility.Hidden;

            UISyncJobEntry currentJobEntry = null;
            try
            {
                currentJobEntry = selectedEntries.Peek();
                // Update UI
                UpdateSyncInfoUI(currentJobEntry.SyncJob);
                SetControlsEnabledState(true, false);
                listAllSyncJobs_SelectionChanged(null, null);

                // Run sync
                syncWorker.RunWorkerAsync(selectedEntries);

            }
            catch (Exception exception)
            {
                string errorMsg = Validator.validateSyncDirs(currentJobEntry.SyncSource, currentJobEntry.IntermediaryStoragePath);
                if (errorMsg != null)
                    showErrorMsg(errorMsg);
                else
                    showErrorMsg(exception.Message);
            }
        }