/// <summary> /// Consturct a SyncNodeStamp from a ChangeLogRecord. /// </summary> /// <param name="record">The record to use.</param> internal SyncNodeInfo(ChangeLogRecord record) { this.ID = record.EventID; this.LocalIncarnation = record.SlaveRev; this.MasterIncarnation = record.MasterRev; this.NodeType = GetSyncNodeType(record.Type.ToString()); switch (record.Operation) { case ChangeLogRecord.ChangeLogOp.Changed: this.Operation = SyncOperation.Change; break; case ChangeLogRecord.ChangeLogOp.Created: this.Operation = SyncOperation.Create; break; case ChangeLogRecord.ChangeLogOp.Deleted: this.Operation = SyncOperation.Delete; break; case ChangeLogRecord.ChangeLogOp.Renamed: this.Operation = SyncOperation.Rename; break; default: this.Operation = SyncOperation.Unknown; break; } }
protected async Task <(IAllowSync, IDeleteGraphSyncer?)> GetDeleteGraphSyncerIfDeleteAllowed( ContentItem contentItem, IContentItemVersion contentItemVersion, SyncOperation syncOperation) { try { IDeleteGraphSyncer deleteGraphSyncer = _serviceProvider.GetRequiredService <IDeleteGraphSyncer>(); IAllowSync allowSync = await deleteGraphSyncer.DeleteAllowed( contentItem, contentItemVersion, syncOperation); return(allowSync, deleteGraphSyncer); } catch (Exception exception) { string contentType = GetContentTypeDisplayName(contentItem); //todo: will get logged twice, but want to keep the param version _logger.LogError(exception, "Unable to check if the '{ContentItem}' {ContentType} can be {DeleteOperation} from the {GraphReplicaSetName} graph.", contentItem.DisplayText, contentType, syncOperation.ToString("PrP", null).ToLower(), contentItemVersion.GraphReplicaSetName); await _notifier.Add(GetSyncOperationCancelledUserMessage(syncOperation, contentItem.DisplayText, contentType), $"Unable to check if the '{contentItem.DisplayText}' {contentType} can be {syncOperation.ToString("PrP", null).ToLower()} from the {contentItemVersion.GraphReplicaSetName} graph.", exception : exception); throw; } }
private void ActionWithStatus(SyncOperation operation) { List <SyncOperation> ops = new List <SyncOperation>(); ops.Add(operation); ActionWithStatus(ops); }
protected string GetSyncOperationCancelledUserMessage( SyncOperation syncOperation, string displayText, string contentType) { return($"{syncOperation} the '{displayText}' {contentType} has been cancelled, due to an issue with graph syncing."); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } if (RunningOperation != null) { RunningOperation.Dispose(); RunningOperation = null; } /* * if (Watcher != null) * { * Watcher.Dispose(); * Watcher = null; * } */ } base.Dispose(disposing); }
protected async Task DeleteFromGraphReplicaSet( IDeleteGraphSyncer deleteGraphSyncer, ContentItem contentItem, SyncOperation syncOperation) { try { await deleteGraphSyncer.Delete(); } catch (CommandValidationException ex) { // don't fail when node was not found in the graph // at the moment, we only add published items to the graph, // so if you try to delete a draft only item, this task fails and the item isn't deleted //todo: if this check is needed after the published/draft work, don't rely on the message! if (ex.Message == "Expecting 1 node to be deleted, but 0 were actually deleted.") { return; } AddFailureNotifier(deleteGraphSyncer, contentItem, ex, syncOperation); throw; } catch (Exception ex) { AddFailureNotifier(deleteGraphSyncer, contentItem, ex, syncOperation); throw; } }
public async Task <IAllowSync> DeleteAllowed(ContentItem contentItem, IContentItemVersion contentItemVersion, SyncOperation syncOperation, IEnumerable <KeyValuePair <string, object> >?deleteIncomingRelationshipsProperties = null, IGraphDeleteContext?parentContext = null) { _syncNameProvider.ContentType = contentItem.ContentType; if (contentItem.Content.GraphSyncPart == null || _syncNameProvider.GraphSyncPartSettings.PreexistingNode) { return(AllowSync.NotRequired); } //todo: helper for this var allDeleteIncomingRelationshipsProperties = new HashSet <KeyValuePair <string, object> >(); if (deleteIncomingRelationshipsProperties != null) { allDeleteIncomingRelationshipsProperties.UnionWith(deleteIncomingRelationshipsProperties); } //todo: unions unnecessarily when called embeddedly : new deleteembeddedallowed method? if (syncOperation == SyncOperation.Unpublish) { allDeleteIncomingRelationshipsProperties.UnionWith( ContentPickerFieldGraphSyncer.ContentPickerRelationshipProperties); } _graphDeleteItemSyncContext = new GraphDeleteContext( contentItem, _deleteNodeCommand, this, syncOperation, _syncNameProvider, _contentManager, contentItemVersion, allDeleteIncomingRelationshipsProperties, parentContext, _serviceProvider); return(await DeleteAllowed()); }
/// <summary> /// Construct a SyncNodeStamp from a Node. /// </summary> /// <param name="node">the node to use.</param> internal SyncNodeInfo(Node node) { this.ID = node.ID; this.LocalIncarnation = node.LocalIncarnation; this.MasterIncarnation = node.MasterIncarnation; this.NodeType = GetSyncNodeType(node.Type); this.Operation = node.Type == NodeTypes.TombstoneType ? SyncOperation.Delete : SyncOperation.Unknown; }
/// <summary> /// Construct a SyncNodeInfo from a stream. /// </summary> /// <param name="reader"></param> internal SyncNodeInfo(BinaryReader reader) { this.ID = new Guid(reader.ReadBytes(16)).ToString(); this.LocalIncarnation = reader.ReadUInt64(); this.MasterIncarnation = reader.ReadUInt64(); this.NodeType = (SyncNodeType)reader.ReadByte(); this.Operation = (SyncOperation)reader.ReadByte(); }
public void RunOperation(Func <Task> op) { var so = new SyncOperation(op); _operations.Enqueue(so); so.Wait(); }
public void SyncOperationTest() { var store = CreateStore(); var user = CreateTestUser(); try { var operation = new SyncOperation(); operation.UserIDGuid = user.UserIDGuid; operation.Comment = "Comment"; operation.IsSuccessBoolean = true; operation.OperationBeginTimeDateTime = new DateTime(2015, 06, 05); operation.OperationEndTimeDateTime = new DateTime(2015, 05, 06); store.SaveSyncOperation(operation); var savedItem = store.GetSyncOperation(operation.SyncOperationIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(operation.Comment, savedItem.Comment); Assert.AreEqual(operation.IsSuccess, savedItem.IsSuccess); Assert.AreEqual(operation.OperationBeginTime, savedItem.OperationBeginTime); Assert.AreEqual(operation.OperationEndTime, savedItem.OperationEndTime); Assert.AreEqual(operation.UserID, savedItem.UserID); operation.Comment = "Comment2"; operation.IsSuccessBoolean = false; operation.OperationBeginTimeDateTime = new DateTime(2015, 07, 05); operation.OperationEndTimeDateTime = new DateTime(2015, 08, 06); store.SaveSyncOperation(operation); savedItem = store.GetSyncOperation(operation.SyncOperationIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(operation.Comment, savedItem.Comment); Assert.AreEqual(operation.IsSuccess, savedItem.IsSuccess); Assert.AreEqual(operation.OperationBeginTime, savedItem.OperationBeginTime); Assert.AreEqual(operation.OperationEndTime, savedItem.OperationEndTime); Assert.AreEqual(operation.UserID, savedItem.UserID); store.DeleteSyncOperation(operation.SyncOperationIDGuid); savedItem = store.GetSyncOperation(operation.SyncOperationIDGuid); Assert.IsNull(savedItem); } finally { DeleteTestUser(); } }
private void AddFailureNotifier(IDeleteGraphSyncer deleteGraphSyncer, ContentItem contentItem, Exception exception, SyncOperation syncOperation) { string contentType = GetContentTypeDisplayName(contentItem); string operation = syncOperation.ToString("PrP", null); _logger.LogError(exception, "{Operation} the '{ContentItem}' {ContentType} has been cancelled because the {GraphReplicaSetName} graph couldn't be updated.", operation, contentItem.DisplayText, contentType, deleteGraphSyncer.GraphReplicaSetName); _notifier.Add(GetSyncOperationCancelledUserMessage(syncOperation, contentItem.DisplayText, contentType), $"{operation} the '{contentItem.DisplayText}' {contentType} has been cancelled because the {deleteGraphSyncer.GraphReplicaSetName} graph couldn't be updated.", exception: exception); }
/// <summary> /// Creates diagnostic entity in DB to trace progress of syncing operation /// </summary> /// <param name="uniqueId"></param> /// <param name="totalItemCount"></param> /// <returns></returns> private async Task ReportStartProcedure(Guid uniqueId) { _uniqueId = uniqueId; using var uow = new UnitOfWork(); var syncOperation = new SyncOperation(uow) { UniqueId = _uniqueId, IsRunning = true }; await uow.CommitChangesAsync(); uow.Dispose(); }
// Token: 0x0600139F RID: 5023 RVA: 0x00070F40 File Offset: 0x0006F140 public ReadFlagDataObject(IList <IProperty> propertyFromSchemaLinkId, SyncOperation syncOp) { if (syncOp == null) { throw new ArgumentNullException("syncOp"); } if (propertyFromSchemaLinkId == null) { throw new ArgumentNullException("propertyFromSchemaLinkId"); } this.propertyFromSchemaLinkId = propertyFromSchemaLinkId; ReadFlagProperty readFlagProperty = new ReadFlagProperty(syncOp.IsRead); this.propertyList = new ReadFlagProperty[] { readFlagProperty }; }
private async Task <bool> DeleteFromGraphReplicaSetIfAllowed( ContentItem contentItem, IContentItemVersion contentItemVersion, SyncOperation syncOperation) { (IAllowSync allowSync, IDeleteGraphSyncer? publishedDeleteGraphSyncer) = await GetDeleteGraphSyncerIfDeleteAllowed( contentItem, contentItemVersion, syncOperation); switch (allowSync.Result) { case AllowSyncResult.Blocked: await _notifier.AddBlocked( syncOperation, contentItem, new[] { (contentItemVersion.GraphReplicaSetName, allowSync) });
private void NewSyncOperation(Models.Synchronization sync) { // Create new sync operation. SyncOperation obj = new NewSyncOperation(sync) as SyncOperation; obj.Updated += (sender2, e2) => UpdateStatsInfo(e2.Status); //obj.EventLog = ... //obj.TransferListControl = ... // IMPORTANT: Dispose before assigning. if (RunningOperation != null) { RunningOperation.Dispose(); } RunningOperation = obj; UpdateStatsInfo(SyncOperationStatus.Unknown); }
public void InjectSyncOperation(SyncOperation Code) { if (!IsInGame()) { return; } if (Memory != null && Memory.IsRunning) { string msg = GetEnumDescription((SyncOperation)Code) + ";" + Attributes.Serial + ";" + Attributes.ServerPosition.X + ";" + Attributes.ServerPosition.Y; var cds = new COPYDATASTRUCT { dwData = (IntPtr)(int)Code, cbData = msg.Length + 1, lpData = msg }; SendMessage((int)Memory.Windows.MainWindowHandle, WM_COPYDATA, 0, ref cds); } }
public async Task <IAllowSync> DeleteIfAllowed( ContentItem contentItem, IContentItemVersion contentItemVersion, SyncOperation syncOperation, IEnumerable <KeyValuePair <string, object> >?deleteIncomingRelationshipsProperties = null) { IAllowSync allowSync = await DeleteAllowed( contentItem, contentItemVersion, syncOperation, deleteIncomingRelationshipsProperties); if (allowSync.Result == AllowSyncResult.Allowed) { await Delete(); } return(allowSync); }
public CustomSetField(SyncSide syncSide, string fieldNameToCompare, string fieldNameToUpdate, Func <DataRow, Object> customSetMethod, SyncOperation appliesTo, bool onlyApplyWithOtherChanges = false) { if (String.IsNullOrWhiteSpace(fieldNameToCompare)) { throw new Exception("Field name to compare is missing or empty."); } if (String.IsNullOrWhiteSpace(fieldNameToUpdate)) { throw new Exception("Field name to update is missing or empty."); } if (customSetMethod == null) { throw new Exception("Custom method can not be null."); } SyncSide = syncSide; FieldNameToCompare = fieldNameToCompare; FieldNameToUpdate = fieldNameToUpdate; if (SyncSide == Core.SyncSide.Source) { FieldNameToCompareWithPrefix = DataTableHelper.SOURCE_PREFIX + fieldNameToCompare; FieldNameToUpdateWithPrefix = DataTableHelper.SOURCE_PREFIX + fieldNameToUpdate; } else { FieldNameToCompareWithPrefix = DataTableHelper.TARGET_PREFIX + fieldNameToCompare; FieldNameToUpdateWithPrefix = DataTableHelper.TARGET_PREFIX + fieldNameToUpdate; } CustomSetMethod = customSetMethod; AppliesTo = appliesTo; OnlyApplyWithOtherChanges = onlyApplyWithOtherChanges; }
static void PerformAction(SyncOperation operation, FileInfo f, string targetDir, SyncResolution resolutionmode) { string newFile = Path.Combine(targetDir, f.Name); Console.WriteLine(operation + " " + f.FullName + Environment.NewLine + " => " + newFile + Environment.NewLine); if (operation == SyncOperation.Copy) { if (!File.Exists(newFile) || resolutionmode == SyncResolution.overwrite) { File.Copy(f.FullName, newFile, true); } } else if (operation == SyncOperation.Move) { if (!File.Exists(newFile) || resolutionmode == SyncResolution.overwrite) { File.Delete(newFile); File.Move(f.FullName, newFile); } } }
public GraphDeleteContext(ContentItem contentItem, IDeleteNodeCommand deleteNodeCommand, IDeleteGraphSyncer deleteGraphSyncer, SyncOperation syncOperation, ISyncNameProvider syncNameProvider, IContentManager contentManager, IContentItemVersion contentItemVersion, IEnumerable <KeyValuePair <string, object> >?deleteIncomingRelationshipsProperties, IGraphDeleteContext?parentGraphDeleteContext, IServiceProvider serviceProvider) : base( contentItem, syncNameProvider, contentManager, contentItemVersion, parentGraphDeleteContext, serviceProvider.GetRequiredService <ILogger <GraphDeleteContext> >()) { DeleteGraphSyncer = deleteGraphSyncer; DeleteNodeCommand = deleteNodeCommand; SyncOperation = syncOperation; DeleteIncomingRelationshipsProperties = deleteIncomingRelationshipsProperties; }
InternalGetOperationAsync(ServerScopeInfo serverScopeInfo, ClientScopeInfo clientScopeInfo, SyncContext context, DbConnection connection = default, DbTransaction transaction = default, CancellationToken cancellationToken = default, IProgress <ProgressArgs> progress = null) { try { SyncOperation syncOperation = SyncOperation.Normal; await using var runner = await this.GetConnectionAsync(context, SyncMode.Writing, SyncStage.Provisioning, connection, transaction, cancellationToken, progress).ConfigureAwait(false); var operationArgs = new OperationArgs(context, serverScopeInfo, clientScopeInfo, runner.Connection, runner.Transaction); await this.InterceptAsync(operationArgs, runner.Progress, runner.CancellationToken).ConfigureAwait(false); syncOperation = operationArgs.Operation; await runner.CommitAsync().ConfigureAwait(false); return(context, syncOperation); } catch (Exception ex) { throw GetSyncError(context, ex); } }
public void AddAutoSetField(SyncSide syncSide, string fieldToCompare, string fieldToUpdate, object value, SyncOperation appliesTo, bool onlyApplyWithOtherChanges = false) { base.AddCustomSetField(syncSide, fieldToCompare, fieldToUpdate, (row) => { return(value); }, appliesTo, onlyApplyWithOtherChanges); }
public void AddAutoSetField(SyncSide syncSide, string fieldToUpdate, object value, SyncOperation appliesTo, bool onlyApplyWithOtherChanges = false) { AddAutoSetField(syncSide, fieldToUpdate, fieldToUpdate, value, appliesTo, onlyApplyWithOtherChanges); }
public override void ConvertServerToClientObject(ISyncItem syncItem, XmlNode airSyncParentNode, SyncOperation changeObject, GlobalInfo globalInfo) { RecipientInfoCacheEntry entry = (RecipientInfoCacheEntry)syncItem.NativeItem; this.recipientInfoCacheDataObject.Bind(entry); base.AirSyncDataObject.Bind(airSyncParentNode); base.AirSyncDataObject.CopyFrom(this.recipientInfoCacheDataObject); base.AirSyncDataObject.Unbind(); if (changeObject != null && (changeObject.ChangeType == ChangeType.Add || changeObject.ChangeType == ChangeType.Change)) { changeObject.ChangeTrackingInformation = base.ChangeTrackFilter.Filter(airSyncParentNode, changeObject.ChangeTrackingInformation); } if (changeObject != null && (changeObject.ChangeType == ChangeType.Add || changeObject.ChangeType == ChangeType.Change)) { base.HasAddsOrChangesToReturnToClientImmediately = true; } base.HasServerChanges = true; }
public static OperationContext CreateOperationContext(OperationArgumentsBase arguments, IEnumerator <DateTime> enumerator) { if (repositories == null) { throw new FieldAccessException("Repositories member was never set"); } switch (arguments) { case ImportWmsInventoryOperationArguments wmsInventoryOperationArgs: ImportWmsInventoryOperation wmsInventoryOperation = new ImportWmsInventoryOperation( repositories[wmsInventoryOperationArgs.HarvesterDatabase], repositories[wmsInventoryOperationArgs.DestinationDatabase], repositories[wmsInventoryOperationArgs.SourceDirectory]) { Name = wmsInventoryOperationArgs.Name }; return(new OperationContext(wmsInventoryOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportWmsTransactionOperationArguments wmsTransactionOperationArgs: ImportWmsTransactionOperation wmsTransactionOperation = new ImportWmsTransactionOperation( repositories[wmsTransactionOperationArgs.HarvesterDatabase], repositories[wmsTransactionOperationArgs.DestinationDatabase], repositories[wmsTransactionOperationArgs.SourceDirectory]) { Name = wmsTransactionOperationArgs.Name }; return(new OperationContext(wmsTransactionOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportCounterTransactionsOperationArguments counterTransactionOperationArgs: ImportCounterTransactionsOperation counterOperation = new ImportCounterTransactionsOperation( repositories[counterTransactionOperationArgs.DestinationDatabase], repositories[counterTransactionOperationArgs.HarvesterDatabase], repositories[counterTransactionOperationArgs.SourceCounter], repositories.ContainsKey(counterTransactionOperationArgs.LocalJsonStorage) ? repositories[counterTransactionOperationArgs.LocalJsonStorage]: null) { Name = counterTransactionOperationArgs.Name }; return(new OperationContext(counterOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportDemographicsOperationArguments demographicOperationArgs: ImportDemographicsOperation demographicOperation = new ImportDemographicsOperation( repositories[demographicOperationArgs.HarvesterDatabase], repositories[demographicOperationArgs.DestinationDatabase], repositories[demographicOperationArgs.SourceDirectory]) { Name = demographicOperationArgs.Name }; return(new OperationContext(demographicOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case SyncOperationArguments syncOperationArgs: SyncOperation syncOperation = new SyncOperation( syncOperationArgs, repositories[syncOperationArgs.DestinationDirectory], repositories[syncOperationArgs.SourceDirectory]) { Name = syncOperationArgs.Name }; return(new OperationContext(syncOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportStatistaOperationArguments statistaOperationArgs: ImportStatistaOperation statistaOperation = new ImportStatistaOperation( statistaOperationArgs, repositories[statistaOperationArgs.HarvesterDatabase], repositories[statistaOperationArgs.DestinationDatabase], repositories[statistaOperationArgs.SourceDirectory]) { Name = statistaOperationArgs.Name }; return(new OperationContext(statistaOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportEZProxyAuditOperationArguments auditOperationArgs: ImportEZProxyAuditOperation auditOperation = new ImportEZProxyAuditOperation( auditOperationArgs, repositories[auditOperationArgs.HarvesterDatabase], repositories[auditOperationArgs.DestinationDatabase], repositories[auditOperationArgs.SourceDirectory], repositories[auditOperationArgs.LogDirectory]) { Name = auditOperationArgs.Name }; return(new OperationContext(auditOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); case ImportEZProxyLogOperationArguments logOperationArgs: ImportEZProxyLogOperation logOperation = new ImportEZProxyLogOperation( logOperationArgs, repositories[logOperationArgs.HarvesterDatabase], repositories[logOperationArgs.DestinationDatabase], repositories[logOperationArgs.SourceDirectory]) { Name = logOperationArgs.Name }; return(new OperationContext(logOperation, enumerator) { MaximumRunsPerDay = arguments.MaximumRunsPerDay, MaximumConcurrentlyRunning = arguments.MaximumConcurrentlyRunning }); } throw new NotImplementedException($"{arguments.Name} is not a recognized operation"); }
public void Synchronize(Action completion, Action<string, double> progressChanged, Action<Exception> errorHandler) { if (IsSynchronizing) return; if (cache.Credentials == null) throw new InvalidOperationException("Cannot update the cache when not logged in"); IsSynchronizing = true; SyncStatus = "Synchronizing..."; var operation = new SyncOperation( op => { cache.UpdateMySets(op.MySets); UpdateSets(MySets, op.MySets); cache.UpdateFavourites(op.Favourites); UpdateSets(FavouriteSets, op.Favourites); // Because the new sets won't have this property group to true. foreach (var set in FavouriteSets) set.Starred = true; cache.Update(op.Groups); UpdateGroups(op.Groups); LoadProfileImage(); IsSynchronizing = false; HasSynchronized = true; cache.Write(); completion(); }, (n, total) => { if (progressChanged != null) progressChanged(string.Format("Synchronizing ({0}/{1})...", n, total), n/(double)total); }, e => { IsSynchronizing = false; errorHandler(e); }); // Fetch the four data sets in parallel. api.FetchUserSets(userName, sets => operation.MySets = sets, operation.Failed, new CancellationToken()); api.FetchUserFavourites(userName, sets => operation.Favourites = sets, operation.Failed, new CancellationToken()); api.FetchUserGroups(userName, newGroups => operation.Groups = newGroups, operation.Failed, new CancellationToken()); api.FetchUserData( userName, user => { if (user.ProfileImage == null) { cache.DeleteProfileImage(); operation.ProfileImageLoaded = true; return; } if (user.ProfileImage == cache.ProfileImage) { operation.ProfileImageLoaded = true; return; } cache.ProfileImage = user.ProfileImage; cache.FetchProfileImage(e => { if (e != null) operation.Failed(e); else operation.ProfileImageLoaded = true; }); }, operation.Failed, new CancellationToken()); }
public void Synchronize(Action completion, Action <string, double> progressChanged, Action <Exception> errorHandler) { if (IsSynchronizing) { return; } if (cache.Credentials == null) { throw new InvalidOperationException("Cannot update the cache when not logged in"); } IsSynchronizing = true; SyncStatus = "Synchronizing..."; var operation = new SyncOperation( op => { cache.UpdateMySets(op.MySets); UpdateSets(MySets, op.MySets); cache.UpdateFavourites(op.Favourites); UpdateSets(FavouriteSets, op.Favourites); // Because the new sets won't have this property group to true. foreach (var set in FavouriteSets) { set.Starred = true; } cache.Update(op.Groups); UpdateGroups(op.Groups); LoadProfileImage(); IsSynchronizing = false; HasSynchronized = true; cache.Write(); completion(); }, (n, total) => { if (progressChanged != null) { progressChanged(string.Format("Synchronizing ({0}/{1})...", n, total), n / (double)total); } }, e => { IsSynchronizing = false; errorHandler(e); }); // Fetch the four data sets in parallel. api.FetchUserSets(userName, sets => operation.MySets = sets, operation.Failed, new CancellationToken()); api.FetchUserFavourites(userName, sets => operation.Favourites = sets, operation.Failed, new CancellationToken()); api.FetchUserGroups(userName, newGroups => operation.Groups = newGroups, operation.Failed, new CancellationToken()); api.FetchUserData( userName, user => { if (user.ProfileImage == null) { cache.DeleteProfileImage(); operation.ProfileImageLoaded = true; return; } if (user.ProfileImage == cache.ProfileImage) { operation.ProfileImageLoaded = true; return; } cache.ProfileImage = user.ProfileImage; cache.FetchProfileImage(e => { if (e != null) { operation.Failed(e); } else { operation.ProfileImageLoaded = true; } }); }, operation.Failed, new CancellationToken()); }
public void UpdateFilterState(SyncOperation syncOperation) { if (syncOperation == null) { throw new ArgumentNullException("syncOperation"); } if (this.prepopulate) { return; } if (this.CustomFilterState == null) { this.CustomFilterState = new Dictionary <ISyncItemId, DateTimeCustomSyncFilter.FilterState>(); } switch (syncOperation.ChangeType) { case ChangeType.Add: case ChangeType.Change: case ChangeType.ReadFlagChange: { CalendarItem calendarItem = null; try { calendarItem = (syncOperation.GetItem(new PropertyDefinition[0]).NativeItem as CalendarItem); if (calendarItem == null) { this.UpdateFilterStateWithAddOrChange(syncOperation.Id, false, false, ExDateTime.MinValue); } else if (calendarItem.Recurrence == null) { this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, false, calendarItem.EndTime); } else if (calendarItem.Recurrence.Range is NoEndRecurrenceRange) { this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, true, ExDateTime.MinValue); } else { this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, true, calendarItem.Recurrence.GetLastOccurrence().EndTime); } } catch (Exception ex) { if (ex is ObjectNotFoundException) { if (this.CustomFilterState.ContainsKey(syncOperation.Id)) { this.CustomFilterState.Remove(syncOperation.Id); } } else { if (!SyncCommand.IsItemSyncTolerableException(ex)) { throw; } StoreId storeId = null; string text = "Unknown"; ExDateTime exDateTime = ExDateTime.MinValue; try { if (calendarItem != null) { storeId = calendarItem.Id; text = calendarItem.Subject; exDateTime = calendarItem.StartTime; } } catch { } AirSyncUtility.ExceptionToStringHelper exceptionToStringHelper = new AirSyncUtility.ExceptionToStringHelper(ex); AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Exception was caught in UpdateFilterState. Item id=\"{0}\", subject=\"{1}\", meetingTime={2}\r\n{3}\r\nIgnoring exception and proceeding to next item.", new object[] { (storeId != null) ? storeId : "null", text, exDateTime, exceptionToStringHelper }); } } break; } case (ChangeType)3: break; case ChangeType.Delete: this.CustomFilterState.Remove(syncOperation.Id); return; default: return; } }
public override void ConvertServerToClientObject(ISyncItem syncItem, XmlNode airSyncParentNode, SyncOperation changeObject, GlobalInfo globalInfo) { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "EntitySyncCollection.ConvertServerToClientObject"); IItem item = ((EntitySyncItem)syncItem).Item; Item item2 = ((EntitySyncItem)syncItem).NativeItem as Item; if (item2 == null || !this.EntityDataObject.CanConvertItemClassUsingCurrentSchema(item2.ClassName)) { throw new ConversionException(string.Format("Cannot convert item '{0}' of .NET type \"{1}\" using current schema. ClassName: '{2}'", item.Id, item.GetType().FullName, (item2 == null) ? "<NULL>" : item2.ClassName)); } try { base.AirSyncDataObject.Bind(airSyncParentNode); this.EntityDataObject.Bind(item); AirSyncDiagnostics.FaultInjectionTracer.TraceTest(2170957117U); base.AirSyncDataObject.CopyFrom(this.EntityDataObject); } finally { this.EntityDataObject.Unbind(); base.AirSyncDataObject.Unbind(); } base.ApplyChangeTrackFilter(changeObject, airSyncParentNode); base.SetHasChanges(changeObject); }
protected void AddCustomSetField(SyncSide syncSide, string fieldToCompare, string fieldToUpdate, Func <DataRow, object> customSetMethod, SyncOperation appliesTo, bool onlyApplyWithOtherChanges) { if (_customSetFields.Exists(d => (appliesTo.HasFlag(SyncOperation.Inserts) || appliesTo.HasFlag(SyncOperation.All)) && (d.AppliesTo.HasFlag(SyncOperation.Inserts) || d.AppliesTo.HasFlag(SyncOperation.All)) && d.SyncSide == syncSide && string.Equals(d.FieldNameToUpdate, fieldToUpdate, StringComparison.OrdinalIgnoreCase))) { throw new Exception(string.Format("Field '{0}' already exists for operation '{1}' and sync side '{2}'.", fieldToUpdate, Enum.GetName(typeof(SyncOperation), SyncOperation.Inserts), Enum.GetName(typeof(SyncSide), syncSide))); } if (_customSetFields.Exists(d => (appliesTo.HasFlag(SyncOperation.Updates) || appliesTo.HasFlag(SyncOperation.All)) && (d.AppliesTo.HasFlag(SyncOperation.Updates) || d.AppliesTo.HasFlag(SyncOperation.All)) && d.SyncSide == syncSide && string.Equals(d.FieldNameToUpdate, fieldToUpdate, StringComparison.OrdinalIgnoreCase))) { throw new Exception(string.Format("Field '{0}' already exists for operation '{1}' and sync side '{2}'.", fieldToUpdate, Enum.GetName(typeof(SyncOperation), SyncOperation.Updates), Enum.GetName(typeof(SyncSide), syncSide))); } if (_customSetFields.Exists(d => (appliesTo.HasFlag(SyncOperation.Deletes) || appliesTo.HasFlag(SyncOperation.All)) && (d.AppliesTo.HasFlag(SyncOperation.Deletes) || d.AppliesTo.HasFlag(SyncOperation.All)) && d.SyncSide == syncSide && string.Equals(d.FieldNameToUpdate, fieldToUpdate, StringComparison.OrdinalIgnoreCase))) { throw new Exception(string.Format("Field '{0}' already exists for operation '{1}' and sync side '{2}'.", fieldToUpdate, Enum.GetName(typeof(SyncOperation), SyncOperation.Deletes), Enum.GetName(typeof(SyncSide), syncSide))); } switch (syncSide) { case SyncSide.Source: if (!_addedSourceFields.Contains(fieldToUpdate, StringComparer.OrdinalIgnoreCase)) { AddToSyncSideFieldsList(syncSide, fieldToUpdate); } break; case SyncSide.Target: if (!_addedTargetFields.Contains(fieldToUpdate, StringComparer.OrdinalIgnoreCase)) { AddToSyncSideFieldsList(syncSide, fieldToUpdate); } break; default: throw new EnumValueNotImplementedException <SyncSide>(syncSide); } _customSetFields.Add(new CustomSetField(syncSide, fieldToCompare, fieldToUpdate, customSetMethod, appliesTo, onlyApplyWithOtherChanges)); }
/// <summary> /// The synchronize. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> /// <exception cref="ApplicationException"> /// </exception> public bool Synchronize(SyncOperation operation, IProgressCallback callback) { if (this.DataSynchronizer == null) { throw new ApplicationException("There is no available file synchronizer. Please make sure that the proper plugin is installed"); } return this.DataSynchronizer.Synchronize(operation, this.DataFileName, callback); }
public async Task AddBlocked( SyncOperation syncOperation, ContentItem contentItem, IEnumerable <(string GraphReplicaSetName, IAllowSync AllowSync)> graphBlockers)