コード例 #1
0
        /// <summary>
        /// Get activity
        /// </summary>
        /// <param name="activityId"></param>
        /// <returns></returns>
        public void GetActivity(string activityId, ActivityServiceDelegate activityCallback)
        {
            _log.Debug("Enter - GetActivity()");
            if (activityId == null || activityId.Trim().Equals("") || activityCallback == null)
            {
                return;
            }
            var backgroundService = new ToaBackgroundServiceUtil();

            /*backgroundService.RunAsync(() =>
             *  { */
            try
            {
                var activityModel    = new WorkOrderModel();
                var getActivityParam = new get_activity_parameters();
                getActivityParam.activity_id = activityId;
                getActivityParam.user        = ToaUserUtil.GetActivityUser();
                activity_response response = _activityClient.get_activity(getActivityParam);

                // initialize  toa result and activity model object
                var toaRequestResult = new ToaRequestResult();
                toaRequestResult.DataModels.Add(activityModel);

                activityCallback.Invoke(toaRequestResult);
            }
            catch (Exception exception)
            {
                // Todo: logg exception
            }

            /*});*/
            _log.Debug("Exit - GetActivity()");
        }
コード例 #2
0
ファイル: InboundRequest.cs プロジェクト: thollu/accelerators
        internal InboundInterfaceElement GetInboundRequestElement()
        {
            var inboundRequest = new InboundInterfaceElement();

            // Initialize User
            inboundRequest.user = ToaUserUtil.GetInboundUser();

            //Initialize Head
            var head = new HeadElement();

            head.allow_change_date = ToaStringsUtil.GetString(_allowChangeDate);
            head.date = _uploadDate;
            head.default_appointment_pool = _defaultAppointmentPool;
            head.id = _transactionId;
            head.processing_mode = ToaStringsUtil.GetString(_processingMode);
            head.properties_mode = ToaStringsUtil.GetString(_propertiesMode);
            head.upload_type     = ToaStringsUtil.GetString(_uploadType);
            head.provider_group  = _providerGroup;
            if (null != _activitySettings)
            {
                head.appointment = _activitySettings.GetActivitySettings();
            }
            if (null != _inventorySettings)
            {
                head.inventory = _inventorySettings.GetInventorySettings();
            }
            inboundRequest.head = head;

            //initialize Data
            var data       = new DataElement();
            var noOfModels = _dataModels.Count;

            CommandElement []  commands  = null;
            ProviderElement [] providers = null;
            if (UploadType == UploadType.Full) // Full Upload
            {
                providers = new ProviderElement[noOfModels];
                foreach (var model in _dataModels)
                {
                    if (model is WorkOrderModel)
                    {
                        var activityModel   = ((WorkOrderModel)model);
                        var providerElement = new ProviderElement();
                        providerElement.appointment = activityModel.GetActivityElement();
                        providers[--noOfModels]     = providerElement;
                    }
                    else if (model is InventoryModel)
                    {
                        //TODO: Need to initialize inventory object
                    }
                }
                data.providers = providers;
            }
            else // Incremental Upload
            {
                commands = new CommandElement[noOfModels];
                foreach (var model in _dataModels)
                {
                    if (model is WorkOrderModel)
                    {
                        var workOrderModel = ((WorkOrderModel)model);
                        var command        = new CommandElement();
                        command.appointment    = workOrderModel.GetActivityElement();
                        command.date           = workOrderModel.AssignedDate;
                        command.external_id    = workOrderModel.ExternalId;
                        command.type           = ToaStringsUtil.GetString(workOrderModel.CommandType);
                        commands[--noOfModels] = command;
                    }
                    else if (model is InventoryModel)
                    {
                        //TODO: Need to initialize inventory object
                    }
                }
                data.commands = commands;
            }



            inboundRequest.data = data;

            return(inboundRequest);
        }
コード例 #3
0
        /// <summary>
        /// Get Work Order Area mapped to zipcode
        /// </summary>
        /// <param name="capacityModel">Capacity Model object</param>
        /// <param name="capacityCallback">Callback method</param>
        public void GetWorkOrderArea(CapacityModel capacityModel, CapacityServiceDelegate capacityCallback)
        {
            _log.Notice("Inside GetWorkOrderArea");
            var backgroundService = new ToaBackgroundServiceUtil();

            backgroundService.RunAsync(() =>
            {
                try
                {
                    capacity_element[] capacityElement           = capacityModel.getCapacityElement();
                    time_slot_info_element[] timeSlotInfoElement = capacityModel.getTimeSlotInfoElement();
                    long activityTravelTime          = capacityModel.ActivityTravelTime;
                    bool activityTravelTimeSpecified = capacityModel.AggregateResultsSpecified;

                    _toaCapacityInterface.get_capacity(ToaUserUtil.GetCapacityUser(), capacityModel.QuotaDates, capacityModel.Location,
                                                       capacityModel.CalculateDuration, capacityModel.CalculateDurationSpecified, capacityModel.CalculateTravelTime, capacityModel.CalculateTravelTimeSpecified,
                                                       capacityModel.CalculateWorkSkill, capacityModel.CalculateWorkSkillSpecified, capacityModel.ReturnTimeSlotInfo, capacityModel.ReturnTimeSlotInfoSpecified,
                                                       capacityModel.DetermineLocationByWorkZone, capacityModel.DetermineLocationByWorkZoneSpecified, capacityModel.DontAggregateResults, capacityModel.DontAggregateResultsSpecified,
                                                       capacityModel.MinTimeEndOfTimeSlot, capacityModel.MinTimeEndOfTimeSlotSpecified,
                                                       capacityModel.DefaultDuration, capacityModel.DefaultDurationSpecified, capacityModel.Timeslots, capacityModel.WorkSkill,
                                                       capacityModel.getActivityFieldElement(),
                                                       out activityTravelTime, out activityTravelTimeSpecified, out activityTravelTime, out activityTravelTimeSpecified, out capacityElement, out timeSlotInfoElement);

                    CapacityModel response = new CapacityModel();

                    HashSet <string> locations = new HashSet <string>();
                    if (capacityElement != null)
                    {
                        foreach (capacity_element ce in capacityElement)
                        {
                            if (!locations.Contains(ce.location))
                            {
                                locations.Add(ce.location);
                            }
                        }
                    }

                    response.Location = new string[locations.Count];
                    locations.CopyTo(response.Location);
                    // initialize  toa result and activity model object
                    var toaRequestResult = new ToaRequestResult();
                    toaRequestResult.DataModels.Add(response);

                    toaRequestResult.ResultCode = ToaRequestResultCode.Success;

                    if (locations.Count == 0)
                    {
                        List <ReportMessageModel> reportMessageModel = new List <ReportMessageModel>();
                        _log.Error("Unable to determine work zone for given fields");
                        reportMessageModel.Add(new ReportMessageModel("No Work Order Areas exist for this Postal Code, please update the Postal Code field or submit with no timeslot and data selected", null, null, "Unable to determine work zone for given fields"));
                        toaRequestResult.ReportMessages = reportMessageModel;
                        toaRequestResult.ResultCode     = ToaRequestResultCode.Failure;
                    }

                    capacityCallback.Invoke(toaRequestResult);
                }
                catch (Exception exception)
                {
                    _log.Error("Unable to fetch Work Order Area");
                    _log.Error(exception.StackTrace);
                    MessageBox.Show("No Work Order Areas exist for this Postal Code, please update the Postal Code field or submit with no timeslot and data selected");
                }
            });
        }
コード例 #4
0
        /// <summary>
        /// Get Quota for month
        /// </summary>
        /// <param name="capacityModel"></param>
        /// <returns></returns>
        public ToaRequestResult GetQuotaForMonth(CapacityModel capacityModel)
        {
            _log.Notice("Inside GetQuotaForMonth");
            var toaRequestResult = new ToaRequestResult();

            try
            {
                capacity_element[]       capacityElement     = capacityModel.getCapacityElement();
                time_slot_info_element[] timeSlotInfoElement = capacityModel.getTimeSlotInfoElement();
                long activityTravelTime          = capacityModel.ActivityTravelTime;
                bool activityTravelTimeSpecified = capacityModel.ActivityTravelTimeSpecified;
                long activityDuration            = capacityModel.ActivityDuration;
                bool activityDurationSpecified   = capacityModel.ActivityDurationSpecified;

                _toaCapacityInterface.get_capacity(ToaUserUtil.GetCapacityUser(), capacityModel.QuotaDates, capacityModel.Location,
                                                   capacityModel.CalculateDuration, capacityModel.CalculateDurationSpecified, capacityModel.CalculateTravelTime, capacityModel.CalculateTravelTimeSpecified,
                                                   capacityModel.CalculateWorkSkill, capacityModel.CalculateWorkSkillSpecified, capacityModel.ReturnTimeSlotInfo, capacityModel.ReturnTimeSlotInfoSpecified,
                                                   capacityModel.DetermineLocationByWorkZone, capacityModel.DetermineLocationByWorkZoneSpecified, capacityModel.DontAggregateResults, capacityModel.DontAggregateResultsSpecified,
                                                   capacityModel.MinTimeEndOfTimeSlot, capacityModel.MinTimeEndOfTimeSlotSpecified,
                                                   capacityModel.DefaultDuration, capacityModel.DefaultDurationSpecified, capacityModel.Timeslots, capacityModel.WorkSkill,
                                                   capacityModel.getActivityFieldElement(),
                                                   out activityDuration, out activityDurationSpecified, out activityTravelTime, out activityTravelTimeSpecified, out capacityElement, out timeSlotInfoElement);

                CapacityModel response = new CapacityModel();

                if (activityDuration != null)
                {
                    response.ActivityDuration = activityDuration;
                }

                if (activityTravelTime != null)
                {
                    response.ActivityTravelTime = activityTravelTime;
                }

                Dictionary <DateTime, DayQuota> dayQuota = new Dictionary <DateTime, DayQuota>();
                if (capacityElement != null)
                {
                    foreach (capacity_element ce in capacityElement)
                    {
                        if (dayQuota.ContainsKey(ce.date))
                        {
                            DayQuota quota = dayQuota[ce.date];
                            if (quota.TimeSlotQuota == null)
                            {
                                quota.TimeSlotQuota = new Dictionary <string, float>();
                            }
                            float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota);

                            quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable);
                        }
                        else
                        {
                            DayQuota quota = new DayQuota();
                            quota.QuotaDate     = ce.date;
                            quota.TimeSlotQuota = new Dictionary <string, float>();
                            float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota);
                            quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable);
                            dayQuota.Add(ce.date, quota);
                        }
                    }
                }

                _log.Debug("Monthy Quota Response: ", Json.Encode(capacityElement));
                _log.Debug("TimeSlots: ", Json.Encode(timeSlotInfoElement));

                HashSet <string> timeSlotSet = new HashSet <string>();
                if (timeSlotInfoElement != null)
                {
                    foreach (time_slot_info_element ts in timeSlotInfoElement)
                    {
                        timeSlotSet.Add(ts.label);
                    }
                }

                if (timeSlotSet.Count > 0)
                {
                    response.Timeslots = new string[timeSlotSet.Count];
                    timeSlotSet.CopyTo(response.Timeslots);
                    Array.Sort(response.Timeslots);
                }

                DateTime currentDate = DateTime.Today;
                bool     todayExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0;

                //Fix the closing quota issue
                if (todayExists)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        if (dayQuota.ContainsKey(currentDate))
                        {
                            DayQuota quota = dayQuota[currentDate];
                            foreach (string timeSlot in response.Timeslots)
                            {
                                if (!quota.TimeSlotQuota.ContainsKey(timeSlot))
                                {
                                    quota.TimeSlotQuota.Add(timeSlot, 0);
                                }
                            }
                        }
                        else
                        {
                            DayQuota quota = new DayQuota();
                            quota.QuotaDate     = currentDate;
                            quota.TimeSlotQuota = new Dictionary <string, float>();
                            foreach (string timeSlot in response.Timeslots)
                            {
                                quota.TimeSlotQuota.Add(timeSlot, 0);
                            }
                            dayQuota.Add(currentDate, quota);
                        }

                        currentDate = DateTime.Today.AddDays(1);
                        bool currentDateExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0;
                        if (!currentDateExists)
                        {
                            break;
                        }
                    }
                }

                response.DayQuota = dayQuota;
                // initialize  toa result and activity model object

                toaRequestResult.DataModels.Add(response);
                if (dayQuota.Count == 0 || timeSlotSet.Count == 0)
                {
                    toaRequestResult.ResultCode = ToaRequestResultCode.Failure;
                }
                else
                {
                    toaRequestResult.ResultCode = ToaRequestResultCode.Success;
                }

                return(toaRequestResult);
            }
            catch (Exception exception)
            {
                _log.Error("Unable to fetch Quota for given dates");
                _log.Error(exception.StackTrace);
                MessageBox.Show("No quota available for the Work Order Type and Work Order Area selected.  Please reselect, if you continue to receive this warning, please contact support for assistance.",
                                "Warning: No Quota Available", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                toaRequestResult.ResultCode = ToaRequestResultCode.Failure;
            }
            return(toaRequestResult);
        }