private void ExcludeDataTypesFromProfile(PredefinedClasses cimPredefined) { if ((cimPredefined != null) && (profile != null) && (profile.ClassCount > 0)) { ClassCategory packageCorePE = profile.FindProfileElementByUri("#Package_Core") as ClassCategory; if (packageCorePE != null) { foreach (string dataTypeName in cimPredefined.PedifinedClassesList) { ProfileElement dataTypePE = profile.ProfileMap[ProfileElementTypes.Class].Find(x => string.Compare(x.Name, dataTypeName) == 0); if (dataTypePE != null) { //// remove dataTypePE from package Core packageCorePE.MembersOfClassCategory.Remove(dataTypePE); //// remove dataTypePE from profile profile.ProfileMap[ProfileElementTypes.Class].Remove(dataTypePE); } } //// remove enums UnitSymbol and UnitMultiplier ProfileElement unitSymbolPE = profile.FindProfileElementByUri("#UnitSymbol"); ProfileElement unitMultiplierlPE = profile.FindProfileElementByUri("#UnitMultiplier"); //// remove from package Core packageCorePE.MembersOfClassCategory.Remove(unitSymbolPE); packageCorePE.MembersOfClassCategory.Remove(unitMultiplierlPE); //// remove from profile profile.ProfileMap[ProfileElementTypes.Class].Remove(unitSymbolPE); profile.ProfileMap[ProfileElementTypes.Class].Remove(unitMultiplierlPE); } } }
private void ReplaceDataTypesWithSimpleTypes(PredefinedClasses cimPredefined) { if ((cimPredefined != null) && (profile != null) && (profile.PropertyCount > 0)) { foreach (Property property in profile.ProfileMap[ProfileElementTypes.Property]) { string dataTypeName = StringManipulationManager.ExtractAllAfterSeparator(property.DataType, StringManipulationManager.SeparatorSharp); if (string.IsNullOrEmpty(dataTypeName)) { //// support cim15 dataTypeName = StringManipulationManager.ExtractAllAfterSeparator(property.Range, StringManipulationManager.SeparatorSharp); } if (cimPredefined.PedifinedClassesList.Contains(dataTypeName)) { //// read the simple type from "value" attribute Class dataTypeClass = profile.FindProfileElementByName(dataTypeName) as Class; foreach (Property p in dataTypeClass.MyProperties) { if (string.Compare(p.Name, "value") == 0) { property.DataType = p.DataType; if (!string.IsNullOrEmpty(property.Range)) { property.Range = null; property.RangeAsObject = null; } } } } } } }
/// <summary> /// Parse RDF file from <c>path</c> and create profile /// </summary> /// <param name="profile">Profile profile the data will be stored in</param> public Profile LoadProfileDocument(Stream stream, string path, bool createCore = true) { try { this.profile = new Profile(); profile.SourcePath = path; StringBuilder message = new StringBuilder(); message.Append("\r\n\t------------------Parsing profile------------------"); message.Append("\r\nParsing file: ").Append(profile.SourcePath); OnMessage(message.ToString()); if (!string.IsNullOrEmpty(profile.SourcePath)) { bool success; TimeSpan durationOfParsing = new TimeSpan(0); RDFSXMLReaderHandler handler = new RDFSXMLReaderHandler(); handler = (RDFSXMLReaderHandler)XMLParser.DoParse(handler, stream, profile.SourcePath, out success, out durationOfParsing); StringBuilder msg = new StringBuilder("\r\nCIM profile loaded\r\n\t Duration of CIM profile loading: " + durationOfParsing); if (success) { profile = handler.Profile; msg.Append("\r\n TOTAL:\r\n\tPackages: ").Append(profile.PackageCount); msg.Append("\r\n\tClasses: ").Append(profile.ClassCount); } else { msg.Append("\r\n\t loading CIM profile was unsuccessful"); } OnMessage(msg.ToString()); } else { OnMessage("Parsing impossible - no profile or incorrect path"); return(null); } OnMessage("\r\n\t--------------Done parsing profile--------------"); #region Manage dataType classes PredefinedClasses pf = new PredefinedClasses(); if (profile.FindProfileElementByUri("#Package_Core") == null && createCore) { pf.CreatePackage(profile, "Package_Core"); } if (profile.FindProfileElementByUri("#UnitSymbol") == null) { pf.CreateEnumeration(profile, "UnitSymbol"); } if (profile.FindProfileElementByUri("#UnitMultiplier") == null) { pf.CreateEnumeration(profile, "UnitMultiplier"); } ExtractDataTypeClasses(); if (predefined.Count > 0) { foreach (Class e in predefined) { pf.updateClassData(e, profile); } AddPredefined(); } #endregion Manage dataType classes #region Adjustments to simplify profile if (RemoveDataTypes) { //// replace predefined data types with simple types ReplaceDataTypesWithSimpleTypes(pf); ExcludeDataTypesFromProfile(pf); } #endregion Adjustments to simplify profile return(profile); } catch (ThreadAbortException) { return(null); } }
private void ExcludeDataTypesFromProfile(PredefinedClasses cimPredefined) { if ((cimPredefined != null) && (profile != null) && (profile.ClassCount > 0)) { ClassCategory packageCorePE = profile.FindProfileElementByUri("#Package_Core") as ClassCategory; if (packageCorePE != null) { foreach (string dataTypeName in cimPredefined.PedifinedClassesList) { ProfileElement dataTypePE = profile.ProfileMap[ProfileElementTypes.Class].Find(x => string.Compare(x.Name, dataTypeName) == 0); if (dataTypePE != null) { //// remove dataTypePE from package Core packageCorePE.MembersOfClassCategory.Remove(dataTypePE); //// remove dataTypePE from profile profile.ProfileMap[ProfileElementTypes.Class].Remove(dataTypePE); } } //// remove enums UnitSymbol and UnitMultiplier if not used in classes ProfileElement unitSymbolPE = profile.FindProfileElementByUri("#UnitSymbol"); ProfileElement unitMultiplierlPE = profile.FindProfileElementByUri("#UnitMultiplier"); bool removeUnitSymbol = !profile.GetAllProfileElementsOfType(ProfileElementTypes.Property).Cast <Property>().Any(p => string.Equals(p.Range, "#UnitSymbol")); bool removeUnitMultiplier = !profile.GetAllProfileElementsOfType(ProfileElementTypes.Property).Cast <Property>().Any(p => string.Equals(p.Range, "#UnitMultiplier")); if (removeUnitSymbol) { //// remove from package Core packageCorePE.MembersOfClassCategory.Remove(unitSymbolPE); //// remove from profile profile.ProfileMap[ProfileElementTypes.Class].Remove(unitSymbolPE); unitSymbolPE = null; } if (removeUnitMultiplier) { //// remove from package Core packageCorePE.MembersOfClassCategory.Remove(unitMultiplierlPE); //// remove from profile profile.ProfileMap[ProfileElementTypes.Class].Remove(unitMultiplierlPE); unitMultiplierlPE = null; } //// remove Domain package or just remove all members not used elsewhere ClassCategory packageDomainPE = profile.FindProfileElementByUri("#Package_Domain") as ClassCategory; if (packageDomainPE != null) { if (packageDomainPE.CountMembersOfClassCategory > 0) { packageDomainPE.MembersOfClassCategory.Clear(); if (unitSymbolPE != null) { packageDomainPE.AddToMembersOfClassCategory(unitSymbolPE); } if (unitMultiplierlPE != null) { packageDomainPE.AddToMembersOfClassCategory(unitMultiplierlPE); } } if ((unitSymbolPE == null) && (unitMultiplierlPE == null)) { profile.ProfileMap[ProfileElementTypes.ClassCategory].Remove(packageDomainPE); } } } } }