示例#1
0
        private static async Task LoadResourcesAsync()
        {
            //cfg.AppSettings.Settings.Clear();
            Console.WriteLine("Loading resources...");

            if (cfg.AppSettings.Settings[CFG_PREFIX] == null)
            {
                cfg.AppSettings.Settings.Add(CFG_PREFIX, "");
                Console.WriteLine("Loading resources complete");
                return;
            }

            foreach (var key in cfg.AppSettings.Settings.AllKeys)
            {
                Console.WriteLine("KEY={0}, Value=\n{1}\n\n\n", key, cfg.AppSettings.Settings[key].Value);

                if (key.Equals(CFG_PREFIX))
                {
                    string value = cfg.AppSettings.Settings[key].Value;

                    Console.WriteLine("Caching data...");
                    List <string> forums = new List <string>(value.Split(CFG_SEPARATOR, StringSplitOptions.RemoveEmptyEntries).ToArray());

                    foreach (var forumUrl in forums)
                    {
                        var path = resolveFullPath(forumUrl);
                        Console.WriteLine("\t{0}", path);
                        if (!subs.Contains(path))
                        {
                            subs.Add(path);

                            var forumObj = await fetchForum(path);

                            snapshot.GetOrAdd(path, forumObj);

                            for (int i = 0; i < snapshot[path].threads.Count; ++i)
                            {
                                ForumThread thread = snapshot[path].threads[i];

                                if (!visitedThreads.Contains(thread.ID))
                                {
                                    visitedThreads.Add(thread.ID);
                                }
                                snapshot[path].threads[i].IsNew = false;
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Loading resources complete");
        }