Example #1
0
        private void tmrPCRemote_Tick(object sender, EventArgs e)
        {
            tmrPCRemote.Enabled = false;
            if (ShowInTaskbar)
            {
                return;
            }

            NotifyIcon.Text = @"正在检查是否有新的微博...";
            DebugPrintHelper("当前状态:正在检查是否有新的微博...");

            //检查用户账号是否合法
            try
            {
                _service = WeiboServiceFactory.CreateInstance();
                _service.VerifyCredentials();
            }
            catch (Exception ex)
            {
                DebugPrintHelper("错误:用户登录失败。\n" + ex.Message);
                tmrPCRemote.Enabled = true;
            }

            //检查新微博
            try
            {
                var status = _service.GetMyFirstWeibo();
                if (status.Id.Trim() != Settings.Default.LastID.Trim())
                {
                    Settings.Default.LastID = status.Id.Trim();
                    Settings.Default.IdsToClear += string.IsNullOrEmpty(Settings.Default.IdsToClear)
                                                       ? status.Id.Trim()
                                                       : "," + status.Id.Trim();

                    Settings.Default.Save();

                    //把最新的一条微博的命令部分拆出来
                    var command = status.Text.Split(new[] { "$$" }, StringSplitOptions.None)[0];
                    while (command.EndsWith(" "))
                    {
                        command = command.Remove(command.Length - 1, 1);
                    }
                    DebugPrintHelper("新发布的命令为: \"" + command + "\"");
                    tmrPCRemote.Interval = 7000;

                    //解释命令
                    ProcessCommand(command, status.Id);
                }
                else
                {
                    if (tmrPCRemote.Interval == 7000)
                    {
                        tmrPCRemote.Interval = 8000;
                    }
                    else if (tmrPCRemote.Interval == 8000)
                    {
                        tmrPCRemote.Interval = 9000;
                    }
                    else if (tmrPCRemote.Interval == 9000)
                    {
                        tmrPCRemote.Interval = 10000;
                    }
                    else if (tmrPCRemote.Interval == 10000)
                    {
                        tmrPCRemote.Interval = 16000;
                    }
                    else
                    {
                        tmrPCRemote.Interval = 16000;
                    }
                }
            }
            catch (Exception ex)
            {
                DebugPrintHelper(ex.Message);
                tmrPCRemote.Interval = 16000;
                tmrPCRemote.Enabled = true;
                return;
            }

            tmrPCRemote.Enabled = true;
            NotifyIcon.Text = @"PC遥控器已经激活,正在等待新的命令...";
            DebugPrintHelper("当前状态:PC遥控器已经激活,正在等待新的命令...");
        }