Beispiel #1
0
 /// <summary>
 /// Initialize the SyncProgressWatcher Object and adds the SyncProgressWatcher as an observer to the progress
 /// </summary>
 /// <param name="main">Reference to the MainWindow</param>
 /// <param name="tagName">Tagname associated with the SyncProgressWatcher</param>
 /// <param name="p">SyncProgress to watch</param>
 public SyncProgressWatcher(MainWindow main, string tagName, SyncProgress p)
 {
     _main = main;
     _progress = p;
     _progress.AddObserver(this);
     SyncStart();
 }
 /// <summary>
 /// Initialize a Sync Start Notification
 /// </summary>
 /// <param name="tagName">name of the tag</param>
 public SyncStartNotification(string tagName)
     : base("Sync Start Notification", NotificationCode.SyncStartNotification)
 {
     Progress = new SyncProgress(tagName);
     
     TagName = tagName;
 }
Beispiel #3
0
        /// <summary>
        /// Notify that that a state changed has occured and refreshes the UI if the tag of the progress is the currently selected tag
        /// </summary>
        /// <param name="progress">Progress to notify</param>
        public void ProgressNotifyChange(SyncProgress progress)
        {
            string message = string.Empty;
            string breakString = progress.Message ?? string.Empty;

            if (breakString.Length >= 45)
            {
                breakString = breakString.Substring(0, 10) + " ... " +
                              breakString.Substring(breakString.Length - 35, 35);
            }

            switch (progress.State)
            {
                case SyncState.Analyzing:
                    message = "Analyzing " + breakString;
                    break;
                case SyncState.Synchronizing:
                    message = "Synchronizing " + breakString;
                    break;
                case SyncState.Finalizing:
                    message = "Finalizing " + breakString;
                    break;
                default:
                    return;
            }

            double percentageComplete = progress.PercentComplete;
            string tagname = progress.TagName;

            if (SelectedTag == tagname)
            {
                LblStatusText.Content = message;
                ProgressBarSync.Value = percentageComplete;
                SetProgressBarColor(percentageComplete);
                if (LogicLayer.GetTagState(SelectedTag) == TagState.ManualToSeamless ||
                    LogicLayer.GetTagState(SelectedTag) == TagState.SeamlessToManual)
                {
                    SwitchingMode();
                }
            }

            _syncProgressNotificationDictionary[tagname] = percentageComplete;
            _tagStatusNotificationDictionary[tagname] = message;
        }
Beispiel #4
0
        /// <summary>
        /// Notify that synchronization has completed and refreshes the UI if the tag of the progress is the currently selected tag
        /// </summary>
        /// <param name="progress">Progress to notify</param>
        public void ProgressNotifySyncComplete(SyncProgress progress)
        {
            string message = "Synchronization Completed at " + DateTime.Now;
            double percentageComplete = progress.PercentComplete;
            _tagStatusNotificationDictionary[progress.TagName] = message;
            _syncProgressNotificationDictionary[progress.TagName] = percentageComplete;
            NotifyBalloon("Synchronization Completed", progress.TagName + " is now synchronized.");

            if (SelectedTag == progress.TagName)
            {
                ProgressBarSync.IsIndeterminate = false;
                LblStatusText.Content = message;
                ProgressBarSync.Value = percentageComplete;
                SetProgressBarColor(percentageComplete);
                BtnSyncNow.IsEnabled = true;
                BtnPreview.IsEnabled = true;
                BtnSyncMode.IsEnabled = true;
                _manualSyncEnabled = true;

                if (LogicLayer.GetTag(SelectedTag).IsSeamless)
                {
                    BtnSyncNow.Visibility = Visibility.Hidden;
                    BtnPreview.Visibility = Visibility.Hidden;
                }
                else
                {
                    SyncButtonMode();
                    BtnSyncNow.Visibility = Visibility.Visible;
                    BtnPreview.Visibility = Visibility.Visible;
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Notify that finalizing has started and refreshes the UI if the tag of the progress is the currently selected tag
 /// </summary>
 /// <param name="progress">Progress to notify</param>
 public void ProgressNotifyFinalizing(SyncProgress progress)
 {
     if (SelectedTag == progress.TagName)
     {
         BtnPreview.Visibility = Visibility.Hidden;
         BtnSyncNow.Visibility = Visibility.Hidden;
         ProgressBarSync.IsIndeterminate = false;
         LblProgress.Visibility = Visibility.Visible;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Notify that analyzing has started and refreshes the UI if the tag of the progress is the currently selected tag
        /// </summary>
        /// <param name="progress">Progress to notify</param>
        public void ProgressNotifyAnalyzing(SyncProgress progress)
        {
            const string message = "Analyzing Folders";
            const double percentageComplete = 0;
            string tagname = progress.TagName;

            if (SelectedTag == tagname)
            {
                BtnPreview.Visibility = Visibility.Hidden;
                LblStatusText.Content = message;
                ProgressBarSync.Value = percentageComplete;
                SetProgressBarColor(percentageComplete);
                ProgressBarSync.IsIndeterminate = true;
                LblProgress.Visibility = Visibility.Hidden;
            }

            _syncProgressNotificationDictionary[tagname] = percentageComplete;
            _tagStatusNotificationDictionary[tagname] = message;
        }
Beispiel #7
0
        /// <summary>
        /// Notify that a synchronization has started and refreshes the UI if the tag of the progress is the currently selected tag
        /// </summary>
        /// <param name="progress">Progress to notify</param>
        public void ProgressNotifySyncStart(SyncProgress progress)
        {
            const string message = "Synchronization Started";

            if (SelectedTag == progress.TagName)
            {
                LblStatusText.Content = message;
            }

            _tagStatusNotificationDictionary[progress.TagName] = message;
            NotifyBalloon("Synchronization Started", progress.TagName + " is being synchronized.");
        }
Beispiel #8
0
        /// <summary>
        /// Synchronizes a job given a <see cref="ManualSyncRequest"/> and a <see cref="SyncProgress"/>.
        /// </summary>
        /// <param name="request">The <see cref="ManualSyncRequest"/> to pass in.</param>
        /// <param name="progress">The <see cref="SyncProgress"/> to pass in.</param>
        /// <returns></returns>
        public static RootCompareObject Sync(ManualSyncRequest request, SyncProgress progress)
        {
            ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.SYNC_STARTED, "Started Manual Sync for " + request.TagName));

            //Initialize and add filters conflict and archive filters to it
            List<Filter> filters = request.Filters.ToList();
            filters.Add(FilterFactory.CreateArchiveFilter(request.Config.ArchiveName));
            filters.Add(FilterFactory.CreateArchiveFilter(request.Config.ConflictDir));
            RootCompareObject rco = new RootCompareObject(request.Paths);

            // Analyzing
            progress.ChangeToAnalyzing();
            List<string> typeConflicts = new List<string>();
            CompareObjectHelper.PreTraverseFolder(rco, new BuilderVisitor(filters, typeConflicts, progress), progress);
            
            if (progress.State == SyncState.Cancelled)
            {
                ServiceLocator.UIPriorityQueue().Enqueue(new CancelSyncNotification(request.TagName, true));
                return null;
            }

            CompareObjectHelper.PreTraverseFolder(rco, new XMLMetadataVisitor(), progress);
            
            if (progress.State == SyncState.Cancelled)
            {
                ServiceLocator.UIPriorityQueue().Enqueue(new CancelSyncNotification(request.TagName, true));
                return null;
            }

            CompareObjectHelper.PreTraverseFolder(rco, new ProcessMetadataVisitor(), progress);
           
            if (progress.State == SyncState.Cancelled)
            {
                ServiceLocator.UIPriorityQueue().Enqueue(new CancelSyncNotification(request.TagName, true));
                return null;
            }

            CompareObjectHelper.LevelOrderTraverseFolder(rco, new FolderRenameVisitor(), progress);
            
            if (progress.State == SyncState.Cancelled)
            {
                ServiceLocator.UIPriorityQueue().Enqueue(new CancelSyncNotification(request.TagName, true));
                return null;
            }

            ComparerVisitor comparerVisitor = new ComparerVisitor();
            CompareObjectHelper.PostTraverseFolder(rco, comparerVisitor, progress);
            
            if (progress.State == SyncState.Cancelled)
            {
                ServiceLocator.UIPriorityQueue().Enqueue(new CancelSyncNotification(request.TagName, true));
                return null;
            }

            if (progress.State != SyncState.Cancelled)
            {
                // Syncing
                progress.ChangeToSyncing(comparerVisitor.TotalNodes);
                HandleBuildConflicts(typeConflicts, request.Config);
                CompareObjectHelper.PreTraverseFolder(rco, new ConflictVisitor(request.Config), progress);
                SyncerVisitor syncerVisitor = new SyncerVisitor(request.Config, progress);
                CompareObjectHelper.PreTraverseFolder(rco, syncerVisitor, progress);

                // XML Writer
                progress.ChangeToFinalizing(syncerVisitor.NodesCount);
                CompareObjectHelper.PreTraverseFolder(rco, new XMLWriterVisitor(progress), progress);
                progress.ChangeToFinished();

                if (request.Notify)
                    ServiceLocator.LogicLayerNotificationQueue().Enqueue(new MonitorTagNotification(request.TagName));

                // Finished
                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.SYNC_STOPPED, "Completed Manual Sync for " + request.TagName));
                return rco;
            }

            ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.SYNC_STOPPED, "Cancelled Manual Sync for " + request.TagName));
            return null;
        }
Beispiel #9
0
 /// <summary>
 /// Instantiates the XMLWriterVisitor by taking in a SyncProgress object
 /// </summary>
 /// <param name="progress"></param>
 public XMLWriterVisitor(SyncProgress progress)
 {
     _progress = progress;
     _dateTime = DateTime.UtcNow.Ticks;
 }
Beispiel #10
0
        /// <summary>
        /// Worker thread to dequeue and process jobs in the queue.
        /// </summary>
        private void Work()
        {
            while (true)
            {
                lock (Locker)
                {
                    if (_jobs.Count > 0)
                    {
                        try
                        {
                            _currJob = _jobs[0];
                            _jobs.RemoveAt(0);

                            if (_currJob == null)
                                return;

                            _queuedJobsLookup.Remove(_currJob.TagName);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                }
                if (_currJob != null)
                {
                    if (_currJob.Paths.Length < 2)
                    {
                        ServiceLocator.UINotificationQueue().Enqueue(new NothingToSyncNotification(_currJob.TagName));
                        if (_currJob.Notify)
                            ServiceLocator.LogicLayerNotificationQueue().Enqueue(new MonitorTagNotification(_currJob.TagName));
                        _currJobProgress = null;
                        _currJob = null;
                    }
                    else
                    {
                        SyncStartNotification notification = new SyncStartNotification(_currJob.TagName);
                        _currJobProgress = notification.Progress;
                        ServiceLocator.UINotificationQueue().Enqueue(notification);
                        RootCompareObject rco = ManualSyncer.Sync(_currJob, _currJobProgress);

                        //Set both to null
                        AbstractNotification endnotification = new SyncCompleteNotification(_currJob.TagName, rco);
                        if (_currJob != null)
                            _isPendingCancel.Remove(_currJob.TagName);
                        _currJob = null;
                        _currJobProgress = null;
                        ServiceLocator.UINotificationQueue().Enqueue(endnotification);


                    }
                }
                else
                {
                    _wh.WaitOne();
                }
            }
        }