コード例 #1
0
ファイル: Home.razor.cs プロジェクト: nakulLukan/Note
        protected override async Task OnInitializedAsync()
        {
            Threads = await DataService.GetLastNThreads();

            if (Threads.Any())
            {
                HasThreads = true;
            }
        }
コード例 #2
0
        public virtual ApiResult Shutdown()
        {
            ThrowIfNotOk();
            shutdownRequested = true;
            if (!cancellationToken.IsCancellationRequested)
            {
                Global.CancellationTokenSource.Cancel();
            }
            int waitCount = 0;

            while (Threads.Any(t => t.IsAlive) && waitCount < 30)
            {
                Thread.Sleep(100);
                waitCount++;
            }
            if (Threads.All(t => !t.IsAlive))
            {
                shutdownCompleted = true;
                Info("All threads stopped. {0} service shutdown completed successfully.", Name);
                return(ApiResult.Success);
            }
            else
            {
                Info("{0} threads in {1} did not stop. Aborting {0} threads", Threads.Count(t => t.IsAlive),
                     this.GetType().Name);
                foreach (Thread thread in Threads.Where(t => t.IsAlive))
                {
                    thread.Abort();
                }
                if (Threads.All(t => !t.IsAlive))
                {
                    shutdownCompleted = true;
                    Info("All threads stopped. {0} service shutdown completed successfully.", Name);
                    return(ApiResult.Success);
                }
                else
                {
                    return(ApiResult.Failure);
                }
            }
        }
コード例 #3
0
        private async Task UpdateThreadList()
        {
            if (SlowStuffSemaphore.CurrentCount == 0)
            {
                return;
            }
            await SlowStuffSemaphore.WaitAsync();

            try
            {
                var threads = await Client.fetchThreadList(20, ThreadLocation.INBOX, Threads.LastOrDefault()?.last_message_timestamp);

                threads.RemoveAll(x => Threads.Any(y => x.uid == y.uid));
                foreach (var thread in threads)
                {
                    Threads.Add(thread);
                }
            }
            finally
            {
                SlowStuffSemaphore.Release();
            }
        }
コード例 #4
0
 /// <summary>
 /// Checks if the bot is already connected to the channel.
 /// </summary>
 /// <param name="channel">Channel name</param>
 /// <returns>True whether could connect, otherwise false.</returns>
 public bool IsConnectedToChannel(string channel)
 {
     return(Threads?.Any(t => t.Channel.Equals(channel, StringComparison.OrdinalIgnoreCase)) ?? false);
 }
コード例 #5
0
ファイル: Board.cs プロジェクト: hexafluoride/SharpChannel
        public void Update()
        {
            _updated.Reset();
            Updating = true;
#if DEBUG
            Console.WriteLine("Started update on board /{0}/", Name);
#endif
            string board_url = EndpointProvider.GetBoardEndpoint(Name);

            if (board_url == "")
            {
                return;
            }

            string json = Utilities.Download(board_url);

            if (json == "-")
            {
                return;
            }

            JArray pages = JArray.Parse(json);

            List <int> current_threads = new List <int>();

            foreach (JObject page in pages)
            {
                JArray threads = page.Value <JArray>("threads");
                foreach (JObject rawthread in threads)
                {
                    int id = rawthread.Value <int>("no");

                    if (!Threads.Any(t => t.ID == id))
                    {
                        Thread thread = new Thread(id, this);

                        Threads.Add(thread);

                        if (NewThread != null)
                        {
                            NewThread(thread);
                        }
                    }
                    else
                    {
                        Thread thread = Threads.First(t => t.ID == id);

                        if (thread.OP.ModificationTime != rawthread.Value <ulong>("last_modified"))
                        {
                            thread.Update();
                            thread.OP.ModificationTime = rawthread.Value <ulong>("last_modified");
                        }
                    }

                    current_threads.Add(id);
                }
            }

            Func <Thread, bool> dead = (t => !current_threads.Contains(t.ID) && t.Alive);

            Threads.Where(dead).ToList().ForEach(RemoveThread);

            while (updating_threads.CurrentCount > 0)
            {
                System.Threading.Thread.Sleep(100);
            }

            if (UpdateFinished != null)
            {
                UpdateFinished(this);
            }

            Updating = false;
            _updated.Set();
#if DEBUG
            Console.WriteLine("Ended update on board /{0}/", Name);
#endif
        }