コード例 #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);
            }
        }
コード例 #2
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: CalculateProjectRequestOperatingCapacity", DateTime.Now.ToLongTimeString());

            var recordId = context.PrimaryEntityId;

            var startingDesign_K = 0;
            var startingDesign_E = 0;
            var startingDesign_S = 0;

            var startingOperating_K = 0;
            var startingOperating_E = 0;
            var startingOperating_S = 0;

            //Get Project Request
            var projectRequestColumns = new ColumnSet("caps_facility",
                                                      "caps_changeindesigncapacitykindergarten",
                                                      "caps_changeindesigncapacityelementary",
                                                      "caps_changeindesigncapacitysecondary",
                                                      "caps_futurelowestgrade",
                                                      "caps_futurehighestgrade");
            var projectRequest = service.Retrieve(caps_Project.EntityLogicalName, recordId, projectRequestColumns) as caps_Project;

            if (projectRequest.caps_FutureLowestGrade != null && projectRequest.caps_FutureHighestGrade != null)
            {
                //if facility exists, then retrieve it
                if (projectRequest.caps_Facility != null && projectRequest.caps_Facility.Id != Guid.Empty)
                {
                    var facility = service.Retrieve(caps_Facility.EntityLogicalName, projectRequest.caps_Facility.Id, new ColumnSet("caps_adjusteddesigncapacitykindergarten", "caps_adjusteddesigncapacityelementary", "caps_adjusteddesigncapacitysecondary", "caps_operatingcapacitykindergarten", "caps_operatingcapacityelementary", "caps_operatingcapacitysecondary")) 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);

                        startingOperating_K = Convert.ToInt32(facility.caps_OperatingCapacityKindergarten.GetValueOrDefault(0));
                        startingOperating_E = Convert.ToInt32(facility.caps_OperatingCapacityElementary.GetValueOrDefault(0));
                        startingOperating_S = Convert.ToInt32(facility.caps_OperatingCapacitySecondary.GetValueOrDefault(0));
                    }
                }

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

                //Get Operating Capacity Values
                var capacity = new Services.CapacityFactors(service);

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

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

                var changeInOperating_K = Convert.ToInt32(result.KindergartenCapacity) - startingOperating_K;
                var changeInOperating_E = Convert.ToInt32(result.ElementaryCapacity) - startingOperating_E;
                var changeInOperating_S = Convert.ToInt32(result.SecondaryCapacity) - startingOperating_S;

                var recordToUpdate = new caps_Project();
                recordToUpdate.Id = recordId;
                recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = changeInOperating_K;
                recordToUpdate.caps_ChangeinOperatingCapacityElementary   = changeInOperating_E;
                recordToUpdate.caps_ChangeinOperatingCapacitySecondary    = changeInOperating_S;
                service.Update(recordToUpdate);
            }
            else
            {
                //blank out operating capacity
                var recordToUpdate = new caps_Project();
                recordToUpdate.Id = recordId;
                recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = null;
                recordToUpdate.caps_ChangeinOperatingCapacityElementary   = null;
                recordToUpdate.caps_ChangeinOperatingCapacitySecondary    = null;
                service.Update(recordToUpdate);
            }
        }
コード例 #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: SetCapacityReporting", DateTime.Now.ToLongTimeString());

            var recordId = context.PrimaryEntityId;

            decimal?enrolmentK = 0;
            decimal?enrolmentE = 0;
            decimal?enrolmentS = 0;

            //Get Facility record with all current design capacity fields & school district
            var columns = new ColumnSet("caps_adjusteddesigncapacityelementary",
                                        "caps_adjusteddesigncapacitykindergarten",
                                        "caps_adjusteddesigncapacitysecondary",
                                        "caps_schooldistrict",
                                        "caps_currentenrolment",
                                        "caps_lowestgrade",
                                        "caps_highestgrade",
                                        "caps_name",
                                        "caps_districtoperatingcapacitykindergarten",
                                        "caps_districtoperatingcapacityelementary",
                                        "caps_districtoperatingcapacitysecondary",
                                        "caps_operatingcapacitykindergarten",
                                        "caps_operatingcapacityelementary",
                                        "caps_operatingcapacitysecondary",
                                        "caps_usefutureforutilization");
            var facilityRecord = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, columns) as caps_Facility;

            tracingService.Trace("Facility Name:{0}", facilityRecord.caps_Name);

            var capacity = new Services.CapacityFactors(service);

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

            tracingService.Trace("Line: {0}", "40");
            if (facilityRecord.caps_CurrentEnrolment != null)
            {
                var enrolmentRecord = service.Retrieve(caps_facilityenrolment.EntityLogicalName, facilityRecord.caps_CurrentEnrolment.Id, new ColumnSet("caps_sumofkindergarten", "caps_sumofelementary", "caps_sumofsecondary")) as caps_facilityenrolment;

                enrolmentK = enrolmentRecord.caps_SumofKindergarten.GetValueOrDefault(0);
                enrolmentE = enrolmentRecord.caps_SumofElementary.GetValueOrDefault(0);
                enrolmentS = enrolmentRecord.caps_SumofSecondary.GetValueOrDefault(0);

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

            //Get Current Enrolment Projections
            QueryExpression enrolmentQuery = new QueryExpression("caps_enrolmentprojections_sd");

            enrolmentQuery.ColumnSet.AllColumns = true;
            enrolmentQuery.Criteria             = new FilterExpression();
            enrolmentQuery.Criteria.AddCondition("caps_facility", ConditionOperator.Equal, recordId);
            if (facilityRecord.caps_UseFutureForUtilization.GetValueOrDefault(false))
            {
                //submitted
                enrolmentQuery.Criteria.AddCondition("statuscode", ConditionOperator.Equal, 200870001);
            }
            else
            {
                //current
                enrolmentQuery.Criteria.AddCondition("statuscode", ConditionOperator.Equal, 200870000);
            }

            EntityCollection enrolmentProjectionRecords = service.RetrieveMultiple(enrolmentQuery);
            var enrolmentProjectionList = enrolmentProjectionRecords.Entities.Select(r => r.ToEntity <caps_EnrolmentProjections_SD>()).ToList();


            //Get Projects for this facility with occupancy dates in the future
            QueryExpression projectQuery = new QueryExpression("caps_projecttracker");

            projectQuery.ColumnSet.AddColumns("caps_designcapacitykindergarten", "caps_designcapacityelementary", "caps_designcapacitysecondary", "caps_districtoperatingcapacitykindergarten", "caps_districtoperatingcapacityelementary", "caps_districtoperatingcapacitysecondary");
            projectQuery.Criteria = new FilterExpression();
            projectQuery.Criteria.AddCondition("caps_facility", ConditionOperator.Equal, recordId);
            projectQuery.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);

            LinkEntity milestoneLink = projectQuery.AddLink("caps_projectmilestone", "caps_projecttrackerid", "caps_projecttracker", JoinOperator.Inner);

            milestoneLink.Columns.AddColumn("caps_expectedactualdate");
            milestoneLink.EntityAlias  = "milestone";
            milestoneLink.LinkCriteria = new FilterExpression();
            milestoneLink.LinkCriteria.AddCondition("caps_name", ConditionOperator.Equal, "Occupancy");
            milestoneLink.LinkCriteria.AddCondition("caps_expectedactualdate", ConditionOperator.OnOrAfter, DateTime.Now);

            EntityCollection projectRecords = service.RetrieveMultiple(projectQuery);

            //Get Capacity Reporting Records
            QueryExpression query = new QueryExpression("caps_capacityreporting");

            query.ColumnSet.AllColumns = true;
            LinkEntity yearLink = query.AddLink("edu_year", "caps_schoolyear", "edu_yearid");

            yearLink.Columns.AddColumns("edu_yearid", "statuscode", "edu_enddate");
            yearLink.EntityAlias = "year";
            query.Criteria       = new FilterExpression();
            query.Criteria.AddCondition("year", "edu_type", ConditionOperator.Equal, 757500001);
            query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
            query.Criteria.AddCondition("caps_facility", ConditionOperator.Equal, recordId);
            EntityCollection reportingRecords = service.RetrieveMultiple(query);

            foreach (var reportingRecord in reportingRecords.Entities)
            {
                tracingService.Trace("Line: {0}", "71");
                //Get Type - Historical, Current, Future
                var recordType = (OptionSetValue)((AliasedValue)reportingRecord["year.statuscode"]).Value;

                if (recordType.Value == 757500001)
                {
                    //Historical
                    #region Historical

                    //For each record, get top 1 Facility History record where year snapshot equals the school year record, order by created on date descending
                    tracingService.Trace("Year Value: {0}", ((AliasedValue)reportingRecord["year.edu_yearid"]).Value);
                    var schoolYearRecord = ((AliasedValue)reportingRecord["year.edu_yearid"]).Value;

                    QueryExpression snapshotQuery = new QueryExpression("caps_facilityhistory");
                    snapshotQuery.ColumnSet.AllColumns = true;
                    LinkEntity enrolmentLink = snapshotQuery.AddLink("caps_facilityenrolment", "caps_facilityenrolment", "caps_facilityenrolmentid");
                    enrolmentLink.EntityAlias = "enrolment";
                    enrolmentLink.Columns.AddColumns("caps_sumofkindergarten", "caps_sumofelementary", "caps_sumofsecondary");

                    snapshotQuery.Criteria = new FilterExpression();
                    snapshotQuery.Criteria.AddCondition("caps_facility", ConditionOperator.Equal, recordId);
                    snapshotQuery.Criteria.AddCondition("caps_year", ConditionOperator.Equal, schoolYearRecord);
                    snapshotQuery.AddOrder("createdon", OrderType.Descending);
                    snapshotQuery.TopCount = 1;

                    EntityCollection snapshotRecords = service.RetrieveMultiple(snapshotQuery);

                    //Get top record
                    if (snapshotRecords.Entities.Count() == 1)
                    {
                        tracingService.Trace("Line: {0}", "93");
                        var topRecord = snapshotRecords.Entities[0] as caps_FacilityHistory;

                        //Update the capacity record
                        var recordToUpdate = new caps_CapacityReporting();
                        recordToUpdate.Id = reportingRecord.Id;

                        decimal?historicalEnrolmentK = (!reportingRecord.Contains("enrolment.caps_sumofkindergarten")) ? 0 : ((int?)((AliasedValue)reportingRecord["enrolment.caps_sumofkindergarten"]).Value).GetValueOrDefault(0);
                        decimal?historicalEnrolmentE = (!reportingRecord.Contains("enrolment.caps_sumofelementary")) ? 0 : ((int?)((AliasedValue)reportingRecord["enrolment.caps_sumofelementary"]).Value).GetValueOrDefault(0);
                        decimal?historicalEnrolmentS = (!reportingRecord.Contains("enrolment.caps_sumofsecondary")) ? 0 : ((int?)((AliasedValue)reportingRecord["enrolment.caps_sumofsecondary"]).Value).GetValueOrDefault(0);

                        recordToUpdate.caps_Kindergarten_enrolment = historicalEnrolmentK;
                        recordToUpdate.caps_Elementary_enrolment   = historicalEnrolmentE;
                        recordToUpdate.caps_Secondary_enrolment    = historicalEnrolmentS;

                        recordToUpdate.caps_Kindergarten_designcapacity = topRecord.caps_DesignCapacityKindergarten;
                        recordToUpdate.caps_Elementary_designcapacity   = topRecord.caps_DesignCapacityElementary;
                        recordToUpdate.caps_Secondary_designcapacity    = topRecord.caps_DesignCapacitySecondary;

                        recordToUpdate.caps_Kindergarten_designutilization = (topRecord.caps_DesignCapacityKindergarten == 0) ? 0 : historicalEnrolmentK / topRecord.caps_DesignCapacityKindergarten * 100;
                        recordToUpdate.caps_Elementary_designutilization   = (topRecord.caps_DesignCapacityElementary == 0) ? 0 : historicalEnrolmentE / topRecord.caps_DesignCapacityElementary * 100;
                        recordToUpdate.caps_Secondary_designutilization    = (topRecord.caps_DesignCapacitySecondary == 0) ? 0 : historicalEnrolmentS / topRecord.caps_DesignCapacitySecondary * 100;

                        recordToUpdate.caps_Kindergarten_operatingcapacity = topRecord.caps_OperatingCapacityKindergarten;
                        recordToUpdate.caps_Elementary_operatingcapacity   = topRecord.caps_OperatingCapacityElementary;
                        recordToUpdate.caps_Secondary_operatingcapacity    = topRecord.caps_OperatingCapacitySecondary;

                        recordToUpdate.caps_Kindergarten_operatingutilization = (topRecord.caps_OperatingCapacityKindergarten == 0) ? 0 : historicalEnrolmentK / topRecord.caps_OperatingCapacityKindergarten * 100;
                        recordToUpdate.caps_Elementary_operatingutilization   = (topRecord.caps_OperatingCapacityElementary == 0) ? 0 : historicalEnrolmentE / topRecord.caps_OperatingCapacityElementary * 100;
                        recordToUpdate.caps_Secondary_operatingutilization    = (topRecord.caps_OperatingCapacitySecondary == 0) ? 0 : historicalEnrolmentS / topRecord.caps_OperatingCapacitySecondary * 100;

                        recordToUpdate.caps_kindergarten_operatingcapacity_district = topRecord.caps_DistrictOperatingCapacityKindergarten;
                        recordToUpdate.caps_elementary_operatingcapacity_district   = topRecord.caps_DistrictOperatingCapacityElementary;
                        recordToUpdate.caps_secondary_operatingcapacity_district    = topRecord.caps_DistrictOperatingCapacitySecondary;

                        recordToUpdate.caps_kindergarten_operatingutilizatio_district = (topRecord.caps_DistrictOperatingCapacityKindergarten == 0) ? 0 : historicalEnrolmentK / topRecord.caps_DistrictOperatingCapacityKindergarten * 100;
                        recordToUpdate.caps_elementary_operatingutilization_district  = (topRecord.caps_DistrictOperatingCapacityElementary == 0) ? 0 : historicalEnrolmentE / topRecord.caps_DistrictOperatingCapacityElementary * 100;
                        recordToUpdate.caps_secondary_operatingutilization_district   = (topRecord.caps_DistrictOperatingCapacitySecondary == 0) ? 0 : historicalEnrolmentS / topRecord.caps_DistrictOperatingCapacitySecondary * 100;

                        service.Update(recordToUpdate);
                    }
                    #endregion
                }
                else if (recordType.Value == 1)
                {
                    //Current
                    #region Current
                    tracingService.Trace("Line: {0}", "123");

                    //Update the capacity record
                    var recordToUpdate = new caps_CapacityReporting();
                    recordToUpdate.Id = reportingRecord.Id;

                    recordToUpdate.caps_Kindergarten_enrolment = enrolmentK;
                    recordToUpdate.caps_Elementary_enrolment   = enrolmentE;
                    recordToUpdate.caps_Secondary_enrolment    = enrolmentS;

                    recordToUpdate.caps_Kindergarten_designcapacity = facilityRecord.caps_AdjustedDesignCapacityKindergarten;
                    recordToUpdate.caps_Elementary_designcapacity   = facilityRecord.caps_AdjustedDesignCapacityElementary;
                    recordToUpdate.caps_Secondary_designcapacity    = facilityRecord.caps_AdjustedDesignCapacitySecondary;

                    recordToUpdate.caps_Kindergarten_designutilization = (facilityRecord.caps_AdjustedDesignCapacityKindergarten == 0) ? 0 : enrolmentK / facilityRecord.caps_AdjustedDesignCapacityKindergarten * 100;
                    recordToUpdate.caps_Elementary_designutilization   = (facilityRecord.caps_AdjustedDesignCapacityElementary == 0) ? 0 : enrolmentE / facilityRecord.caps_AdjustedDesignCapacityElementary * 100;
                    recordToUpdate.caps_Secondary_designutilization    = (facilityRecord.caps_AdjustedDesignCapacitySecondary == 0) ? 0 : enrolmentS / facilityRecord.caps_AdjustedDesignCapacitySecondary * 100;

                    //Note: Operating capacity is kept up to date on the facility record so no calculation is needed
                    recordToUpdate.caps_Kindergarten_operatingcapacity = facilityRecord.caps_OperatingCapacityKindergarten;
                    recordToUpdate.caps_Elementary_operatingcapacity   = facilityRecord.caps_OperatingCapacityElementary;
                    recordToUpdate.caps_Secondary_operatingcapacity    = facilityRecord.caps_OperatingCapacitySecondary;

                    recordToUpdate.caps_Kindergarten_operatingutilization = (facilityRecord.caps_OperatingCapacityKindergarten == 0) ? 0 : enrolmentK / facilityRecord.caps_OperatingCapacityKindergarten * 100;
                    recordToUpdate.caps_Elementary_operatingutilization   = (facilityRecord.caps_OperatingCapacityElementary == 0) ? 0 : enrolmentE / facilityRecord.caps_OperatingCapacityElementary * 100;
                    recordToUpdate.caps_Secondary_operatingutilization    = (facilityRecord.caps_OperatingCapacitySecondary == 0) ? 0 : enrolmentS / facilityRecord.caps_OperatingCapacitySecondary * 100;

                    recordToUpdate.caps_kindergarten_operatingcapacity_district = facilityRecord.caps_DistrictOperatingCapacityKindergarten;
                    recordToUpdate.caps_elementary_operatingcapacity_district   = facilityRecord.caps_DistrictOperatingCapacityElementary;
                    recordToUpdate.caps_secondary_operatingcapacity_district    = facilityRecord.caps_DistrictOperatingCapacitySecondary;

                    recordToUpdate.caps_kindergarten_operatingutilizatio_district = (facilityRecord.caps_DistrictOperatingCapacityKindergarten == 0) ? 0 : enrolmentK / facilityRecord.caps_DistrictOperatingCapacityKindergarten * 100;
                    recordToUpdate.caps_elementary_operatingutilization_district  = (facilityRecord.caps_DistrictOperatingCapacityElementary == 0) ? 0 : enrolmentE / facilityRecord.caps_DistrictOperatingCapacityElementary * 100;
                    recordToUpdate.caps_secondary_operatingutilization_district   = (facilityRecord.caps_DistrictOperatingCapacitySecondary == 0) ? 0 : enrolmentS / facilityRecord.caps_DistrictOperatingCapacitySecondary * 100;

                    service.Update(recordToUpdate);
                    #endregion
                }
                else
                {
                    //Future
                    #region Future
                    var endDate = (DateTime?)((AliasedValue)reportingRecord["year.edu_enddate"]).Value;

                    var recordToUpdate = new caps_CapacityReporting();
                    recordToUpdate.Id = reportingRecord.Id;

                    //get matching enrolment projection record
                    var matchingProjection = enrolmentProjectionList.FirstOrDefault(r => r.caps_ProjectionYear.Id == reportingRecord.GetAttributeValue <EntityReference>("caps_schoolyear").Id);

                    var kDesign = facilityRecord.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0);
                    var eDesign = facilityRecord.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0);
                    var sDesign = facilityRecord.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0);

                    var kDistrict = facilityRecord.caps_DistrictOperatingCapacityKindergarten.GetValueOrDefault(0);
                    var eDistrict = facilityRecord.caps_DistrictOperatingCapacityElementary.GetValueOrDefault(0);
                    var sDistrict = facilityRecord.caps_DistrictOperatingCapacitySecondary.GetValueOrDefault(0);

                    tracingService.Trace("Design Capacity - K:{0}; E:{1}; S:{2}", kDesign, eDesign, sDesign);

                    if (endDate.HasValue)
                    {
                        //loop project records
                        foreach (var projectRecord in projectRecords.Entities)
                        {
                            if ((DateTime?)((AliasedValue)projectRecord["milestone.caps_expectedactualdate"]).Value <= endDate)
                            {
                                //add design capacity on
                                kDesign += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_designcapacitykindergarten").GetValueOrDefault(0));
                                eDesign += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_designcapacityelementary").GetValueOrDefault(0));
                                sDesign += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_designcapacitysecondary").GetValueOrDefault(0));

                                //add district operating capacity
                                kDistrict += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_districtoperatingcapacitykindergarten").GetValueOrDefault(0));
                                eDistrict += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_districtoperatingcapacityelementary").GetValueOrDefault(0));
                                sDistrict += Convert.ToInt32(projectRecord.GetAttributeValue <decimal?>("caps_districtoperatingcapacitysecondary").GetValueOrDefault(0));
                            }
                        }
                    }

                    tracingService.Trace("Updated Design Capacity - K:{0}; E:{1}; S:{2}", kDesign, eDesign, sDesign);

                    decimal?futureEnrolmentK = (matchingProjection != null) ? matchingProjection.caps_EnrolmentProjectionKindergarten : 0;
                    decimal?futureEnrolmentE = (matchingProjection != null) ? matchingProjection.caps_EnrolmentProjectionElementary : 0;
                    decimal?futureEnrolmentS = (matchingProjection != null) ? matchingProjection.caps_EnrolmentProjectionSecondary : 0;
                    decimal?futureEnrolmentI = (matchingProjection != null) ? matchingProjection.caps_enrolmentprojectioninternational : 0;

                    recordToUpdate.caps_Kindergarten_enrolment  = futureEnrolmentK;
                    recordToUpdate.caps_Elementary_enrolment    = futureEnrolmentE;
                    recordToUpdate.caps_Secondary_enrolment     = futureEnrolmentS;
                    recordToUpdate.caps_International_enrolment = futureEnrolmentI;

                    recordToUpdate.caps_Kindergarten_designcapacity = kDesign;
                    recordToUpdate.caps_Elementary_designcapacity   = eDesign;
                    recordToUpdate.caps_Secondary_designcapacity    = sDesign;

                    tracingService.Trace("Enrolment - K:{0}; E:{1}; S:{2}", futureEnrolmentK, futureEnrolmentE, futureEnrolmentS);

                    recordToUpdate.caps_Kindergarten_designutilization = (kDesign == 0) ? 0 : futureEnrolmentK / kDesign * 100;
                    recordToUpdate.caps_Elementary_designutilization   = (eDesign == 0) ? 0 : futureEnrolmentE / eDesign * 100;
                    recordToUpdate.caps_Secondary_designutilization    = (sDesign == 0) ? 0 : futureEnrolmentS / sDesign * 100;

                    //no sense in running this if the grade range isn't specified
                    if (facilityRecord.caps_LowestGrade != null && facilityRecord.caps_HighestGrade != null)
                    {
                        //Get operating capacity for the design numbers
                        var lowestGrade  = facilityRecord.caps_LowestGrade.Value;
                        var highestGrade = facilityRecord.caps_HighestGrade.Value;

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

                        recordToUpdate.caps_Kindergarten_operatingcapacity = result.KindergartenCapacity;
                        recordToUpdate.caps_Elementary_operatingcapacity   = result.ElementaryCapacity;
                        recordToUpdate.caps_Secondary_operatingcapacity    = result.SecondaryCapacity;

                        recordToUpdate.caps_Kindergarten_operatingutilization = (result.KindergartenCapacity == 0) ? 0 : futureEnrolmentK / result.KindergartenCapacity * 100;
                        recordToUpdate.caps_Elementary_operatingutilization   = (result.ElementaryCapacity == 0) ? 0 : futureEnrolmentE / result.ElementaryCapacity * 100;
                        recordToUpdate.caps_Secondary_operatingutilization    = (result.SecondaryCapacity == 0) ? 0 : futureEnrolmentS / result.SecondaryCapacity * 100;
                    }

                    recordToUpdate.caps_kindergarten_operatingcapacity_district = kDistrict;
                    recordToUpdate.caps_elementary_operatingcapacity_district   = eDistrict;
                    recordToUpdate.caps_secondary_operatingcapacity_district    = sDistrict;

                    recordToUpdate.caps_kindergarten_operatingutilizatio_district = (kDistrict == 0) ? 0 : futureEnrolmentK / kDistrict * 100;
                    recordToUpdate.caps_elementary_operatingutilization_district  = (eDistrict == 0) ? 0 : futureEnrolmentE / eDistrict * 100;
                    recordToUpdate.caps_secondary_operatingutilization_district   = (sDistrict == 0) ? 0 : futureEnrolmentS / sDistrict * 100;

                    service.Update(recordToUpdate);
                }
                #endregion
            }
        }
コード例 #4
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());
        }
コード例 #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 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\" /> " +
                                       "</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> ";

                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);
                    var lowestGrade  = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_lowestgrade"]).Value).Value;
                    var highestGrade = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_highestgrade"]).Value).Value;

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

                    //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

                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());
        }
コード例 #6
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 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\" /> " +
                                             "<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 = recordId;
                        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 = recordId;
                        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());
        }
コード例 #7
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());
        }