private void MessageClient_MessageReceived(object sender, MessageQueues.MessageReceivedEventArgs e)
        {
            List <Func <MessageBase, string> > funcs;

            if (transforms.TryGetValue(e.MessageEnevelope.Message.GetType(), out funcs))
            {
                foreach (var func in funcs)
                {
                    string result = func(e.MessageEnevelope.Message);

                    if (!string.IsNullOrEmpty(result))
                    {
                        pushoverClient.Push("", result, pushoverUserKey);
                    }
                }
            }

            e.Response = MessageQueues.MessageResponse.Ack;
        }
Ejemplo n.º 2
0
        static void PushTest()
        {
            PushoverClient.Pushover pclient = new PushoverClient.Pushover(MasterConfiguration.PushoverAppAPIKey);

                    PushoverClient.PushResponse response = pclient.Push(
              "Notifyd Notification",
              "This is the test message.",
              "uiMFPuuVUTQiQu28YRKgi3vxkU5rbS"
              );
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            string          userName = ConfigurationManager.AppSettings["Username"];
            string          password = ConfigurationManager.AppSettings["Password"];
            CookieContainer cookies;

            try
            {
                cookies = Login(userName, password);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting login details...{0}... ending...", ex.Message);
                return;
            }
            List <ParcelMotelObject> packages = new List <ParcelMotelObject>();

            for (int i = 1; i <= 25; i++)
            {
                try
                {
                    var stream = Request("http://www.parcelmotel.com/MyParcelMotel/Member/PackageHistoryPage?Page=" + i, null, cookies, "https://www.parcelmotel.com/MyParcelMotel/").GetResponseStream();

                    string webtext = StreamToString(stream);
                    var    result  = ParseHTML(webtext);
                    packages.AddRange(result);
                    if (result.Count == 0)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting text from Parcel Motel...: {0}", ex.Message);
                }
            }
            Console.WriteLine("Found a total of {0} packages", packages.Count);

            string pushoverAPIKey = ConfigurationManager.AppSettings["POAPIKey"];
            string pushoverDevice = ConfigurationManager.AppSettings["PODevice"];

            //send notification...
            PushoverClient.Pushover po = new PushoverClient.Pushover(pushoverAPIKey);

            foreach (ParcelMotelObject obj in packages)
            {
                string packageFile = string.Format("{0}.txt", obj.TrackingNumber);
                if (!File.Exists(packageFile))
                {
                    if (obj.Status != "Delivered")
                    {
                        string message = string.Format("Parcel {0} is new. Status: {1} Date: {2}", obj.TrackingNumber, obj.Status, obj.StatusTime);
                        var    resp    = po.Push("New Parcel Motel Package", message, pushoverDevice);
                        Console.WriteLine(resp.Status);
                    }
                    File.WriteAllText(packageFile, string.Format("{0};{1}", obj.Status, obj.StatusTime));
                }
                else
                {
                    string   data      = File.ReadAllText(packageFile);
                    string[] oldData   = data.Split(';');
                    string   oldStatus = oldData[0];
                    DateTime oldDate   = DateTime.Parse(oldData[1]);

                    if (obj.Status != oldStatus)
                    {
                        string message = string.Format("Parcel {0} status changed from {1} to {2} at {3}", obj.TrackingNumber, oldStatus, obj.Status, obj.StatusTime);
                        var    resp    = po.Push("New Parcel Motel Package", message, pushoverDevice);
                        Console.WriteLine(resp.Status);
                        File.WriteAllText(packageFile, string.Format("{0};{1}", obj.Status, obj.StatusTime)); // fixing bug #1 on github
                    }
                }
            }

            var locations = packages.GroupBy(x => x.Location);
            var statuses  = packages.GroupBy(x => x.Status);

            foreach (var location in locations)
            {
                Console.WriteLine("location: {0} number: {1}", location.Key, location.Count());
            }
            foreach (var status in statuses)
            {
                Console.WriteLine("Status: {0} number: {1}", status.Key, status.Count());
            }
        }