示例#1
0
 /// <summary>
 /// <see cref="ExchangeSyncProvider.OnLocalItemAppliedInRemoteStore"/>
 /// </summary>
 public override void OnLocalItemAppliedInRemoteStore(SyncContext context, IRemoteItem remoteItem,
                                                      LocalItem localItem)
 {
     if (!_userConnection.GetIsFeatureEnabled("SyncDeletedAppointments"))
     {
         return;
     }
     if (remoteItem.Action == SyncAction.Delete && remoteItem.State == SyncState.Deleted)
     {
         EntitySchema       schema    = context.UserConnection.EntitySchemaManager.GetInstanceByName("Activity");
         IEnumerable <Guid> entityIds = localItem.Entities["Activity"]
                                        .Where(se => se.State != SyncState.Deleted).Select(se => se.EntityId).ToList();
         foreach (Guid activityId in entityIds)
         {
             Entity activity = schema.CreateEntity(context.UserConnection);
             if (activity.FetchFromDB(activityId, false))
             {
                 localItem.AddOrReplace("Activity", new SyncEntity(activity, SyncState.Modified)
                 {
                     Action = SyncAction.Delete
                 });
             }
         }
         context.LocalProvider.ApplyChanges(context, localItem);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        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);
        }
示例#5
0
        private List <SyncEntity> GetContactSyncItems(SyncContext context, LocalItem localItem, Guid storedId)
        {
            var contacts = localItem.Entities["Contact"];

            if (storedId.IsEmpty() || contacts.Count > 0)
            {
                return(contacts);
            }
            EntitySchema schema          = context.UserConnection.EntitySchemaManager.GetInstanceByName("Contact");
            Entity       existingContact = schema.CreateEntity(context.UserConnection);

            if (existingContact.FetchFromDB(storedId))
            {
                localItem.AddOrReplace("Contact", new SyncEntity(existingContact, SyncState.None)
                {
                    Action = SyncAction.Update
                });
            }
            return(contacts);
        }
示例#6
0
        /// <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));
        }