コード例 #1
0
        /// <summary>
        /// Cancels all downloads
        /// </summary>
        public void CancelAllDownloads()
        {
            Messenger.Default.Send(SyncManagerMessage.Create(SyncManagerMessageKey.WillCancelAllDownloadsNotification));

            this.currentResourceDownload?.CancelDownload();

            this.ResourceDownloads.Clear();
        }
コード例 #2
0
        /// <summary>
        /// Moves given resource download list to front of the queue
        /// </summary>
        /// <param name="resourceDownloadsToMove">Resource download list</param>
        /// <returns>Returns true if succeeds</returns>
        public bool MoveResourceDownloadsToFrontOfQueue(List <ResourceDownload> resourceDownloadsToMove)
        {
            if (resourceDownloadsToMove.Count == 0)
            {
                return(false);
            }

            var firstDownload = resourceDownloadsToMove[0];

            if (this.currentResourceDownload == firstDownload)
            {
                return(false);
            }

            foreach (var download in resourceDownloadsToMove)
            {
                this.ResourceDownloads.Remove(download);
            }

            this.ResourceDownloads.InsertRange(0, resourceDownloadsToMove);

            if (this.currentDownloadFileHandle != null)
            {
                this.currentDownloadFileHandle.Flush();
                this.currentDownloadFileHandle.Dispose();
                this.currentDownloadFileHandle = null;
            }

            ResourceDownload cancelledDownload = this.currentResourceDownload;

            if (this.currentResourceDownload != null)
            {
                this.currentResourceDownload.Connection?.Cancel();
                this.currentResourceDownload.Connection = null;
                this.currentResourceDownload            = null;
            }

            if (cancelledDownload != null)
            {
                Messenger.Default.Send(SyncManagerMessage.Create(
                                           SyncManagerMessageKey.WillCancelRunningDownloadNotification,
                                           new Dictionary <string, object> {
                    { "TheObject", cancelledDownload }
                }));
            }

            this.StartDownloadForFrontMostFile();

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Does the discard.
        /// </summary>
        private void DoDiscard()
        {
            UPMSyncConflictWithContext syncConflictWithContext = (UPMSyncConflictWithContext)this.discardedSyncConflict;

            if (syncConflictWithContext.OfflineRequest.DeleteRequest(true) != 0)
            {
                SimpleIoc.Default.GetInstance <ILogger>().LogError("Offline request could not be deleted because of database error");
            }
            else
            {
                this.SyncConflictsPage.RemoveConflict(this.discardedSyncConflict);
                if (this.SyncConflictsPage.NumberOfSyncConflicts == 0)
                {
                    this.AddNoConflictsFoundPage(this.SyncConflictsPage);
                }

                this.InformAboutDidChangeTopLevelElement(this.TopLevelElement, this.TopLevelElement, new List <IIdentifier> {
                    this.discardedSyncConflict.Identifier
                }, UPChangeHints.ChangeHintsWithHint("DiscardConflict"));
                Messenger.Default.Send(SyncManagerMessage.Create(SyncManagerMessageKey.NumberOfConflictsChanged));
            }
        }
コード例 #4
0
        /// <summary>
        /// Cancels resource download
        /// </summary>
        /// <param name="resourceDownload">Resource download</param>
        /// <returns>Returns true if succeeds</returns>
        public bool CancelResourceDownload(ResourceDownload resourceDownload)
        {
            var cancelledDownload = false;

            if (this.currentDownloadFileHandle != null)
            {
                this.currentDownloadFileHandle.Flush();
                this.currentDownloadFileHandle.Dispose();
                this.currentDownloadFileHandle = null;
            }

            if (this.currentResourceDownload == resourceDownload)
            {
                if (this.serverSupportRangeHeader == false)
                {
                    Exception error;
                    this.StorageService.TryDelete(this.currentResourceDownload.LocalUrl, out error);
                }

                this.currentResourceDownload.Connection?.Cancel();
                this.currentResourceDownload.Connection = null;
                this.currentResourceDownload            = null;
            }

            if (this.ResourceDownloads.Contains(resourceDownload))
            {
                cancelledDownload = true;
            }

            this.ResourceDownloads.Remove(resourceDownload);
            Messenger.Default.Send(SyncManagerMessage.Create(
                                       SyncManagerMessageKey.WillCancelRunningDownloadNotification,
                                       new Dictionary <string, object> {
                { "TheObject", resourceDownload }
            }));

            return(cancelledDownload);
        }
コード例 #5
0
        /// <summary>
        /// Stop processing download queue
        /// </summary>
        public void StopProcessingDownloadQueue()
        {
            this.currentDownloadFileHandle?.Dispose();
            this.currentDownloadFileHandle = null;

            var currentDownload = this.currentResourceDownload;

            if (this.currentResourceDownload != null)
            {
                this.currentResourceDownload.Connection?.Cancel();
                this.currentResourceDownload.Connection = null;
                this.currentResourceDownload            = null;
            }

            if (currentDownload != null)
            {
                Messenger.Default.Send(SyncManagerMessage.Create(
                                           SyncManagerMessageKey.WillCancelRunningDownloadNotification,
                                           new Dictionary <string, object> {
                    { "TheObject", currentDownload }
                }));
            }
        }
コード例 #6
0
        /// <summary>
        /// Updateds the element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        /// The <see cref="UPMElement" />.
        /// </returns>
        public override UPMElement UpdatedElement(UPMElement element)
        {
            UPMSyncConflictsPage page = new UPMSyncConflictsPage(StringIdentifier.IdentifierWithStringId("SyncConflictsPage"));

            page.SyncConflictEmail = ConfigurationUnitStore.DefaultStore.ConfigValue("Sync.ConflictEmailAddress");
            IOfflineStorage offlineStorage  = UPOfflineStorage.DefaultStorage;
            var             offlineRequests = this.ShowAllOfflineRequests ? offlineStorage.OfflineRequests : offlineStorage.ConflictRequests;

            if (offlineRequests == null || offlineRequests.Count == 0)
            {
                this.AddNoConflictsFoundPage(page);
                return(page);
            }

            foreach (UPOfflineRequest request in offlineRequests)
            {
                IIdentifier identifier;
                if (!string.IsNullOrEmpty(request.IdentifyingRecordIdentification))
                {
                    identifier = new RecordIdentifier(request.IdentifyingRecordIdentification);
                }
                else
                {
                    identifier = StringIdentifier.IdentifierWithStringId($"request_{request.RequestNr}");
                }

                UPMSyncConflictWithContext syncConflict = new UPMSyncConflictWithContext(identifier);
                request.LoadFromOfflineStorage();
                syncConflict.OfflineRequest = request;
                syncConflict.CanBeFixed     = request.FixableByUser;
                syncConflict.CanBeReported  = !string.IsNullOrEmpty(page.SyncConflictEmail) && syncConflict.OfflineRequest.HasXml;
                if (!string.IsNullOrEmpty(request.ImageName))
                {
                    //SyncConflict.Icon = UIImage.ImageNamed(request.ImageName);    // CRM-5007
                }

                UPMStringField titleLineField = new UPMStringField(null);
                titleLineField.StringValue = request.TitleLine;
                syncConflict.MainField     = titleLineField;
                string detailsLine = request.DetailsLine;
                if (!string.IsNullOrEmpty(detailsLine))
                {
                    UPMStringField detailsLineField = new UPMStringField(null);
                    detailsLineField.StringValue = detailsLine;
                    syncConflict.DetailField     = detailsLineField;
                }

                if (!this.ShowAllOfflineRequests)
                {
                    UPMErrorStatus error = UPMErrorStatus.ErrorStatusWithMessageDetails(request.Error, request.Response);
                    syncConflict.AddStatus(error);
                }

                List <UPOfflineRequest> dependingRequests = request.DependentRequests;
                if (dependingRequests != null)
                {
                    foreach (UPOfflineRequest dependentRequest in dependingRequests)
                    {
                        string        description = $"{dependentRequest.TitleLine}-{dependentRequest.DetailsLine}";
                        UPMWarnStatus warning     = UPMWarnStatus.WarnStatusWithMessageDetails(description, null);
                        syncConflict.AddStatus(warning);
                    }
                }

                page.AddSyncConflict(syncConflict);
            }

            if (this.oldNumberOfConflicts >= 0 && this.oldNumberOfConflicts != offlineRequests.Count)
            {
                Messenger.Default.Send(SyncManagerMessage.Create(SyncManagerMessageKey.NumberOfConflictsChanged));
            }

            this.oldNumberOfConflicts = offlineRequests.Count;
            return(page);
        }