Exemple #1
0
        private IEnumerable <Task <SynchronizationReport> > SynchronizePendingFilesAsync(IAsyncFilesSynchronizationCommands destination, bool forceSyncingContinuation)
        {
            var commands = (IAsyncFilesCommandsImpl)destination.Commands;

            var destinationUrl = commands.UrlFor();

            for (var i = 0; i < AvailableSynchronizationRequestsTo(destinationUrl); i++)
            {
                SynchronizationWorkItem work;
                if (!synchronizationQueue.TryDequePendingSynchronization(destinationUrl, out work))
                {
                    break;
                }

                if (synchronizationQueue.IsDifferentWorkForTheSameFileBeingPerformed(work, destinationUrl))
                {
                    Log.Debug("There was an already being performed synchronization of a file '{0}' to {1}", work.FileName,
                              destination);

                    if (synchronizationQueue.EnqueueSynchronization(destinationUrl, work)) // add it again at the end of the queue
                    {
                        // add it again at the end of the queue
                        publisher.Publish(new SynchronizationUpdateNotification
                        {
                            FileName = work.FileName,
                            DestinationFileSystemUrl = destinationUrl,
                            SourceServerId           = storage.Id,
                            SourceFileSystemUrl      = FileSystemUrl,
                            Type      = work.SynchronizationType,
                            Action    = SynchronizationAction.Enqueue,
                            Direction = SynchronizationDirection.Outgoing
                        });
                    }
                }
                else
                {
                    var workTask = PerformSynchronizationAsync(destination, work);
                    if (forceSyncingContinuation)
                    {
                        workTask.ContinueWith(t => SynchronizePendingFilesAsync(destination, true).ToArray());
                    }

                    yield return(workTask);
                }
            }
        }
        private IEnumerable <Task <SynchronizationReport> > SynchronizePendingFilesAsync(ISynchronizationServerClient destinationCommands, bool forceSyncingAll)
        {
            var destinationUrl = destinationCommands.BaseUrl;

            while (AvailableSynchronizationRequestsTo(destinationUrl) > 0)
            {
                SynchronizationWorkItem work;
                if (synchronizationQueue.TryDequePending(destinationUrl, out work) == false)
                {
                    break;
                }

                if (synchronizationQueue.IsDifferentWorkForTheSameFileBeingPerformed(work, destinationUrl))
                {
                    Log.Debug("There was an already being performed synchronization of a file '{0}' to {1}", work.FileName,
                              destinationCommands);

                    if (synchronizationQueue.EnqueueSynchronization(destinationUrl, work))             // add it again at the end of the queue
                    {
                        // add it again at the end of the queue
                        publisher.Publish(new SynchronizationUpdateNotification
                        {
                            FileName = work.FileName,
                            DestinationFileSystemUrl = destinationUrl,
                            SourceServerId           = storage.Id,
                            SourceFileSystemUrl      = FileSystemUrl,
                            Type      = work.SynchronizationType,
                            Action    = SynchronizationAction.Enqueue,
                            Direction = SynchronizationDirection.Outgoing
                        });
                    }

                    continue;
                }

                var workTask = PerformSynchronizationAsync(destinationCommands, work);

                if (forceSyncingAll)
                {
                    workTask.ContinueWith(_ => context.NotifyAboutWork());             // synchronization slot released, next file can be synchronized
                }

                yield return(workTask);
            }
        }