private string GetWebPageForRemoteItem(LocalItem localItem, UserConnection userConnection, Guid contactId) { string result = string.Empty; IEnumerable <SyncEntity> webPageEntities = localItem.Entities["ContactCommunication"].Where(e => e.State != SyncState.New && e.State != SyncState.Deleted && e.Entity.GetTypedColumnValue <Guid>("CommunicationTypeId") == Guid.Parse(CommunicationTypeConsts.WebId)); if (webPageEntities.Any()) { SyncEntity webPageSyncEntity = webPageEntities.First(); result = webPageSyncEntity.Entity.GetTypedColumnValue <string>("Number"); } else { Guid id = TryFindWebPageDetailInLocalStore(userConnection, contactId); if (id == Guid.Empty) { return(result); } EntitySchema schema = userConnection.EntitySchemaManager.GetInstanceByName("ContactCommunication"); var instance = (ContactCommunication)schema.CreateEntity(userConnection); if (instance.FetchFromDB(id, false)) { localItem.AddOrReplace(schema.Name, SyncEntity.CreateNew(instance)); result = instance.Number; } } return(result); }
/// <summary>Returns activity instance for exchange appointment, in case of changed remote id.</summary> /// <param name="context">Synchronization context.</param> /// <param name="exchangeItem">Exchange item in external storage.</param> /// <param name="storedId">Id of bpm activity, stored in external property of exchange item.</param> /// <param name="localItem">Local storage item.</param> /// <returns>Activity instance.</returns> protected Entity GetSyncedActivityWithChangedRemoteId(SyncContext context, Exchange.Item exchangeItem, Guid storedId, LocalItem localItem) { Entity instance; var syncValueName = localItem.Schema.SyncValueName; var schema = context.UserConnection.EntitySchemaManager.GetInstanceByName("Activity"); instance = schema.CreateEntity(context.UserConnection); if (!localItem.Entities["Activity"].Any(se => se.EntityId.Equals(storedId)) && instance.FetchFromDB(storedId)) { SyncEntity syncEntity = SyncEntity.CreateNew(instance); var isCurrentUserOwner = context.UserConnection.CurrentUser.ContactId == instance.GetTypedColumnValue <Guid>("OwnerId"); syncEntity.Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None; context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId set action {0} for {1}", syncEntity.Action, GetDisplayName()); localItem.AddOrReplace("Activity", syncEntity); if (syncValueName == ExchangeConsts.ExchangeAppointmentClassName) { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId ExchangeAppointmentClassName action update for {0}", GetDisplayName()); Action = SyncAction.Update; syncEntity.Action = SyncAction.Update; } else { Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None; context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId action {0} for {1}", Action, GetDisplayName()); if (isCurrentUserOwner) { ActualizeOldMetadata(context, storedId, Id); } } } else { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId not found entity action {0} for {1}", Action, GetDisplayName()); instance = GetEntityInstance <Entity>(context, localItem, "Activity"); } return(instance); }
protected static T GetEntityInstance <T>(SyncContext context, LocalItem localItem, string schemaName) where T : Terrasoft.Core.Entities.Entity { T instance; if (localItem.Entities[schemaName].Count == 0) { var schema = context.UserConnection.EntitySchemaManager.GetInstanceByName(schemaName); instance = (T)schema.CreateEntity(context.UserConnection); instance.SetDefColumnValues(); localItem.AddOrReplace(schemaName, SyncEntity.CreateNew(instance)); } else { var instanceSync = localItem.Entities[schemaName][0]; instanceSync.Action = SyncAction.Update; instance = (T)instanceSync.Entity; } return(instance); }
/// <summary> /// Creates o replaces <c>Web</c> <see cref="ContactCommunication"/> instance, using <paramref name="value"/>, /// in <paramref name="localItem"/> sync entities collection. /// </summary> /// <param name="userConnection">User connection instance.</param> /// <param name="contactId"><see cref="Contact"/> unique id.</param> /// <param name="value">ContactCommunication value.</param> /// <param name="localItem">Local storage synchronization element.</param> private static void AddOrReplaceWebPageInstance(UserConnection userConnection, string value, Guid contactId, LocalItem localItem) { EntitySchema schema = userConnection.EntitySchemaManager.GetInstanceByName("ContactCommunication"); var instance = (ContactCommunication)schema.CreateEntity(userConnection); Guid id = TryFindWebPageDetailInLocalStore(userConnection, contactId, value); if (id == Guid.Empty) { instance.SetDefColumnValues(); } else if (!instance.FetchFromDB(id, false)) { instance.SetDefColumnValues(); } instance.SetColumnValue("Number", value); instance.SetColumnValue("CommunicationTypeId", CommunicationTypeConsts.WebId); instance.SetColumnValue("ContactId", contactId); localItem.AddOrReplace(schema.Name, SyncEntity.CreateNew(instance)); }