Пример #1
0
        private async Task <bool> UpdateTopicList(int cat_id, int offset = 0)
        {
            TopicList topicList;

            if (cat_id == -1)
            {
                topicList = await mAskMonaApi.FetchFavoriteTopicListAsync();
            }
            else
            {
                topicList = await mAskMonaApi.FetchTopicListAsync(cat_id, 50, offset);
            }

            if (topicList == null)
            {
                return(false);
            }

            listView1.BeginUpdate();
            var time = Common.DateTimeToUnixTimeStamp(DateTime.Now);

            foreach (var topic in topicList.Topics)
            {
                var oldTopic = mTopicList.Find(x => x.Id == topic.Id);
                if (oldTopic == null)
                {
                    topic.Increased = 0;
                }
                else
                {
                    topic.Increased = topic.Count - oldTopic.Count;
                }

                topic.CachedCount = 0;
                var cache = mResponseCache.Find(x => x.Topic.Id == topic.Id);
                if (cache != null)
                {
                    topic.CachedCount = cache.Topic.Count;
                }

                var lvi = InitializeListViewItem(topic, time);
                listView1.Items.Add(lvi);
            }
            listView1.ListViewItemSorter = mListViewItemSorter;
            Common.UpdateColumnColors(listView1, Color.White, Color.Lavender);
            listView1.EndUpdate();

            mTopicList.AddRange(topicList.Topics);

            return(true);
        }
Пример #2
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            LoadSettings();
            LoadHtmlHeader();

            mAskMonaApi = new AskMonaApi("3738", "", mSettings.Account);
            if (await mAskMonaApi.VerifySecretKeyAsync() == null)
            {
                var signUpDialog = new SignUpDialog(mSettings.Account);
                signUpDialog.ShowDialog();
                mAskMonaApi.Account = signUpDialog.Account;
                mSettings.Account   = signUpDialog.Account;
            }
            if (await mAskMonaApi.VerifySecretKeyAsync() == null)
            {
                MessageBox.Show("ログインに失敗しました", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var topicList = await mAskMonaApi.FetchFavoriteTopicListAsync();

            if (topicList != null)
            {
                mFavoriteTopicList = topicList.Topics;
            }

            var ngUsers = await mAskMonaApi.FetchNGUsersAsync();

            if (ngUsers != null)
            {
                mNGUsers = ngUsers.Users.Select(x => x.UserId).ToList <int>();
            }

            foreach (var topicId in mSettings.MainFormSettings.TabTopicList)
            {
                UpdateConnectionStatus("通信中");
                toolStripComboBox1.Text = "https://askmona.org/" + topicId;
                if (await InitializeTabPage(topicId))
                {
                    UpdateConnectionStatus("受信完了");
                }
                else
                {
                    UpdateConnectionStatus("受信失敗");
                }
            }

            UpdateConnectionStatus("通信中");
            if (await UpdateTopicList(mCategoryId))
            {
                UpdateConnectionStatus("受信完了");
            }
            else
            {
                UpdateConnectionStatus("受信失敗");
            }

            tabControl1.SelectedIndex = mSettings.MainFormSettings.SelectedTabIndex;
            if (tabControl1.SelectedIndex == 0)
            {
                tabControl1_SelectedIndexChanged(this, new EventArgs());
            }

            await UpdateCurrencyPrice();

            EnableControls();
        }