Пример #1
0
        private void start(Period currentPeriod, Period sourcePeriod, IEventPublisher publisher)
        {
            basicDataCopyingProgress.State = new PeriodBasicDataCopying();
            basicDataCopyingProgress.Messages.Add("شروع کپی دوره");
            var preState = currentPeriod.State;
            publisher.OnHandlerError(exp => { basicDataCopyingProgress.Messages.Add(exp.Message); });
            copyCompletedSub = new DelegateHandler<CopyBasicDataCompleted>(
                p =>
                {
                    var srvManagerPeriod = periodServiceFactory.Create();
                    try
                    {
                        var ps = srvManagerPeriod.GetService();
                        ps.CompleteCopyingBasicData(currentPeriod.Id, preState);
                    }
                    finally
                    {
                        IsCopying = false;
                        basicDataCopyingProgress = new BasicDataCopyingProgress();
                        periodServiceFactory.Release(srvManagerPeriod);
                    }
                });
            publisher.RegisterHandler(copyCompletedSub);

            try
            {
                BasicDataCopyingProgress.SetProgress(100, 5);
                deleteAllPeriodData(currentPeriod);
                basicDataCopyingProgress.Messages.Add("اطلاعات پایه پیشین پاک شد.");

                basicDataCopyingProgress.SetProgress(100, 25);
                copyUnits(sourcePeriod, currentPeriod);
                basicDataCopyingProgress.Messages.Add("کپی واحد های سازمانی انجام شد.");


                basicDataCopyingProgress.SetProgress(100, 35);
                copyPeriodJobIndices(sourcePeriod, currentPeriod);
                basicDataCopyingProgress.Messages.Add("کپی شاخص ها انجام شد.");

                basicDataCopyingProgress.SetProgress(100, 45);
                copyJobs(sourcePeriod, currentPeriod);
                basicDataCopyingProgress.Messages.Add("کپی شغل ها انجام شد.");
                basicDataCopyingProgress.SetProgress(100, 65);

                copyJobPositions(sourcePeriod, currentPeriod);
                basicDataCopyingProgress.Messages.Add("کپی پست ها انجام شد.");
                basicDataCopyingProgress.SetProgress(100, 100);
                basicDataCopyingProgress.Messages.Add("اتمام عملیات کپی دوره.");
                lastPeriod=new KeyValuePair<PeriodId,List<string>>(currentPeriod.Id, basicDataCopyingProgress.Messages);
                publisher.Publish(new CopyBasicDataCompleted(currentPeriod,preState));
            }
            catch (Exception ex)
            {
                basicDataCopyingProgress.Messages.Add("خطا در کپی اطلاعات " + ex.Message);
                var logServiceMngt = LogServiceFactory.Create();
                try
                {
                    var logService = logServiceMngt.GetService();
                    logService.AddEventLog("Copy Exception",
                        LogLevel.Error,
                        null, this.GetType().Name, "start", ex.Message, ex.StackTrace);
                    logService.AddExceptionLog(ex);
                }
                finally
                {
                    LogServiceFactory.Release(logServiceMngt);
                }
                IsCopying = false;
                basicDataCopyingProgress = new BasicDataCopyingProgress();
            }
        }
Пример #2
0
        public void Configure(Period period, IEventPublisher publisher)
        {
            if (!IsRunning)
            {
                isRunning = true;
                inquiryInitializingProgress.State = new PeriodInitializingForInquiryState();
                inquiryInitializingProgress.Messages.Add("شروع آماده سازی دوره");

                #region JobPosition

                var jobPositionIds = new List <JobPositionId>();
                var srvManagerJob  = jobPositionServiceFactory.Create();
                try
                {
                    var jpService = srvManagerJob.GetService();
                    jobPositionIds = jpService.GetAllJobPositionId(period);
                }
                catch (Exception exp)
                {
                    isRunning = false;
                    inquiryInitializingProgress.State = new PeriodInitializingForInquiryState();
                    throw exp;
                }
                finally
                {
                    jobPositionServiceFactory.Release(srvManagerJob);
                }

                var jobPositionTotalCount = jobPositionIds.Count();

                #endregion

                #region Unit

                var unitIds        = new List <UnitId>();
                var srvManagerUnit = unitServiceFactory.Create();
                try
                {
                    var uService = srvManagerUnit.GetService();
                    unitIds = uService.GetAllUnitId(period);
                }
                catch (Exception exp)
                {
                    isRunning = false;
                    inquiryInitializingProgress.State = new PeriodInitializingForInquiryState();
                    throw exp;
                }
                finally
                {
                    unitServiceFactory.Release(srvManagerUnit);
                }

                var unitTotalCount = unitIds.Count();

                #endregion

                inquiryInitializingProgress.Messages.Add("تعداد " + jobPositionTotalCount + " پست برای پیکر بندی نظر سنجی آماده می باشد");
                inquiryInitializingProgress.Messages.Add("تعداد " + unitTotalCount + " واحد برای پیکر بندی نظر سنجی آماده می باشد");

                var totalCount = jobPositionTotalCount + unitTotalCount;

                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        #region JobPosition

                        long jobPositionIndex = 0;
                        foreach (var jobPositionId in jobPositionIds)
                        {
                            JobPosition jobPosition;
                            var srvManagerJobPosition = jobPositionServiceFactory.Create();
                            try
                            {
                                var jps     = srvManagerJobPosition.GetService();
                                jobPosition = jps.ConfigureInquiry(jobPositionId, true);
                                var dummy   = jobPosition.ConfigurationItemList;
                            }
                            finally
                            {
                                jobPositionServiceFactory.Release(srvManagerJobPosition);
                            }


                            foreach (var itm in jobPosition.ConfigurationItemList)
                            {
                                var srvManagerInquiry = inquiryServiceFactory.Create();

                                try
                                {
                                    var iqs = srvManagerInquiry.GetService();
                                    iqs.CreateAllInquiryJobIndexPoint(itm);
                                }
                                finally
                                {
                                    inquiryServiceFactory.Release(srvManagerInquiry);
                                }
                            }
                            jobPositionIndex++;
                            inquiryInitializingProgress.SetProgress(totalCount, jobPositionIndex);
                        }

                        #endregion

                        #region Unit

                        long unitIndex = 0;
                        foreach (var unitId in unitIds)
                        {
                            Unit unit;
                            var srvManagerUnitInquiry = unitServiceFactory.Create();
                            try
                            {
                                var us    = srvManagerUnitInquiry.GetService();
                                unit      = us.GetUnitBy(unitId);
                                var dummy = unit.ConfigurationItemList;
                            }
                            finally
                            {
                                unitServiceFactory.Release(srvManagerUnitInquiry);
                            }


                            foreach (var itm in unit.ConfigurationItemList)
                            {
                                var srvManagerUnitInquiry2 = unitInquiryServiceFactory.Create();

                                try
                                {
                                    var iqs = srvManagerUnitInquiry2.GetService();
                                    iqs.CreateAllInquiryUnitIndexPoint(itm);
                                }
                                finally
                                {
                                    unitInquiryServiceFactory.Release(srvManagerUnitInquiry2);
                                }
                            }
                            unitIndex++;
                            inquiryInitializingProgress.SetProgress(totalCount, unitIndex);
                        }

                        #endregion

                        inquiryInitializingProgress.Messages.Add("اتمام آماده سازی دوره برای نظر سنجی");

                        var serviceManager = periodServiceFactory.Create();
                        try
                        {
                            var ps = serviceManager.GetService();
                            ps.CompleteInitializeInquiry(period.Id);
                        }
                        catch (Exception exp)
                        {
                            throw exp;
                        }
                        finally
                        {
                            isRunning = false;
                            inquiryInitializingProgress = new InquiryInitializingProgress();
                            periodServiceFactory.Release(serviceManager);
                        }
                    }
                    catch (Exception exp)
                    {
                        isRunning = false;
                        inquiryInitializingProgress.State = new PeriodInitializingForInquiryState();
                        throw exp;
                    }
                });
            }
        }