Ejemplo n.º 1
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: GetOperatingCapacityByFacility", DateTime.Now.ToLongTimeString());

            var recordId = context.PrimaryEntityId;

            try
            {
                //get Facility
                var columns = new ColumnSet("caps_adjusteddesigncapacitykindergarten",
                                            "caps_adjusteddesigncapacityelementary",
                                            "caps_adjusteddesigncapacitysecondary",
                                            "caps_lowestgrade",
                                            "caps_highestgrade");

                var facilityRecord = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, columns) as caps_Facility;

                var capacity = new Services.CapacityFactors(service);

                Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity);

                var kDesign      = facilityRecord.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0);
                var eDesign      = facilityRecord.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0);
                var sDesign      = facilityRecord.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0);
                var lowestGrade  = facilityRecord.caps_LowestGrade.Value;
                var highestGrade = facilityRecord.caps_HighestGrade.Value;

                var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade);

                //Update Facility
                var recordToUpdate = new caps_Facility();
                recordToUpdate.Id = context.PrimaryEntityId;
                recordToUpdate.caps_OperatingCapacityKindergarten = result.KindergartenCapacity;
                recordToUpdate.caps_OperatingCapacityElementary   = result.ElementaryCapacity;
                recordToUpdate.caps_OperatingCapacitySecondary    = result.SecondaryCapacity;
                service.Update(recordToUpdate);

                this.error.Set(executionContext, false);
            }
            catch (Exception ex)
            {
                tracingService.Trace("Error Details: {0}", ex.Message);
                //might want to also include error message
                this.error.Set(executionContext, true);
                this.errorMessage.Set(executionContext, ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext     context        = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);
            ITracingService             tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracingService.Trace("{0}", "CalculateStrongStartAdjustment Plug-in");

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                (context.InputParameters["Target"] is Entity || context.InputParameters["Target"] is EntityReference))
            {
                var facilitiesToUpdate = new EntityReferenceCollection();

                if (context.MessageName == "Create" || context.MessageName == "Update")
                {
                    Entity entity = (Entity)context.InputParameters["Target"];

                    if (entity.LogicalName != caps_StrongStartCentre.EntityLogicalName)
                    {
                        return;
                    }

                    //Keep CRUD in mind, need to handle all scenarios
                    //Get previous facility (if exists) and current facility
                    if (context.MessageName == "Create" && entity.Contains("caps_facility"))
                    {
                        facilitiesToUpdate.Add(entity.GetAttributeValue <EntityReference>("caps_facility"));
                    }

                    if (context.MessageName == "Update")
                    {
                        Entity preImage = context.PreEntityImages["preImage"];

                        if (preImage.Contains("caps_facility"))
                        {
                            facilitiesToUpdate.Add(preImage.GetAttributeValue <EntityReference>("caps_facility"));
                        }
                        if (entity.Contains("caps_facility"))
                        {
                            facilitiesToUpdate.Add(entity.GetAttributeValue <EntityReference>("caps_facility"));
                        }
                    }
                }
                if (context.MessageName == "Delete")
                {
                    EntityReference entity = (EntityReference)context.InputParameters["Target"];

                    if (entity.LogicalName != caps_StrongStartCentre.EntityLogicalName)
                    {
                        return;
                    }

                    Entity preImage = context.PreEntityImages["preImage"];

                    if (preImage.Contains("caps_facility"))
                    {
                        facilitiesToUpdate.Add(preImage.GetAttributeValue <EntityReference>("caps_facility"));
                    }
                }

                tracingService.Trace("{0}", "Line 66");

                foreach (var facilityToUpdate in facilitiesToUpdate)
                {
                    var kindergardenCount = 0;
                    var elementaryCount   = 0;
                    var secondaryCount    = 0;
                    //For each facility, get all strong starts
                    using (var crmContext = new CrmServiceContext(service))
                    {
                        var strongStartRecords = crmContext.caps_StrongStartCentreSet.Where(r => r.caps_facility.Id == facilityToUpdate.Id && r.StateCode == caps_StrongStartCentreState.Active);

                        foreach (var strongStartRecord in strongStartRecords)
                        {
                            if (strongStartRecord.Contains("caps_classroomtypeoccupied"))
                            {
                                if (strongStartRecord.GetAttributeValue <OptionSetValue>("caps_classroomtypeoccupied").Value == (int)caps_ClassType.Kindergarten)
                                {
                                    kindergardenCount -= strongStartRecord.caps_CapacityUtilized.GetValueOrDefault(0);
                                }

                                if (strongStartRecord.GetAttributeValue <OptionSetValue>("caps_classroomtypeoccupied").Value == (int)caps_ClassType.Elementary)
                                {
                                    elementaryCount -= strongStartRecord.caps_CapacityUtilized.GetValueOrDefault(0);
                                }

                                if (strongStartRecord.GetAttributeValue <OptionSetValue>("caps_classroomtypeoccupied").Value == (int)caps_ClassType.Secondary)
                                {
                                    secondaryCount -= strongStartRecord.caps_CapacityUtilized.GetValueOrDefault(0);
                                }
                            }
                        }

                        tracingService.Trace("{0} - K:{1}; E:{2}; S:{3}", facilityToUpdate.Name, kindergardenCount, elementaryCount, secondaryCount);
                        //Update the facility
                        var recordToUpdate = new caps_Facility();
                        recordToUpdate.Id = facilityToUpdate.Id;
                        recordToUpdate.caps_StrongStartCapacityElementary   = elementaryCount;
                        recordToUpdate.caps_StrongStartCapacityKindergarten = kindergardenCount;
                        recordToUpdate.caps_StrongStartCapacitySecondary    = secondaryCount;
                        service.Update(recordToUpdate);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString());

            //Update to run on school district
            var recordId = context.PrimaryEntityId;

            try
            {
                //Get Global Capacity values
                var capacity = new Services.CapacityFactors(service);

                Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity);

                tracingService.Trace("Section: {0}", "Update Facilities");
                #region Update Facilities
                //get Facilities
                var fetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\" >" +
                               "<entity name=\"caps_facility\">" +
                               "<attribute name=\"caps_facilityid\" /> " +
                               "<attribute name=\"caps_name\" /> " +
                               "<attribute name=\"caps_lowestgrade\" /> " +
                               "<attribute name=\"caps_highestgrade\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacitysecondary\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacitykindergarten\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacityelementary\" /> " +
                               "<order attribute=\"caps_name\" descending=\"false\" /> " +
                               "<filter type=\"and\" > " +
                               "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /> " +
                               "<condition attribute=\"caps_lowestgrade\" operator=\"not-null\" />" +
                               "<condition attribute=\"caps_highestgrade\" operator=\"not-null\" />" +
                               "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" +
                               "</filter> " +
                               "<link-entity name=\"caps_facilitytype\" from=\"caps_facilitytypeid\" to=\"caps_currentfacilitytype\" link-type=\"inner\" alias=\"ac\" > " +
                               "<filter type=\"and\" > " +
                               "<condition attribute=\"caps_schooltype\" operator=\"not-null\" /> " +
                               "</filter> " +
                               "</link-entity> " +
                               "</entity> " +
                               "</fetch>";


                EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchXML));

                foreach (caps_Facility facilityRecord in results.Entities)
                {
                    tracingService.Trace("Facility:{0}", facilityRecord.caps_Name);

                    var kDesign      = facilityRecord.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0);
                    var eDesign      = facilityRecord.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0);
                    var sDesign      = facilityRecord.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0);
                    var lowestGrade  = facilityRecord.caps_LowestGrade.Value;
                    var highestGrade = facilityRecord.caps_HighestGrade.Value;

                    var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade);

                    //Update Facility
                    var recordToUpdate = new caps_Facility();
                    recordToUpdate.Id = facilityRecord.Id;
                    recordToUpdate.caps_OperatingCapacityKindergarten = result.KindergartenCapacity;
                    recordToUpdate.caps_OperatingCapacityElementary   = result.ElementaryCapacity;
                    recordToUpdate.caps_OperatingCapacitySecondary    = result.SecondaryCapacity;
                    service.Update(recordToUpdate);
                }
                #endregion

                tracingService.Trace("Section: {0}", "Update Capacity Reporting");
                #region Update Capacity Reporting
                //Update Capacity Reporting
                var capacityFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\" >" +
                                       "<entity name=\"caps_capacityreporting\" > " +
                                       "<attribute name=\"caps_capacityreportingid\" /> " +
                                       "<attribute name=\"caps_secondary_designcapacity\" /> " +
                                       "<attribute name=\"caps_kindergarten_designcapacity\" /> " +
                                       "<attribute name=\"caps_elementary_designcapacity\" /> " +
                                       "<order attribute=\"caps_secondary_designutilization\" descending=\"false\" /> " +
                                       "<link-entity name=\"caps_facility\" from=\"caps_facilityid\" to=\"caps_facility\" visible=\"false\" link-type=\"inner\" alias=\"facility\" > " +
                                       "<attribute name=\"caps_lowestgrade\" /> " +
                                       "<attribute name=\"caps_highestgrade\" /> " +
                                       "<filter type=\"and\" > " +
                                       "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" +
                                       "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /> " +
                                       "<condition attribute=\"caps_lowestgrade\" operator=\"not-null\" />" +
                                       "<condition attribute=\"caps_highestgrade\" operator=\"not-null\" />" +
                                       "</filter> " +
                                       "</link-entity> " +
                                       "<link-entity name=\"edu_year\" from=\"edu_yearid\" to=\"caps_schoolyear\" link-type=\"inner\" alias=\"ab\" >" +
                                       "<filter type=\"and\"> " +
                                       "<condition attribute=\"statuscode\" operator=\"in\">" +
                                       "<value>1</value> " +
                                       "<value>757500000</value> " +
                                       "</condition>" +
                                       "</filter>" +
                                       "</link-entity>" +
                                       "</entity> " +
                                       "</fetch> ";

                tracingService.Trace("Capacity Reporting Fetch: {0}", capacityFetchXML);

                EntityCollection capacityResults = service.RetrieveMultiple(new FetchExpression(capacityFetchXML));

                foreach (caps_CapacityReporting capacityRecord in capacityResults.Entities)
                {
                    var kDesign = capacityRecord.caps_Kindergarten_designcapacity.GetValueOrDefault(0);
                    var eDesign = capacityRecord.caps_Elementary_designcapacity.GetValueOrDefault(0);
                    var sDesign = capacityRecord.caps_Secondary_designcapacity.GetValueOrDefault(0);

                    tracingService.Trace("Capacity Reporting: {0}", capacityRecord.Id);
                    tracingService.Trace("Lowest: {0}", ((AliasedValue)capacityRecord["facility.caps_lowestgrade"]).Value);
                    tracingService.Trace("Highest: {0}", ((AliasedValue)capacityRecord["facility.caps_highestgrade"]).Value);

                    var lowestGrade  = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_lowestgrade"]).Value).Value;
                    var highestGrade = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_highestgrade"]).Value).Value;

                    tracingService.Trace("Start Calculate: {0}", capacityRecord.Id);
                    var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade);
                    tracingService.Trace("End Calculate: {0}", capacityRecord.Id);

                    //Update Capacity Reporting
                    var recordToUpdate = new caps_CapacityReporting();
                    recordToUpdate.Id = capacityRecord.Id;
                    recordToUpdate.caps_Kindergarten_operatingcapacity = result.KindergartenCapacity;
                    recordToUpdate.caps_Elementary_operatingcapacity   = result.ElementaryCapacity;
                    recordToUpdate.caps_Secondary_operatingcapacity    = result.SecondaryCapacity;
                    service.Update(recordToUpdate);
                }
                #endregion

                tracingService.Trace("Section: {0}", "Update Draft Project Requests");
                #region Update Draft Project Requests
                //Update Draft Project Requests
                var projectRequestFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" +
                                             "<entity name=\"caps_project\" > " +
                                             "<attribute name=\"caps_facility\" /> " +
                                             "<attribute name=\"caps_changeindesigncapacitykindergarten\" /> " +
                                             "<attribute name=\"caps_changeindesigncapacityelementary\" /> " +
                                             "<attribute name=\"caps_changeindesigncapacitysecondary\" /> " +
                                             "<attribute name=\"caps_futurelowestgrade\" /> " +
                                             "<attribute name=\"caps_futurehighestgrade\" /> " +
                                             "<order attribute=\"caps_projectcode\" descending=\"false\" /> " +
                                             "<filter type=\"and\" > " +
                                             "<condition attribute=\"statuscode\" operator=\"eq\" value=\"1\" /> " +
                                             "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" +
                                             "<filter type=\"or\" > " +
                                             "<condition attribute=\"caps_changeinoperatingcapacitykindergarten\" operator=\"not-null\" /> " +
                                             "<condition attribute=\"caps_changeinoperatingcapacityelementary\" operator=\"not-null\" /> " +
                                             "<condition attribute=\"caps_changeinoperatingcapacitysecondary\" operator=\"not-null\" /> " +
                                             "</filter> " +
                                             "</filter> " +
                                             "</entity> " +
                                             "</fetch> ";

                EntityCollection projectResults = service.RetrieveMultiple(new FetchExpression(projectRequestFetchXML));

                foreach (caps_Project projectRecord in projectResults.Entities)
                {
                    if (projectRecord.caps_FutureLowestGrade != null && projectRecord.caps_FutureHighestGrade != null)
                    {
                        var startingDesign_K = 0;
                        var startingDesign_E = 0;
                        var startingDesign_S = 0;

                        //if facility exists, then retrieve it
                        if (projectRecord.caps_Facility != null && projectRecord.caps_Facility.Id != Guid.Empty)
                        {
                            var facility = service.Retrieve(caps_Facility.EntityLogicalName, projectRecord.caps_Facility.Id, new ColumnSet("caps_adjusteddesigncapacitykindergarten", "caps_adjusteddesigncapacityelementary", "caps_adjusteddesigncapacitysecondary")) as caps_Facility;

                            if (facility != null)
                            {
                                startingDesign_K = facility.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0);
                                startingDesign_E = facility.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0);
                                startingDesign_S = facility.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0);
                            }
                        }

                        var changeInDesign_K = startingDesign_K + projectRecord.caps_ChangeinDesignCapacityKindergarten.GetValueOrDefault(0);
                        var changeInDesign_E = startingDesign_E + projectRecord.caps_ChangeinDesignCapacityElementary.GetValueOrDefault(0);
                        var changeInDesign_S = startingDesign_S + projectRecord.caps_ChangeinDesignCapacitySecondary.GetValueOrDefault(0);

                        var result = capacityService.Calculate(changeInDesign_K, changeInDesign_E, changeInDesign_S, projectRecord.caps_FutureLowestGrade.Value, projectRecord.caps_FutureHighestGrade.Value);

                        var recordToUpdate = new caps_Project();
                        recordToUpdate.Id = projectRecord.Id;
                        recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = Convert.ToInt32(result.KindergartenCapacity);
                        recordToUpdate.caps_ChangeinOperatingCapacityElementary   = Convert.ToInt32(result.ElementaryCapacity);
                        recordToUpdate.caps_ChangeinOperatingCapacitySecondary    = Convert.ToInt32(result.SecondaryCapacity);
                        service.Update(recordToUpdate);
                    }
                    else
                    {
                        //blank out operating capacity
                        var recordToUpdate = new caps_Project();
                        recordToUpdate.Id = projectRecord.Id;
                        recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = null;
                        recordToUpdate.caps_ChangeinOperatingCapacityElementary   = null;
                        recordToUpdate.caps_ChangeinOperatingCapacitySecondary    = null;
                        service.Update(recordToUpdate);
                    }
                }
                #endregion


                this.error.Set(executionContext, false);
            }
            catch (Exception ex)
            {
                tracingService.Trace("Error Details: {0}", ex.Message);
                //might want to also include error message
                this.error.Set(executionContext, true);
                this.errorMessage.Set(executionContext, ex.Message);
            }

            tracingService.Trace("{0}{1}", "End Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString());
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: CalculateFacilityReplacementCost", DateTime.Now.ToLongTimeString());

            var recordId = context.PrimaryEntityId;

            try
            {
                //Get all facilities for the school district
                FilterExpression filterName = new FilterExpression();
                filterName.Conditions.Add(new ConditionExpression("caps_schooldistrict", ConditionOperator.Equal, recordId));
                filterName.Conditions.Add(new ConditionExpression("caps_isschool", ConditionOperator.Equal, true));
                filterName.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
                filterName.Conditions.Add(new ConditionExpression("caps_geographicalschooldistrict", ConditionOperator.NotNull));
                filterName.Conditions.Add(new ConditionExpression("caps_communitylocation", ConditionOperator.NotNull));

                QueryExpression query = new QueryExpression("caps_facility");
                query.ColumnSet.AddColumns("caps_communitylocation"
                                           , "caps_designcapacitykindergarten"
                                           , "caps_strongstartcapacitykindergarten"
                                           , "caps_designcapacityelementary"
                                           , "caps_strongstartcapacityelementary"
                                           , "caps_designcapacitysecondary"
                                           , "caps_strongstartcapacitysecondary"
                                           , "caps_currentfacilitytype"
                                           , "caps_geographicalschooldistrict"
                                           , "caps_neighbourhoodlearningcentre");

                query.Criteria.AddFilter(filterName);

                EntityCollection results = service.RetrieveMultiple(query);

                tracingService.Trace("Line: {0}", "58");

                foreach (caps_Facility facility in results.Entities)
                {
                    var communityLocationRecord = service.Retrieve(facility.caps_CommunityLocation.LogicalName, facility.caps_CommunityLocation.Id, new ColumnSet("caps_projectlocationfactor")) as caps_BudgetCalc_CommunityLocation;
                    tracingService.Trace("Line: {0}", "63");
                    var hostSchoolDistrictRecord = service.Retrieve(facility.caps_GeographicalSchoolDistrict.LogicalName, facility.caps_GeographicalSchoolDistrict.Id, new ColumnSet("caps_freightrateallowance")) as edu_schooldistrict;
                    tracingService.Trace("Line: {0}", "65");
                    var facilityTypeRecord = service.Retrieve(facility.caps_CurrentFacilityType.LogicalName, facility.caps_CurrentFacilityType.Id, new ColumnSet("caps_schooltype")) as caps_FacilityType;
                    tracingService.Trace("Line: {0}", "67");
                    var adjustedDesignK = (int)facility.caps_DesignCapacityKindergarten.GetValueOrDefault(0) + facility.caps_StrongStartCapacityKindergarten.GetValueOrDefault(0);
                    var adjustedDesignE = (int)facility.caps_DesignCapacityElementary.GetValueOrDefault(0) + facility.caps_StrongStartCapacityElementary.GetValueOrDefault(0);
                    var adjustedDesignS = (int)facility.caps_DesignCapacitySecondary.GetValueOrDefault(0) + facility.caps_StrongStartCapacitySecondary.GetValueOrDefault(0);

                    tracingService.Trace("Line: {0}", "72");
                    var scheduleB = new ScheduleB(service, tracingService);
                    //set parameters
                    scheduleB.SchoolType            = facilityTypeRecord.caps_SchoolType.Id;
                    scheduleB.BudgetCalculationType = (int)caps_BudgetCalculationType.Replacement;
                    scheduleB.IncludeNLC            = facility.caps_NeighbourhoodLearningCentre.GetValueOrDefault(false);
                    scheduleB.ProjectLocationFactor = communityLocationRecord.caps_ProjectLocationFactor.GetValueOrDefault(1);

                    scheduleB.ExistingAndDecreaseDesignCapacity = new Services.DesignCapacity(0, 0, 0);
                    scheduleB.ExtraSpaceAllocation   = 0;
                    scheduleB.ApprovedDesignCapacity = new Services.DesignCapacity(adjustedDesignK, adjustedDesignE, adjustedDesignS);

                    scheduleB.MunicipalFees = 0;
                    //scheduleB.ConstructionNonStructuralSeismicUpgrade = 0;
                    scheduleB.ConstructionSeismicUpgrade = 0;
                    //scheduleB.ConstructionSPIRAdjustment = 0;

                    tracingService.Trace("Line: {0}", "89");
                    //scheduleB.SPIRFees = 0;

                    scheduleB.FreightRateAllowance = hostSchoolDistrictRecord.caps_FreightRateAllowance.GetValueOrDefault(0);

                    //Supplemental Items
                    scheduleB.Demolition         = 0;
                    scheduleB.AbnormalTopography = 0;
                    scheduleB.TempAccommodation  = 0;
                    scheduleB.OtherSupplemental  = 0;

                    //call Calculate
                    tracingService.Trace("CalculateScheduleB: {0}", "Call Calculate Function");
                    CalculationResult result = scheduleB.Calculate();

                    tracingService.Trace("Line: {0}", "104");
                    //Update the facility
                    var recordToUpdate = new caps_Facility();
                    recordToUpdate.Id = facility.Id;
                    recordToUpdate.caps_PreliminaryReplacementValue        = result.Total;
                    recordToUpdate.caps_PreliminaryReplacementCalculatedOn = DateTime.Now;
                    service.Update(recordToUpdate);
                }

                //Update Project Request
                this.error.Set(executionContext, false);
            }
            catch (Exception ex)
            {
                tracingService.Trace("Error Details: {0}", ex.Message);
                //might want to also include error message
                this.error.Set(executionContext, true);
                this.errorMessage.Set(executionContext, ex.Message);
            }
        }
Ejemplo n.º 5
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString());

            var recordId = context.PrimaryEntityId;

            try
            {
                //Get Global Capacity values
                var capacity = new Services.CapacityFactors(service);

                Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity);

                #region Update Facilities
                //get Facilities
                var fetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\" >" +
                               "<entity name=\"caps_facility\">" +
                               "<attribute name=\"caps_facilityid\" /> " +
                               "<attribute name=\"caps_name\" /> " +
                               "<attribute name=\"caps_lowestgrade\" /> " +
                               "<attribute name=\"caps_highestgrade\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacitysecondary\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacitykindergarten\" /> " +
                               "<attribute name=\"caps_adjusteddesigncapacityelementary\" /> " +
                               "<order attribute=\"caps_name\" descending=\"false\" /> " +
                               "<filter type=\"and\" > " +
                               "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /> " +
                               "<condition attribute=\"caps_lowestgrade\" operator=\"not-null\" />" +
                               "<condition attribute=\"caps_highestgrade\" operator=\"not-null\" />" +
                               "</filter> " +
                               "<link-entity name=\"caps_facilitytype\" from=\"caps_facilitytypeid\" to=\"caps_currentfacilitytype\" link-type=\"inner\" alias=\"ac\" > " +
                               "<filter type=\"and\" > " +
                               "<condition attribute=\"caps_schooltype\" operator=\"not-null\" /> " +
                               "</filter> " +
                               "</link-entity> " +
                               "</entity> " +
                               "</fetch>";


                EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchXML));

                foreach (caps_Facility facilityRecord in results.Entities)
                {
                    tracingService.Trace("Facility:{0}", facilityRecord.caps_Name);

                    var kDesign      = facilityRecord.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0);
                    var eDesign      = facilityRecord.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0);
                    var sDesign      = facilityRecord.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0);
                    var lowestGrade  = facilityRecord.caps_LowestGrade.Value;
                    var highestGrade = facilityRecord.caps_HighestGrade.Value;

                    var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade);

                    //Update Facility
                    var recordToUpdate = new caps_Facility();
                    recordToUpdate.Id = facilityRecord.Id;
                    recordToUpdate.caps_OperatingCapacityKindergarten = result.KindergartenCapacity;
                    recordToUpdate.caps_OperatingCapacityElementary   = result.ElementaryCapacity;
                    recordToUpdate.caps_OperatingCapacitySecondary    = result.SecondaryCapacity;
                    service.Update(recordToUpdate);
                }
                #endregion

                this.error.Set(executionContext, false);
            }
            catch (Exception ex)
            {
                tracingService.Trace("Error Details: {0}", ex.Message);
                //might want to also include error message
                this.error.Set(executionContext, true);
                this.errorMessage.Set(executionContext, ex.Message);
            }

            tracingService.Trace("{0}{1}", "End Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString());
        }