public static Dictionary <string, object> Build(IExtensionReader extensionReader, IRobotTemplateRelations robotTemplateRelations, EntityDefault ed)
            {
                var info = ed.ToDictionary();

                try
                {
                    Entity entity = null;

                    var robotTemplate = robotTemplateRelations.GetRelatedTemplate(ed);
                    if (robotTemplate != null)
                    {
                        entity = robotTemplate.Build();
                    }

                    if (entity == null)
                    {
                        entity = Entity.Factory.CreateWithRandomEID(ed);
                    }

                    var item = entity as Item;
                    item?.Initialize();

                    var builder = new InfoBuilder(extensionReader, info);
                    entity.AcceptVisitor(builder);
                }
                catch (Exception ex)
                {
                    Logger.Error($"troubled definition: {ed.Definition}  {ex.Message}");
                    Logger.Error($"{ex}\n{ex.Message}\n{ex.Source}\n{ex.InnerException?.Message}\n{ex.StackTrace}\n");
                }

                return(info);
            }
        public void WriteRobotPrices()
        {
            foreach (var ed in _entityDefaultReader.GetAll().GetByCategoryFlags(CategoryFlags.cf_robots))
            {
                var robotTemplate = _robotTemplateRelations.GetRelatedTemplate(ed);
                if (robotTemplate == null)
                {
                    continue;
                }

                var robot = robotTemplate.Build();

                var avg = PriceCalculator.GetAveragePrice(robot);
                if (avg <= 0)
                {
                    continue;
                }

                var res = Db.Query().CommandText("insert marketaveragesbycomponent (definition,price) values (@definition,@price)")
                          .SetParameter("@definition", ed.Definition)
                          .SetParameter("@price", avg)
                          .ExecuteNonQuery();

                if (res != 1)
                {
                    Logger.Error("error in WriteRobotPrices");
                    return;
                }
            }
        }
        public static RobotTemplate GetRelatedTemplateOrDefault(this IRobotTemplateRelations relations, int definition)
        {
            var template = relations.GetRelatedTemplate(definition);

            if (template != null)
            {
                return(template);
            }

            Logger.Warning("robot template was not found for definition: " + definition + ", falling back to starter_master.");
            //fallback to arkhe
            return(relations.EquippedDefault);
        }
 public static RobotTemplate GetRelatedTemplate(this IRobotTemplateRelations relations, EntityDefault ed)
 {
     return(relations.GetRelatedTemplate(ed.Definition));
 }