Beispiel #1
0
        public ObservableCollection <ItemViewModel> GetPushes()
        {
            EnsureClient();
            var pushesModel         = new ObservableCollection <ItemViewModel>();
            PushbulletPushes pushes = _client.GetPushes();

            foreach (ActivePush push in pushes.Pushes.OfType <ActivePush>().OrderByDescending(push => push.CreatedRaw))
            {
                pushesModel.Add(ItemViewModelFactory.FromPush(push));
            }
            return(pushesModel);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string key = "--YOURKEYGOESHERE--";
            JavaScriptSerializer js     = new JavaScriptSerializer();
            PushbulletClient     Client = new PushbulletClient(key, TimeZoneInfo.Local);

            DateTime lastChecked = DateTime.Now;

            using (var ws = new WebSocket(string.Concat("wss://stream.pushbullet.com/websocket/", key)))
            {
                ws.OnMessage += (sender, e) =>
                {
                    WebSocketResponse response = js.Deserialize <WebSocketResponse>(e.Data);

                    switch (response.Type)
                    {
                    case "nop":
                        Console.WriteLine(string.Format("Updated {0}", DateTime.Now));
                        break;

                    case "tickle":
                        Console.WriteLine(string.Format("Tickle recieved on {0}. Go check it out.", DateTime.Now));
                        PushResponseFilter filter = new PushResponseFilter()
                        {
                            Active       = true,
                            ModifiedDate = lastChecked
                        };

                        var pushes = Client.GetPushes(filter);
                        foreach (var push in pushes.Pushes)
                        {
                            Console.WriteLine(push.Title);
                        }

                        lastChecked = DateTime.Now;
                        break;

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

                    default:
                        Console.WriteLine("new type that is not supported");
                        break;
                    }
                };
                ws.Connect();
                Console.ReadKey(true);
            }
        }
Beispiel #3
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;
            }
        }