Ejemplo n.º 1
0
 public void Release()
 {
     //TODO invalidate view information
     Logger.LogTrace("Release()");
     if (Running)
     {
         Logger.LogTrace("Release() locking");
         SemaphoreSlim.Wait(CancelSource.Token);
         Logger.LogTrace("Release() locked");
         Running = false;
         CancelSource.Cancel();
         IncomingMessagesTask?.Wait();
         OutgoingMessagesTask?.Wait();
         Instance = null;
         Logger.LogTrace("Release() releasing global");
         LibUtils.Unlock();
         Logger.LogTrace("Release() releasing local");
         SemaphoreSlim.Release();
         Logger.LogTrace("Release() released");
     }
     else
     {
         Logger.LogWarning("SignalLibHandle was already closed");
     }
 }
Ejemplo n.º 2
0
        public async Task Reacquire()
        {
            Logger.LogTrace("Reacquire() locking");
            CancelSource = new CancellationTokenSource();
            SemaphoreSlim.Wait(CancelSource.Token);
            GlobalResetEvent = LibUtils.OpenResetEventSet();
            LibUtils.Lock();
            GlobalResetEvent.Reset();
            LibsignalDBContext.ClearSessionCache();
            Instance = this;
            await Task.Run(() =>
            {
                List <Task> tasks = new List <Task>();
                foreach (var f in Frames)
                {
                    var conversations = GetConversations();
                    tasks.Add(f.Key.RunTaskAsync(() =>
                    {
                        f.Value.ReplaceConversationList(conversations);
                    }));
                }
                Task.WaitAll(tasks.ToArray());
                InitNetwork();
            });

            Running = true;
            Logger.LogTrace("Reacquire() releasing");
            SemaphoreSlim.Release();
        }
Ejemplo n.º 3
0
        public async Task Reacquire()
        {
            Logger.LogTrace("Reacquire() locking");
            CancelSource = new CancellationTokenSource();
            SemaphoreSlim.Wait(CancelSource.Token);
            try
            {
                GlobalResetEvent = LibUtils.OpenResetEventSet();
                LibUtils.Lock();
                GlobalResetEvent.Reset();
                LibsignalDBContext.ClearSessionCache();
                Instance = this;
                await Task.Run(async() =>
                {
                    List <Task> tasks = new List <Task>();
                    foreach (var f in Frames)
                    {
                        var conversations        = GetConversations();
                        var taskCompletionSource = new TaskCompletionSource <bool>();
                        await f.Key.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            try
                            {
                                f.Value.ReplaceConversationList(conversations);
                            }
                            catch (Exception e)
                            {
                                Logger.LogError("Reacquire() ReplaceConversationList() failed: {0}\n{1}", e.Message, e.StackTrace);
                            }
                            finally
                            {
                                taskCompletionSource.SetResult(false);
                            }
                        });
                        tasks.Add(taskCompletionSource.Task);
                    }
                    foreach (var t in tasks)
                    {
                        await t;
                    }
                    await RecoverDownloads();
                    Store = LibsignalDBContext.GetSignalStore();
                    if (Store != null)
                    {
                        LikelyHasValidStore = true;
                    }
                });

                if (LikelyHasValidStore)
                {
                    InitNetwork();
                }
                Running = true;
            }
            finally
            {
                SemaphoreSlim.Release();
                Logger.LogTrace("Reacquire() released");
            }
        }
Ejemplo n.º 4
0
 public void BackgroundRelease()
 {
     Running = false;
     CancelSource.Cancel();
     IncomingMessagesTask?.Wait();
     OutgoingMessagesTask?.Wait();
     Instance = null;
 }
Ejemplo n.º 5
0
 public void BackgroundAcquire()
 {
     CancelSource = new CancellationTokenSource();
     Instance     = this;
     SignalDBContext.FailAllPendingMessages();
     Store = LibsignalDBContext.GetSignalStore();
     InitNetwork();
     Running = true;
 }
Ejemplo n.º 6
0
        public async Task <bool> Acquire(CoreDispatcher d, ISignalFrontend w) //TODO wrap trycatch dispatch auth failure
        {
            Logger.LogTrace("Acquire() locking");
            CancelSource = new CancellationTokenSource();
            SemaphoreSlim.Wait(CancelSource.Token);
            try
            {
                GlobalResetEvent = LibUtils.OpenResetEventSet();
                LibUtils.Lock();
                GlobalResetEvent.Reset();
                MainWindowDispatcher = d;
                MainWindow           = w;
                Logger.LogDebug("Acquire() locked (global and local)");
                var getConversationsTask = Task.Run(() =>
                {
                    return(GetConversations()); // we want to display the conversations asap!
                });
                Instance = this;
                Frames.Add(d, w);
                w.ReplaceConversationList(await getConversationsTask);
                var failTask = Task.Run(() =>
                {
                    SignalDBContext.FailAllPendingMessages(); // TODO GetMessages needs to be protected by semaphoreslim as we fail defered
                });
                Store = await Task.Run(() =>
                {
                    return(LibsignalDBContext.GetSignalStore());
                });

                if (Store == null)
                {
                    return(false);
                }
                else
                {
                    LikelyHasValidStore = true;
                }
                var initNetwork = Task.Run(async() =>
                {
                    await InitNetwork();
                });
                var recoverDownloadsTask = Task.Run(() =>
                {
                    RecoverDownloads().Wait();
                });
                await failTask; // has to complete before messages are loaded
                await recoverDownloadsTask;
                Running = true;
                return(true);
            }
            finally
            {
                SemaphoreSlim.Release();
                Logger.LogTrace("Acquire() released");
            }
        }
Ejemplo n.º 7
0
 public void Release()
 {
     //TODO invalidate view information
     Logger.LogTrace("Release() locking");
     SemaphoreSlim.Wait(CancelSource.Token);
     Running = false;
     CancelSource.Cancel();
     IncomingMessagesTask?.Wait();
     OutgoingMessagesTask?.Wait();
     Instance = null;
     Logger.LogTrace("Release() releasing global)");
     LibUtils.Unlock();
     Logger.LogTrace("Release() releasing local)");
     SemaphoreSlim.Release();
     Logger.LogTrace("Release() released");
 }
Ejemplo n.º 8
0
        public async Task Acquire(CoreDispatcher d, ISignalFrontend w) //TODO wrap trycatch dispatch auth failure
        {
            Logger.LogTrace("Acquire() locking");
            CancelSource = new CancellationTokenSource();
            SemaphoreSlim.Wait(CancelSource.Token);
            GlobalResetEvent = LibUtils.OpenResetEventSet();
            LibUtils.Lock();
            GlobalResetEvent.Reset();
            var getConversationsTask = Task.Run(() =>
            {
                return(GetConversations()); // we want to display the conversations asap!
            });

            Logger.LogDebug("Acquire() locked (global and local)");
            Instance = this;
            Frames.Add(d, w);
            w.ReplaceConversationList(await getConversationsTask);
            var failTask = Task.Run(() =>
            {
                SignalDBContext.FailAllPendingMessages(); // TODO GetMessages needs to be protected by semaphoreslim as we fail defered
            });

            Store = await Task.Run(() =>
            {
                return(LibsignalDBContext.GetSignalStore());
            });

            if (Store == null)
            {
                SemaphoreSlim.Release();
                throw new Exception("Signal Store has not been setup yet.");
            }
            await Task.Run(() =>
            {
                InitNetwork();
            });

            await failTask; // has to complete before messages are loaded

            Running = true;
            Logger.LogTrace("Acquire() releasing");
            SemaphoreSlim.Release();
        }
Ejemplo n.º 9
0
 public SignalLibHandle(bool headless)
 {
     Headless = headless;
     Instance = this;
 }
Ejemplo n.º 10
0
 public OutgoingMessages(CancellationToken token, SignalServiceMessageSender sender, SignalLibHandle handle)
 {
     Token         = token;
     MessageSender = sender;
     Handle        = handle;
 }
Ejemplo n.º 11
0
 public IncomingMessages(CancellationToken token, SignalServiceMessagePipe pipe, SignalLibHandle handle)
 {
     Token  = token;
     Pipe   = pipe;
     Handle = handle;
 }