Ejemplo n.º 1
0
        public static SyncStateStorage Bind(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata   userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            DeviceSyncStateMetadata device = userSyncStateMetadata.GetDevice(mailboxSession, deviceIdentity, syncLogger);

            if (device != null)
            {
                return(SyncStateStorage.GetSyncStateStorage(mailboxSession, device, syncLogger));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public static bool DeleteSyncStateStorage(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            syncLogger.Information <DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Need to delete folder {0}", deviceIdentity);
            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata          userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            List <DeviceSyncStateMetadata> allDevices            = userSyncStateMetadata.GetAllDevices(mailboxSession, false, syncLogger);
            bool result = false;

            if (allDevices != null)
            {
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    syncLogger.Information <DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Found syncstate folder {0}", deviceSyncStateMetadata.Id);
                    if (string.Compare(deviceSyncStateMetadata.Id.Protocol, deviceIdentity.Protocol, StringComparison.Ordinal) == 0)
                    {
                        if (deviceSyncStateMetadata.Id.Equals(deviceIdentity))
                        {
                            mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                            {
                                deviceSyncStateMetadata.DeviceFolderId
                            });
                            userSyncStateMetadata.TryRemove(deviceSyncStateMetadata.Id, syncLogger);
                        }
                        else
                        {
                            syncLogger.Information(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. found more devices with same protocol");
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static SyncStateRootStorage GetOrCreateSyncStateRootStorage(MailboxSession mailboxSession, string protocol, ISyncLogger syncLogger = null)
        {
            if (mailboxSession == null)
            {
                throw new ArgumentNullException("mailboxSession");
            }
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            string           protocol2        = protocol + "Root";
            DeviceIdentity   deviceIdentity   = new DeviceIdentity("RootDeviceId", "RootDeviceType", protocol2);
            SyncStateStorage syncStateStorage = SyncStateStorage.Bind(mailboxSession, deviceIdentity, syncLogger);

            if (syncStateStorage == null)
            {
                syncStateStorage = SyncStateStorage.Create(mailboxSession, deviceIdentity, StateStorageFeatures.ContentState, syncLogger);
            }
            return(new SyncStateRootStorage(syncStateStorage));
        }
Ejemplo n.º 4
0
 private static bool ShouldAddDevice(ParsedCallData callData, DeviceIdentity deviceIdentity)
 {
     return(callData.DeviceId == null || deviceIdentity.Equals(callData.DeviceId, callData.DeviceType));
 }
Ejemplo n.º 5
0
        public static bool DeleteSyncStateStorage(MailboxSession mailboxSession, StoreObjectId deviceFolderId, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            ArgumentValidator.ThrowIfNull("folderId", deviceFolderId);
            bool result = false;

            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata    userSyncStateMetadata    = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            AggregateOperationResult aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
            {
                deviceFolderId
            });

            syncLogger.Information <string>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Result = {0}", aggregateOperationResult.OperationResult.ToString());
            userSyncStateMetadata.TryRemove(deviceIdentity, syncLogger);
            List <DeviceSyncStateMetadata> allDevices = userSyncStateMetadata.GetAllDevices(mailboxSession, false, syncLogger);

            if (allDevices != null)
            {
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    syncLogger.Information <DeviceIdentity, DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Found device folder '{0}', Looking for folder '{1}'", deviceSyncStateMetadata.Id, deviceIdentity);
                    if (deviceSyncStateMetadata.Id.Equals(deviceIdentity))
                    {
                        try
                        {
                            aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                            {
                                deviceSyncStateMetadata.DeviceFolderId
                            });
                            syncLogger.Information <DeviceIdentity, DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. try Deleting SyncState folder again.folderName:{0}, originalFolder:{1}, result:{2}", deviceSyncStateMetadata.Id, deviceIdentity, aggregateOperationResult.OperationResult.ToString());
                            continue;
                        }
                        catch
                        {
                            syncLogger.Information(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Error deleting the sync state folder.");
                            continue;
                        }
                    }
                    if (deviceSyncStateMetadata.Id.IsProtocol("AirSync"))
                    {
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
 public static SyncStateStorage Create(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, StateStorageFeatures features, ISyncLogger syncLogger = null)
 {
     return(SyncStateStorage.Create(mailboxSession, deviceIdentity, features, false, syncLogger));
 }