Esempio n. 1
0
        //INT-CHQ 2-002
        public GeneraIncidenciaResponseDTO GeneraIncidencia(IOrganizationService _service, GeneraIncidenciaRequestDTO requestDTO, string url)
        {
            //string requestToJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestDTO);
            Util util = new Util();
            GeneraIncidenciaResponseDTO response = new GeneraIncidenciaResponseDTO();

            try
            {
                string request;
                request = @"{
                            ""request"":{
                            ""$type"":""AmxPeruPSBActivities.Activities.External.GeneraIncidenciaRequestDTO, AmxPeruPSBActivities""" + ",";

                request += "\"Password\": " + "\"" + requestDTO.request.Password + "\"" + ",";
                request += "\"UserName\": " + "\"" + requestDTO.request.UserName + "\"" + ",";
                request += "\"Urgency\": " + "\"" + requestDTO.request.Urgency + "\"" + ",";
                request += "\"ServiceCI\": " + "\"" + requestDTO.request.ServiceCI + "\"" + ",";
                request += "\"Impact\": " + "\"" + requestDTO.request.Impact + "\"" + ",";
                request += "\"Action\": " + "\"" + requestDTO.request.Action + "\"" + ",";
                request += "\"Description\": " + "\"" + requestDTO.request.Description + "\"" + ",";
                request += "\"CategorizationTier1\": " + "\"" + requestDTO.request.CategorizationTier1 + "\"" + ",";
                request += "\"CategorizationTier2\": " + "\"" + requestDTO.request.CategorizationTier2 + "\"" + ",";
                request += "\"CategorizationTier3\": " + "\"" + requestDTO.request.CategorizationTier3 + "\"" + ",";
                request += "\"RecordType\": " + "\"" + requestDTO.request.RecordType + "\"" + ",";
                request += "\"RecordID\":" + "\"" + requestDTO.request.RecordID + "\"" + "}" + "}";

                response = Newtonsoft.Json.JsonConvert.DeserializeObject <GeneraIncidenciaResponseDTO>(util.SendRestRequest(_service, request, url));

                #region 04_HardCode
                //response.CurrentBookmark = null;
                //response.Output.response.ProblemId = "INC000001227281";
                //response.Output.response.Status = 0;
                //response.Output.response.CodeResponse = "0";
                //response.Output.response.DescriptionResponse = "Transaccion OK";
                //response.Output.response.ErrorLocation = "";
                //response.CanRollback = false;
                //response.RunDate = Convert.ToDateTime("2018-06-27T12:07:08.453821Z");
                //response.WorkflowName = "AmxPeruGeneraIncidenciaExternal";
                //response.WorkflowVersion = "1.0.0.0";
                //response.Status = 4;
                #endregion

                return(response);
            }
            catch (Exception)
            {
                //TO DO:Manejo de excepciones o logging.
                throw;
            }
        }
Esempio n. 2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            IOrganizationService iServices = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));

            // Get a reference to the tracing service.
            myTrace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            try
            {
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    //Variables Locales
                    string sCodCaseType      = string.Empty;
                    string sCodCategory1     = string.Empty;
                    string sCodCategory2     = string.Empty;
                    string sCodCategory3     = string.Empty;
                    string sCodCategory4     = string.Empty;
                    int    ticketRemedyValue = 0;

                    Entity target = (Entity)context.InputParameters["Target"];

                    if (target.LogicalName != "task")
                    {
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }

                    EntityReference erRegardingObject = null;
                    EntityReference erCategory1       = null;
                    EntityReference erCategory2       = null;
                    EntityReference erCategory3       = null;

                    //EntityReference erCategory5 = null;

                    if (target.Attributes.Contains("regardingobjectid") && target["regardingobjectid"] != null)
                    {
                        erRegardingObject = (EntityReference)target["regardingobjectid"];

                        if (erRegardingObject.LogicalName == "incident")
                        {
                            if (target.Attributes.Contains("amxperu_tasktype") && target["amxperu_tasktype"] != null)
                            {
                                ticketRemedyValue = ((OptionSetValue)target["amxperu_tasktype"]).Value;
                            }
                        }
                    }
                    else
                    {
                        throw new InvalidPluginExecutionException("Task should be realted to a case. Check [regardingobject] field. ");
                    }

                    Entity eCase = service.Retrieve("incident", erRegardingObject.Id, new ColumnSet("amxperu_casetype", "ust_category1", "ust_category2", "ust_category3", "ust_category4"));


                    if (eCase.Attributes.Contains("ust_category1") && eCase.Attributes["ust_category1"] != null)
                    {
                        erCategory1 = ((EntityReference)eCase.Attributes["ust_category1"]);
                    }

                    if (eCase.Attributes.Contains("ust_category2") && eCase.Attributes["ust_category2"] != null)
                    {
                        erCategory2 = ((EntityReference)eCase.Attributes["ust_category2"]);
                    }

                    if (eCase.Attributes.Contains("ust_category3") && eCase.Attributes["ust_category3"] != null)
                    {
                        erCategory3 = ((EntityReference)eCase.Attributes["ust_category3"]);
                    }

                    //TO DO: TAREA REMEDY
                    if (ticketRemedyValue == 1)
                    {
                        //TO DO: Este servicio aún no está operativo para consumir.
                        GeneraIncidenciaResponseDTO response = CallPsbServiceAmxPeruGeneraIncidencia(service, "1", "", "INT-CHQ 2-002_generarIncidenciatask", erCategory1 != null ? erCategory1.Name : string.Empty, erCategory2 != null ? erCategory2.Name : string.Empty, erCategory3 != null ? erCategory3.Name : string.Empty, target.Id.ToString());
                        //throw new InvalidPluginExecutionException(response.Output.response.DescriptionResponse);


                        if (response != null)
                        {
                            if (response.Output != null)
                            {
                                if (response.Output.response != null)
                                {
                                    if (response.Output.response.Status == 0)
                                    {
                                        //target.Attributes["ust_remedyticketstatus"] = response.Output.response.Status.ToString();

                                        if (response.Output.response.ProblemId != null)
                                        {
                                            target.Attributes["ust_remedyticketid"] = response.Output.response.ProblemId;
                                        }
                                        else
                                        {
                                            return;
                                        }

                                        //if (response.Output.response.DescriptionResponse != null)
                                        //  target.Attributes["ust_remedyticketanswer"] = response.Output.response.DescriptionResponse;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (ApplicationException ex)
            {
                throw new ApplicationException("Controlled Error: " + ex.Message, ex);
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw new InvalidPluginExecutionException("PlugIn Error: " + ex.Message, ex);
            }
            catch (EndpointNotFoundException ex)
            {
                throw new EndpointNotFoundException("EndPoint Error: " + ex.Message, ex);
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("Crm Service error: " + ex.Message, ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Uncontrolled error: " + ex.Message, ex);;
            }
        }
Esempio n. 3
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            service = factory.CreateOrganizationService(context.UserId);

            IOrganizationService iServices = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));

            // Get a reference to the tracing service.
            myTrace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            try
            {
                string sTicketNumber = string.Empty;

                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    //Variables Locales
                    Entity target = (Entity)context.InputParameters["Target"];

                    if (target.LogicalName != "incident")
                    {
                        return;
                    }

                    if (target.Attributes.Contains("ticketnumber") && target.Attributes["ticketnumber"] != null)
                    {
                        sTicketNumber = target.Attributes["ticketnumber"].ToString();
                    }

                    RemedyDTO obj = IsApplyToRemedy(target);


                    if (obj == null)
                    {
                        return;
                    }

                    //TO DO: CONSUMIR SERVICIO REMEDY
                    if (obj.isRemedy)
                    {
                        GeneraIncidenciaResponseDTO response = CallPsbServiceAmxPeruGeneraIncidencia(service, "1", "", "INT-CHQ 2-002_generarIncidenciacase", obj.categoryCode1, obj.categoryCode2, obj.categoryCode3, target.Id.ToString());
                        //throw new InvalidPluginExecutionException(response.Output.response.DescriptionResponse);

                        if (response != null)
                        {
                            if (response.Output != null)
                            {
                                if (response.Output.response != null)
                                {
                                    if (response.Output.response.Status == 0)
                                    {
                                        //target.Attributes["ust_remedyticketstatus"] = response.Output.response.Status.ToString();

                                        if (response.Output.response.ProblemId != null)
                                        {
                                            target.Attributes["ust_remedyticketid"] = response.Output.response.ProblemId;
                                        }
                                        else
                                        {
                                            return;
                                        }

                                        //if (response.Output.response.DescriptionResponse != null)
                                        //    target.Attributes["ust_remedyticketanswer"] = response.Output.response.DescriptionResponse;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (ApplicationException ex)
            {
                throw new ApplicationException("Controlled Error: " + ex.Message, ex);
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw new InvalidPluginExecutionException("PlugIn Error: " + ex.Message, ex);
            }
            catch (EndpointNotFoundException ex)
            {
                throw new EndpointNotFoundException("EndPoint Error: " + ex.Message, ex);
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("Crm Service error: " + ex.Message, ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Uncontrolled error: " + ex.Message, ex);;
            }
        }