/// <summary>
 /// Saves the selected file in StorageApplicationPermissions store and saves conversation in database.
 /// </summary>
 /// <returns>Task that saves conversation in database.</returns>
 public async Task SaveCurrentConversationInDatabase()
 {
     if (SignalConversation != null)
     {
         SignalConversation.Draft = UserInputBar.InputText;
         if (SelectedFile == null)
         {
             if (!string.IsNullOrEmpty(SignalConversation.DraftFileTokens) &&
                 StorageApplicationPermissions.FutureAccessList.ContainsItem(SignalConversation.DraftFileTokens))
             {
                 StorageApplicationPermissions.FutureAccessList.Remove(SignalConversation.DraftFileTokens);
             }
             SignalConversation.DraftFileTokens = null;
         }
         else
         {
             if (string.IsNullOrEmpty(SignalConversation.DraftFileTokens) ||
                 !StorageApplicationPermissions.FutureAccessList.ContainsItem(SignalConversation.DraftFileTokens))
             {
                 SignalConversation.DraftFileTokens = StorageApplicationPermissions.FutureAccessList.Add(SelectedFile);
             }
             else
             {
                 // Just reuse the old key
                 StorageApplicationPermissions.FutureAccessList.AddOrReplace(SignalConversation.DraftFileTokens, SelectedFile);
             }
         }
         // SignalConversation can change while starting Thread.
         SignalConversation conversationToSave = SignalConversation;
         await Task.Run(() =>
         {
             SignalDBContext.InsertOrUpdateConversationLocked(conversationToSave);
         });
     }
 }
예제 #2
0
 public void SaveAndDispatchSignalConversation(SignalConversation updatedConversation, SignalMessage updateMessage)
 {
     Logger.LogTrace("SaveAndDispatchSignalConversation() locking");
     SemaphoreSlim.Wait(CancelSource.Token);
     SignalDBContext.InsertOrUpdateConversationLocked(updatedConversation);
     DispatchAddOrUpdateConversation(updatedConversation, updateMessage);
     SemaphoreSlim.Release();
     Logger.LogTrace("SaveAndDispatchSignalConversation() released");
 }
예제 #3
0
        public async Task SaveAndDispatchSignalConversation(SignalConversation updatedConversation, SignalMessage updateMessage)
        {
            Logger.LogTrace("SaveAndDispatchSignalConversation() locking");
            await SemaphoreSlim.WaitAsync(CancelSource.Token);

            try
            {
                SignalDBContext.InsertOrUpdateConversationLocked(updatedConversation);
                await DispatchAddOrUpdateConversation(updatedConversation, updateMessage);
            }
            catch (Exception e)
            {
                Logger.LogError("SaveAndDispatchSignalConversation() failed: {0}\n{1}", e.Message, e.StackTrace);
            }
            finally
            {
                SemaphoreSlim.Release();
                Logger.LogTrace("SaveAndDispatchSignalConversation() released");
            }
        }