Пример #1
0
 /// <summary>
 /// اجرای محاسبات برای یک نفر
 /// </summary>
 /// <param name="personId">شناسه شخص</param>
 /// <param name="todate">انتهای بازه ی محاسبات</param>
 public void Execute(string CallerIdentity, decimal personId, DateTime toDate)
 {
     try
     {
         ExecutablePersonCalculation MustExecuted = ExecutablePersonCalculation.GetExecutablePersonCalcRepositoy(false).GetByPrsId(personId, toDate);
         ThreadHelper.CleanupThreads();
         logger.Logger.Info(
             string.Format("Execute for person '{0}' start at '{1}', Total Thread Count: '{2}', Runing Thread Count: '{3}'", personId.ToString()
                           , DateTime.Now.ToShortDateString()
                           , ThreadHelper.TotalThreadCount
                           , ThreadHelper.TotalExecutingThreadCount));
         logger.Flush();
         if (MustExecuted != null /*&& !MustExecuted.CalculationIsValid*/)
         {
             MustExecuted.ToDate = toDate;
             ExecutableThread.ThreadParam param = ThreadHelper.ForceToExecute(CallerIdentity, MustExecuted, this.FinishedCallback);
             if (param != null)
             {
                 this.Execute(param);
             }
         }
     }
     catch (BaseException ex)
     {
         throw ex;
     }
 }
Пример #2
0
        /// <summary>
        /// تاریخ آخرین زمان محاسبات پرسنلی که محاسبه برای وی انجام شده است را بروزرسانی می نماید
        /// </summary>
        /// <param name="InvalidCalcResult"></param>
        private void UpdateExecutablePersonCalculation(decimal ExecutablePrsCalcId, decimal PersonId, DateTime ToDate)
        {
            ExecutablePersonCalculation ExecPrsCalc = ExecutablePersonCalculation.GetExecutablePersonCalcRepositoy(false).GetById(ExecutablePrsCalcId, false);

            if (ExecPrsCalc != null)
            {
                ExecPrsCalc.FromDate           = ToDate;
                ExecPrsCalc.CalculationIsValid = true;
                ExecPrsCalc.MidNightCalculate  = true;
                ExecutablePersonCalculation.GetExecutablePersonCalcRepositoy(false).WithoutTransactUpdate(ExecPrsCalc);
            }
            else
            {
                gtsRuleLogger.Error(PersonId.ToString(), "This is a test log", new Exception());
                gtsRuleLogger.Flush();
            }
        }
Пример #3
0
        /// <summary>
        /// این تابع وظیفه اجرای قوانین برای تماممی اشخاص شده در پارامتر تا تاریخ ورودی را برعهده دارد
        /// </summary>
        /// <param name="Persons"></param>
        /// <param name="Date"></param>
        public void Execute(string CallerIdentity, IList <decimal> Persons, DateTime toDate)
        {
            try
            {
                IList <ExecutablePersonCalculation> MustExecuted = ExecutablePersonCalculation.GetExecutablePersonCalcRepositoy(false).GetAllByPrsIds(Persons, toDate);
                ThreadHelper.CleanupThreads();
                IList <ExecutablePersonCalculation> Threads = ThreadHelper.AddThreads(CallerIdentity, MustExecuted, this.FinishedCallback);
                logger.Logger.Info(
                    string.Format("Execute all start at '{0}', Total Thread Count: '{1}', Executable Thread Count: '{2}', Runing Thread Count: '{3}'", DateTime.Now.ToShortDateString()
                                  , ThreadHelper.TotalThreadCount
                                  , ThreadHelper.TotalThreadCount - ThreadHelper.TotalExecutingThreadCount
                                  , ThreadHelper.TotalExecutingThreadCount));
                logger.Flush();

                IList <Action> actions = new List <Action>();

                foreach (ExecutablePersonCalculation item in Threads /*.Where(x => x.CalculationIsValid == false)*/)
                {
                    item.ToDate = toDate;
                    ExecutableThread.ThreadParam param = ThreadHelper.PrepareToExecute(CallerIdentity, item);
                    if (param != null)
                    {
                        //ThreadPool.QueueUserWorkItem(new WaitCallback(this.Execute), param);
                        actions.Add(() => this.Execute(param));
                    }
                }
                Task.Factory.StartNew(() => Parallel.Invoke(
                                          new ParallelOptions()
                {
                    MaxDegreeOfParallelism = MaxThread
                },
                                          actions.ToArray()));
            }
            catch (Exception ex)
            {
                logger.Error("Execute(string CallerIdentity, IList<decimal> Persons, DateTime toDate)->", "" + ex.Message, ex);
                logger.Flush();
                throw ex;
            }
        }
Пример #4
0
        /// <summary>
        /// این تابع وظیفه اجرای قوانین برای تماممی اشخاصی که محاسباتشان نامعتبر است را برعهده دارد
        /// همجنین تنها توسط سرویس ویندوزی اجرا میگردد
        /// </summary>
        /// <param name="toDate"></param>
        public void ExecuteByRobot(string CallerIdentity, DateTime toDate)
        {
            try
            {
                IList <ExecutablePersonCalculation> MustExecuted = ExecutablePersonCalculation.GetExecutablePersonCalcRepositoy(false).GetAll(toDate);
                ThreadHelper.CleanupThreads();
                IList <ExecutablePersonCalculation> Threads = ThreadHelper.AddThreads(CallerIdentity, MustExecuted, this.FinishedCallback);
                logger.Logger.Info(
                    string.Format("ExecuteByRobot start at '{0}', Total Thread Count: '{1}', Executable Thread Count: '{2}', Runing Thread Count: '{3}'", DateTime.Now.ToShortDateString()
                                  , ThreadHelper.TotalThreadCount
                                  , ThreadHelper.TotalThreadCount - ThreadHelper.TotalExecutingThreadCount
                                  , ThreadHelper.TotalExecutingThreadCount));
                logger.Flush();


                IList <Action> actions         = new List <Action>();
                int            threadGroupSize = Threads.Count / MaxThread;
                if (Threads.Count % MaxThread > 0)
                {
                    MaxThread++;
                }
                var groupThreadParams = new ExecutableThread.GroupThreadParam[MaxThread];
                for (int i = 0; i < MaxThread; i++)
                {
                    //if (Utility.CpuUsage < MaxCPUUsage)
                    //{
                    groupThreadParams[i] = new ExecutableThread.GroupThreadParam();
                    Threads.Skip(threadGroupSize * i).Take(threadGroupSize).ToList().ForEach((item) =>
                    {
                        item.ToDate = toDate;
                        var param   = ThreadHelper.PrepareToExecute(CallerIdentity, item);
                        if (param != null)
                        {
                            param.ExecuteByRobot = true;
                            groupThreadParams[i].ThreadParams.Add(param);
                        }
                    });
                    //}
                    //else
                    //{
                    //    cpuUsageExtraCount++;
                    //    ThreadHelper.RemoveThread(CallerIdentity, item.PersonId);
                    //}
                }

                groupThreadParams.ToList().ForEach((threadParams) => {
                    Task.Factory.StartNew(() => { ExecuteGroup(threadParams); });
                });
                //Task.Factory.StartNew(() => Parallel.Invoke(
                //                           new ParallelOptions() { MaxDegreeOfParallelism = MaxThread },
                //                           actions.ToArray()));

                //if (cpuUsageExtraCount > 0)
                //{
                //    logger.Info("ExecuteByRobot", String.Format("عدم اجرا تعداد {0} نفر بدلیل محدودیت پردازنده", cpuUsageExtraCount.ToString()));
                //    logger.Flush();
                //}
            }
            catch (Exception ex)
            {
                logger.Error("ExecuteByRobot", "Eception on ExecuteByRobot : " + Utility.GetExecptionMessage(ex), ex);
                logger.Flush();
            }
        }