Beispiel #1
0
        private void bTest_Click(object sender, EventArgs e)
        {
#if DEBUG
            this._FakingRequests = true;
            this.label1.Text     = "Fake Query:";

            var text = this.tbPushBullet.Text.Trim();

            if (text.Length == 0)
            {
                this.tbPushBullet.Text = "play, artist adele";
            }

            var str_split = this.tbPushBullet.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (str_split.Length == 0)
            {
                return;
            }

            String title = str_split[0];
            String body  = null;
            if (str_split.Length > 1)
            {
                body = str_split[1];
            }

            using (Logger.Time("Processing Request"))
            {
                for (int i = 0; i < 3; i++) // 3 attempts.
                {
                    using (Logger.Time("Attempt " + i))
                    {
                        //try
                        {
                            this._RequestHandler.NewNotification(title, body);
                            break;
                        }

                        /*
                         * catch (Exception exc)
                         * {
                         *  Logger.WriteException(this, "FindBestMatchAndPlay", exc);
                         *  System.Threading.Thread.Sleep(500); // Give itunes a breath.
                         * }
                         * //*/
                    }
                }
            }
#endif
        }
Beispiel #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.LoadFormState();

            Logger.AddTab();

            var tb = this.tbConsole;

            Logger.WriterSupportTabs = new Action <string, string>((String ln, String tab) =>
            {
                MainForm.ThreadSafeTextBoxWrite(tb, ln, tab);
            });


            this.tbPushBullet.Text = TextSettings.Read("pbkey.txt") ?? "";
            this.ActiveControl     = this.label1; // Prevents textbox text from starting highlighted

            this.bStartPushbullet_Click(sender, e);
        }
Beispiel #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.LoadFormState();

            Logger.AddTab();

            var tb = this.tbConsole;

            Logger.WriterSupportTabs = new Action <string, string>((String ln, String tab) =>
            {
                MainForm.ThreadSafeTextBoxWrite(tb, ln, tab);
            });

            Logger.WriteLine("Loading access token from: " + Path.Combine(TextSettings.Folder, fileName));
            this.tbPushBullet.Text = TextSettings.Read(fileName) ?? "";
            this.ActiveControl     = this.label1; // Prevents textbox text from starting highlighted

            this.bStartPushbullet_Click(sender, e);

#if !DEBUG
            this.bTest.RemoveFromParent();
            this.bTest = null;
#endif
        }
Beispiel #4
0
        public void HandleResponseMainThread(WebSocketResponse response)
        {
            switch (response.Type)
            {
            // Heartbeat
            case "nop":
                Logger.WriteLine("PushBullet Heartbeat");
                if (!this.hasHiddenOnStartup)
                {
                    this.hasHiddenOnStartup = true;
                    this.Hide();
                    Logger.WriteLine("Saving access token to: " + Path.Combine(TextSettings.Folder, fileName));
                    TextSettings.Save(fileName, this.Client.AccessToken);
                }
                break;

            case "tickle":
                PushResponseFilter filter = new PushResponseFilter()
                {
                    Active       = true,
                    ModifiedDate = lastChecked
                };

                var pushes = Client.GetPushes(filter);
                foreach (var push in pushes.Pushes)
                {
                    if ((push.Created - lastChecked).TotalDays > 0)
                    {
                        lastChecked = push.Created;

                        using (Logger.Time("Processing Request"))
                        {
                            for (int i = 0; i < 3; i++)     // 3 attempts.
                            {
                                using (Logger.Time("Attempt " + i))
                                {
                                    try
                                    {
                                        this._RequestHandler.NewNotification(push.Title, push.Body);
                                        break;
                                    }
                                    catch (Exception exc)
                                    {
                                        Logger.WriteException(this, "FindBestMatchAndPlay", exc);
                                        System.Threading.Thread.Sleep(500);     // Give itunes a breath.
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Logger.WriteLine("Ignoring Old PushBullet: " + push.Title);
                    }
                }
                break;

            case "push":
                Logger.WriteLine(string.Format("New push recieved on {0}.", DateTime.Now));
                Logger.WriteLine("Push Type: " + response.Push.Type);
                Logger.WriteLine("Response SubType: " + response.Subtype);
                break;

            default:
                Logger.WriteLine("PushBullet type not supported!");
                break;
            }
        }