public void ProcessForestry(Models.DTO.WorkRequest workRequest, Models.DTO.WorkPacket workPacket, ForestryRequest forestry)
        {
            Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-sending Forestry Job to IBM MQ");

            try
            {
                var obj = Newtonsoft.Json.JsonConvert.SerializeObject(forestry);

                HttpResponseMessage htm = _forestryRequestor.Post(
                    new Uri(Properties.Settings.Default.MqApiUriHost + Properties.Settings.Default.MqApiUri),
                    forestry
                    );

                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-sent Forestry Job to IBM MQ");
            }
            catch (HttpResponseException ex)
            {
                AddStormsTracking(workRequest, workPacket, "FOBATCH", "FOCREATE", "Failed to create order in Forestry system");

                foreach (var header in ex.Response.Headers)
                {
                    Console.WriteLine(header.Key + ", " + header.Value.ToList()[0]);
                }

                CreateRemedyTicket(workRequest, workPacket, ex);
            }
        }
        public void CreateRemedyTicket(Forestry.Models.DTO.WorkRequest workRequest, Forestry.Models.DTO.WorkPacket workPacket, List <ValidationResult> errors)
        {
            try
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-sending invalid data to Remedy");

                string allErrors = string.Empty;
                foreach (var str in errors)
                {
                    allErrors += str + $"\r\n";
                }
                string notes = "[WR: " + workPacket.WorkRequestId + " " + "WP: " + workPacket.WorkPacketId + "]" + "\r\n" + allErrors;

                HttpResponseMessage hrm = _incidentRequestor.Post(
                    new Uri(Properties.Settings.Default.RemedyUriHost + Properties.Settings.Default.RemedyUri),
                    new Incident
                {
                    AssignedSupportGroup = "CO - Work Management Process",
                    ClientService        = "IT - Work Management",
                    Company = "WEC Business Services",     //or We Energies
                    Impact  = "4-Minor/Localized",
                    Urgency = "4-Low",
                    Notes   = notes,
                    Summary = "STORMS to Forestry validation failed."
                }
                    );

                var    incident       = hrm.Headers.Single(m => m.Key == "X-Id");
                string incidentNumber = incident.Value.ToList()[0];

                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-" + incidentNumber + "" + " created in Remedy");
            }
            catch (HttpResponseException exception)
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][FAILED-]-failed to send invalid data to Remedy");
                Console.WriteLine("*************Http Response Error***************");
                Console.WriteLine("Http Status Code:" + exception.Response.StatusCode.ToString());

                foreach (var header in exception.Response.Headers)
                {
                    Console.WriteLine(header.Key + ", " + header.Value.ToList()[0]);
                }

                Console.WriteLine("*************Http Response Error***************");
            }
        }
        private void CreateMilestoneRequirement(WorkRequest workRequest, WorkPacket workPacket)
        {
            Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-adding invalid data STORMS milestone requirement");

            //add to STORMS TWMIFREQUIREMENT table.. then an existing STORMS process will automatically run to add it to STORMS
            HttpResponseMessage hrm = _workRequestMilestoneRequirementRequestor.Post(
                new Uri(BaseManagedWorkApiUri + ResolveCurlyBrackets(Properties.Settings.Default.ManagedWorkOrderApiResourse_MilestoneRequirements, workRequest.Id.ToString())),
                new MilestoneRequirement()
            {
                WorkRequestId = workRequest.Id.ToString(),
                District      = workRequest.District,
                RequirementId = "624",
                Description   = "Forestry Data Invalid",
                Status        = "R"
            }
                );

            Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-added invalid data STORMS milestone requirement");
        }
        public void AddStormsTracking(Models.DTO.WorkRequest workRequest, Models.DTO.WorkPacket workPacket, string operatorId, string function, string typeOfChange)
        {
            try
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-adding to STORMS tracking audit log");

                string timeStamp = Convert.ToDateTime(DateTime.Now).ToString("dd-MMM-yy HH:mm:ss");

                HttpResponseMessage hrm = _workRequestTrackingRequestor.Post(
                    new Uri(BaseManagedWorkApiUri + ResolveCurlyBrackets(Properties.Settings.Default.ManagedWorkOrderApiResourse_WorkRequestTrackings, workRequest.Id.ToString())),
                    new Forestry.Models.DTO.WorkRequestTracking()
                {
                    District      = workRequest.District.Trim(),
                    Status        = workRequest.Status,
                    OperatorId    = operatorId,
                    WorkRequestId = Convert.ToInt64(workRequest.Id),
                    ChangeDate    = Convert.ToDateTime(timeStamp),
                    Function      = function,
                    TypeOfChange  = typeOfChange
                }
                    );

                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-added to STORMS tracking audit log");
            }
            catch (HttpResponseException ex)
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][FAILED-]-failed to log to STORMS tracking audit log");
                Console.WriteLine("*************Http Response Error***************");
                Console.WriteLine("Http Status Code:" + ex.Response.StatusCode.ToString());

                foreach (var header in ex.Response.Headers)
                {
                    Console.WriteLine(header.Key + ", " + header.Value.ToList()[0]);
                }

                Console.WriteLine("*************Http Response Error***************");

                CreateRemedyTicket(workRequest, workPacket, ex);
            }
        }
        public void AddStormsWorkQueue(Models.DTO.WorkRequest workRequest, Models.DTO.WorkPacket workPacket, string details)
        {
            //add to STORMS TWMIFEXCEPTIONCOND table.. then an existing STORMS process will automatically run to add it to STORMS
            try
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][BEGIN--]-logging invalid data to STORMS work queue");

                HttpResponseMessage hrm = _stormsWorkQueueRequestor.Post(
                    new Uri(BaseManagedWorkApiUri + ResolveCurlyBrackets(Properties.Settings.Default.ManagedWorkOrderApiResourse_IfExceptionConditions, workRequest.Id.ToString())),
                    new IFExceptionCond()
                {
                    CD_DIST            = workRequest.District,
                    CD_WR              = Convert.ToInt64(workRequest.Id),
                    DS_COND            = details,
                    ID_OPER            = workRequest.AssignedTo,
                    FG_ERROR           = "N",
                    TS_IFEXCEPTIONCOND = DateTime.Now,
                    CD_SEQ             = 0
                }
                    );

                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][SUCCESS]-logged invalid data to STORMS work queue");
            }
            catch (HttpResponseException ex)
            {
                Console.WriteLine("[WR:" + workPacket.WorkRequestId + " " + "WP:" + workPacket.WorkPacketId + "][FAILED-]-failed to log to STORMS work queue");
                Console.WriteLine("Http Status Code:" + ex.Response.StatusCode.ToString());
                Console.WriteLine("*************Http Response Error***************");

                foreach (var header in ex.Response.Headers)
                {
                    Console.WriteLine(header.Key + ", " + header.Value.ToList()[0]);
                }

                Console.WriteLine("*************Http Response Error***************");

                CreateRemedyTicket(workRequest, workPacket, ex);
            }
        }