internal Context Copy() { Context ctx = new Context() { Name = this.Name }; Entites.ForEach((t) => { EntityClass entity = new EntityClass() { Name = t.Name, EntityType = t.EntityType, PrimaryKey = t.PrimaryKey, }; entity.Validators.AddRange(t.Validators); entity.Attributes.AddRange(t.Attributes); t.SynchronizedCollection.Keys.ToList().ForEach((s) => { entity.SynchronizedCollection.Add(s, new List <string>(t.SynchronizedCollection[s])); }); ctx.Entites.Add(entity); }); Relations.ForEach((r) => { EntitiesRelation relation = new EntitiesRelation() { Ordinal = r.Ordinal, Name = r.Name, Parent = new EntityRelated() { EntityName = r.Parent.EntityName, Key = r.Parent.Key, Type = r.Parent.Type, Value = r.Parent.Value }, Child = new EntityRelated() { EntityName = r.Child.EntityName, Key = r.Child.Key, Type = r.Child.Type, Value = r.Child.Value }, OnDelete = r.OnDelete }; ctx.Relations.Add(relation); relation.Parent.Entity = ctx.Entites.FirstOrDefault(t => t.Name == r.Parent.EntityName); relation.Child.Entity = ctx.Entites.FirstOrDefault(t => t.Name == r.Child.EntityName); }); ctx.Entites.ForEach((t) => { EntityClass entity = Entites.FirstOrDefault(e => e.Name == t.Name); Debug.Assert(entity.IsNotNull(), "Somthing gone wrrong"); entity.Properties.ForEach((p) => { EntityProperty property = new EntityProperty() { Name = p.Name, PropertyType = p.PropertyType, PrimaryKey = p.PrimaryKey, DefaultValue = p.DefaultValue, Setter = p.Setter, Getter = p.Getter }; if (p.ReletedEntity.IsNotNull()) { property.ReletedEntity = new ReletedEntity() { Related = p.ReletedEntity.Related, RelatedEntity = ctx.Entites.FirstOrDefault(e => e.Name == p.ReletedEntity.RelatedEntityName), RelatedEntityName = p.ReletedEntity.RelatedEntityName, Relation = ctx.Relations.FirstOrDefault(r => r.Ordinal == p.ReletedEntity.Relation.Ordinal), RelationName = p.ReletedEntity.RelationName }; property.ReletedEntity.Discriminators.AddRange(p.ReletedEntity.Discriminators); } property.Validators.AddRange(p.Validators); property.Attibutes.AddRange(p.Attibutes); p.Formatters.Keys.ToList().ForEach((k) => property.Formatters.Add(k, p.Formatters[k])); t.Properties.Add(property); }); if (entity.PrimaryKeyProperty.IsNotNull()) { t.PrimaryKeyProperty = t.Properties.FirstOrDefault(p => p.Name == entity.PrimaryKeyProperty.Name); } if (entity.DynamicProperties.IsNotNull()) { t.DynamicProperties = new DynamicProperties() { CodeProperty = entity.DynamicProperties.CodeProperty, Property = t.Properties.FirstOrDefault(p => p.Name == entity.DynamicProperties.Property.Name) }; entity.DynamicProperties.ValuesProperties.Keys.ToList().ForEach((type) => { t.DynamicProperties.ValuesProperties.Add(type, entity.DynamicProperties.ValuesProperties[type]); }); } }); return(ctx); }
//------------------------------------- public CResultAErreur FillFromSNMP(CInterrogateurSnmp agent) { CResultAErreur result = CResultAErreur.True; try { agent.Connexion.Version = SnmpVersion; agent.ConnexionIp = Ip; agent.ConnexionPort = SnmpPort; agent.ConnexionCommunity = Communaute; CEasyQuerySource source = new CEasyQuerySource(); source.Connexion = new CSnmpConnexionForEasyQuery(agent); if (TypeAgent != null) { foreach (CTypeEntiteSnmpPourSupervision typeEntite in TypeAgent.TypesEntites) { //Repere tous les existants Dictionary <string, CEntiteSnmpPourSupervision> dicEntites = new Dictionary <string, CEntiteSnmpPourSupervision>(); foreach (CEntiteSnmpPourSupervision entite in GetEntites(typeEntite)) { string strIndex = entite.Index; if (strIndex != null) { dicEntites[strIndex] = entite; } } //récupère les données de la table CODEQBase objetDeQuery = typeEntite.GetObjetDeQuery(TypeAgent); if (objetDeQuery != null) { CEasyQueryFromEasyQueryASourcesSpecifique query = new CEasyQueryFromEasyQueryASourcesSpecifique(objetDeQuery.Query, source); DataTable table = query.GetTable(objetDeQuery.NomFinal); if (table != null) { foreach (DataRow row in table.Rows) { CEntiteSnmpPourSupervision entite = new CEntiteSnmpPourSupervision(Database); entite.CreateNew(); entite.AgentSnmp = this; entite.TypeEntite = typeEntite; entite.FillFromSource(row); entite.UpdateIndexEtLibelle(); string strIndex = entite.Index; //Si l'entité existe déjà CEntiteSnmpPourSupervision oldEntite = Entites.FirstOrDefault( e => e.Index == strIndex && e.TypeEntite.Id == typeEntite.Id && e.Id != entite.Id); if (oldEntite != null) { oldEntite.FillFromSource(row); entite.Delete(); } } } } } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }