private void StoreOffline(Message message, IOfflineStore offlineStore) { if ((message.Type == MessageType.normal || message.Type == MessageType.chat) && !string.IsNullOrEmpty(message.To.User)) { offlineStore.SaveOfflineMessages(message); } }
/// <summary> /// Executes the operation on the offline store. /// </summary> /// <param name="store">The offline store.</param> /// <param name="item">The item to use for the store operation.</param> /// <returns>A task that completes when the store operation is completed.</returns> public override async Task ExecuteOperationOnOfflineStoreAsync(IOfflineStore store, JObject item, CancellationToken cancellationToken = default) { var existingItem = await store.GetItemAsync(TableName, ItemId, cancellationToken).ConfigureAwait(false); if (existingItem != null) { throw new OfflineStoreException("Insert failed - the item already exists in the offline store"); } await store.UpsertAsync(TableName, new[] { item }, false, cancellationToken).ConfigureAwait(false); }
public void OnRegister(IServiceProvider serviceProvider) { offlineStore = ((StorageManager)serviceProvider.GetService(typeof(StorageManager))).OfflineStorage; rosterStore = ((StorageManager)serviceProvider.GetService(typeof(StorageManager))).RosterStorage; sender = (IXmppSender)serviceProvider.GetService(typeof(IXmppSender)); sessionManager = (XmppSessionManager)serviceProvider.GetService(typeof(XmppSessionManager)); handlerManager = (XmppHandlerManager)serviceProvider.GetService(typeof(XmppHandlerManager)); sessionManager.SessionAvailable += SessionAvailable; sessionManager.SessionUnavailable += SessionUnavailable; }
/// <summary> /// Executes the operation on the offline store. /// </summary> /// <param name="store">The offline store.</param> /// <param name="item">The item to use for the store operation.</param> /// <returns>A task that completes when the store operation is completed.</returns> public override async Task ExecuteOperationOnOfflineStoreAsync(IOfflineStore store, JObject item, CancellationToken cancellationToken = default) { var itemId = ServiceSerializer.GetId(item); var originalItem = await store.GetItemAsync(TableName, itemId, cancellationToken).ConfigureAwait(false); if (originalItem == null) { throw new OfflineStoreException($"Item with ID '{itemId}' does not exist in the offline store."); } await store.UpsertAsync(TableName, new[] { item }, false, cancellationToken).ConfigureAwait(false); }
public void SetUp() { store = new DbOfflineStore(ConfigurationManager.ConnectionStrings["UserStore"]); }
/// <summary> /// Executes the operation on the offline store. /// </summary> /// <param name="store">The offline store.</param> /// <param name="item">The item to use for the store operation.</param> /// <returns>A task that completes when the store operation is completed.</returns> public override Task ExecuteOperationOnOfflineStoreAsync(IOfflineStore store, JObject item, CancellationToken cancellationToken = default) => store.DeleteAsync(TableName, new[] { ItemId }, cancellationToken);