/// <exception cref="UnAuthorizedProjectException">Thrown when the project is not valid or active</exception>
        /// <exception cref="UnableToAddExceptionizerMessageException">Thrown when we have been unable to fully persist the exception message</exception>
        public void Add(ExceptionizerMessage message)
        {
            try
            {
                authorizationService.AuthorizeProject(Guid.Parse(message.ApiKey));

                var messageDto = Mapper.Map <ExceptionizerMessageDto>(message);
                exceptionRepository.Add(messageDto);
            }
            catch (UnAuthorizedProjectException exception)
            {
                //Already logged
                throw;
            }
            catch (UnableToPersistToMongoDbException exception)
            {
                logger.Log(ExceptionType.ExceptionizerApi, "ExceptionService: Add", exception);
                throw new UnableToAddExceptionizerMessageException("Cannot add message to mongodb", exception);
            }
            catch (UnableToPersistToElasticSearchException exception)
            {
                logger.Log(ExceptionType.ExceptionizerApi, "ExceptionService: Add", exception);
                throw new UnableToAddExceptionizerMessageException("Cannot add message to elasticsearch", exception);
            }
            catch (Exception exception)
            {
                logger.Log(ExceptionType.Unhandled, "ExceptionService: Add", exception);
                throw new UnableToAddExceptionizerMessageException("UNHANDLED EXCEPTION!", exception);
            }
        }
        public void Send(ExceptionizerMessage message)
        {
            try
            {
                var requst = WebRequest.Create(this.configuration.ServerUri) as HttpWebRequest;

                if (requst == null)                 // log here
                {
                    return;
                }

                requst.ContentType = "application/json";
                requst.Accept      = "application/json";
                requst.KeepAlive   = false;
                requst.Method      = "POST";

                PopulateRequestBody(requst, message);

                requst.BeginGetResponse(RequestCallback, requst);
            }
            catch (Exception)
            {
                //Log and return
            }
        }
        private void PopulateRequestBody(HttpWebRequest requst, ExceptionizerMessage message)
        {
            var    jsonSerializer        = new JavaScriptSerializer();
            string jsonSerializedMessage = jsonSerializer.Serialize(message);

            byte[] messagePayload = Encoding.UTF8.GetBytes(jsonSerializedMessage);
            requst.ContentLength = messagePayload.Length;

            using (var streamWriter = requst.GetRequestStream())
            {
                streamWriter.Write(messagePayload, 0, messagePayload.Length);
            }
        }
Esempio n. 4
0
        // For testing purposes only
        public ExceptionizerMessage Get(string productid)
        {
            var exception = new ExceptionizerMessage();

            exception.ApiKey = "a6584184-14a6-4ddf-a652-0c86ac1d16e0";

            exception.ClientSource = new ClientSource
            {
                Name    = "local",
                Url     = "http://ryantomlinson.com",
                Version = "0.1"
            };
            exception.Environment = new Environment
            {
                OperatingSystem   = "windows",
                Url               = "http://exceptionizer.com",
                ProductVersion    = "1.0.0",
                SourceEnvironment = "production"
            };
            exception.UserInformation = new UserInformation
            {
                UserEmail = "*****@*****.**",
                UserId    = "1235",
                UserName  = "******"
            };
            exception.Exceptions = new List <ExceptionizerException>()
            {
                new ExceptionizerException()
                {
                    Message    = "something gone wrong like",
                    StackTrace = "this be the stacktracez",
                    Type       = "this be the type"
                }
            };
            try
            {
                exceptionService.Add(exception);
            }
            catch (Exception)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent("An error occured trying to process your request. Please contact us for details [email protected]"),
                    ReasonPhrase = "Critical Exception"
                });
            }

            return(exception);
        }
Esempio n. 5
0
 // PUT api/exception/5
 public void Put(ExceptionizerMessage message)
 {
     try
     {
         exceptionService.Add(message);
     }
     catch (Exception)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent("An error occured trying to process your request. Please contact us for details [email protected]"),
             ReasonPhrase = "Critical Exception"
         });
     }
 }
Esempio n. 6
0
 // POST api/exception
 public void Post(ExceptionizerMessage message)
 {
 }