示例#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();
            }
        }