private bool LoadModelFromExtractFile(Stream extract, ref ConcreteModel concreteModelResult, out string errorLog) { bool valid = false; errorLog = string.Empty; System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); try { Assembly assembly; LoadAssembly(".\\" + ProfileName + ".dll", out assembly); if (assembly != null) { CIMModel cimModel = new CIMModel(); CIMModelLoaderResult modelLoadResult = CIMModelLoader.LoadCIMXMLModel(extract, Namespace, out cimModel); if (modelLoadResult.Success) { concreteModelResult = new ConcreteModel(); ConcreteModelBuilder builder = new ConcreteModelBuilder(); ConcreteModelBuildingResult modelBuildResult = builder.GenerateModel(cimModel, assembly, Namespace, ref concreteModelResult); if (modelBuildResult.Success) { valid = true; } else { errorLog = modelBuildResult.Report.ToString(); } } else { errorLog = modelLoadResult.Report.ToString(); } } Thread.CurrentThread.CurrentCulture = culture; } catch (Exception e) { Thread.CurrentThread.CurrentCulture = culture; errorLog = e.Message; } return(valid); }
private bool LoadModelFromExtractFile(Stream extract, SupportedProfiles extractType, ref ConcreteModel concreteModelResult, ref Assembly assembly, out string log) { bool valid = false; log = string.Empty; System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); try { ProfileManager.LoadAssembly(extractType, out assembly); if (assembly != null) { CIMModel cimModel = new CIMModel(); CIMModelLoaderResult modelLoadResult = CIMModelLoader.LoadCIMXMLModel(extract, ProfileManager.Namespace, out cimModel); if (modelLoadResult.Success) { concreteModelResult = new ConcreteModel(); ConcreteModelBuilder builder = new ConcreteModelBuilder(); ConcreteModelBuildingResult modelBuildResult = builder.GenerateModel(cimModel, assembly, ProfileManager.Namespace, ref concreteModelResult); if (modelBuildResult.Success) { valid = true; } log = modelBuildResult.Report.ToString(); } else { log = modelLoadResult.Report.ToString(); } } } catch (Exception e) { log = e.Message; } finally { Thread.CurrentThread.CurrentCulture = culture; } return(valid); }
private void FindAttributeDifferences() { modified = new List <CIMEntityDifference>(); if (updated != null) { CIMModelContext context = new CIMModelContext(); foreach (KeyValuePair <CIMEntity, CIMEntity> pair in updated) { CIMObject oldVersion = null; CIMModelLoader.LoadCIMObject(ref oldVersion, context, string.Format("{0}{1}\n</rdf:RDF>", beforeModel.Header, pair.Key.Source)); CIMObject newVersion = null; CIMModelLoader.LoadCIMObject(ref newVersion, context, string.Format("{0}{1}\n</rdf:RDF>", afterModel.Header, pair.Value.Source)); if ((oldVersion != null) && (newVersion != null)) { CIMEntityDifference diff = new CIMEntityDifference(); diff.RdfId = oldVersion.ID; //// TODO uporediti atribute u oba objekta i spakovati ih u CIMEntityDifference instancu //PROVERA ZA OLD if (oldVersion.HasAttributes) { foreach (ObjectAttribute oldAtt in oldVersion.MyAttributesAsList) { if (string.Compare(oldAtt.FullName, CIMConstants.AttributeNameIdentifiedObjectMRID) == 0) { //postavi mrid diff.MRID = oldAtt.Value; } //uzmem sve sa istim imenom - ako nema dodajem ako ima proveravam if (newVersion.GetAttributeList(oldAtt.FullName) != null) { if (newVersion.GetAttributeList(oldAtt.FullName).Count == 0) { //dodajem diff.AddAttribute(oldAtt, null); } else { bool found = false; if (newVersion.HasAttributes) { foreach (ObjectAttribute newAtt in newVersion.GetAttributeList(oldAtt.FullName)) { //proveravam da li se javlja ista vrednost if (string.Compare(oldAtt.Value, newAtt.Value) == 0) { //ako se javlja dodajem ga kao nadjen i ne treba da se pojavi found = true; break; } } } //ako je found false, znaci da je dodat if (!found) { diff.AddAttribute(oldAtt, null); } } } else { diff.AddAttribute(oldAtt, null); } } } //PROVERA ZA NEW if (newVersion.HasAttributes) { if (newVersion.MyAttributesAsList != null) { foreach (ObjectAttribute newAtt in newVersion.MyAttributesAsList) { if (string.Compare(newAtt.FullName, CIMConstants.AttributeNameIdentifiedObjectMRID) == 0) { //postavi mrid if (string.IsNullOrEmpty(diff.MRID)) { diff.MRID = newAtt.Value; } } //uzmem sve sa istim imenom - ako nema dodajem ako ima proveravam if (oldVersion.GetAttributeList(newAtt.FullName) != null) { if (oldVersion.GetAttributeList(newAtt.FullName).Count == 0) { //dodajem diff.AddAttribute(newAtt, null); } else { bool found = false; if (oldVersion.HasAttributes) { foreach (ObjectAttribute oldAtt in oldVersion.GetAttributeList(newAtt.FullName)) { //proveravam da li se javlja ista vrednost if (string.Compare(newAtt.Value, oldAtt.Value) == 0) { //ako se javlja i isti je obelezavam ga kao nadjen found = true; break; } } } //ako je found false, znaci da je dodat if (!found) { diff.AddAttribute(null, newAtt); } } } else { diff.AddAttribute(null, newAtt); } } } } if (diff.Attributes.Count > 0) { this.modified.Add(diff); } } } } }