Ejemplo n.º 1
0
        /// <summary>
        /// Creates Exception Request for given user.  If user does not exist it will get created first
        /// </summary>
        /// <param name="emailName">The user email name</param>
        /// <param name="fullName">The user full name</param>
        /// <param name="exceptionRequestJson">The <see cref="ExceptionRequest"/> object with values submitted by user from UI</param>
        /// <returns><see cref="ExceptionRequest"/> created</returns>
        public ExceptionRequest CreateNewRequest(string emailName, string fullName, ExceptionRequest newRequest)
        {
            // Get the user
            var user = this.GetUserByEmail(emailName);

            // If user is not there, then add new user
            if (user == null)
            {
                var newUser = new User
                {
                    EmailName = emailName,
                    FullName  = fullName
                };

                this.dataContext.Users.Add(newUser);
                this.dataContext.SaveChanges();
                user = newUser;
            }

            // Fill in the system generated values
            var status = this.dataContext.Statuses.Where(s => s.Id == 1).First();

            newRequest.SubmittedDate = DateTime.Now;
            newRequest.Status        = status;
            newRequest.StatusId      = 1; //Pending - TODO: Should be enum?
            newRequest.TrackingId    = Guid.NewGuid();
            newRequest.UserId        = user.Id;

            // Now create the Exception Request
            this.dataContext.ExceptionRequests.Add(newRequest);
            this.dataContext.SaveChanges();

            return(newRequest);
        }
        public async Task <DispatchRiderEvent> Dispatch(DispatchRiderEvent evt)
        {
            if (evt.Exception is AggregateException)
            {
                foreach (var agrex in ((AggregateException)evt.Exception).Flatten().InnerExceptions)
                {
                    await Dispatch(agrex, evt.HttpMethod, evt.Route, evt.RequestParams);
                }
                return(evt);
            }
            var endpoint = new Uri(_options.BaseUri, "/1.0/record/exception");

            using (var client = new HttpClient())
            {
                if (!string.IsNullOrEmpty(_options.ApiKey))
                {
                    var authArray = Encoding.UTF8.GetBytes("APIKEYUSER:"******"Basic", Convert.ToBase64String(authArray));
                }
                var req = new ExceptionRequest(evt.Exception);
                req.HttpMethod    = evt.HttpMethod;
                req.Route         = evt.Route;
                req.RequestParams = evt.RequestParams;
                var innerException = evt.Exception.InnerException;
                while (null != innerException)
                {
                    req.AddException(innerException);
                    innerException = innerException.InnerException;
                }
                var json = JsonConvert.SerializeObject(req);
                System.Console.WriteLine("Preparing to send payload");
                System.Console.WriteLine(json);
                using (var content = new StringContent(json, Encoding.UTF8, "application/json"))
                {
                    var request = await client.PostAsync(endpoint, content);
                }
            }
            return(evt);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates Exception Request for given user.
        /// </summary>
        /// <param name="emailName">The user email name</param>
        /// <param name="fullName">The user full name</param>
        /// <param name="exceptionRequestJson">The request submitted by user from UI</param>
        /// <returns><see cref="ExceptionRequest"/> created</returns>
        public ExceptionRequest CreateNewRequest(string emailName, string fullName, JObject exceptionRequestJson)
        {
            // TODO: Validate SubscriptionId??  Others??
            Guid subsId;

            if (!Guid.TryParse(exceptionRequestJson["subscriptionId"].ToString(), out subsId))
            {
                subsId = Guid.Empty;
            }

            // Fill in properties that can be passed by User from UI
            var newRequest = new ExceptionRequest
            {
                SubscriptionId   = subsId,
                ContactEmail     = exceptionRequestJson["contactEmail"].ToString(),
                ExpectedVolumeId = int.Parse(exceptionRequestJson["expectedVolumeId"].ToString()),
                IPAddresses      = exceptionRequestJson["ipAddresses"].ToString(),
                Justification    = exceptionRequestJson["justification"].ToString()
            };

            var exceptionRequest = new ExceptionRequestRepository(this).CreateNewRequest(emailName, fullName, newRequest);

            return(exceptionRequest);
        }