Esempio n. 1
0
        private string BuildNotificationRequestUrl(NMANotification notification_)
        {
            if (!(_clientCfg.BaseUrl.EndsWith("/")))
            {
                _clientCfg.BaseUrl += "/";
            }

            var nmaUrlSb = new StringBuilder(_clientCfg.BaseUrl);

            nmaUrlSb.AppendFormat(
                POST_NOTIFICATION_BASE_METHOD,
                HttpUtility.UrlEncode(_clientCfg.ApiKeychain),
                HttpUtility.UrlEncode(_clientCfg.ApplicationName),
                HttpUtility.UrlEncode(notification_.Description),
                HttpUtility.UrlEncode(notification_.Event),
                ((sbyte)(notification_.Priority)));

            if (!String.IsNullOrEmpty(_clientCfg.ProviderKey))
            {
                nmaUrlSb.AppendFormat(
                    POST_NOTIFICATION_PROVIDER_PARAMETER,
                    HttpUtility.UrlEncode(_clientCfg.ProviderKey));
            }

            return(nmaUrlSb.ToString());
        }
Esempio n. 2
0
        public void PostNotification(NMANotification notification_)
        {
            notification_.Validate();

            var updateRequest =
                HttpWebRequest.Create(BuildNotificationRequestUrl(notification_)) as HttpWebRequest;

            updateRequest.ContentLength = 0;
            updateRequest.ContentType   = REQUEST_CONTENT_TYPE;
            updateRequest.Method        = REQUEST_METHOD_TYPE;

            var postResponse = default(WebResponse);

            try
            {
                postResponse = updateRequest.GetResponse();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.ToString());
            }
            finally
            {
                if (postResponse != null)
                {
                    postResponse.Close();
                }
            }
        }