Example #1
0
        public virtual bool ScriptTask1Execute(ProcessExecutingContext context)
        {
            Guid CaseRecordId = default(Guid);

            if (StartSignal1.RecordId != Guid.Empty)
            {
                CaseRecordId = StartSignal1.RecordId;
            }
            if (StartSignal2.RecordId != Guid.Empty)
            {
                CaseRecordId = StartSignal2.RecordId;
            }
            var parameterReader = ClassFactory.Get <CaseCalculationParameterReader>(
                new ConstructorArgument("userConnection", UserConnection));
            var dictionaryParams            = parameterReader.GetParams(CaseRecordId);
            var caseTermCalculateEntryPoint = ClassFactory.Get <CaseTermCalculateEntryPoint>(
                new ConstructorArgument("userConnection", UserConnection));
            ServiceTermResponse response = caseTermCalculateEntryPoint.CalculateTerms(dictionaryParams, UserConnection.CurrentUser.GetCurrentDateTime());
            var    entitySchemaManager   = UserConnection.EntitySchemaManager;
            var    entitySchema          = entitySchemaManager.GetInstanceByName("Case");
            Entity entityCase            = entitySchema.CreateEntity(UserConnection);

            if (entityCase.FetchFromDB(CaseRecordId))
            {
                entityCase.SetColumnValue("SolutionDate", response.SolutionTime);
                entityCase.SetColumnValue("ResponseDate", response.ReactionTime);
                entityCase.Save();
            }
            return(true);
        }
        /// <summary>
        /// Counts reaction time and a solution time to Case.
        /// </summary>
        /// <param name="arguments">Dictionary with params for strategies.</param>
        /// <param name="startDate">Start date for calculation.</param>
        /// <returns>An object that contains the reaction time and solution time.</returns>
        public ServiceTermResponse CalculateTerms(Dictionary <string, object> arguments, DateTime startDate)
        {
            var response          = new ServiceTermResponse();
            var userConnectionArg = new ConstructorArgument("userConnection", UserConnection);
            var argumentsArg      = new ConstructorArgument("arguments", arguments);
            var selector          = ClassFactory.Get <CaseTermIntervalSelector>(userConnectionArg);
            var termInterval      = selector.Get(arguments) as CaseTermInterval;
            var mask = termInterval.GetMask();

            if (mask != CaseTermStates.None)
            {
                var intervalReader = ClassFactory.Get <CaseActiveIntervalReader>(userConnectionArg, argumentsArg);
                var userTimeZone   = UserConnection.CurrentUser.TimeZone;
                IEnumerable <DateTimeInterval> intervals = intervalReader.GetActiveIntervals();
                if (intervals.IsEmpty())
                {
                    response = ExecuteCalculateTerms(startDate, termInterval, userTimeZone, mask);
                }
                else
                {
                    var dateTime = ConvertFromUtc(DateTime.UtcNow, userTimeZone);
                    response = ExecuteRecalculateTerms(dateTime, termInterval, intervals, userTimeZone, mask);
                }
            }
            return(response);
        }
Example #3
0
        public string CalculateTerms(Dictionary <string, object> arguments, string registrationDate)
        {
            Dictionary <string, object> featuredDictionary = GetDictionaryWithGuids(arguments);
            var parsedRegistrationDate = DateTime.Parse(registrationDate);
            var stringResponse         = new ServiceTermStringResponse();

            try
            {
                var userConnectionArg = new ConstructorArgument("userConnection", UserConnection);
                var entryPoint        = ClassFactory.Get <CaseTermCalculateEntryPoint>(userConnectionArg);
                //ServiceTermResponse response = entryPoint.CalculateTerms(featuredDictionary, parsedRegistrationDate);
                ServiceTermResponse response = CalculateTerms(featuredDictionary, parsedRegistrationDate);
                if (response.ReactionTime != null)
                {
                    stringResponse.ReactionTime = response.ReactionTime.Value.ToString(_dateFormat);
                }
                if (response.SolutionTime != null)
                {
                    stringResponse.SolutionTime = response.SolutionTime.Value.ToString(_dateFormat);
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            return(JsonConvert.SerializeObject(stringResponse));
        }
        private ServiceTermResponse ExecuteCalculateTerms(DateTime startDate, CaseTermInterval termInterval,
                                                          TimeZoneInfo userTimeZone, CaseTermStates mask)
        {
            var calendarutility = new CalendarUtility(UserConnection);
            var response        = new ServiceTermResponse();

            response.ReactionTime = mask.HasFlag(CaseTermStates.ContainsResponse)
                                ? calendarutility.Add(startDate, termInterval.ResponseTerm, userTimeZone) as DateTime?
                                : null;
            response.SolutionTime = mask.HasFlag(CaseTermStates.ContainsResolve)
                                ? calendarutility.Add(startDate, termInterval.ResolveTerm, userTimeZone) as DateTime?
                                : null;
            return(response);
        }
        private ServiceTermResponse ExecuteRecalculateTerms(DateTime startDate, CaseTermInterval termInterval,
                                                            IEnumerable <DateTimeInterval> intervals, TimeZoneInfo userTimeZone, CaseTermStates mask)
        {
            var calendarutility = new CalendarUtility(UserConnection);
            var response        = new ServiceTermResponse();
            var dateTime        = ConvertFromUtc(DateTime.UtcNow, userTimeZone);

            response.ReactionTime = mask.HasFlag(CaseTermStates.ContainsResponse)
                                ? calendarutility.Add(dateTime, termInterval.ResponseTerm, intervals, userTimeZone) as DateTime?
                                : null;
            response.SolutionTime = mask.HasFlag(CaseTermStates.ContainsResolve)
                                ? calendarutility.Add(dateTime, termInterval.ResolveTerm, intervals, userTimeZone) as DateTime?
                                : null;
            return(response);
        }
        /// <summary>
        /// Start calculation reaction time and a solution time to Case.
        /// </summary>
        /// <param name="arguments">Dictionary with params for strategies.</param>
        /// <param name="startDate">Start date for calculation.</param>
        /// <returns></returns>
        public ServiceTermResponse ForceCalculateTerms(Dictionary <string, object> arguments, DateTime startDate)
        {
            var response          = new ServiceTermResponse();
            var userConnectionArg = new ConstructorArgument("userConnection", UserConnection);
            var argumentsArg      = new ConstructorArgument("arguments", arguments);
            var selector          = ClassFactory.Get <CaseTermIntervalSelector>(userConnectionArg);
            var termInterval      = selector.Get(arguments) as CaseTermInterval;
            var mask = termInterval.GetMask();

            if (mask != CaseTermStates.None)
            {
                var userTimeZone = UserConnection.CurrentUser.TimeZone;
                response = ExecuteCalculateTerms(startDate, termInterval, userTimeZone, mask);
            }
            return(response);
        }
Example #7
0
        public ServiceTermResponse CalculateTerms(Dictionary <string, object> arguments, DateTime startDate)
        {
            var response          = new ServiceTermResponse();
            var userConnectionArg = new ConstructorArgument("userConnection", UserConnection);
            var argumentsArg      = new ConstructorArgument("arguments", arguments);
            var selector          = ClassFactory.Get <CaseTermIntervalSelector>(userConnectionArg);
            //var termInterval = selector.Get(arguments) as CaseTermInterval;
            var termInterval = new CaseTermInterval();

            var d = "";

            termInterval.ResolveTerm            = new TimeTerm();
            termInterval.ResolveTerm.CalendarId = new Guid("F0FF1F0E-F46B-1410-1787-0026185BFCD3");
            termInterval.ResolveTerm.Type       = TimeUnit.WorkingHour;
            termInterval.ResolveTerm.Value      = 1;
            var mask = termInterval.GetMask();
            var intervalResolveTerm = 0;
            var procent             = 0;
            var userTimeZone        = UserConnection.CurrentUser.TimeZone;

            if (mask != CaseTermStates.None)
            {
                var intervalReader = ClassFactory.Get <CaseActiveIntervalReader>(userConnectionArg, argumentsArg);

                IEnumerable <DateTimeInterval> intervals = intervalReader.GetActiveIntervals();
                if (intervals.IsEmpty())
                {
                    //termInterval.ResolveTerm.Value = 10;
                    response = ExecuteCalculateTerms(startDate, termInterval, userTimeZone, mask);
                }
                else
                {
                    var dateTime = ConvertFromUtc(DateTime.UtcNow, userTimeZone);
                    response = ExecuteRecalculateTerms(dateTime, termInterval, intervals, userTimeZone, mask);
                }
            }
            //поиск порядка уведомлений ICLTimeToNotifyDic
            var caseId    = Guid.Parse(arguments["CaseId"].ToString());
            var accountId = Guid.Parse(arguments["AccountId"].ToString());
            var del       = new Delete(UserConnection).From("ICLCaseReminder")
                            .Where("ICLCaseId").IsEqual(new QueryParameter(caseId)) as Delete;

            del.Execute();
            if (termInterval.ResolveTerm.Type == TimeUnit.WorkingHour || termInterval.ResolveTerm.Type == TimeUnit.Hour)
            {
                intervalResolveTerm = termInterval.ResolveTerm.Value * 60;//минуты
            }
            if (termInterval.ResolveTerm.Type == TimeUnit.WorkingDay || termInterval.ResolveTerm.Type == TimeUnit.Day)
            {
                intervalResolveTerm = termInterval.ResolveTerm.Value * 60 * 24;//минуты
            }
            if (termInterval.ResolveTerm.Type == TimeUnit.WorkingMinute || termInterval.ResolveTerm.Type == TimeUnit.Minute)
            {
                intervalResolveTerm = termInterval.ResolveTerm.Value;//минуты
            }
            termInterval.ResolveTerm.Type = TimeUnit.WorkingMinute;

            var collnotify = FindCollectionTimeNotify(accountId);

            foreach (ICLTimeToNotifyDic notify in collnotify)
            {
                //проценты
                if (notify.ICLUnitId.Equals(new Guid("7a5e5d2d-7400-4469-9674-3a74d6b32de4")))
                {
                    termInterval.ResolveTerm.Value = intervalResolveTerm * notify.ICLValue / 100;
                }
                else
                {
                    termInterval.ResolveTerm.Value = notify.ICLValue;
                }
                var notifyTime = ExecuteCalculateTerms(startDate, termInterval, userTimeZone, mask);

                ICLCaseReminder iclCaseReminder = new ICLCaseReminder(UserConnection);
                iclCaseReminder.SetDefColumnValues();
                iclCaseReminder.ICLCaseId     = caseId;
                iclCaseReminder.ICLTimeSend   = notifyTime.SolutionTime.GetValueOrDefault();
                iclCaseReminder.ICLTimeRuleId = notify.Id;
                if (iclCaseReminder.ICLTimeSend < ConvertFromUtc(DateTime.UtcNow, userTimeZone))
                {
                    iclCaseReminder.ICLStatusId = new Guid("095CB711-8480-4EA5-9D25-E567648A3255"); //просрочена
                }
                else
                {
                    iclCaseReminder.ICLStatusId = new Guid("be9c92ca-b092-4950-8548-bb2160a61f8b");//не начата
                }
                iclCaseReminder.ICLOverTimeSolution = intervalResolveTerm - termInterval.ResolveTerm.Value;
                iclCaseReminder.Save();
            }
            return(response);
        }