コード例 #1
0
ファイル: SessionDto.cs プロジェクト: sr-2020/Billing
 public BeatItemsDto(BillingBeat beat, List <CorporationDto> corporations, List <ShopDto> shops)
     : base(beat)
 {
     if (beat == null || corporations == null)
     {
         return;
     }
     Corporations = corporations;
     ShopsSum     = shops.Sum(s => s.Balance);
 }
コード例 #2
0
ファイル: SessionDto.cs プロジェクト: sr-2020/Billing
 public BeatDto(BillingBeat beat)
 {
     if (beat == null)
     {
         return;
     }
     Number     = beat.Number;
     StartTime  = beat.StartTime;
     FinishTime = beat.FinishTime;
 }
コード例 #3
0
ファイル: SessionDto.cs プロジェクト: sr-2020/Billing
 public BeatCharactersDto(BillingBeat beat, JobLifeStyleDto ls)
     : base(beat)
 {
     if (beat == null || ls == null)
     {
         return;
     }
     SumAll         = ls.SumAll;
     ForecastSumAll = ls.ForecastSumAll;
     Min            = ls.Min;
     ForecastMin    = ls.ForecastMin;
     Max            = ls.Max;
     ForecastMax    = ls.ForecastMax;
     SumRents       = ls.SumRents;
     SumKarma       = ls.SumKarma;
     SumDividends   = ls.SumDividends;
     Insolvent      = ls.Insolvent;
     Irridium       = ls.Irridium;
     Count          = ls.Count;
 }
コード例 #4
0
ファイル: JobLifeService.cs プロジェクト: sr-2020/Billing
        public string DoBeat(BeatTypes type = BeatTypes.Test, string token = "", bool wait = false)
        {
            var cycle = Factory.Job.GetLastCycle(token);

            if (!cycle.IsActive || cycle == null)
            {
                return("цикл не запущен");
            }
            if (type == BeatTypes.Characters)
            {
                if (!Factory.Job.BlockBilling())
                {
                    throw new BillingException(BillingException);
                }
            }
            var task = Task.Run(() =>
            {
                try
                {
                    var beat          = Factory.Job.GetLastBeatAsNoTracking(cycle.Id, type);
                    var newBeat       = new BillingBeat();
                    newBeat.Number    = beat != null ? beat.Number + 1 : 1;
                    newBeat.StartTime = DateTime.Now.ToUniversalTime();
                    newBeat.CycleId   = cycle.Id;
                    newBeat.BeatType  = (int)type;
                    Factory.Job.AddAndSave(newBeat);
                    var dto = new JobLifeDto
                    {
                        Beat = newBeat
                    };
                    switch ((BeatTypes)newBeat.BeatType)
                    {
                    case BeatTypes.Test:
                        dto.AddHistory("test beat");
                        break;

                    case BeatTypes.Items:
                        dto = DoItemsBeat(dto);
                        break;

                    case BeatTypes.Characters:
                        dto = DoCharactersBeat(dto);
                        break;

                    default:
                        dto.AddHistory("unknown beat type");
                        break;
                    }
                    dto.Beat.FinishTime = DateTime.Now.ToUniversalTime();
                    Factory.Job.AddAndSave(dto.Beat);
                    Factory.Job.AddRangeAndSave(dto.History);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.ToString());
                    throw;
                }
                finally
                {
                    if (type == BeatTypes.Characters)
                    {
                        if (!Factory.Job.UnblockBilling())
                        {
                            throw new Exception("Биллинг был разблокирован раньше времени");
                        }
                    }
                }
            });

            if (wait)
            {
                task.Wait();
            }
            return($"Пересчет для {cycle.Token}_{cycle.Number} запущен ");
        }