Esempio n. 1
0
        /// <summary>
        /// Adds a ManualSyncRequest to the queue.
        /// </summary>
        /// <param name="item">ManualSyncRequest</param>
        /// <exception cref="ArgumentNullException">Thrown when ManualSyncRequest is null</exception>
        public void AddSyncJob(ManualSyncRequest item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            lock (Locker)
            {
                if (!_queuedJobsLookup.Contains(item.TagName))
                {
                    _jobs.Add(item);
                    _queuedJobsLookup.Add(item.TagName);
                }
            }
            _wh.Set();
        }
Esempio n. 2
0
        private bool ManualSync(Tag tag, bool switchSeamless)
        {
            //Try and cleanup the deletepaths first before syncing.
            //This is the find all the folder that is deleted but still tagged.
            //This will ensure that if the folder does not exist, no files will be propagated over.
            FindAndCleanDeletedPaths();
            //If the Tag is already synchronzing or is already queued , return false.
            if (CompareAndSyncController.Instance.IsQueuedOrSyncing(tag.TagName))
            {
                return false;
            }
            //Retrieve the list of paths that are not deleted.
            List<string> paths = tag.FilteredPathListString;
            //Convert the path to physical address.
            List<string>[] filterPaths = ProfilingLayer.Instance.ConvertAndFilter(paths);
            //If the number of path is less than 2,  does not sync and return a true 
            //If switch Seamless is true , set the mode of the tag to seamless.
            if (filterPaths[0].Count < 2)
            {
                if (switchSeamless)
                {
                    SetTagMode(tag, true);
                }
                return true;
            }
            //Create the manual Sync request and send it to CompareAndSyncController.
            ManualSyncRequest syncRequest = new ManualSyncRequest(filterPaths[0].ToArray(), tag.Filters, SyncConfig.Copy, tag.TagName, switchSeamless);
            CompareAndSyncController.Instance.Sync(syncRequest);

            return true;
        }
 /// <summary>
 /// Adds a ManualSyncRequest job to the single-instance ManualQueueControl.
 /// </summary>
 /// <param name="request">ManualSyncRequest request to add to the queue.</param>
 public void Sync(ManualSyncRequest request)
 {
     ManualQueueControl.Instance.AddSyncJob(request);
 }
Esempio n. 4
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;
        }
Esempio n. 5
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();
                }
            }
        }