public static Schema.KRPC.Services GetServices() { var services = new Schema.KRPC.Services (); foreach (var serviceSignature in Services.Instance.Signatures.Values) { var service = new Schema.KRPC.Service (); service.Name = serviceSignature.Name; foreach (var procedureSignature in serviceSignature.Procedures.Values) { var procedure = new Procedure (); procedure.Name = procedureSignature.Name; if (procedureSignature.HasReturnType) { procedure.HasReturnType = true; procedure.ReturnType = TypeUtils.GetTypeName (procedureSignature.ReturnType); } foreach (var parameterSignature in procedureSignature.Parameters) { var parameter = new Parameter (); parameter.Name = parameterSignature.Name; parameter.Type = TypeUtils.GetTypeName (parameterSignature.Type); if (parameterSignature.HasDefaultArgument) { parameter.HasDefaultArgument = true; parameter.DefaultArgument = parameterSignature.DefaultArgument; } procedure.Parameters.Add (parameter); } foreach (var attribute in procedureSignature.Attributes) { procedure.Attributes.Add (attribute); } if (procedureSignature.Documentation != "") procedure.Documentation = procedureSignature.Documentation; service.Procedures.Add (procedure); } foreach (var clsSignature in serviceSignature.Classes.Values) { var cls = new Class (); cls.Name = clsSignature.Name; if (clsSignature.Documentation != "") cls.Documentation = clsSignature.Documentation; service.Classes.Add (cls); } foreach (var enmSignature in serviceSignature.Enumerations.Values) { var enm = new Enumeration (); enm.Name = enmSignature.Name; if (enmSignature.Documentation != "") enm.Documentation = enmSignature.Documentation; foreach (var enmValueSignature in enmSignature.Values) { var enmValue = new EnumerationValue (); enmValue.Name = enmValueSignature.Name; enmValue.Value = enmValueSignature.Value; if (enmValueSignature.Documentation != "") enmValue.Documentation = enmValueSignature.Documentation; enm.Values.Add (enmValue); } service.Enumerations.Add (enm); } if (serviceSignature.Documentation != "") service.Documentation = serviceSignature.Documentation; services.Services_.Add (service); } return services; }
private Enumeration FindOrCreateFilterFunctionsEnumeration() { foreach (var enumeration in Project.Enumerations) { if (enumeration.GetAttributeValue("isFilterFunctionsEnumeration", NamespaceUri, false)) { return(enumeration); } } Enumeration e = Project.Enumerations.FirstOrDefault(_ => string.Equals(_.Name, "FilterFunction", StringComparison.OrdinalIgnoreCase) || string.Equals(_.Name, "FilterFunctions", StringComparison.OrdinalIgnoreCase)); if (e != null) { return(e); } e = new Enumeration(); e.Name = typeof(FilterFunctions).Name; e.Namespace = Project.DefaultNamespace; e.IsFlags = Project.GetAttributeValue("createMultiValuedEnumeration", NamespaceUri, true); e.SetAttributeValue(PreferredPrefix, "isFilterFunctionsEnumeration", NamespaceUri, true); Project.Enumerations.Add(e); foreach (FilterFunctions value in ConvertUtilities.EnumEnumerateValues <FilterFunctions>()) { EnumerationValue enumerationValue = new EnumerationValue(); enumerationValue.Name = value.ToString(); enumerationValue.SetAttributeValue(PreferredPrefix, "filterFunction", NamespaceUri, value); e.Values.Add(enumerationValue); } return(e); }
public bool Output ( [ScriptEnumParameter(ColourTypesFactory.SecondaryColour)] EnumerationValue mix ) { Console.WriteLine($"{mix}"); return(true); }
public static Schema.KRPC.EnumerationValue ToProtobufMessage(this EnumerationValue enumerationValue) { var result = new Schema.KRPC.EnumerationValue(); result.Name = enumerationValue.Name; result.Value = enumerationValue.Value; result.Documentation = enumerationValue.Documentation; return(result); }
private FilterFunctions GetFilterFunction(EnumerationValue enumValue) { var op = enumValue.GetAttributeValue("filterFunction", NamespaceUri, FilterFunctions.None); if (op == FilterFunctions.None) { op = ConvertUtilities.ChangeType(enumValue.Name, FilterFunctions.None); } return(op); }
private static string GetEnumTextForIdValue(string idValue, DataType dataType, string language = "en") { string result = ""; EnumerationValue enumValue = null; try { enumValue = dataType.Enumeration.First(e => e.ID == idValue); } catch { } if (enumValue != null) { MultilanguageText enumText = null; foreach (MultilanguageText multilanguageText in enumValue.Value) { if (language == null || language == "en") { if (multilanguageText.Language == null || multilanguageText.Language == "en") { enumText = multilanguageText; break; } } else { if (multilanguageText.Language != null && multilanguageText.Language == language) { enumText = multilanguageText; break; } } } // language not found, take first value as default if (enumText == null && enumValue.Value.Count > 0) { enumText = enumValue.Value[0]; } if (enumText != null) { result = enumText.Text; } } return(result); }
private Enumeration FindOrCreateFilterFunctionsEnumeration() { foreach (Enumeration enumeration in Project.Enumerations) { if (enumeration.GetAttributeValue("isFilterFunctionsEnumeration", NamespaceUri, false)) { return(enumeration); } } Enumeration e = Project.Enumerations.FirstOrDefault(_ => string.Equals(_.Name, "FilterFunction", StringComparison.OrdinalIgnoreCase) || string.Equals(_.Name, "FilterFunctions", StringComparison.OrdinalIgnoreCase)); if (e != null) { return(e); } e = new Enumeration(); e.Name = typeof(FilterFunctions).Name; e.Namespace = Project.DefaultNamespace; e.IsFlags = Project.GetAttributeValue("createMultiValuedEnumeration", NamespaceUri, true); e.SetAttributeValue(PreferredPrefix, "isFilterFunctionsEnumeration", NamespaceUri, true); Project.Enumerations.Add(e); foreach (FilterFunctions value in ConvertUtilities.EnumEnumerateValues <FilterFunctions>()) { EnumerationValue enumerationValue = new EnumerationValue(); enumerationValue.Name = value.ToString(); enumerationValue.SetAttributeValue(PreferredPrefix, "filterFunction", NamespaceUri, value); List <string> enumNames = ConvertUtilities.SplitEnumNames(value).ToList(); if (enumNames.Count() > 1) { if (!e.IsFlags) { continue; } enumerationValue.Value = ConvertUtilities.Concatenate(enumNames, " | "); } else { enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture); } enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture); e.Values.Add(enumerationValue); } return(e); }
public bool Mix ( [ScriptEnumParameter(ColourTypesFactory.PrimaryColour)] EnumerationValue colour1, [ScriptEnumParameter(ColourTypesFactory.PrimaryColour)] EnumerationValue colour2, [ScriptEnumParameter(ColourTypesFactory.SecondaryColour)] EnumerationValue mix ) { if ($"{colour1}" == "Primary.Red" && $"{colour2}" == "Primary.Yellow") { return($"{mix}" == "Secondary.Orange"); } return(false); }
private ProcedureExpressionStatement CreateEnumerationEqualsStatement(ProcedureStatement parent, Parameter enumParameter, EnumerationValue enumValue) { if (FilterFunctionsEnumeration.IsFlags) { // Sample: (@FilterFunctions & FilterFunctions.Equals) = FilterFunctions.Equals return(new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, ProcedureOperationType.BitwiseAnd, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)), new ProcedureExpressionStatement(parent, enumValue.TypedValue))); } else { // Sample: @FilterFunctions = FilterFunctions.Equals return(new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue))); } }
private List <Property> LoadProperties(PropertySetDef pset, List <PropertyDef> PropertyDefs) { List <Property> properties = new List <Property>(); foreach (PropertyDef psetProperty in PropertyDefs) { numberOfProperties++; log.Info(" ................."); int itemNumber = 0; foreach (var item in psetProperty.Items) { string ty = item.ToString(); if (item.ToString().Contains("PropertyType")) { break; } itemNumber++; } PropertyType psetValueType = (PropertyType)psetProperty.Items[itemNumber]; PropertyTypeTypePropertyBoundedValue psetBoundedValue = null; PropertyTypeTypeComplexProperty psetComplexProperty = null; PropertyTypeTypePropertyEnumeratedValue psetEnumeratedValue = null; PropertyTypeTypePropertyListValue psetListValue = null; PropertyTypeTypePropertyReferenceValue psetReferenceValue = null; PropertyTypeTypePropertySingleValue psetSingleValue = null; PropertyTypeTypePropertyTableValue psetTableValue = null; string valueTypeAsString = psetValueType.Item.ToString().Replace("PSetManager.", ""); Property property = new Property() { name = psetProperty.Items[0].ToString(), definition = psetProperty.Items[1].ToString(), dictionaryReference = new DictionaryReference() { dictionaryIdentifier = "http://bsdd.buildingsmart.org", dictionaryNamespace = "PSet", ifdGuid = "", legacyGuid = psetProperty.ifdguid, legacyGuidAsIfcGlobalId = Utils.GuidConverterToIfcGuid(psetProperty.ifdguid) } }; log.Info($" Name: {property.name}"); if (property.dictionaryReference.legacyGuidAsIfcGlobalId.Length == 0) { Console.ForegroundColor = ConsoleColor.Red; log.Info($" ERROR: The GUID for {property.name} is missing in PSet!"); Console.ResetColor(); } if (CheckBSDD) { if (GuidExistsInBsdd(property.dictionaryReference.legacyGuidAsIfcGlobalId) == false) { Console.ForegroundColor = ConsoleColor.Red; log.Info($" ERROR: The GUID {property.dictionaryReference.legacyGuidAsIfcGlobalId} for {property.name} is not resolved by http://bsdd.buildingsmart.org"); Console.ResetColor(); IfdConceptList ifdConceptList = _bsdd.SearchProperties(pset.Name + "." + property.name); if (ifdConceptList == null) { log.Info($" Could not find the Property in bSDD"); } else { numberOfPropertiesWithbSDDGuid++; IfdConcept bsddProperty = ifdConceptList.IfdConcept.FirstOrDefault(); log.Info($" Loaded Property from bSDD (1 out of {ifdConceptList.IfdConcept.Count})"); log.Info($" Guid: {bsddProperty.Guid}"); log.Info($" Status: {bsddProperty.Status}"); log.Info($" VersionDate: {bsddProperty.VersionDate}"); log.Info($" Web: http://bsdd.buildingsmart.org/#concept/browse/{bsddProperty.Guid}"); foreach (var item in bsddProperty.FullNames) { int l = item.Language.LanguageCode.Length; string tab = new string(' ', 10 - l); log.Info($" Name {item.Language.LanguageCode}:{tab}{item.Name}"); } if (ifdConceptList.IfdConcept.Count == 1) { log.Info($" The GUID in the PSet file was changed {property.dictionaryReference.legacyGuid} => {bsddProperty.Guid}"); property.dictionaryReference.ifdGuid = bsddProperty.Guid; } } } else { Console.ForegroundColor = ConsoleColor.Green; log.Info($" OK: The GUID {property.dictionaryReference.legacyGuidAsIfcGlobalId} for {property.name} is properly resolved by http://bsdd.buildingsmart.org"); property.dictionaryReference.ifdGuid = property.dictionaryReference.legacyGuidAsIfcGlobalId; Console.ResetColor(); } } property.dictionaryReference.dictionaryWebUri = $"http://bsdd.buildingsmart.org/#concept/browse/{property.dictionaryReference.ifdGuid}"; property.dictionaryReference.dictionaryApiUri = $"http://bsdd.buildingsmart.org/api/4.0/IfdConcept/{property.dictionaryReference.ifdGuid}"; property.localizations = new List <Localization>(); PropertyDefNameAliases nameAliases = null; PropertyDefDefinitionAliases definitionAliases = null; if (psetProperty.Items.Length >= 4) { foreach (var item in psetProperty.Items) { if (item.GetType() == typeof(PSetManager.PropertyDefNameAliases)) { nameAliases = (PropertyDefNameAliases)item; } } foreach (var item in psetProperty.Items) { if (item.GetType() == typeof(PSetManager.PropertyDefDefinitionAliases)) { definitionAliases = (PropertyDefDefinitionAliases)item; } } foreach (var alias in nameAliases.NameAlias) { property.localizations.Add(new Localization() { language = alias.lang, name = alias.Value ?? string.Empty, definition = definitionAliases.DefinitionAlias.Where(x => x.lang == alias.lang)?.FirstOrDefault()?.Value ?? string.Empty }); } } //Insert missing standard localizations as dummys foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { if (property.localizations.Where(x => x.language == standardLanguage).FirstOrDefault() == null) { property.localizations.Add(new Localization() { language = standardLanguage, name = string.Empty, definition = string.Empty }); } } IfcDataType resultParseIfcDataType; ReferenceClass resultParseReferenceClass; switch (valueTypeAsString) { case "PropertyTypeTypePropertyBoundedValue": psetBoundedValue = (PropertyTypeTypePropertyBoundedValue)psetValueType.Item; property.typePropertyBoundedValue = new TypePropertyBoundedValue(); property.typePropertyBoundedValue.typeName = nameof(TypePropertyBoundedValue); Enum.TryParse(psetSingleValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyBoundedValue.dataType = resultParseIfcDataType; property.typePropertyBoundedValue.unitType = psetBoundedValue.UnitType.type.ToString() ?? string.Empty; property.typePropertyBoundedValue.LowerBoundValue = psetBoundedValue.ValueRangeDef.LowerBoundValue.value?.ToString() ?? string.Empty; property.typePropertyBoundedValue.UpperBoundValue = psetBoundedValue.ValueRangeDef.UpperBoundValue.value?.ToString() ?? string.Empty; break; case "PropertyTypeTypeComplexProperty": psetComplexProperty = (PropertyTypeTypeComplexProperty)psetValueType.Item; property.typeComplexProperty = new TypeComplexProperty(); property.typeComplexProperty.name = psetComplexProperty.name ?? string.Empty; property.typeComplexProperty.subProperties = LoadProperties(pset, psetComplexProperty.PropertyDef); //Recursiv loading break; case "PropertyTypeTypePropertyEnumeratedValue": psetEnumeratedValue = (PropertyTypeTypePropertyEnumeratedValue)psetValueType.Item; if (psetEnumeratedValue.EnumList.EnumItem.Count != 0) { property.typePropertyEnumeratedValue = new TypePropertyEnumeratedValue(); property.typePropertyEnumeratedValue.listName = psetEnumeratedValue.EnumList.name; property.typePropertyEnumeratedValue.enumerationValues = new List <EnumerationValue>(); foreach (var item in psetEnumeratedValue.EnumList.EnumItem) { EnumerationValue enumerationValue = new EnumerationValue() { ifdGuid = string.Empty,// Utils.GuidConverterToIfcGuid(Guid.NewGuid().ToString()), name = Utils.CleanUp(item), definition = string.Empty, localizations = new List <Localization>() }; foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { enumerationValue.localizations.Add(new Localization() { language = standardLanguage, name = Utils.FirstUpperRestLower(item.ToString()), definition = string.Empty }); } property.typePropertyEnumeratedValue.enumerationValues.Add(enumerationValue); } } if (psetEnumeratedValue.ConstantList.ConstantDef.Count != 0) { property.typePropertyEnumeratedValue = new TypePropertyEnumeratedValue(); property.typePropertyEnumeratedValue.constantValues = new List <ConstantValue>(); //property.typePropertyEnumeratedValue.listName = psetEnumeratedValue.ConstantList.ConstantDef foreach (var item in psetEnumeratedValue.ConstantList.ConstantDef) { string nameItem = item.Items[0].ToString(); string definitionItem; if (item.Items[1].GetType() == typeof(String)) { definitionItem = item.Items[1].ToString(); } else { definitionItem = string.Empty; } ConstantValue constantValue = new ConstantValue() { ifdGuid = string.Empty, name = Utils.CleanUp(nameItem), definition = Utils.CleanUp(definitionItem), localizations = new List <Localization>() }; foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { ConstantDefNameAliases constantDefNameAlias = null; foreach (var i in item.Items) { if (i.GetType() == typeof(PSetManager.ConstantDefNameAliases)) { constantDefNameAlias = (ConstantDefNameAliases)i; } } ConstantDefDefinitionAliases constantDefDefinitionAliases = null; foreach (var i in item.Items) { if (i.GetType() == typeof(PSetManager.ConstantDefDefinitionAliases)) { constantDefDefinitionAliases = (ConstantDefDefinitionAliases)i; } } //if ((constantDefNameAlias.NameAlias.FirstOrDefault().Value != null) || (constantDefDefinitionAliases.NameAlias.FirstOrDefault().Value != null)) constantValue.localizations.Add(new Localization() { language = standardLanguage, name = Utils.FirstUpperRestLower(constantDefNameAlias.NameAlias.Where(l => l.lang.ToLower() == standardLanguage.ToLower()).FirstOrDefault()?.Value ?? string.Empty), definition = Utils.FirstUpperRestLower(constantDefDefinitionAliases.DefinitionAlias.Where(l => l.lang.ToLower() == standardLanguage.ToLower()).FirstOrDefault()?.Value ?? string.Empty) }); } property.typePropertyEnumeratedValue.constantValues.Add(constantValue); } } break; case "PropertyTypeTypePropertyListValue": psetListValue = (PropertyTypeTypePropertyListValue)psetValueType.Item; property.typePropertyListValue = new TypePropertyListValue(); Enum.TryParse(psetListValue?.ListValue.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyListValue.dataType = resultParseIfcDataType; property.typePropertyListValue.unitType = psetListValue?.ListValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyListValue.measureType = ""; if (psetListValue.ListValue.Values.ValueItem.Count > 0) { property.typePropertyListValue.listValues = new List <string>(); foreach (string valueItem in psetListValue.ListValue.Values.ValueItem) { property.typePropertyListValue.listValues.Add(valueItem); } } break; case "PropertyTypeTypePropertyReferenceValue": psetReferenceValue = (PropertyTypeTypePropertyReferenceValue)psetValueType.Item; property.typePropertyReferenceValue = new TypePropertyReferenceValue(); Enum.TryParse(psetReferenceValue.reftype.ToString() ?? string.Empty, out resultParseReferenceClass); property.typePropertyReferenceValue.refType = resultParseReferenceClass; if (property.typePropertyReferenceValue.refType.ToString().StartsWith("Ifc")) { property.typePropertyReferenceValue.guid = string.Empty; property.typePropertyReferenceValue.url = "http://buildingsmart-tech.org"; property.typePropertyReferenceValue.libraryName = "Industry Foundation Classes by buildingSMART International"; property.typePropertyReferenceValue.sectionref = "Core Schema"; } else { property.typePropertyReferenceValue.guid = string.Empty; property.typePropertyReferenceValue.url = string.Empty; property.typePropertyReferenceValue.libraryName = string.Empty; property.typePropertyReferenceValue.sectionref = string.Empty; } break; case "PropertyTypeTypePropertySingleValue": psetSingleValue = (PropertyTypeTypePropertySingleValue)psetValueType.Item; property.typePropertySingleValue = new TypePropertySingleValue(); Enum.TryParse(psetSingleValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertySingleValue.dataType = resultParseIfcDataType; property.typePropertySingleValue.unitType = psetSingleValue?.UnitType?.type.ToString() ?? string.Empty; property.typePropertySingleValue.measureType = ""; break; case "PropertyTypeTypePropertyTableValue": psetTableValue = (PropertyTypeTypePropertyTableValue)psetValueType.Item; property.typePropertyTableValue = new TypePropertyTableValue(); property.typePropertyTableValue.Expression = psetTableValue.Expression; property.typePropertyTableValue.DefiningValue = new TableDefValues(); Enum.TryParse(psetTableValue?.DefiningValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyTableValue.DefiningValue.dataType = resultParseIfcDataType; property.typePropertyTableValue.DefiningValue.unitType = psetTableValue?.DefiningValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyTableValue.DefiningValue.measureType = ""; property.typePropertyTableValue.DefinedValue = new TableDefValues(); Enum.TryParse(psetTableValue?.DefinedValue.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyTableValue.DefinedValue.dataType = resultParseIfcDataType; property.typePropertyTableValue.DefinedValue.unitType = psetTableValue?.DefiningValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyTableValue.DefinedValue.measureType = ""; break; } ; property.status = new PublicationStatus() { versionNumber = 4, dateOfVersion = new DateTime(2018, 1, 1), revisionNumber = 2, dateOfRevision = new DateTime(2018, 1, 1), status = PublicationStatus.Status.Active.ToString(), dateOfCreation = new DateTime(2018, 1, 1), dateOfActivation = new DateTime(2018, 1, 1), dateOfLastChange = new DateTime(2018, 1, 1), languageOfCreator = "en-EN" }; properties.Add(property); } return(properties); }
private static Either <Node, IError> Process(IConversationNodeData node, DomainDomain source, int depth) { if (node == null) { return(null); } depth++; if (depth > 100) { return(new OverRecursionError()); } var c = Children(node).Select(n => Process(n, source, depth)); var cc = Either.Split(c); var ne = Next(node).Select(n => Process(n, source, depth)); var nene = Either.Split(ne); if (cc.Item2.Any()) { return(new Either <Node, IError>(cc.Item2.First())); } else if (nene.Item2.Any()) { return(new Either <Node, IError>(nene.Item2.First())); } Node[] children = cc.Item1.ToArray(); Node[] nexts = nene.Item1.ToArray(); //Node child = (children.Length == 0) ? null : children.Length == 1 ? children[0] : new OneOf() { Next = null, Options = children }; //Node next = (nexts.Length == 0) ? null : nexts.Length == 1 ? nexts[0] : new OneOf() { Next = null, Options = nexts }; if (node.NodeTypeId == DomainIDs.AutoComplete.ExactlyOne) { return(new Count() { Min = 1, Max = 1, Subjects = children, Next = nexts }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.OneOrMore) { return(new Count() { Min = 1, Max = int.MaxValue, Subjects = children, Next = nexts }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.ZeroOrMore) { return(new Count() { Min = 0, Max = int.MaxValue, Subjects = children, Next = nexts }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.ZeroOrOne) { return(new Count() { Min = 0, Max = 1, Subjects = children, Next = nexts }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.String) { return(new String() { Next = nexts, Value = node.Parameters.Single(p => p.Id == DomainIDs.AutoComplete.StringParameter).ValueAsString() }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.Character) { var result = Character.Make(node.Parameters.Single(p => p.Id == DomainIDs.AutoComplete.CharacterParameter).ValueAsString()); result.Next = nexts; return(result); } else if (node.NodeTypeId == DomainIDs.AutoComplete.EnumerationValue) { var result = EnumerationValue.Make(node.Parameters.Single() as IEnumParameter, source); result.Next = nexts; return(result); } else if (node.NodeTypeId == DomainIDs.AutoComplete.DynamicEnumerationValue) { return(new DynamicEnumerationValue(node.Parameters.Single() as IEnumParameter) { Next = nexts }); } else if (node.NodeTypeId == DomainIDs.AutoComplete.LocalDynamicEnumerationValue) { return(new DynamicEnumerationValue(node.Parameters.Single() as IEnumParameter) { Next = nexts }); } else { return(null);//TODO: Not sure what effect this would have } }
private Enumeration FindOrCreateFilterFunctionsEnumeration() { foreach (var enumeration in Project.Enumerations) { if (enumeration.GetAttributeValue("isFilterFunctionsEnumeration", NamespaceUri, false)) { return enumeration; } } Enumeration e = Project.Enumerations.FirstOrDefault(_ => string.Equals(_.Name, "FilterFunction", StringComparison.OrdinalIgnoreCase) || string.Equals(_.Name, "FilterFunctions", StringComparison.OrdinalIgnoreCase)); if (e != null) return e; e = new Enumeration(); e.Name = typeof(FilterFunctions).Name; e.Namespace = Project.DefaultNamespace; e.IsFlags = Project.GetAttributeValue("createMultiValuedEnumeration", NamespaceUri, true); e.SetAttributeValue(PreferredPrefix, "isFilterFunctionsEnumeration", NamespaceUri, true); Project.Enumerations.Add(e); foreach (FilterFunctions value in ConvertUtilities.EnumEnumerateValues<FilterFunctions>()) { EnumerationValue enumerationValue = new EnumerationValue(); enumerationValue.Name = value.ToString(); enumerationValue.SetAttributeValue(PreferredPrefix, "filterFunction", NamespaceUri, value); e.Values.Add(enumerationValue); } return e; }
private ProcedureExpressionStatement CreateEnumerationEqualsStatement(ProcedureStatement parent, Parameter enumParameter, EnumerationValue enumValue) { if (FilterFunctionsEnumeration.IsFlags) { // Sample: (@FilterFunctions & FilterFunctions.Equals) = FilterFunctions.Equals return new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, ProcedureOperationType.BitwiseAnd, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)), new ProcedureExpressionStatement(parent, enumValue.TypedValue)); } else { // Sample: @FilterFunctions = FilterFunctions.Equals return new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)); } }
private FilterFunctions GetFilterFunction(EnumerationValue enumValue) { var op = enumValue.GetAttributeValue("filterFunction", NamespaceUri, FilterFunctions.None); if (op == FilterFunctions.None) { op = ConvertUtilities.ChangeType(enumValue.Name, FilterFunctions.None); } return op; }
private ProcedureExpressionStatement CreateEnumerationEqualsStatement(ProcedureStatement parent, Parameter enumParameter, EnumerationValue enumValue) { bool isZero = ConvertUtilities.ChangeType<int>(enumValue) == 0; if (!isZero && FilterFunctionsEnumeration.IsFlags) { // Sample: (@FilterFunctions & FilterFunctions.Equals) = FilterFunctions.Equals return new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, ProcedureOperationType.BitwiseAnd, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)), new ProcedureExpressionStatement(parent, enumValue.TypedValue)); } else { // Sample: @FilterFunctions = FilterFunctions.Equals return new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)); } }
public static Schema.KRPC.Services GetServices() { var services = new Schema.KRPC.Services(); foreach (var serviceSignature in Services.Instance.Signatures.Values) { var service = new Schema.KRPC.Service(); service.Name = serviceSignature.Name; foreach (var procedureSignature in serviceSignature.Procedures.Values) { var procedure = new Procedure(); procedure.Name = procedureSignature.Name; if (procedureSignature.HasReturnType) { procedure.HasReturnType = true; procedure.ReturnType = TypeUtils.GetTypeName(procedureSignature.ReturnType); } foreach (var parameterSignature in procedureSignature.Parameters) { var parameter = new Parameter(); parameter.Name = parameterSignature.Name; parameter.Type = TypeUtils.GetTypeName(parameterSignature.Type); if (parameterSignature.HasDefaultArgument) { parameter.HasDefaultArgument = true; parameter.DefaultArgument = parameterSignature.DefaultArgument; } procedure.Parameters.Add(parameter); } foreach (var attribute in procedureSignature.Attributes) { procedure.Attributes.Add(attribute); } if (procedureSignature.Documentation != "") { procedure.Documentation = procedureSignature.Documentation; } service.Procedures.Add(procedure); } foreach (var clsSignature in serviceSignature.Classes.Values) { var cls = new Class(); cls.Name = clsSignature.Name; if (clsSignature.Documentation != "") { cls.Documentation = clsSignature.Documentation; } service.Classes.Add(cls); } foreach (var enmSignature in serviceSignature.Enumerations.Values) { var enm = new Enumeration(); enm.Name = enmSignature.Name; if (enmSignature.Documentation != "") { enm.Documentation = enmSignature.Documentation; } foreach (var enmValueSignature in enmSignature.Values) { var enmValue = new EnumerationValue(); enmValue.Name = enmValueSignature.Name; enmValue.Value = enmValueSignature.Value; if (enmValueSignature.Documentation != "") { enmValue.Documentation = enmValueSignature.Documentation; } enm.Values.Add(enmValue); } service.Enumerations.Add(enm); } if (serviceSignature.Documentation != "") { service.Documentation = serviceSignature.Documentation; } services.Services_.Add(service); } return(services); }
private Enumeration FindOrCreateFilterFunctionsEnumeration() { foreach (Enumeration enumeration in Project.Enumerations) { if (enumeration.GetAttributeValue("isFilterFunctionsEnumeration", NamespaceUri, false)) { return enumeration; } } Enumeration e = Project.Enumerations.FirstOrDefault(_ => string.Equals(_.Name, "FilterFunction", StringComparison.OrdinalIgnoreCase) || string.Equals(_.Name, "FilterFunctions", StringComparison.OrdinalIgnoreCase)); if (e != null) return e; e = new Enumeration(); e.Name = typeof(FilterFunctions).Name; e.Namespace = Project.DefaultNamespace; e.IsFlags = Project.GetAttributeValue("createMultiValuedEnumeration", NamespaceUri, true); e.SetAttributeValue(PreferredPrefix, "isFilterFunctionsEnumeration", NamespaceUri, true); Project.Enumerations.Add(e); foreach (FilterFunctions value in ConvertUtilities.EnumEnumerateValues<FilterFunctions>()) { EnumerationValue enumerationValue = new EnumerationValue(); enumerationValue.Name = value.ToString(); enumerationValue.SetAttributeValue(PreferredPrefix, "filterFunction", NamespaceUri, value); List<string> enumNames = ConvertUtilities.SplitEnumNames(value).ToList(); if (enumNames.Count() > 1) { if (!e.IsFlags) continue; enumerationValue.Value = ConvertUtilities.Concatenate(enumNames, " | "); } else { enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture); } enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture); e.Values.Add(enumerationValue); } return e; }
public static Messages.Services GetServices() { var services = new Messages.Services(); foreach (var serviceSignature in Services.Instance.Signatures.Values) { var service = new Messages.Service(serviceSignature.Name); foreach (var procedureSignature in serviceSignature.Procedures.Values) { var procedure = new Procedure(procedureSignature.Name); if (procedureSignature.HasReturnType) { procedure.ReturnType = procedureSignature.ReturnType; procedure.ReturnIsNullable = procedureSignature.ReturnIsNullable; } foreach (var parameterSignature in procedureSignature.Parameters) { var parameter = new Parameter(parameterSignature.Name, parameterSignature.Type); if (parameterSignature.HasDefaultValue) { parameter.DefaultValue = parameterSignature.DefaultValue; } procedure.Parameters.Add(parameter); } if (procedureSignature.Documentation.Length > 0) { procedure.Documentation = procedureSignature.Documentation; } service.Procedures.Add(procedure); } foreach (var clsSignature in serviceSignature.Classes.Values) { var cls = new Class(clsSignature.Name); if (clsSignature.Documentation.Length > 0) { cls.Documentation = clsSignature.Documentation; } service.Classes.Add(cls); } foreach (var enmSignature in serviceSignature.Enumerations.Values) { var enm = new Enumeration(enmSignature.Name); if (enmSignature.Documentation.Length > 0) { enm.Documentation = enmSignature.Documentation; } foreach (var enmValueSignature in enmSignature.Values) { var enmValue = new EnumerationValue(enmValueSignature.Name, enmValueSignature.Value); if (enmValueSignature.Documentation.Length > 0) { enmValue.Documentation = enmValueSignature.Documentation; } enm.Values.Add(enmValue); } service.Enumerations.Add(enm); } foreach (var exnSignature in serviceSignature.Exceptions.Values) { var exn = new Messages.Exception(exnSignature.Name); if (exnSignature.Documentation.Length > 0) { exn.Documentation = exnSignature.Documentation; } service.Exceptions.Add(exn); } if (serviceSignature.Documentation.Length > 0) { service.Documentation = serviceSignature.Documentation; } services.ServicesList.Add(service); } return(services); }
private ProcedureExpressionStatement CreateEnumerationEqualsStatement(ProcedureStatement parent, Parameter enumParameter, EnumerationValue enumValue) { bool isZero = ConvertUtilities.ChangeType <int>(enumValue.TypedValue) == 0; if (!isZero && FilterFunctionsEnumeration.IsFlags) { // Sample: (@FilterFunctions & FilterFunctions.Equals) = FilterFunctions.Equals return(new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, ProcedureOperationType.BitwiseAnd, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue)), new ProcedureExpressionStatement(parent, enumValue.TypedValue))); } else { // Sample: @FilterFunctions = FilterFunctions.Equals return(new ProcedureExpressionStatement( parent, ProcedureOperationType.Equals, new ProcedureExpressionStatement(parent, enumParameter), new ProcedureExpressionStatement(parent, enumValue.TypedValue))); } }