Example #1
0
        /// <summary>
        /// Prepares result as an interval (<seealso cref="CaseTermInterval"/>).
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="state">Case term state.</param>
        /// <param name="timeColumns">Time columns.</param>
        /// <param name="calendarId">Calendar identifier.</param>
        /// <returns>Case term interval.</returns>
        protected CaseTermInterval PrepareResult(Entity entity, CaseTermStates state, TimeColumnData timeColumns,
                                                 Guid calendarId)
        {
            var result = new CaseTermInterval();

            if (!state.HasFlag(CaseTermStates.ContainsResponse))
            {
                var reactionTimeUnitName = entity.GetTypedColumnValue <string>(timeColumns.ReactionColumn.UnitCode);
                CalendarsTimeUnit timeUnit;
                Enum.TryParse(reactionTimeUnitName, out timeUnit);
                var term = new TimeTerm {
                    Type       = timeUnit,
                    Value      = entity.GetTypedColumnValue <int>(timeColumns.ReactionColumn.Value),
                    CalendarId = calendarId
                };
                result.ResponseTerm = term.ConvertToMinutes();
            }
            if (!state.HasFlag(CaseTermStates.ContainsResolve))
            {
                var solutionTimeUnitName = entity.GetTypedColumnValue <string>(timeColumns.SolutionColumn.UnitCode);
                CalendarsTimeUnit timeUnit;
                Enum.TryParse(solutionTimeUnitName, out timeUnit);
                var term = new TimeTerm {
                    Type       = timeUnit,
                    Value      = entity.GetTypedColumnValue <int>(timeColumns.SolutionColumn.Value),
                    CalendarId = calendarId
                };
                result.ResolveTerm = term.ConvertToMinutes();
            }
            return(result);
        }
        private TimeTerm GetTerm(Entity entity, string timeUnitColumnName, string timeValueColumnName,
                                 Guid calendarId)
        {
            var term         = new TimeTerm();
            var timeUnitName = entity.GetTypedColumnValue <string>(timeUnitColumnName);
            CalendarsTimeUnit timeUnit;

            if (Enum.TryParse(timeUnitName, out timeUnit))
            {
                term.Type = timeUnit;
            }
            term.Value      = entity.GetTypedColumnValue <int>(timeValueColumnName);
            term.CalendarId = calendarId;
            return(term.ConvertToMinutes());
        }
        /// <summary>
        /// Method that returns case term interval for calculation.
        /// </summary>
        /// <param name="mask">Mask for case term interval.</param>
        /// <returns>Case term interval.</returns>
        public override CaseTermInterval GetTermInterval(CaseTermStates mask)
        {
            CaseTermInterval  result = new CaseTermInterval();
            EntitySchemaQuery esqTimeToPrioritize = new EntitySchemaQuery(UserConnection.EntitySchemaManager,
                                                                          "TimeToPrioritize");
            IntervalColumnsNames names = PrepareEntitySchemaQuery(esqTimeToPrioritize, mask);
            var entityCollection       = esqTimeToPrioritize.GetEntityCollection(UserConnection);

            if (entityCollection.IsEmpty())
            {
                return(result);
            }
            Entity entity         = entityCollection[0];
            var    entityCalendar = entity.GetTypedColumnValue <Guid>(names.Calendar);
            var    calendarId     = entityCalendar != Guid.Empty ? entityCalendar : GetCalendar();

            if (calendarId == Guid.Empty)
            {
                return(result);
            }
            if (!mask.HasFlag(CaseTermStates.ContainsResponse))
            {
                var reactionTimeUnitName = entity.GetTypedColumnValue <string>(names.ReactionType);
                var timeUnit             = default(CalendarsTimeUnit);
                var term = new TimeTerm();
                if (Enum.TryParse <CalendarsTimeUnit>(reactionTimeUnitName, out timeUnit))
                {
                    term.Type = timeUnit;
                }
                term.Value          = entity.GetTypedColumnValue <int>(names.ReactionValue);
                term.CalendarId     = calendarId;
                result.ResponseTerm = term.ConvertToMinutes();
            }
            if (!mask.HasFlag(CaseTermStates.ContainsResolve))
            {
                var solutionTimeUnitName = entity.GetTypedColumnValue <string>(names.SolutionType);
                var timeUnit             = default(CalendarsTimeUnit);
                var term = new TimeTerm();
                if (Enum.TryParse <CalendarsTimeUnit>(solutionTimeUnitName, out timeUnit))
                {
                    term.Type = timeUnit;
                }
                term.Value         = entity.GetTypedColumnValue <int>(names.SolutionValue);
                term.CalendarId    = calendarId;
                result.ResolveTerm = term.ConvertToMinutes();
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// Gets case term interval for this strategy.
        /// </summary>
        /// <param name="state">Case term state.</param>
        /// <returns>Case term interval.</returns>
        public override CaseTermInterval GetTermInterval(CaseTermStates state)
        {
            var result = new CaseTermInterval();
            var esq    = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "ServiceItem");
            TimeUnitColumnsNames names = PrepareEntitySchemaQuery(esq, state);
            var serviceItem            = esq.GetEntity(UserConnection, _serviceDataModel.ServiceItemId);

            if (serviceItem == null)
            {
                return(result);
            }
            var serviceItemCalendar = serviceItem.GetTypedColumnValue <Guid>("CalendarId");
            var calendarId          = serviceItemCalendar != default(Guid) ? serviceItemCalendar : GetCalendarBySysSetting();

            if (calendarId == default(Guid))
            {
                return(result);
            }
            if (!state.HasFlag(CaseTermStates.ContainsResponse))
            {
                var term = new TimeTerm();
                var reactionTimeUnitName = serviceItem.GetTypedColumnValue <string>(names.ReactionType);
                CalendarsTimeUnit timeUnit;
                if (Enum.TryParse(reactionTimeUnitName, out timeUnit))
                {
                    term.Type = timeUnit;
                }
                term.Value          = serviceItem.GetTypedColumnValue <int>("ReactionTimeValue");
                term.CalendarId     = calendarId;
                result.ResponseTerm = term.ConvertToMinutes();
            }
            if (!state.HasFlag(CaseTermStates.ContainsResolve))
            {
                var term = new TimeTerm();
                var solutionTimeUnitName = serviceItem.GetTypedColumnValue <string>(names.SolutionType);
                CalendarsTimeUnit timeUnit;
                if (Enum.TryParse(solutionTimeUnitName, out timeUnit))
                {
                    term.Type = timeUnit;
                }
                term.Value         = serviceItem.GetTypedColumnValue <int>("SolutionTimeValue");
                term.CalendarId    = calendarId;
                result.ResolveTerm = term.ConvertToMinutes();
            }
            return(result);
        }
Example #5
0
 /// <summary>
 /// Fills used time intervals.
 /// </summary>
 /// <param name="provider">Calendar operation provider.</param>
 /// <param name="term">Calculation term.</param>
 /// <param name="loader">Calendar data loader.</param>
 public void FillUsedTimeIntervals(ICalendarOperationProvider provider, TimeTerm term, ITermCalculationCalendarDataLoader loader)
 {
     _logStore.TermTimeRemains = term.Value;
     _logStore.CalendarData    = loader.GetCalendarData(term.CalendarId);
     if (_logStore.UsedTimeTermIntervals.Count == 0)
     {
         foreach (var timeInterval in _logStore.ActiveTimeIntervals)
         {
             var interval      = GetDateTimeInterval(timeInterval);
             int alreadyWorked = provider.GetTimeUnits(new List <DateTimeInterval> {
                 interval
             });
             _logStore.UsedTimeTermIntervals.Add(new UsedTimeIntervals {
                 TimeInterval       = interval,
                 IntervalStartDate  = interval.Start.ToString(_logStore.UserCulture.DateTimeFormat.ShortDatePattern),
                 CaseStatusName     = timeInterval.CaseStatusName,
                 SpentTimeUnitValue = alreadyWorked
             });
             _logStore.TermTimeRemains -= alreadyWorked;
         }
     }
 }