Exemple #1
0
        public void Update(RobotTemplate template)
        {
            var descriptionString = GenxyConverter.Serialize(template.ToDictionary());

            Db.Query().CommandText("update robottemplates set name=@name,description=@description where id=@id")
            .SetParameter("@id", template.ID)
            .SetParameter("@name", template.Name)
            .SetParameter("@description", descriptionString)
            .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLUpdateError);
        }
Exemple #2
0
        public void Insert(RobotTemplate template)
        {
            var descriptionString = GenxyConverter.Serialize(template.ToDictionary());

            var id = Db.Query().CommandText("insert robottemplates (name,description) values (@name,@description); select cast(scope_identity() as integer)")
                     .SetParameter("@name", template.Name)
                     .SetParameter("@description", descriptionString)
                     .ExecuteScalar <int>().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            template.ID = id;
        }
        public void Init()
        {
            var records = Db.Query().CommandText("select * from robottemplaterelation").Execute();

            foreach (var record in records)
            {
                var relation = CreateRobotTemplateRelationFromRecord(record);
                _relations[relation.EntityDefault.Definition] = relation;
            }
            _equippedDefault   = _robotTemplateReader.GetByName("starter_master");
            _unequippedDefault = _robotTemplateReader.GetByName("arkhe_empty");
        }
Exemple #4
0
        private static RobotTemplate CreateRobotTemplateFromRecord(IDataRecord record)
        {
            var id          = record.GetValue <int>("id");
            var name        = record.GetValue <string>("name");
            var description = record.GetValue <string>("description");
            var dictionary  = GenxyConverter.Deserialize(description);
            var template    = RobotTemplate.CreateFromDictionary(name, dictionary);

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

            template.ID = id;
            return(template);
        }
Exemple #5
0
        public static RobotTemplate CreateFromDictionary(string name, IDictionary <string, object> dictionary)
        {
            if (dictionary == null)
            {
                return(null);
            }

            var template = new RobotTemplate(name)
            {
                EntityDefault = EntityDefault.Get(dictionary.GetOrDefault(k.robot, 0)),
                Head          = RobotComponentTemplate <RobotHead> .Create(dictionary.GetOrDefault(k.head, 0), ModulesFromDictionary(dictionary, k.headModules)),
                Chassis       = RobotComponentTemplate <RobotChassis> .Create(dictionary.GetOrDefault(k.chassis, 0), ModulesFromDictionary(dictionary, k.chassisModules)),
                Leg           = RobotComponentTemplate <RobotLeg> .Create(dictionary.GetOrDefault(k.leg, 0), ModulesFromDictionary(dictionary, k.legModules)),
                Inventory     = RobotInventoryTemplate.Create(dictionary.GetOrDefault(k.container, 0), ItemsFromDictionary(dictionary, k.items))
            };

            return(template);
        }
Exemple #6
0
 public void Delete(RobotTemplate item)
 {
     DeleteByID(item.ID);
 }