Ejemplo n.º 1
0
        public void ParseTokenResult_should_parse_Url_correctly_when_success()
        {
            XDocument           xDoc = XDocument.Parse(_successfulTokenResult);
            RetrieveTokenResult notificationResult = new RetrieveTokenResult();

            ResultParser.ParseTokenResult(xDoc, notificationResult);

            Assert.Equal("http://www.nnihlen.com/blog", notificationResult.Url);
        }
Ejemplo n.º 2
0
        public void ParseTokenResult_should_parse_Token_correctly_when_success()
        {
            XDocument           xDoc = XDocument.Parse(_successfulTokenResult);
            RetrieveTokenResult notificationResult = new RetrieveTokenResult();

            ResultParser.ParseTokenResult(xDoc, notificationResult);

            Assert.Equal("1234567890123456789012345678901234567890", notificationResult.Token);
        }
Ejemplo n.º 3
0
        private void Run(string[] args)
        {
            ArgumentsObject arguments = Configuration.Configure <ArgumentsObject>().CreateAndBind(args);

            if (arguments.Help || args.Length == 0)
            {
                ShowHelp();
                return;
            }

            var prowlClient = new ProwlClient();

            if (arguments.RetrieveToken)
            {
                RetrieveToken retrieveToken = new RetrieveToken();
                retrieveToken.ProviderKey = arguments.ProviderKey;

                RetrieveTokenResult result = prowlClient.RetreiveToken(retrieveToken);
                System.Console.WriteLine("Token retreived\nToken: {0}\nUrl: {1}",
                                         result.Token,
                                         result.Url);

                return;
            }

            if (arguments.NewKey)
            {
                if (string.IsNullOrEmpty(arguments.Token) || string.IsNullOrEmpty(arguments.ProviderKey))
                {
                    System.Console.WriteLine("ProviderKey and Token required for this operation.");
                    return;
                }
                RetrieveApikey retrieveApikey = new RetrieveApikey();
                retrieveApikey.Token       = arguments.Token;
                retrieveApikey.ProviderKey = arguments.ProviderKey;

                RetrieveApikeyResult retrieveApikeyResult = prowlClient.RetrieveApikey(retrieveApikey);
                System.Console.WriteLine("New APIKEY: {0}");
                return;
            }

            if (string.IsNullOrEmpty(arguments.Key))
            {
                System.Console.WriteLine("ApiKey requried");
                return;
            }

            if (arguments.Verify)
            {
                IVerification v = new Verification();
                v.ApiKey      = arguments.Key;
                v.ProviderKey = arguments.ProviderKey;
                System.Console.WriteLine("Sending verification...");
                VerificationResult verificationResult = prowlClient.SendVerification(v);
                System.Console.WriteLine("Verification {3}\n\tVerification returned: {0} \n\tNumber of messages left to send: {1}\n\tReset UNIX timestamp: {2}",
                                         verificationResult.ResultCode,
                                         verificationResult.RemainingMessageCount.ToString(),
                                         verificationResult.TimeStamp,
                                         verificationResult.ResultCode == "200" ? "OK" : "NOT OK");
            }
            else
            {
                if (string.IsNullOrEmpty(arguments.Event))
                {
                    System.Console.WriteLine("Event is required");
                    return;
                }

                if (string.IsNullOrEmpty(arguments.Application))
                {
                    System.Console.WriteLine("Application is required");
                    return;
                }

                var notification = new Notification
                {
                    Application = arguments.Application,
                    Description = arguments.Description,
                    Event       = arguments.Event,
                    Url         = arguments.Url
                };


                switch (arguments.Priority.ToLower())
                {
                case "verylow":
                    notification.Priority = NotificationPriority.VeryLow;
                    break;

                case "moderate":
                    notification.Priority = NotificationPriority.Moderate;
                    break;

                case "high":
                    notification.Priority = NotificationPriority.High;
                    break;

                case "emergency":
                    notification.Priority = NotificationPriority.Emergency;
                    break;

                default:
                    notification.Priority = NotificationPriority.Normal;
                    break;
                }

                foreach (string s in arguments.Key.Split(new[] { ',', ';' }))
                {
                    notification.AddApiKey(s);
                }

                NotificationResult notificationResult = prowlClient.SendNotification(notification);

                System.Console.WriteLine("Remaing number of messages: {0}", notificationResult.RemainingMessageCount.ToString());
            }
        }
Ejemplo n.º 4
0
        public void ParseTokenResult_should_parse_Url_correctly_when_success()
        {
            XDocument xDoc = XDocument.Parse(_successfulTokenResult);
            RetrieveTokenResult notificationResult = new RetrieveTokenResult();
            ResultParser.ParseTokenResult(xDoc, notificationResult);

            Assert.Equal("http://www.nnihlen.com/blog", notificationResult.Url);
        }
Ejemplo n.º 5
0
        public void ParseTokenResult_should_parse_Token_correctly_when_success()
        {
            XDocument xDoc = XDocument.Parse(_successfulTokenResult);
            RetrieveTokenResult notificationResult = new RetrieveTokenResult();
            ResultParser.ParseTokenResult(xDoc, notificationResult);

            Assert.Equal("1234567890123456789012345678901234567890", notificationResult.Token);
        }