Exemple #1
0
        public async Task <bool> QueueOperationAsync(IMobileServiceFileOperation operation)
        {
            bool operationEnqueued = false;

            await processingSemaphore.WaitAsync();

            try
            {
                var pendingItemOperation = await this.operationsQueue.GetOperationByFileIdAsync(operation.FileId);

                if (pendingItemOperation != null)
                {
                    pendingItemOperation.OnQueueingNewOperation(operation);

                    if (pendingItemOperation.State == FileOperationState.Cancelled)
                    {
                        await this.operationsQueue.RemoveAsync(pendingItemOperation.Id);
                    }
                }

                if (operation.State != FileOperationState.Cancelled)
                {
                    await this.operationsQueue.EnqueueAsync(operation);

                    operationEnqueued = true;
                }
            }
            finally
            {
                processingSemaphore.Release();
            }

            return(operationEnqueued);
        }
Exemple #2
0
        public async Task PullFilesAsync(string tableName, string itemId)
        {
            IEnumerable <MobileServiceFile> files = await this.mobileServiceFilesClient.GetFilesAsync(tableName, itemId);

            foreach (var file in files)
            {
                FileSynchronizationAction syncAction = FileSynchronizationAction.Update;

                MobileServiceFileMetadata metadata = await this.metadataStore.GetFileMetadataAsync(file.Id);

                if (metadata == null)
                {
                    syncAction = FileSynchronizationAction.Create;

                    metadata = MobileServiceFileMetadata.FromFile(file);

                    metadata.ContentMD5   = null;
                    metadata.LastModified = null;
                }

                if (string.Compare(metadata.ContentMD5, file.ContentMD5, StringComparison.Ordinal) != 0 ||
                    (metadata.LastModified == null || metadata.LastModified.Value.ToUniversalTime() != file.LastModified.Value.ToUniversalTime()))
                {
                    metadata.LastModified = file.LastModified;
                    metadata.ContentMD5   = file.ContentMD5;

                    await this.metadataStore.CreateOrUpdateAsync(metadata);

                    await this.syncHandler.ProcessFileSynchronizationAction(file, syncAction);

                    NotifyFileOperationCompletion(file, syncAction.ToFileOperationKind(), FileOperationSource.ServerPull);
                }
            }

            var fileMetadata = await this.metadataStore.GetMetadataAsync(tableName, itemId);

            var deletedItemsMetadata = fileMetadata.Where(m => !files.Any(f => string.Compare(f.Id, m.FileId) == 0));

            foreach (var metadata in deletedItemsMetadata)
            {
                IMobileServiceFileOperation pendingOperation = await this.operationsQueue.GetOperationByFileIdAsync(metadata.FileId);

                // TODO: Need to call into the sync handler for conflict resolution here...
                if (pendingOperation == null || pendingOperation is DeleteMobileServiceFileOperation)
                {
                    await metadataStore.DeleteAsync(metadata);

                    await this.syncHandler.ProcessFileSynchronizationAction(MobileServiceFile.FromMetadata(metadata), FileSynchronizationAction.Delete);

                    NotifyFileOperationCompletion(MobileServiceFile.FromMetadata(metadata), FileOperationKind.Delete, FileOperationSource.ServerPull);
                }
            }
        }
        public async Task EnqueueAsync(IMobileServiceFileOperation operation)
        {
            OperationsInfo operationsInfo = this.operationsInfo.Value;
            var            operationItem  = new FileOperationItem
            {
                FileId   = operation.FileId,
                Id       = operation.Id,
                Kind     = operation.Kind,
                Sequence = Interlocked.Increment(ref operationsInfo.Sequence)
            };

            await this.store.UpsertAsync(FileOperationTableName, new[] { operationItem.ToJsonObject() }, ignoreMissingColumns : false);

            Interlocked.Increment(ref operationsInfo.Count);
        }
Exemple #4
0
        public async Task PushChangesAsync(CancellationToken cancellationToken)
        {
            await processingSemaphore.WaitAsync(cancellationToken);

            try
            {
                while (this.operationsQueue.Count > 0)
                {
                    IMobileServiceFileOperation operation = await operationsQueue.PeekAsync();

                    // This would also take the cancellation token
                    await operation.Execute(this.metadataStore, this);

                    await operationsQueue.RemoveAsync(operation.Id);
                }
            }
            finally
            {
                processingSemaphore.Release();
            }
        }
 public abstract void OnQueueingNewOperation(IMobileServiceFileOperation operation);
        public async Task EnqueueAsync(IMobileServiceFileOperation operation)
        {

            OperationsInfo operationsInfo = this.operationsInfo.Value;
            var operationItem = new FileOperationItem
            {
                FileId = operation.FileId,
                Id = operation.Id,
                Kind = operation.Kind,
                Sequence = Interlocked.Increment(ref operationsInfo.Sequence)
            };

            await this.store.UpsertAsync(FileOperationTableName, new[] { operationItem.ToJsonObject() }, ignoreMissingColumns: false);

            Interlocked.Increment(ref operationsInfo.Count);
        }
Exemple #7
0
 public override void OnQueueingNewOperation(IMobileServiceFileOperation operation)
 {
 }
 public abstract void OnQueueingNewOperation(IMobileServiceFileOperation operation);
 public override void OnQueueingNewOperation(IMobileServiceFileOperation operation)
 {
     //
 }
        public async Task<bool> QueueOperationAsync(IMobileServiceFileOperation operation)
        {
            bool operationEnqueued = false;

            await processingSemaphore.WaitAsync();

            try
            {
                var pendingItemOperation = await this.operationsQueue.GetOperationByFileIdAsync(operation.FileId);

                if (pendingItemOperation != null)
                {
                    pendingItemOperation.OnQueueingNewOperation(operation);

                    if (pendingItemOperation.State == FileOperationState.Cancelled)
                    {
                        await this.operationsQueue.RemoveAsync(pendingItemOperation.Id);
                    }
                }

                if (operation.State != FileOperationState.Cancelled)
                {
                    await this.operationsQueue.EnqueueAsync(operation);
                    operationEnqueued = true;
                }

            }
            finally
            {
                processingSemaphore.Release();
            }

            return operationEnqueued;
        }