Ejemplo n.º 1
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);
            EntityReference             changeOrderEntityReference = context.InputParameters.Contains(Constants.TARGET) ? context.InputParameters[Constants.TARGET] as EntityReference : null;
            ProjectTemplateSettings     projectTemplateSettings    = null;

            if (changeOrderEntityReference == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                tracer.Trace("projectTemplateSettings is NULL. UnSecure Plugin Configuration Not Found.");
                return;
            }


            try
            {
                int revision = context.InputParameters.Contains(Constants.CustomActionParam.Revision) ? int.Parse((context.InputParameters[Constants.CustomActionParam.Revision]).ToString()) : 0;
                ServerUrl = context.InputParameters.Contains(Constants.CustomActionParam.ServerUrl) ? context.InputParameters[Constants.CustomActionParam.ServerUrl].ToString() : string.Empty;
                tracer.Trace($"Server Url : {ServerUrl}");
                string errorMessage = ExecuteContext(tracer, service, changeOrderEntityReference, revision, projectTemplateSettings, context.UserId);
                if (string.IsNullOrEmpty(errorMessage))
                {
                    context.OutputParameters[Constants.CustomActionParam.IsSuccess]    = true;
                    context.OutputParameters[Constants.CustomActionParam.ErrorMessage] = string.Empty;
                }
                else
                {
                    tracer.Trace("Error Message " + errorMessage);
                    context.OutputParameters[Constants.CustomActionParam.IsSuccess]    = false;
                    context.OutputParameters[Constants.CustomActionParam.ErrorMessage] = errorMessage;
                }
            }
            catch (Exception ex)
            {
                tracer.Trace(ex.Message + ex.StackTrace);
                context.OutputParameters[Constants.CustomActionParam.IsSuccess]    = false;
                context.OutputParameters[Constants.CustomActionParam.ErrorMessage] = ex.Message;
            }
        }
Ejemplo n.º 2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            ProjectTemplateSettings projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "projectTemplateSettings is NULL.UnSecure Plugin Configuration Not Found.");
            }

            EntityReference projectTaskEntityReference = context.InputParameters.Contains(Constants.TARGET) ? context.InputParameters[Constants.TARGET] as EntityReference : null;

            if (projectTaskEntityReference == null)
            {
                return;
            }

            try
            {
                ExecuteContext(tracer, service, projectTaskEntityReference, projectTemplateSettings);
                context.OutputParameters[Constants.CustomActionParam.IsSuccess]    = true;
                context.OutputParameters[Constants.CustomActionParam.ErrorMessage] = string.Empty;

                //TODO: Do stuff
            }
            catch (Exception ex)
            {
                tracer.Trace(ex.Message + ex.StackTrace);
                context.OutputParameters[Constants.CustomActionParam.IsSuccess]    = false;
                context.OutputParameters[Constants.CustomActionParam.ErrorMessage] = ex.Message;
            }
        }
Ejemplo n.º 3
0
        public static string ExecuteContext(ITracingService tracer, IOrganizationService service, EntityReference changeOrderEntityReference, int revision, ProjectTemplateSettings projectTemplateSettings, Guid currentSystemUserID)
        {
            string errorMessage = string.Empty;

            //ReCalculate Lookup...
            CommonMethods.CalculateRollup(service, Constants.ChangeOrders.TotalAmount, changeOrderEntityReference);

            Entity changeOrderEntity = service.Retrieve(changeOrderEntityReference.LogicalName, changeOrderEntityReference.Id, new ColumnSet(true));

            if (changeOrderEntity is Entity && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.PendingApprovalLevel) && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.Unit) && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.ProjectTemplateID))
            {
                if (changeOrderEntity.Attributes.Contains(Constants.Status.StatusCode) && changeOrderEntity.GetAttributeValue <OptionSetValue>(Constants.Status.StatusCode).Value == 963850005)
                {
                    Entity unitEntity = service.Retrieve(Constants.Units.LogicalName, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.Unit).Id, new ColumnSet(true));
                    if (unitEntity is Entity && unitEntity.Attributes.Contains(Constants.Units.Market))
                    {
                        tracer.Trace("Is Approver is Part of Approve Process");

                        EntityCollection approverEntityCollection = CommonMethods.ApproverOrderList(tracer, service, changeOrderEntity.GetAttributeValue <OptionSetValue>(Constants.ChangeOrders.PendingApprovalLevel).Value,
                                                                                                    unitEntity.GetAttributeValue <OptionSetValue>(Constants.Units.Market).Value, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectTemplateID), currentSystemUserID);

                        if (approverEntityCollection.Entities.Count > 0)
                        {
                            int  nextApprovalLevel    = 0;
                            bool nextApprovelRequired = false;
                            //All levels are approved. Mark Change Order as Approved.
                            CreateChangeOrderApproveRecord(tracer, service, changeOrderEntity, approverEntityCollection.Entities[0].ToEntityReference());
                            if (changeOrderEntity.GetAttributeValue <OptionSetValue>(Constants.ChangeOrders.PendingApprovalLevel).Value != 963850005)
                            {
                                //Perform Approve Process.
                                nextApprovelRequired = IsNextApprovalRequired(tracer, service, changeOrderEntity.GetAttributeValue <Money>(Constants.ChangeOrders.TotalAmount).Value,
                                                                              changeOrderEntity.GetAttributeValue <OptionSetValue>(Constants.ChangeOrders.PendingApprovalLevel).Value, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectTemplateID), projectTemplateSettings, out nextApprovalLevel);
                            }
                            if (!nextApprovelRequired)
                            {
                                Entity tmpChangeOrderEntity = new Entity(changeOrderEntity.LogicalName);
                                tmpChangeOrderEntity.Id = changeOrderEntity.Id;
                                tmpChangeOrderEntity[Constants.ChangeOrders.PendingApprovalLevel] = null;

                                service.Update(tmpChangeOrderEntity);
                                //Set Status to Approved...

                                CommonMethods.ChangeEntityStatus(tracer, service, changeOrderEntityReference, 1, 963850006);

                                EntityCollection changeOrderItemsEntityCollection = CommonMethods.RetrieveChangeOrderItems(tracer, service, changeOrderEntityReference);

                                foreach (Entity changeOrderItemEntity in changeOrderItemsEntityCollection.Entities)
                                {
                                    //Change Status to Approved. Should be part of Inactive.
                                    CommonMethods.ChangeEntityStatus(tracer, service, changeOrderItemEntity.ToEntityReference(), 1, 963850002);
                                }

                                if (changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.ProjectID))
                                {
                                    Entity projectEntity = service.Retrieve(changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectID).LogicalName, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectID).Id, new ColumnSet(true));
                                    if (projectEntity is Entity)
                                    {
                                        if (unitEntity is Entity && (unitEntity.Attributes.Contains(Constants.Units.UnitId) || unitEntity.Attributes.Contains(Constants.Units.SFCode)))
                                        {
                                            CreateOutGoingAzureIntegrationCallRecord(service, tracer, projectEntity, changeOrderEntity, changeOrderItemsEntityCollection, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate),
                                                                                     projectTemplateSettings, (unitEntity.Attributes.Contains(Constants.Units.UnitId)) ? unitEntity.GetAttributeValue <string>(Constants.Units.UnitId) : unitEntity.GetAttributeValue <string>(Constants.Units.SFCode));
                                        }
                                    }
                                }



                                //Send Confirmation Email...
                                Entity fromSystemUserEntity = CommonMethods.RetrieveCRMEMailSystemUser(tracer, service);
                                if (fromSystemUserEntity is Entity)
                                {
                                    EntityCollection fromEntitycollection = new EntityCollection();
                                    Entity           fromParty            = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                    fromParty[ACTIVITYPARTY_ATTR_PARTYID] = fromSystemUserEntity.ToEntityReference();
                                    fromEntitycollection.Entities.Add(fromParty);

                                    EntityCollection toEntitycollection = new EntityCollection();
                                    Entity           toParty            = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                    toParty[ACTIVITYPARTY_ATTR_PARTYID] = changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.Requestor);
                                    toEntitycollection.Entities.Add(toParty);

                                    string recordUrl     = $"{ServerUrl}/main.aspx?etn={changeOrderEntity.LogicalName}&pagetype=entityrecord&id={changeOrderEntity.Id.ToString()}";
                                    Entity emailActivity = new Entity(Constants.Emails.LogicalName);
                                    emailActivity[Constants.Emails.Subject]         = $"Change Order Approved: {changeOrderEntity.GetAttributeValue<EntityReference>(Constants.ChangeOrders.ProjectID).Name}";
                                    emailActivity[Constants.Emails.To]              = toEntitycollection;
                                    emailActivity[Constants.Emails.From]            = fromEntitycollection;
                                    emailActivity[Constants.Emails.DirectionCode]   = true;
                                    emailActivity[Constants.Emails.RegardingObject] = changeOrderEntity.ToEntityReference();
                                    emailActivity[Constants.Emails.Description]     = $"The change order for the project {changeOrderEntity.GetAttributeValue<EntityReference>(Constants.ChangeOrders.ProjectID).Name} has been approved.<br/><br/> Click here to access the change order. <br/><a href ='{recordUrl}'>{changeOrderEntity.GetAttributeValue<string>(Constants.ChangeOrders.Name)}</a>   ";

                                    emailActivity.Id = service.Create(emailActivity);
                                    try
                                    {
                                        //SendEmailResponse emailResponse = CommonMethods.SendEmail(tracer, service, emailActivity.ToEntityReference());
                                        //if (emailResponse is SendEmailResponse)
                                        //    tracer.Trace("Email successfully sent.");
                                        //else
                                        //    errorMessage = "Operation successfully completed but Email Send failed.";
                                    }
                                    catch (Exception ex)
                                    {
                                        tracer.Trace(ex.Message + Environment.NewLine + ex.StackTrace);
                                    }
                                }
                                else
                                {
                                    errorMessage = $"System User Not found with Email Address : {Constants.CRMEmail}. Operation Successfully performed but Email will not be generated.";
                                }
                            }
                            else
                            {
                                //Go To Next Approver...
                                tracer.Trace($"Retrieving Budget Approver.");
                                EntityCollection budgetApproverEntityCollection = CommonMethods.RetrieveAllBudjgetApprovers(tracer, service, unitEntity.GetAttributeValue <OptionSetValue>(Constants.Units.Market).Value, nextApprovalLevel, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectTemplateID));

                                if (budgetApproverEntityCollection.Entities.Count > 0)
                                {
                                    tracer.Trace($"Budget Approver found.");

                                    Entity fromSystemUserEntity = CommonMethods.RetrieveCRMEMailSystemUser(tracer, service);
                                    if (fromSystemUserEntity is Entity)
                                    {
                                        EntityCollection fromEntitycollection = new EntityCollection();
                                        Entity           fromParty            = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                        fromParty.Attributes.Add(ACTIVITYPARTY_ATTR_PARTYID, fromSystemUserEntity.ToEntityReference());
                                        fromEntitycollection.Entities.Add(fromParty);

                                        EntityCollection toEntitycollection = new EntityCollection();

                                        foreach (Entity budgetApproverEntity in budgetApproverEntityCollection.Entities)
                                        {
                                            if (budgetApproverEntity.Attributes.Contains("U.internalemailaddress") || budgetApproverEntity.Attributes.Contains("U.domainname"))
                                            {
                                                Entity toParty = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                                toParty.Attributes.Add(ACTIVITYPARTY_ATTR_PARTYID, budgetApproverEntity.GetAttributeValue <EntityReference>(Constants.BudgetApprovers.ApproverID));
                                                toEntitycollection.Entities.Add(toParty);
                                            }
                                        }

                                        CommonMethods.SendRequestForApprovalEmail(tracer, service, changeOrderEntity, fromEntitycollection, toEntitycollection, ServerUrl);
                                    }
                                    else
                                    {
                                        errorMessage = $"System User Not found with Email Address : {Constants.CRMEmail}. Operation Successfully performed but Email will not be generated.";
                                    }

                                    Entity tmpChangeOrderEntity = new Entity(changeOrderEntity.LogicalName);
                                    tmpChangeOrderEntity.Id = changeOrderEntity.Id;
                                    tmpChangeOrderEntity[Constants.ChangeOrders.PendingApprovalLevel] = new OptionSetValue(nextApprovalLevel);

                                    service.Update(tmpChangeOrderEntity);
                                }
                                else
                                {
                                    tracer.Trace($"No Budget Approver found.");
                                }
                            }
                        }
                        else
                        {
                            errorMessage = "You are not an approver in the current market. Consequently, you may not approve this change order.";
                        }
                    }
                    else
                    {
                        errorMessage = "Unit Not Found or Unit Record does not have Market.";
                    }
                }
                else
                {
                    errorMessage = "Change Order is Not Submit For Approval OR Change Order Already Approved.";
                }
            }
            else
            {
                errorMessage = "Change Order Entity Not Found or Change Order entity does not have Approval Level or Unit";
            }

            return(errorMessage);
        }
Ejemplo n.º 4
0
        private static void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, Entity projectEntity, Entity changeOrderEntity, EntityCollection changeOrderItemsEntityCollection, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, string propertyID)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                EntityCollection          projectTeamMemberEntityCollection = RetrieveProjectTeamMembers(tracer, _service, projectEntity.ToEntityReference());
                EntityCollection          projectTaskEntityCollection       = RetrieveAllProjectTaskByProjectWithContractID(tracer, _service, projectEntity.ToEntityReference());
                Dictionary <Guid, string> vendorContractCode   = new Dictionary <Guid, string>();
                Dictionary <Guid, string> vendorCodeDictionary = new Dictionary <Guid, string>();
                List <Contract>           contractList         = new List <Contract>();
                foreach (Entity changeOrderItemEntity in changeOrderItemsEntityCollection.Entities)
                {
                    if (changeOrderItemEntity.Attributes.Contains(Constants.ChangeOrderItems.Vendor))
                    {
                        string contractCode = string.Empty;
                        //Check whether It is existing Vendor or not.
                        if (vendorContractCode.ContainsKey(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id))
                        {
                            contractCode = vendorContractCode[changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id];
                        }
                        else
                        {
                            if (projectTeamMemberEntityCollection is EntityCollection)
                            {
                                Entity prjTeamMemberEntity = projectTeamMemberEntityCollection.Entities.Where(e => e.Attributes.Contains("B.accountid") && ((EntityReference)e.GetAttributeValue <AliasedValue>("B.accountid").Value).Id.Equals(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id)).FirstOrDefault();
                                if (prjTeamMemberEntity is Entity)
                                {
                                    Entity prjTaskEntity = projectTaskEntityCollection.Entities.Where(e => e.Attributes.Contains(Constants.ProjectTasks.AssignedTeamMembers) && e.GetAttributeValue <EntityReference>(Constants.ProjectTasks.AssignedTeamMembers).Id.Equals(prjTeamMemberEntity.Id)).FirstOrDefault();
                                    if (prjTaskEntity is Entity)
                                    {
                                        vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, prjTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID));
                                        contractCode = prjTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID);
                                    }
                                    else
                                    {
                                        vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                                    }
                                }
                                else
                                {
                                    vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                                }
                            }
                            else
                            {
                                vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                            }
                        }
                        Contract c = new Contract();
                        c.Amount          = changeOrderItemEntity.GetAttributeValue <Money>(Constants.ChangeOrderItems.Amount).Value.ToString();
                        c.Category_Code   = changeOrderItemEntity.GetAttributeValue <AliasedValue>("JC.fkh_jobcategorycode").Value.ToString();
                        c.Contract_Code   = contractCode;
                        c.ItemDescription = changeOrderItemEntity.GetAttributeValue <string>(Constants.ChangeOrderItems.Description);
                        c.Start_Date      = DateTime.Now.ToString();
                        if (vendorCodeDictionary.ContainsKey(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id))
                        {
                            c.Vendor_Code = vendorCodeDictionary[changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id];
                        }
                        else
                        {
                            Entity vendorEntity = _service.Retrieve(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).LogicalName, changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, new ColumnSet(true));
                            if (vendorEntity is Entity && vendorEntity.Attributes.Contains(Constants.Vendors.AccountCode))
                            {
                                c.Vendor_Code = vendorEntity.GetAttributeValue <string>(Constants.Vendors.AccountCode);
                                vendorCodeDictionary.Add(vendorEntity.Id, vendorEntity.GetAttributeValue <string>(Constants.Vendors.AccountCode));
                            }
                        }
                        //c.Vendor_Code =
                        contractList.Add(c);
                    }
                }


                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {Events.CHANGE_ORDER.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {Events.IR_CHANGE_ORDER.ToString()}";
                }
                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = Events.CHANGE_ORDER;
                }
                else
                {
                    gridEventDataPayload.data.Event = Events.IR_CHANGE_ORDER;
                }
                gridEventDataPayload.data.IsForce     = false;
                gridEventDataPayload.data.PropertyID  = propertyID;
                gridEventDataPayload.data.EmailID     = string.Empty;
                gridEventDataPayload.data.FotoNotesID = string.Empty;
                gridEventDataPayload.data.JobID       = string.Empty;
                gridEventDataPayload.data.RenowalkID  = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);
                gridEventDataPayload.data.Contracts   = contractList;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.CHANGE_ORDER.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.IR_CHANGE_ORDER.ToString();
                }
                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Ejemplo n.º 5
0
        private static bool IsNextApprovalRequired(ITracingService tracer, IOrganizationService service, decimal amount, int CurrentApprovalLevel, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, out int nextApprovalLevel)
        {
            bool isnextApprovalRequire = false;

            nextApprovalLevel = 0;
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    if (amount > 1000 && CurrentApprovalLevel == 963850000)          //0 - 1000
                    {
                        isnextApprovalRequire = true;
                        nextApprovalLevel     = 963850001;
                    }
                    else if (amount > 2000 && CurrentApprovalLevel == 963850001)    //1000 - 2000
                    {
                        isnextApprovalRequire = true;
                        nextApprovalLevel     = 963850002;
                    }
                    else if (amount > 10000 && CurrentApprovalLevel == 963850002)    //2000 - 10000
                    {
                        isnextApprovalRequire = true;
                        nextApprovalLevel     = 963850005;
                    }
                }
                else
                {
                    if (amount > 2000 && CurrentApprovalLevel == 963850003)          //0 - 2000
                    {
                        isnextApprovalRequire = true;
                        nextApprovalLevel     = 963850002;
                    }
                    else if (amount > 10000 && CurrentApprovalLevel == 963850002)    //2000 - 10000
                    {
                        isnextApprovalRequire = true;
                        nextApprovalLevel     = 963850005;
                    }
                }
            }
            return(isnextApprovalRequire);
        }
Ejemplo n.º 6
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            ProjectTemplateSettings projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "projectTemplateSettings is NULL.UnSecure Plugin Configuration Not Found.");
            }


            Entity appointmentEntity = null;

            if (!context.InputParameters.Contains(Constants.TARGET))
            {
                return;
            }
            if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.Appointments.LogicalName)
            {
                return;
            }

            try
            {
                //Entity entity = (Entity)context.InputParameters["Target"];

                //TODO: Do stuff
                switch (context.MessageName)
                {
                case Constants.Messages.Create:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity)
                    {
                        appointmentEntity = context.InputParameters[Constants.TARGET] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        appointmentEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }

                if (appointmentEntity == null || context.Depth > 1)
                {
                    tracer.Trace($"Appointment entity is Null OR Context Depth is higher than 1. Actual Depth is : {context.Depth}");
                    return;
                }
                if (!appointmentEntity.Attributes.Contains(Constants.Appointments.Regarding) || !appointmentEntity.Attributes.Contains(Constants.Appointments.ScheduledStart))
                {
                    tracer.Trace($"Appointment missing regardingobject field or Scheduled Start.");
                    return;
                }

                if (!appointmentEntity.GetAttributeValue <EntityReference>(Constants.Appointments.Regarding).LogicalName.Equals(Constants.ProjectTasks.LogicalName))
                {
                    tracer.Trace($"Appointment Regarding Object is NOT type of Project Task.");
                    return;
                }

                if (appointmentEntity is Entity)
                {
                    tracer.Trace("Retrieving Project Task Record.");
                    Entity projectTaskEntity = service.Retrieve(appointmentEntity.GetAttributeValue <EntityReference>(Constants.Appointments.Regarding).LogicalName, appointmentEntity.GetAttributeValue <EntityReference>(Constants.Appointments.Regarding).Id, new ColumnSet(true));
                    if (projectTaskEntity is Entity && projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.TaskIdentifier))
                    {
                        tracer.Trace("Project Task Entity Object Received with Unit value.");
                        Entity taskIdentifierEntity = service.Retrieve(projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.TaskIdentifier).LogicalName, projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.TaskIdentifier).Id, new ColumnSet(true));
                        if (taskIdentifierEntity is Entity)
                        {
                            tracer.Trace("Task Identifier Entity Object Received with Unit value.");
                            if (taskIdentifierEntity.Attributes.Contains(Constants.TaskIdentifiers.WBSID) && projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.WBSID) && taskIdentifierEntity.Attributes.Contains(Constants.TaskIdentifiers.ProjectTemplateId))
                            {
                                tracer.Trace($"Task Identifier & Project Task Contains WBS ID. . Task Identifier WBS ID : {taskIdentifierEntity.GetAttributeValue<string>(Constants.TaskIdentifiers.WBSID)}, Project Task WBS ID : {projectTaskEntity.GetAttributeValue<string>(Constants.ProjectTasks.WBSID)}");
                                if ((taskIdentifierEntity.GetAttributeValue <string>(Constants.TaskIdentifiers.WBSID).Equals("5", StringComparison.OrdinalIgnoreCase) && projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.WBSID).Equals("5", StringComparison.OrdinalIgnoreCase)) ||
                                    (taskIdentifierEntity.GetAttributeValue <string>(Constants.TaskIdentifiers.WBSID).Equals("3", StringComparison.OrdinalIgnoreCase) && projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.WBSID).Equals("3", StringComparison.OrdinalIgnoreCase)))
                                {
                                    Entity propertyEntity = service.Retrieve(projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.UnitId).LogicalName, projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.UnitId).Id, new ColumnSet(true));
                                    if (propertyEntity is Entity && (propertyEntity.Attributes.Contains(Constants.Units.UnitId) || propertyEntity.Attributes.Contains(Constants.Units.SFCode)))
                                    {
                                        if (propertyEntity.Attributes.Contains(Constants.Units.UnitId))
                                        {
                                            tracer.Trace($"Unit found with Unit ID {propertyEntity.GetAttributeValue<string>(Constants.Units.UnitId)}");
                                        }
                                        else if (propertyEntity.Attributes.Contains(Constants.Units.SFCode))
                                        {
                                            tracer.Trace($"Unit found with SF Code ID {propertyEntity.GetAttributeValue<string>(Constants.Units.SFCode)}");
                                        }
                                        tracer.Trace("Creating Incoming Integration Record.");
                                        CreateInComingGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                                      appointmentEntity.GetAttributeValue <DateTime>(Constants.Appointments.CreatedOn), appointmentEntity.GetAttributeValue <DateTime>(Constants.Appointments.ScheduledStart),
                                                                                      appointmentEntity.GetAttributeValue <DateTime>(Constants.Appointments.ScheduledEnd), taskIdentifierEntity.GetAttributeValue <EntityReference>(Constants.TaskIdentifiers.ProjectTemplateId), projectTemplateSettings);
                                        tracer.Trace("Incoming Integration Record successfully created.");
                                    }
                                    else
                                    {
                                        tracer.Trace("Property Entity Record Not Found.");
                                    }
                                }
                                else if (taskIdentifierEntity.GetAttributeValue <string>(Constants.TaskIdentifiers.WBSID).Equals("3", StringComparison.OrdinalIgnoreCase) && projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.WBSID).Equals("3", StringComparison.OrdinalIgnoreCase))
                                {
                                }
                                else
                                {
                                    tracer.Trace($"Project Task Record is Not correct. Task Identifier WBS ID : {taskIdentifierEntity.GetAttributeValue<string>(Constants.TaskIdentifiers.WBSID)}, Project Task WBS ID : {projectTaskEntity.GetAttributeValue<string>(Constants.ProjectTasks.WBSID)}");
                                }
                            }
                            else
                            {
                                tracer.Trace("Either Task Identifier or Project Task Record does Not contain WBS ID.");
                            }
                        }
                        else
                        {
                            tracer.Trace("Task Identifier Record Not Found.");
                        }
                    }
                    else
                    {
                        tracer.Trace($"Project Task Record Not Found Or Not contains Task Identifier. Task Status : {projectTaskEntity.GetAttributeValue<OptionSetValue>(Constants.Status.StatusCode).Value}");
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
Ejemplo n.º 7
0
        private void CreateInComingGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, string propertyID, DateTime appointmentCreatedOn, DateTime appointmentSchStart, DateTime appointmentSchEnd, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {Events.MARKET_SCHEDULES_PRE_MOVE_OUT.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION.ToString()}";
                }

                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = appointmentCreatedOn.ToString();
                tracer.Trace($"App Scheduled Start : {appointmentSchStart.ToString()}");
                tracer.Trace($"App Scheduled End : {appointmentSchEnd.ToString()}");
                gridEventDataPayload.data.Date2 = appointmentSchStart.ToString();
                gridEventDataPayload.data.Date3 = appointmentSchEnd.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = Events.MARKET_SCHEDULES_PRE_MOVE_OUT;
                }
                else
                {
                    gridEventDataPayload.data.Event = Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION;
                }
                gridEventDataPayload.data.IsForce    = false;
                gridEventDataPayload.data.PropertyID = propertyID;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = false;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.MARKET_SCHEDULES_PRE_MOVE_OUT.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION.ToString();
                }

                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Ejemplo n.º 8
0
        public static void ExecuteContext(ITracingService tracer, IOrganizationService service, EntityReference projectTaskEntityReference, ProjectTemplateSettings projectTemplateSettings)
        {
            Entity projectTaskEntity = service.Retrieve(projectTaskEntityReference.LogicalName, projectTaskEntityReference.Id, new ColumnSet(true));

            if (projectTaskEntity is Entity && projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.Project))
            {
                Entity projectEntity = service.Retrieve(projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.Project).LogicalName, projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.Project).Id, new ColumnSet(true));
                if (projectEntity is Entity && projectEntity.Attributes.Contains(Constants.Projects.ProjectTemplate) && projectEntity.Attributes.Contains(Constants.Projects.Unit) &&
                    projectEntity.Attributes.Contains(Constants.Projects.RenowalkID))
                {
                    Mapping mapping = (
                        from m in projectTemplateSettings.Mappings
                        where m.Key.Equals(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate).Id.ToString(), StringComparison.OrdinalIgnoreCase)
                        select m).FirstOrDefault <Mapping>();

                    if (mapping is Mapping)
                    {
                        tracer.Trace("Project Entity Object Received with Unit value.");
                        Entity propertyEntity = service.Retrieve(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).Id, new ColumnSet(true));
                        if (propertyEntity is Entity && (propertyEntity.Attributes.Contains(Constants.Units.UnitId) || propertyEntity.Attributes.Contains(Constants.Units.SFCode)))
                        {
                            int      timeZoneCode    = CommonMethods.RetrieveCurrentUsersSettings(service);
                            DateTime currentDateTime = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, DateTime.Now);
                            Events   gridEvent;
                            if (projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.ParentTask) && projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.ContractID))
                            {
                                EntityCollection entityCollection = RetrieveChildProjectTaskFromParentProjectTask(tracer, service, projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.ParentTask), projectTaskEntity.ToEntityReference());
                                if (entityCollection.Entities.Count == 0)
                                {
                                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                                    {
                                        gridEvent = Events.VENDORS_SAYS_JOB_STARTED;
                                    }
                                    else
                                    {
                                        gridEvent = Events.IR_VENDORS_SAYS_JOB_STARTED;
                                    }
                                    //Publish VENDORS_SAYS_JOB_STARTED message to Grid...
                                    CreateOutGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                             projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID), projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID), gridEvent,
                                                                             projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);

                                    Entity tmpPrj = new Entity(projectEntity.LogicalName);
                                    tmpPrj.Id = projectEntity.Id;
                                    tmpPrj[Constants.Projects.ActualJobStartDate] = currentDateTime;

                                    service.Update(tmpPrj);
                                }
                                else
                                {
                                    int notStartedCount = entityCollection.Entities.Where(e => e.Attributes.Contains(Constants.Status.StatusCode) && e.GetAttributeValue <OptionSetValue>(Constants.Status.StatusCode).Value == 1).Count();
                                    tracer.Trace($"Not Started Count : {notStartedCount}.");
                                    tracer.Trace($"Total Child Task Count : {entityCollection.Entities.Count}.");
                                    if (notStartedCount == entityCollection.Entities.Count)
                                    {
                                        //Publish  VENDORS_SAYS_JOB_STARTED message to Grid
                                        if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                                        {
                                            gridEvent = Events.VENDORS_SAYS_JOB_STARTED;
                                        }
                                        else
                                        {
                                            gridEvent = Events.IR_VENDORS_SAYS_JOB_STARTED;
                                        }
                                        //Publish message to Grid...
                                        CreateOutGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                                 projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID), projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID), gridEvent,
                                                                                 projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);

                                        Entity tmpPrj = new Entity(projectEntity.LogicalName);
                                        tmpPrj.Id = projectEntity.Id;
                                        tmpPrj[Constants.Projects.ActualJobStartDate] = currentDateTime;

                                        service.Update(tmpPrj);
                                    }
                                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                                    {
                                        gridEvent = Events.VENDOR_SAYS_CONTRACT_STARTED;
                                    }
                                    else
                                    {
                                        gridEvent = Events.IR_VENDOR_SAYS_CONTRACT_STARTED;
                                    }

                                    CreateOutGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                             projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID), projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID), gridEvent,
                                                                             projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);
                                }
                            }
                            else if (!projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.ParentTask) && !projectTaskEntity.Attributes.Contains(Constants.ProjectTasks.ContractID))
                            {
                                tracer.Trace("Only updating Actual Job Start Date on Project as Task is not Child.");

                                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                                {
                                    gridEvent = Events.VENDORS_SAYS_JOB_STARTED;
                                }
                                else
                                {
                                    gridEvent = Events.IR_VENDORS_SAYS_JOB_STARTED;
                                }
                                //Publish VENDORS_SAYS_JOB_STARTED message to Grid...
                                tracer.Trace($"Publishing OutGoing message : {gridEvent.ToString()}.");
                                CreateOutGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                         projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID), projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID), gridEvent,
                                                                         projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);

                                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                                {
                                    gridEvent = Events.VENDOR_SAYS_CONTRACT_STARTED;
                                }
                                else
                                {
                                    gridEvent = Events.IR_VENDOR_SAYS_CONTRACT_STARTED;
                                }

                                //Publish CONTRACT_STARTED message to Grid...
                                tracer.Trace($"Publishing OutGoing message : {gridEvent.ToString()}.");
                                CreateOutGoingAzureIntegrationCallRecord(service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode),
                                                                         projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID), projectTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID), gridEvent,
                                                                         projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);

                                Entity tmpPrj = new Entity(projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.Project).LogicalName);
                                tmpPrj.Id = projectTaskEntity.GetAttributeValue <EntityReference>(Constants.ProjectTasks.Project).Id;
                                tmpPrj[Constants.Projects.ActualJobStartDate] = currentDateTime;

                                service.Update(tmpPrj);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private static void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, string propertyID, string renowalkID, string Contract_Code, Events gridEvent, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {gridEvent.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {gridEvent.ToString()}";
                }
                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = gridEvent;
                }
                else
                {
                    gridEventDataPayload.data.Event = gridEvent;
                }
                gridEventDataPayload.data.IsForce       = false;
                gridEventDataPayload.data.PropertyID    = propertyID;
                gridEventDataPayload.data.RenowalkID    = renowalkID;
                gridEventDataPayload.data.Contract_Code = Contract_Code;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = gridEvent.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = gridEvent.ToString();
                }
                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Ejemplo n.º 10
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer             = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context            = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory            = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service            = factory.CreateOrganizationService(context.UserId);
            IOrganizationService        systemuser_service = factory.CreateOrganizationService(null);

            ProjectTemplateSettings projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "projectTemplateSettings is NULL.UnSecure Plugin Configuration Not Found.");
            }

            Entity projectEntity = null;

            if (!context.InputParameters.Contains(Constants.TARGET))
            {
                return;
            }
            if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.Projects.LogicalName)
            {
                return;
            }

            try
            {
                //Entity entity = (Entity)context.InputParameters["Target"];

                //TODO: Do stuff
                switch (context.MessageName)
                {
                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        projectEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }

                if (projectEntity == null || context.Depth > 2)
                {
                    tracer.Trace($"Project entity is Null OR Context Depth is higher than 1. Actual Depth is : {context.Depth}");
                    return;
                }

                if (projectEntity is Entity && projectEntity.Attributes.Contains(Constants.Projects.Unit) && projectEntity.Attributes.Contains(Constants.Projects.ProjectTemplate))
                {
                    tracer.Trace("Project Entity Object Received with Unit value.");
                    Entity propertyEntity = service.Retrieve(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).Id, new ColumnSet(true));
                    if (propertyEntity is Entity && (propertyEntity.Attributes.Contains(Constants.Units.UnitId) || propertyEntity.Attributes.Contains(Constants.Units.SFCode)))
                    {
                        tracer.Trace($"Unit found with Unit ID {propertyEntity.GetAttributeValue<string>(Constants.Units.UnitId)}");
                        tracer.Trace("Creating Incoming Integration Record.");
                        CreateInComingGoingAzureIntegrationCallRecord(systemuser_service, tracer, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode), projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings);
                        tracer.Trace("Incoming Integration Record successfully created.");
                        if (projectEntity.Attributes.Contains(Constants.Projects.ProjectManager) && projectEntity.Attributes.Contains(Constants.Projects.RenowalkID))
                        {
                            CreateOutGoingAzureIntegrationCallRecord(systemuser_service, tracer, projectEntity, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode));
                        }
                        else
                        {
                            tracer.Trace("Project Record does NOT have Project Manager or Renowalk ID.");
                        }

                        tracer.Trace("Assigning Project Manager as Owner for each Project Task.");
                        AssignProjectManagerAsTaskOwner(tracer, service, projectEntity);
                    }
                    else
                    {
                        tracer.Trace("Property Entity Record Not Found.");
                    }
                }
                else
                {
                    tracer.Trace("Project entity Object not found OR Project Entity does not have Unit or does not have Project Template.");
                }
            }
            catch (Exception ex)
            {
                tracer.Trace(ex.Message + ex.StackTrace);
                //UpdateAzureIntegrationCallErrorDetails(service, azureIntegrationCallEntity.ToEntityReference(), ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Ejemplo n.º 11
0
        private void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, Entity projectEntity, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, string propertyID)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");
                Entity systemuserEntity = _service.Retrieve(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectManager).LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectManager).Id, new ColumnSet(true));
                if (systemuserEntity is Entity && systemuserEntity.Attributes.Contains(Constants.SystemUsers.UserName))
                {
                    List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                    GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                    gridEventDataPayload.EventTime = DateTime.Now.ToString();
                    gridEventDataPayload.EventType = "allEvents";
                    gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        gridEventDataPayload.Subject = $"Turn Process : {Events.ASSIGN_PROJECT_MANAGER.ToString()}";
                    }
                    else
                    {
                        gridEventDataPayload.Subject = $"Initial Renovation : {Events.IR_ASSIGN_PROJECT_MANAGER.ToString()}";
                    }
                    gridEventDataPayload.data       = new DataPayLoad();
                    gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        gridEventDataPayload.data.Event = Events.ASSIGN_PROJECT_MANAGER;
                    }
                    else
                    {
                        gridEventDataPayload.data.Event = Events.IR_ASSIGN_PROJECT_MANAGER;
                    }
                    gridEventDataPayload.data.IsForce     = false;
                    gridEventDataPayload.data.PropertyID  = propertyID;
                    gridEventDataPayload.data.EmailID     = systemuserEntity.GetAttributeValue <string>(Constants.SystemUsers.UserName);
                    gridEventDataPayload.data.FotoNotesID = "";
                    gridEventDataPayload.data.JobID       = "";
                    gridEventDataPayload.data.RenowalkID  = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);

                    gridEventDataPayloadList.Add(gridEventDataPayload);

                    Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                    azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.ASSIGN_PROJECT_MANAGER.ToString();
                    }
                    else
                    {
                        azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.IR_ASSIGN_PROJECT_MANAGER.ToString();
                    }
                    _service.Create(azIntCallEntity);
                }
                else
                {
                    tracer.Trace($"System User (Project Manager) Not Found or Primary Email (internalemailaddress) Not found for System User (Project Manager).");
                }
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Ejemplo n.º 12
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);
            ProjectTemplateSettings     projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                tracer.Trace($"Project Template Setting not available in Plugin UnSecure Configuration.");
                return;
            }

            Entity jobEntity = null;

            if (!context.InputParameters.Contains(Constants.TARGET))
            {
                return;
            }
            if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.Jobs.LogicalName)
            {
                return;
            }


            try
            {
                switch (context.MessageName)
                {
                //case Constants.Messages.Create:
                //    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity)
                //        jobEntity = context.InputParameters[Constants.TARGET] as Entity;
                //    else
                //        return;
                //    break;
                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        jobEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                //TODO: Do stuff

                if (jobEntity == null || context.Depth > 2)
                {
                    tracer.Trace($"Job entity is Null OR Context Depth is higher than 2. Actual Depth is : {context.Depth}");
                    return;
                }

                if (!jobEntity.Attributes.Contains(Constants.Jobs.JobStatus) || (!jobEntity.Attributes.Contains(Constants.Jobs.Unit) && !jobEntity.Attributes.Contains(Constants.Jobs.RenowalkID)))
                {
                    tracer.Trace($"Job Enity missing either Job Status or Unit or Renowalk ID field. Exiting PlugIn Pipeline");
                    return;
                }

                tracer.Trace($"Job Enity Job Status : {jobEntity.GetAttributeValue<OptionSetValue>(Constants.Jobs.JobStatus).Value}");
                if (jobEntity.GetAttributeValue <OptionSetValue>(Constants.Jobs.JobStatus).Value != 963850004)
                {
                    tracer.Trace($"Job Enity Job Status is NOT Contract Created (963850004). Existing PlugIn Pipeline.");
                    return;
                }

                if (jobEntity is Entity && projectTemplateSettings is ProjectTemplateSettings)
                {
                    tracer.Trace($"Finding Active Project using Unit or Renowalk ID.");
                    EntityCollection projectEntityCollection = new EntityCollection();
                    if (jobEntity.Attributes.Contains(Constants.Jobs.RenowalkID))
                    {
                        projectEntityCollection = CommonMethods.RetrieveActivtProjectByRenowalkId(tracer, service, jobEntity.GetAttributeValue <string>(Constants.Jobs.RenowalkID));
                    }
                    if (projectEntityCollection.Entities.Count == 0 && jobEntity.Attributes.Contains(Constants.Jobs.Unit))
                    {
                        projectEntityCollection = CommonMethods.RetrieveActivtProjectByUnitId(tracer, service, jobEntity.GetAttributeValue <EntityReference>(Constants.Jobs.Unit));
                    }
                    foreach (Entity projectEntity in projectEntityCollection.Entities)
                    {
                        if (projectEntity.Attributes.Contains(Constants.Projects.ProjectTemplate))
                        {
                            Mapping mapping = (
                                from m in projectTemplateSettings.Mappings
                                where m.Key.Equals(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate).Id.ToString(), StringComparison.OrdinalIgnoreCase)
                                select m).FirstOrDefault <Mapping>();


                            if (mapping is Mapping)
                            {
                                tracer.Trace($"Project Template is : {mapping.Name}");
                                int      timeZoneCode    = CommonMethods.RetrieveCurrentUsersSettings(service);
                                DateTime currentDateTime = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, DateTime.Now);
                                tracer.Trace($"Current Date Time : {currentDateTime}");
                                CalculateTurnSchStartandEndDate(tracer, service, projectEntity, jobEntity, mapping, timeZoneCode);
                                //EntityCollection job_and_contracts_sub_to_yardi_EntityCollection = CommonMethods.RetrieveOpenProjectTaskByProjectAndTaskIdentifier(tracer, service, projectEntity.ToEntityReference(), projectEntity.GetAttributeValue<EntityReference>(Constants.Projects.ProjectTemplate),
                                //    mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? 10 : 209, mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? "10" : "9");
                                //foreach (Entity e in job_and_contracts_sub_to_yardi_EntityCollection.Entities)
                                //{
                                //    Entity num = new Entity(e.LogicalName)
                                //    {
                                //        Id = e.Id
                                //    };
                                //    num[Constants.ProjectTasks.ActualStart] = currentDateTime;
                                //    num[Constants.ProjectTasks.ActualEnd] = currentDateTime;
                                //    num[Constants.ProjectTasks.ActualDurationInMinutes] = (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? 0 : (((currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes > 0) ? (int)Math.Floor((currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes) : 0);
                                //    //(!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? (int) 0 : (currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes;
                                //    num[Constants.ProjectTasks.Progress] = new decimal(100);
                                //    num[Constants.Status.StatusCode] = new OptionSetValue(963850001);
                                //    service.Update(num);
                                //    tracer.Trace("Task for Event : JOB_AND_CONTRACTS_SUBMITTED_TO_YARDI Successfully Updated.");
                                //}

                                EntityCollection job_assign_to_vendor_in_cc_EntityCollection = CommonMethods.RetrieveOpenProjectTaskByProjectAndTaskIdentifier(tracer, service, projectEntity.ToEntityReference(), projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate),
                                                                                                                                                               mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? 9 : 207, mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? "9" : "7");
                                foreach (Entity e in job_assign_to_vendor_in_cc_EntityCollection.Entities)
                                {
                                    Entity num = new Entity(e.LogicalName)
                                    {
                                        Id = e.Id
                                    };
                                    if (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart))
                                    {
                                        num[Constants.ProjectTasks.ActualStart] = currentDateTime;
                                    }
                                    num[Constants.ProjectTasks.ActualEnd] = currentDateTime;
                                    num[Constants.ProjectTasks.ActualDurationInMinutes] = (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? 0 : (((currentDateTime - e.GetAttributeValue <DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes > 0) ? (int)Math.Floor((currentDateTime - e.GetAttributeValue <DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes) : 0);
                                    num[Constants.ProjectTasks.Progress] = new decimal(100);
                                    num[Constants.Status.StatusCode]     = new OptionSetValue(963850001);
                                    service.Update(num);
                                    tracer.Trace("Task for Event : JOB_ASSIGNMENT_TO_VENDORS_IN_CONTRACT_CREATOR Successfully Updated.");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                tracer.Trace(e.Message + e.StackTrace);
            }
        }
Ejemplo n.º 13
0
        private void ExecuteContext(ITracingService tracer, IOrganizationService service, EntityReference changeOrderEntityReference, int revision, ProjectTemplateSettings projectTemplateSettings)
        {
            Entity changeOrderEntity = service.Retrieve(changeOrderEntityReference.LogicalName, changeOrderEntityReference.Id, new ColumnSet(true));

            if (changeOrderEntity is Entity && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.Unit) &&
                changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.ProjectTemplateID))
            {
                Mapping mapping = (
                    from m in projectTemplateSettings.Mappings
                    where m.Key.Equals(changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectTemplateID).Id.ToString(), StringComparison.OrdinalIgnoreCase)
                    select m).FirstOrDefault <Mapping>();

                if (mapping is Mapping)
                {
                    EntityCollection changeOrderItemsEntityCollection = CommonMethods.RetrieveChangeOrderItems(tracer, service, changeOrderEntityReference);
                    foreach (Entity changeOrderItemEntity in changeOrderItemsEntityCollection.Entities)
                    {
                        //Change Status to Submitted for Approval. Should be part of Inactive.
                        CommonMethods.ChangeEntityStatus(tracer, service, changeOrderItemEntity.ToEntityReference(), 1, 2);
                    }
                    Entity tmpCOEntity = new Entity(changeOrderEntityReference.LogicalName);
                    tmpCOEntity.Id = changeOrderEntityReference.Id;
                    OptionSetValue opValue;
                    //Set to 0 - 1500
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        opValue = new OptionSetValue(963850000);
                    }
                    else
                    {
                        opValue = new OptionSetValue(963850003);
                    }
                    tmpCOEntity[Constants.ChangeOrders.PendingApprovalLevel] = opValue;
                    tmpCOEntity[Constants.ChangeOrders.Revision]             = revision + 1;

                    service.Update(tmpCOEntity);

                    tracer.Trace($"Retrieving Change Order Record.");
                    //changeOrderEntity = service.Retrieve(changeOrderEntity.LogicalName, changeOrderEntity.Id, new ColumnSet(true));
                    if (changeOrderEntity is Entity && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.Unit) &&
                        changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.ProjectID) && changeOrderEntity.Attributes.Contains(Constants.ChangeOrders.Requestor))
                    {
                        tracer.Trace($"Change Order successfully retrieved with Unit.");
                        tracer.Trace($"Retrieving Unit Record.");

                        Entity unitEntity = service.Retrieve(changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.Unit).LogicalName, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.Unit).Id, new ColumnSet(true));
                        if (unitEntity is Entity && unitEntity.Attributes.Contains(Constants.Units.Market))
                        {
                            tracer.Trace($"Retrieving Budget Approver.");
                            EntityCollection budgetApproverEntityCollection = CommonMethods.RetrieveAllBudjgetApprovers(tracer, service, unitEntity.GetAttributeValue <OptionSetValue>(Constants.Units.Market).Value,
                                                                                                                        opValue.Value, changeOrderEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrders.ProjectTemplateID));
                            if (budgetApproverEntityCollection.Entities.Count > 0)
                            {
                                tracer.Trace($"Budget Approver found.");
                                Entity fromSystemUserEntity = CommonMethods.RetrieveCRMEMailSystemUser(tracer, service);
                                if (fromSystemUserEntity is Entity)
                                {
                                    EntityCollection fromEntitycollection = new EntityCollection();
                                    Entity           fromParty            = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                    fromParty.Attributes.Add(ACTIVITYPARTY_ATTR_PARTYID, fromSystemUserEntity.ToEntityReference());
                                    fromEntitycollection.Entities.Add(fromParty);

                                    EntityCollection toEntitycollection = new EntityCollection();

                                    foreach (Entity budgetApproverEntity in budgetApproverEntityCollection.Entities)
                                    {
                                        if (budgetApproverEntity.Attributes.Contains("U.internalemailaddress") || budgetApproverEntity.Attributes.Contains("U.domainname"))
                                        {
                                            Entity toParty = new Entity(ACTIVITYPARTY_ENTITY_NAME);
                                            toParty.Attributes.Add(ACTIVITYPARTY_ATTR_PARTYID, budgetApproverEntity.GetAttributeValue <EntityReference>(Constants.BudgetApprovers.ApproverID));
                                            toEntitycollection.Entities.Add(toParty);
                                        }
                                    }

                                    CommonMethods.SendRequestForApprovalEmail(tracer, service, changeOrderEntity, fromEntitycollection, toEntitycollection, ServerUrl);
                                }
                                else
                                {
                                    tracer.Trace($"System User Not found with Email Address : {Constants.CRMEmail}. Operation Successfully performed but Email will not be generated.");
                                }
                            }
                            else
                            {
                                tracer.Trace($"No Budget Approver found.");
                            }
                        }
                        else
                        {
                            tracer.Trace($"Unit Not Found or Unit Market Not available. Unit Guid : {changeOrderEntity.GetAttributeValue<EntityReference>(Constants.ChangeOrders.Unit).Id.ToString()}");
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            ProjectTemplateSettings projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "projectTemplateSettings is NULL.UnSecure Plugin Configuration Not Found.");
            }

            Entity projectEntity = null;

            if (!context.InputParameters.Contains(Constants.TARGET))
            {
                return;
            }
            if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.Projects.LogicalName)
            {
                return;
            }
            try
            {
                switch (context.MessageName)
                {
                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        projectEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }

                if (projectEntity == null || context.Depth > 1)
                {
                    tracer.Trace($"Project entity is Null OR Context Depth is higher than 1. Actual Depth is : {context.Depth}");
                    return;
                }

                if (projectEntity is Entity && projectEntity.Attributes.Contains(Constants.Projects.Unit) && projectEntity.Attributes.Contains(Constants.Projects.ProjectTemplate))
                {
                    tracer.Trace("Project Entity Object Received with Unit value.");
                    Entity propertyEntity = service.Retrieve(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).Id, new ColumnSet(true));
                    if (propertyEntity is Entity && (propertyEntity.Attributes.Contains(Constants.Units.UnitId) || propertyEntity.Attributes.Contains(Constants.Units.SFCode)))
                    {
                        tracer.Trace($"Unit found with Unit ID {propertyEntity.GetAttributeValue<string>(Constants.Units.UnitId)}");
                        if (projectEntity.Attributes.Contains(Constants.Projects.RevisedCompletionDate) && projectEntity.Attributes.Contains(Constants.Projects.RenowalkID))
                        {
                            CreateOutGoingAzureIntegrationCallRecord(service, tracer, projectEntity, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), projectTemplateSettings, (propertyEntity.Attributes.Contains(Constants.Units.UnitId)) ? propertyEntity.GetAttributeValue <string>(Constants.Units.UnitId) : propertyEntity.GetAttributeValue <string>(Constants.Units.SFCode));
                        }
                        else
                        {
                            tracer.Trace("Project Record does NOT have Revised Completion Date or Renowalk ID.");
                        }
                    }
                    else
                    {
                        tracer.Trace("Property Entity Record Not Found.");
                    }
                }
                else
                {
                    tracer.Trace("Project entity Object not found OR Project Entity does not have Unit or does not have Project Template.");
                }

                //TODO: Do stuff
            }
            catch (Exception e)
            {
                tracer.Trace(e.Message + e.StackTrace);
            }
        }