public HHTTag([CanBeNull] int?pID, [CanBeNull] int?householdTraitID, [CanBeNull] TraitTag tag, [NotNull] string connectionString, [NotNull] string name, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     _tag = tag;
     ID   = pID;
     _householdTraitID = householdTraitID;
     TypeDescription   = "Household Trait Tag";
 }
Esempio n. 2
0
 public HHTemplatePerson([CanBeNull] int?pID, [CanBeNull] Person pPerson, int hhTemplateID, [NotNull] string name,
                         [NotNull] string connectionString, [CanBeNull] TraitTag livingPattern, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     ID              = pID;
     _person         = pPerson;
     _hhTemplateID   = hhTemplateID;
     _livingPattern  = livingPattern;
     TypeDescription = "Household Template Person";
 }
 public ModularHouseholdPerson([CanBeNull] int?pID, [CanBeNull] int?modularHouseholdID, [NotNull] string name, [NotNull] string connectionString,
                               [CanBeNull] Person person, [CanBeNull] TraitTag traitTag, StrGuid guid) : base(name, TableName, connectionString,
                                                                                                              guid)
 {
     _person             = person;
     ID                  = pID;
     _traitTag           = traitTag;
     _modularHouseholdID = modularHouseholdID;
     TypeDescription     = "Modular Household Person";
 }
 public HHTemplateEntry([CanBeNull] int?pID, [CanBeNull] int?householdTemplateId, [NotNull] string name, [NotNull] string connectionString,
                        [CanBeNull] TraitTag tag, int traitCountMin, int traitCountMax, StrGuid guid)
     : base(name, TableName, connectionString, guid)
 {
     _householdTemplateId = householdTemplateId;
     _traitCountMin       = traitCountMin;
     _traitCountMax       = traitCountMax;
     _persons             = new ObservableCollection <HHTemplateEntryPerson>();
     _tag            = tag;
     ID              = pID;
     TypeDescription = "Household Template Entry";
 }
        public void SynchronizeDataFromJson(JsonModularHouseholdPerson json, Simulator sim)
        {
            _person = sim.Persons.FindByGuid(json.Person.Guid);
            if (_person == null)
            {
                throw new LPGException("Person with the guid " + json.Person.Guid + " and the name " + json.Person.Name + " could not be found in the database.");
            }

            if (json.TraitTag != null)
            {
                _traitTag = sim.TraitTags.FindByGuid(json.TraitTag.Guid);
            }
        }
        public JsonDto GetJson()
        {
            JsonDto hhte = new JsonDto(TraitTag.GetJsonReference(), Guid,
                                       TraitCountMax, TraitCountMin, Name)
            {
                Persons = new List <JsonReference>()
            };

            foreach (var person in Persons)
            {
                hhte.Persons.Add(person.Person.GetJsonReference());
            }

            return(hhte);
        }
        private static HHTTag AssignFields([NotNull] DataReader dr, [NotNull] string connectionString, bool ignoreMissingFields,
                                           [NotNull] AllItemCollections aic)
        {
            var hhtTagID         = dr.GetIntFromLong("ID");
            var householdTraitID = dr.GetIntFromLong("HouseholdTraitID");
            var traitTagID       = dr.GetNullableIntFromLong("TraitTagID", false, ignoreMissingFields);

            TraitTag traitTag = null;

            if (traitTagID != null)
            {
                traitTag = aic.TraitTags.FirstOrDefault(x => x.ID == traitTagID);
            }
            var name = "unknown";

            if (traitTag != null)
            {
                name = traitTag.Name;
            }
            var guid = GetGuid(dr, ignoreMissingFields);
            var hhad = new HHTTag(hhtTagID, householdTraitID, traitTag, connectionString, name, guid);

            return(hhad);
        }
        public void ImportFromJsonTemplate([NotNull] JsonModularHousehold jsonHH, [NotNull] Simulator sim)
        {
            Logger.Info("Adjusting values based on Json-Data for " + jsonHH.Name);
            Name         = jsonHH.Name;
            Description  = jsonHH.Description ?? "";
            CreationType = jsonHH.CreationType;
            Guid         = jsonHH.Guid;
            if (jsonHH.DeviceSelection != null)
            {
                var devsel = sim.DeviceSelections.FindByGuid(jsonHH.DeviceSelection.Guid);
                DeviceSelection = devsel ?? throw new LPGException("Could not find the device selection with the guid " + jsonHH.DeviceSelection.Guid + " while importing households");
            }
            EnergyIntensityType = jsonHH.EnergyIntensityType;
            if (jsonHH.Vacation != null)
            {
                var vac = sim.Vacations.FindByGuid(jsonHH.Vacation.Guid);
                Vacation = vac;
            }
            //persons
            SynchronizeList(Persons, jsonHH.Persons, out var personsToCreate);
            foreach (var personJson in personsToCreate)
            {
                var person = sim.Persons.FindByGuid(personJson.Person.Guid);
                if (person == null)
                {
                    throw new LPGException("Person with the guid " + personJson.Person.Guid + " and the name " + personJson.Person.Name + " could not be found in the database.");
                }

                TraitTag tag = null;
                if (personJson.TraitTag != null)
                {
                    tag = sim.TraitTags.FindByGuid(personJson.TraitTag.Guid);
                }
                var hhp = AddPerson(person, tag);
                if (hhp != null)
                {
                    hhp.Guid = personJson.Guid;
                }
            }

            foreach (var person in Persons)
            {
                var jtp = jsonHH.Persons.Single(x => person.Guid == x.Guid);
                person.SynchronizeDataFromJson(jtp, sim);
            }

            //traits
            SynchronizeList(Traits, jsonHH.Traits, out var traitsToCreate);
            foreach (var traitJson in traitsToCreate)
            {
                var trait = sim.HouseholdTraits.FindByGuid(traitJson.HouseholdTrait?.Guid);
                if (trait == null)
                {
                    throw new LPGException("TraitTag " + traitJson.HouseholdTrait + " could not be found in the database.");
                }

                Person person = null;
                if (traitJson.DstPerson != null)
                {
                    person = sim.Persons.FindByGuid(traitJson.DstPerson.Guid);
                    if (person == null)
                    {
                        throw new LPGException("Person " + traitJson.DstPerson + " was not found");
                    }
                }
                var t = AddTrait(trait, traitJson.AssignType, person);
                if (t == null)
                {
                    throw new LPGException("Could not add new trait");
                }
                t.Guid = traitJson.Guid;
            }

            foreach (var trait in Traits)
            {
                var jtp = jsonHH.Traits.Single(x => trait.Guid == x.Guid);
                trait.SynchronizeDataFromJson(jtp, sim);
            }

            //traits
            SynchronizeList(ModularHouseholdTags, jsonHH.HouseholdTags, out var tagsToCreate);
            foreach (var tagJsonRef in tagsToCreate)
            {
                var tag = sim.HouseholdTags.FindByGuid(tagJsonRef.Guid);
                if (tag == null)
                {
                    throw new LPGException("Tag " + tagJsonRef.Name + " could not be found in the database.");
                }
                AddHouseholdTag(tag);
            }

            foreach (var trait in Traits)
            {
                var jtp = jsonHH.Traits.Single(x => trait.Guid == x.Guid);
                trait.SynchronizeDataFromJson(jtp, sim);
            }
            SaveToDB();
        }
        public JsonModularHouseholdPerson GetJson()
        {
            var p = new JsonModularHouseholdPerson(Person.GetJsonReference(), TraitTag?.GetJsonReference(), Guid);

            return(p);
        }