Ejemplo n.º 1
0
        private void MetroButton1_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }
            Bitmap       bm = new Bitmap(pictureBox1.Image);
            MemoryStream ms = new MemoryStream();

            bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            var picture    = ms.ToArray();
            var newProfile = new Profile
            {
                picture     = picture,
                title       = metroTextBox1.Text,
                description = metroTextBox3.Text,
                site        = metroTextBox2.Text
            };
            LoginInfo loginInfo = new LoginInfo(loginIDText.Text, idPwdComboBox.Text);

            try
            {
                TwitterProfileScraper.ModifyProfile(newProfile, loginInfo);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                MetroButton1_Click(sender, e);
            }
        }
Ejemplo n.º 2
0
        public async Task startPostingAsync(bool latest, bool popular, int delay)
        {
            int randomNum    = getRandomNum(latest, popular);
            var mainInstance = Main.getInstance();
            var status       = mainInstance.getStatusLabel();
            var comboBox     = mainInstance.getPwdComboBox();

            while (true)
            {
                status.Text = "기사 정보를 수집 중입니다.";
                List <LoginInfo> loginInfos = LoginData.getInstance().getData();

                Article targetArticle;

                var maxIndex = comboBox.Items.Count;
                comboBox.SelectedIndex = 0;
                foreach (var item in loginInfos.Select((value, i) => new { i, value }))
                {
                    if (_cancel)
                    {
                        status.Text = "중지";
                        _cancel     = false;
                        return;
                    }
                    while (true)
                    {
                        try
                        {
                            await TwitterProfileScraper.getUserProfile(item.value);

                            break;
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                            continue;
                        }
                    }
                    try
                    {
                        while (true)
                        {
                            targetArticle = await _scraper[randomNum].getArticleInfoAsync();
                            var title = targetArticle.getTitle();

                            var filter =
                                from data in _articleHistory
                                where data.Equals(title)
                                select data;

                            if (!filter.Any())
                            {
                                _articleHistory.Add(title);
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    if (_cancel)
                    {
                        status.Text = "중지";
                        _cancel     = false;
                        return;
                    }
                    var index     = item.i;
                    var loginInfo = item.value;

                    status.Text = "트위터에 기사를 포스팅 중입니다.";
                    try
                    {
                        await TwitterPoster.twitterAsync(loginInfo, targetArticle);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                        if (index + 1 >= maxIndex)
                        {
                            await Task.Delay(delay * 1000);

                            break;
                        }
                        continue;
                    }

                    status.Text = "다음 계정 대기 중";
                    if (index + 1 >= maxIndex)
                    {
                        await Task.Delay(delay * 1000);

                        break;
                    }
                    comboBox.SelectedIndex = index + 1;
                    await Task.Delay(delay * 1000);
                }
            }
        }