/// <summary> /// Cancels all downloads /// </summary> public void CancelAllDownloads() { Messenger.Default.Send(SyncManagerMessage.Create(SyncManagerMessageKey.WillCancelAllDownloadsNotification)); this.currentResourceDownload?.CancelDownload(); this.ResourceDownloads.Clear(); }
/// <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); }
/// <summary> /// Synchronizes the manager did update records. /// </summary> /// <param name="notification">The notification.</param> public void SyncManagerDidUpdateRecords(SyncManagerMessage notification) { List <string> recordIdentifications = notification.State.ValueOrDefault(Core.Session.Constants.KUPSyncManagerModifiedRecordIdentifications) as List <string>; if (recordIdentifications != null) { List <IIdentifier> recordIdentifiers = new List <IIdentifier>(); foreach (string identification in recordIdentifications) { RecordIdentifier recordIdentifier = new RecordIdentifier(identification); recordIdentifiers.Add(recordIdentifier); } this.RegisterChanges(recordIdentifiers); } }
private void SyncStatusChanged(SyncManagerMessage notification) { switch (notification.MessageKey) { case SyncManagerMessageKey.DidStartFullSync: case SyncManagerMessageKey.DidFinishFullSync: case SyncManagerMessageKey.DidFailFullSync: case SyncManagerMessageKey.DidStartIncrementalSync: case SyncManagerMessageKey.DidFinishIncrementalSync: case SyncManagerMessageKey.DidFailIncrementalSync: case SyncManagerMessageKey.DidStartUpSync: case SyncManagerMessageKey.DidFinishUpSync: case SyncManagerMessageKey.DidFailUpSync: case SyncManagerMessageKey.DidStartMetadataSync: case SyncManagerMessageKey.DidFinishMetadataSync: case SyncManagerMessageKey.DidFailMetadataSync: case SyncManagerMessageKey.DidCancelFullSync: case SyncManagerMessageKey.DidStartResourcesSync: case SyncManagerMessageKey.DidFinishResourcesSync: case SyncManagerMessageKey.DidProgressSync: { this.currentStep = 0; this.totalSteps = 0; this.BuildPage(); var oldPage = this.TopLevelElement as UPMDataSyncPage; if (oldPage != null) { this.InformAboutDidChangeTopLevelElement(oldPage, this.TopLevelElement, null, null); } break; } default: break; } }
/// <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)); } }
/// <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); }
/// <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 } })); } }
/// <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); }