Пример #1
0
 /// <summary>
 /// Handle recurring regular tasks
 /// </summary>
 public void OnTick()
 {
     if (TickCount++ >= TickInterval)
     {
         Logger.LogInformation("Running generators");
         TickCount = 0;
         var generatorItemDatas = GeneratorItemDataRepo.ReadReadyToRun();
         if (generatorItemDatas.Count > 0)
         {
             generatorItemDatas.ForEach((generatorItemData) =>
             {
                 try
                 {
                     var item   = JsonConvert.DeserializeObject <Item>(generatorItemData.Json);
                     var parent = ModuleManager.GetManager <IItemManager>().Read(item.ParentId.Value);
                     if (parent.Children?.Count(x => x.TypeId == item.TypeId) < generatorItemData.Maximum)
                     {
                         Logger.LogDebug($"Generating {item.GetProperty<VisibleItemProperty>()?.Name ?? item.Id.ToString()}");
                         ModuleManager.GetManager <IItemManager>().Create(item);
                     }
                 }
                 catch (Exception e)
                 {
                     ModuleManager.GetLogger().LogException("Failed to generate item", e);
                 }
                 finally
                 {
                     generatorItemData.IntervalTime = DateTime.Now
                                                      .AddMilliseconds(generatorItemData.Interval * TickTime);
                 }
             });
             GeneratorItemDataRepo.Update(generatorItemDatas);
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Append attribute to base item when it is loaded
 /// </summary>
 /// <param name="item">Base item about to be persisted to datastore</param>
 public void OnItemUpdate(Item item)
 {
     if (item.HasData <GeneratorItemData>())
     {
         var data = item.GetData <GeneratorItemData>();
         if (data.Id == Guid.Empty)
         {
             OnItemCreate(item);
         }
         else
         {
             GeneratorItemDataRepo.Update(data);
         }
     }
 }