private Attribute(string name, object value, AttributeValueType valueType, bool writeIfEmpty) { Name = name; Value = value; ValueType = valueType; WriteIfEmpty = writeIfEmpty; }
private List <Article> GetArticleSubsetForAttributeValueType(AttributeValueType attributeValueType, string word) { int highestWordCount = 0; foreach (var article in Articles) { int value; if (article.AllWords.TryGetValue(word, out value) && value > highestWordCount) { highestWordCount = value; } } List <Article> articles; switch (attributeValueType) { case AttributeValueType.Zero: articles = GetArticleSubsetForAttributeTypeZero(word); break; case AttributeValueType.LessHalf: articles = GetArticleSubsetForAttributeTypeLessHalf(word, highestWordCount); break; case AttributeValueType.MoreHalf: articles = GetArticleSubsetForAttributeTypeMoreHalf(word, highestWordCount); break; default: throw new Exception("Article subset selection not implemented for this Attribute Value Type"); } return(articles); }
public AttributeValueEventArgs(byte connection, ushort attHandle, AttributeValueType type, byte[] value) { Connection = connection; AttHandle = attHandle; Type = type; Value = value; }
public Attribute(int line, AttributeTypes atttype, string attributeValue, AttributeValueType type) { Line = line; AttributeType = atttype; AttributeValue = attributeValue; ValueType = type; }
internal Attribute(int line, AttributeTypes atttype, string value, AttributeValueType type, bool isGlobal = false) { Line = line; AttributeType = atttype; Value = value; ValueType = type; IsGlobal = isGlobal; AttributeValueCheck(); }
/// <summary> /// Redosled navodjenja Apply elementa u XACML politici je bitan /// 1. Apply koji definise tip (AttributeDesignator element) /// 2. Donja granica /// 3. Gordnja granica /// </summary> /// <param name="Item"> ApplyType element - Sadrzi listu Apply elemenata</param> /// <param name="request"> Xacml zahtev </param> /// <returns></returns> public override bool EvaluateConditionFor(ApplyType Item, RequestType request) { bool TimeConditionResult = true; ApplyType currentTimeItem = Item.Items[0] as ApplyType; ApplyType lowerBoundItem = Item.Items[1] as ApplyType; ApplyType upperBoundItem = Item.Items[2] as ApplyType; // designator za def DataType, Category, AttributeId AttributeDesignatorType attributeDesignator = currentTimeItem.Items[0] as AttributeDesignatorType; // lower bound time ExpressionType[] lowItems = lowerBoundItem.Items; ApplyType lowItem = lowItems[0] as ApplyType; AttributeValueType lowItemValue = lowItem.Items[0] as AttributeValueType; XmlNode lowItemValueAny = lowItemValue.Any[0] as XmlNode; string lowerBoundTime = lowItemValueAny.Value as string; // upper bound time ExpressionType[] uppItems = upperBoundItem.Items; ApplyType uppItem = uppItems[0] as ApplyType; AttributeValueType uppItemValue = uppItem.Items[0] as AttributeValueType; XmlNode uppItemValueAny = uppItemValue.Any[0] as XmlNode; string upperBoundTime = uppItemValueAny.Value as string; // konverzija vremena - daylight saving time - +1 na vremensku zonu tako da je srbija na +2 po letnjem racunanju vremena // preporuka da se vreme definise u UTC formatu DateTime lowerBoundTimeValue = DateTime.Parse(lowerBoundTime, System.Globalization.CultureInfo.CurrentCulture); DateTime upperBoundTimeValue = DateTime.Parse(upperBoundTime, System.Globalization.CultureInfo.CurrentCulture); bool exists = false; List <AttributeType> Attributes = new List <AttributeType>(2); Attributes = AttributeDesignatorManager.RequestBagOfValues(attributeDesignator, request); if (Attributes.Count == 0) { // Provera MustBePresented atributa if (attributeDesignator.MustBePresent) { // PDP zahteva od PIP dobavljanje atributa koji su potrebni ContextHandler ch = new ContextHandler(); Attributes = ch.RequestForEnvironmentAttribute(attributeDesignator); } else { return(TimeConditionResult); } } TimeConditionResult = TimeConditionEvaluation(lowerBoundTimeValue, upperBoundTimeValue, Attributes, out exists); return(TimeConditionResult); }
private static AttributeValueType GetDateValueType(JProperty property, ItemChoiceType type) { var result = new AttributeValueType(); if (property.Value.Type == JTokenType.Null) result.Item = null; else result.Item = property.Value.Value<DateTime>(); result.ItemElementName = type; return result; }
private static AttributeValueType GetValueType(JProperty property, ItemChoiceType type, object item, JsonSerializer serializer) { var result = new AttributeValueType(); if (property.Value.Type == JTokenType.Null) result.Item = null; else { serializer.Populate(property.Value.CreateReader(), item); result.Item = item; } result.ItemElementName = type; return result; }
private static AttributeValueType GetDateValueType(JProperty property, ItemChoiceType type) { var result = new AttributeValueType(); if (property.Value.Type == JTokenType.Null) { result.Item = null; } else { result.Item = property.Value.Value <DateTime>(); } result.ItemElementName = type; return(result); }
/// <summary> /// Kreira XACML atribut na osnovu domenskog atributa /// </summary> /// <param name="DomainAttribute"></param> /// <returns></returns> private AttributeType CreateXacmlAttribute(DomainAttribute DomainAttribute) { if (DomainAttribute.AttributeId == null || DomainAttribute.DataType == null) { return(null); } AttributeType AttrType = new AttributeType(); AttrType.IncludeInResult = false; string id = null; if (!AttributeConversionManager.IdConversion.TryGetValue(DomainAttribute.AttributeId, out id)) { id = DomainAttribute.AttributeId; } AttrType.AttributeId = id; AttributeValueType AttrValue = new AttributeValueType(); string dataType = null; if (!AttributeConversionManager.DataTypeConversion.TryGetValue(DomainAttribute.DataType, out dataType)) { dataType = DomainAttribute.DataType; } AttrValue.DataType = dataType; XmlDocument doc = new XmlDocument(); XmlNode[] nodes = new XmlNode[1]; XmlNode node = doc.CreateNode(XmlNodeType.Text, "Value", ""); node.Value = DomainAttribute.Value; nodes[0] = node; AttrValue.Any = nodes; AttributeValueType[] attrVals = new AttributeValueType[1]; attrVals[0] = AttrValue; AttrType.AttributeValue = attrVals; return(AttrType); }
private static AttributeValueType GetValueType(JProperty property, ItemChoiceType type, object item, JsonSerializer serializer) { var result = new AttributeValueType(); if (property.Value.Type == JTokenType.Null) { result.Item = null; } else { serializer.Populate(property.Value.CreateReader(), item); result.Item = item; } result.ItemElementName = type; return(result); }
private static AttributeValueType GetAttributeValue(IIfcPropertyBoundedValue ifcPropertyBoundedValue) { var attributeValueType = new AttributeValueType(); IIfcValue ifcValue = ifcPropertyBoundedValue.LowerBoundValue; var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; //only upper and lowwer bounds are supported by COBie on integer and decimal values if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte) || underlyingType == typeof(int?) || underlyingType == typeof(long?) || underlyingType == typeof(short?) || underlyingType == typeof(byte?)) { var integerValue = new AttributeIntegerValueType(); if (ifcPropertyBoundedValue.UpperBoundValue != null) { integerValue.MaxValueInteger = Convert.ToInt32(((IExpressValueType)ifcPropertyBoundedValue.UpperBoundValue).Value); } if (ifcPropertyBoundedValue.LowerBoundValue != null) { integerValue.MinValueInteger = Convert.ToInt32(((IExpressValueType)ifcPropertyBoundedValue.LowerBoundValue).Value); } attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (underlyingType == typeof(double) || underlyingType == typeof(float) || underlyingType == typeof(double?) || underlyingType == typeof(float?)) { var decimalValue = new AttributeDecimalValueType(); if (ifcPropertyBoundedValue.UpperBoundValue != null) { decimalValue.MaxValueDecimal = (double)((IExpressValueType)ifcPropertyBoundedValue.UpperBoundValue).Value; decimalValue.MaxValueDecimalSpecified = true; } if (ifcPropertyBoundedValue.LowerBoundValue != null) { decimalValue.MinValueDecimal = (double)((IExpressValueType)ifcPropertyBoundedValue.LowerBoundValue).Value; decimalValue.MinValueDecimalSpecified = true; } attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else { attributeValueType = null; } return(attributeValueType); }
private void ParseAttributes(Data data, XmlAttributeCollection attributes) { foreach (XmlAttribute attr in attributes) { object outValue; AttributeValueType type = ParseAttributeValue(attr.Value, out outValue); Attribute attribute = new Attribute(type, attr.Name, outValue); if (data.SetAttribute(attribute)) { } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("idspace '{0}' -class '{1}' has more than one attribute named '{2}'.", _idspace, data.Id, attribute.Key); Console.ForegroundColor = ConsoleColor.Gray; } } }
public static XbimSimplePropertyType SimplePropertyType(this AttributeValueType valueType) { if (valueType == null || valueType.Item == null) { return(XbimSimplePropertyType.Null); } string valueTypeString = valueType.Item.GetType().Name; switch (valueTypeString) { case "BooleanValueType": return(XbimSimplePropertyType.SimpleBoolean); case "DateTime": return(XbimSimplePropertyType.SimpleDateTime); case "AttributeDecimalValueType": var dt = valueType.Item as AttributeDecimalValueType; return(dt != null && (dt.MaxValueDecimalSpecified || dt.MinValueDecimalSpecified) ? XbimSimplePropertyType.BoundedDecimal : XbimSimplePropertyType.SimpleDecimal); case "AttributeIntegerValueType": var it = valueType.Item as AttributeIntegerValueType; return(it != null && (it.MaxValueIntegerSpecified || it.MinValueIntegerSpecified) ? XbimSimplePropertyType.BoundedInteger : XbimSimplePropertyType.SimpleInteger); case "AttributeMonetaryValueType": return(XbimSimplePropertyType.SimpleMonetary); case "AttributeStringValueType": var st = valueType.Item as AttributeStringValueType; return(st != null && st.AllowedValues != null && st.AllowedValues.Any() ? XbimSimplePropertyType.EnumerationString : XbimSimplePropertyType.SimpleString); default: return(XbimSimplePropertyType.Null); } }
public string ReadAttribute(string attributeName, AttributeValueType valueType) { XAttribute attribute = CurrentElement.Attribute(attributeName); if (attribute == null) { switch (valueType) { case AttributeValueType.Number: return("0"); case AttributeValueType.String: return(string.Empty); default: throw new NotImplementedException("Unkown value type."); } } return(attribute.Value); }
static public AttributeValueType GetAttributeValueType(IfcPropertySingleValue ifcProperty) { IfcValue ifcValue = ifcProperty.NominalValue; var attributeValueType = new AttributeValueType(); if (ifcValue == null) { return(null); } if (ifcValue is IfcMonetaryMeasure) { attributeValueType.ItemElementName = ItemChoiceType.AttributeMonetaryValue; var monetaryValue = new AttributeMonetaryValueType { MonetaryValue = Convert.ToDecimal((double)ifcValue.Value) }; attributeValueType.Item = monetaryValue; if (ifcProperty.Unit is IfcMonetaryUnit) { var mu = ifcProperty.Unit as IfcMonetaryUnit; CurrencyUnitSimpleType cu; if (Enum.TryParse(mu.Currency.ToString(), true, out cu)) { monetaryValue.MonetaryUnit = cu; } else { CoBieLiteHelper.Logger.WarnFormat("Invalid monetary unit: {0} ", mu.Currency); } } } else if (ifcValue is IfcTimeStamp) { attributeValueType.ItemElementName = ItemChoiceType.AttributeDateTimeValue; var timeStamp = (IfcTimeStamp)ifcValue; attributeValueType.Item = IfcTimeStamp.ToDateTime(timeStamp); } else if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte)) { var integerValue = new AttributeIntegerValueType { IntegerValue = Convert.ToInt32(ifcValue.Value) }; attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float)) { var decimalValue = new AttributeDecimalValueType { DecimalValue = (double)ifcValue.Value, DecimalValueSpecified = true }; attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else if (ifcValue.UnderlyingSystemType == typeof(string)) { var stringValue = new AttributeStringValueType { StringValue = ifcValue.ToString() }; attributeValueType.Item = stringValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeStringValue; } else if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?)) { var boolValue = new BooleanValueType(); if (ifcValue.Value != null && (bool)ifcValue.Value) { var theBool = (bool)ifcValue.Value; boolValue.BooleanValue = theBool; boolValue.BooleanValueSpecified = true; } attributeValueType.Item = boolValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeBooleanValue; } else { attributeValueType = null; } return(attributeValueType); }
/// <summary> /// Adds the attribute. /// </summary> /// <param name="attributeValueType"> /// Type of the attribute value. /// </param> public void AddAttribute(AttributeValueType attributeValueType) { this._attributes.Add(attributeValueType); }
public static TargetResult CheckTarget(TargetType Target, RequestType request) { MatchFunctions[XacmlFunctions.STRING_EQUAL] = new StringEqual(); ContextHandler ch = new ContextHandler(); int numberOfMatchAnyOf = 0; int numberOfNoMatchAnyOf = 0; int numberOfIndeterminateAnyOf = 0; if (Target != null) { if (Target.AnyOf != null) { foreach (AnyOfType AnyOf in Target.AnyOf) { int numberOfMatchAllOf = 0; int numberOfIndeterminateAllOf = 0; int numberOfNoMatchAllOf = 0; AllOfType[] AllOfs = AnyOf.AllOf; foreach (AllOfType AllOf in AllOfs) { int numberOfFalseMatch = 0; int numberOfIndeterminateMatch = 0; MatchType[] Matches = AllOf.Match; try { foreach (MatchType Match in Matches) { AttributeDesignatorType AttributeDesignator = Match.Item as AttributeDesignatorType; AttributeValueType AttributeValue = Match.AttributeValue; List <AttributeType> Attributes = AttributeDesignatorManager.RequestBagOfValues(AttributeDesignator, request); int numberOfMatch = 0; if (Attributes.Count == 0) { // bag of values je prazan, provera atributa MustBePresented if (AttributeDesignator.MustBePresent) { // TODO zahteva dobavljanje atributa od PIP if (AttributeDesignator.Category.Equals(XacmlSubject.CATEGORY)) { string subjectId = SubjectIdResolver.SubjectId(request); if (!(subjectId == null)) { Attributes = ch.RequestForSubjectAttribute(AttributeDesignator, subjectId); } else { Attributes = null; } } else { Attributes = ch.RequestForEnvironmentAttribute(AttributeDesignator); } // ako PIP ne vrati atribut - zbog true vrednosti MustBePresented if (Attributes != null) { if (Attributes[0] == null) { numberOfIndeterminateMatch++; continue; } } else { numberOfIndeterminateMatch++; continue; } if (Attributes.Count == 0) { numberOfIndeterminateMatch++; continue; } } } string attributeValue = string.Empty; foreach (AttributeType attr in Attributes) { AttributeValueType[] attrValues = attr.AttributeValue; foreach (AttributeValueType attrValue in attrValues) { XmlNode node = attrValue.Any[0]; attributeValue = node.Value; } string value = AttributeValue.Any[0].Value.ToString(); // evaluacija prema funkciji definisanoj MatchId atributom bool decision = MatchFunctions[Match.MatchId].CheckIfMatch(ref value, ref attributeValue); if (decision) { numberOfMatch++; } } if (numberOfMatch == 0) { numberOfFalseMatch++; } } } catch (Exception) { numberOfIndeterminateMatch++; } /// AllOf evaluacija if (numberOfFalseMatch != 0) { numberOfNoMatchAllOf++; } else if (numberOfIndeterminateMatch > 0) { numberOfIndeterminateAllOf++; } else if (numberOfFalseMatch == 0 && numberOfIndeterminateMatch == 0) { numberOfMatchAllOf++; } } /// AnyOf evaluacija if (numberOfIndeterminateAllOf > 0 && numberOfMatchAllOf == 0) { numberOfIndeterminateAnyOf++; } else if (numberOfMatchAllOf > 0) { numberOfMatchAnyOf++; } else if (numberOfNoMatchAllOf > 0) { numberOfNoMatchAnyOf++; } } } else { // empty target return(TargetResult.Match); } } else { // empty target return(TargetResult.Match); } if (numberOfNoMatchAnyOf > 0) { return(TargetResult.NoMatch); } else if (numberOfMatchAnyOf > 0 && numberOfIndeterminateAnyOf == 0) { return(TargetResult.Match); } else { return(TargetResult.Indeterminate); } }
public void RemoveType(AttributeValueType type) { this.Types &= ~(int)type; }
public static AttributeValueType GetAttributeValueType(IIfcPropertySingleValue ifcProperty) { IIfcValue ifcValue = ifcProperty.NominalValue; var attributeValueType = new AttributeValueType(); if (ifcValue == null) { return(null); } var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; if (ifcValue is Xbim.Ifc4.MeasureResource.IfcMonetaryMeasure) { attributeValueType.ItemElementName = ItemChoiceType.AttributeMonetaryValue; var monetaryValue = new AttributeMonetaryValueType { MonetaryValue = Convert.ToDecimal((double)expressValue.Value) }; attributeValueType.Item = monetaryValue; if (!(ifcProperty.Unit is IIfcMonetaryUnit)) { return(attributeValueType); } var mu = (IIfcMonetaryUnit)ifcProperty.Unit; CurrencyUnitSimpleType cu; if (Enum.TryParse(mu.Currency.ToString(), true, out cu)) { monetaryValue.MonetaryUnit = cu; } else { logger.LogWarning("Invalid monetary unit: {currency} ", mu.Currency); } } else if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp) { attributeValueType.ItemElementName = ItemChoiceType.AttributeDateTimeValue; var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue; attributeValueType.Item = timeStamp.ToDateTime(); } else if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte)) { var integerValue = new AttributeIntegerValueType { IntegerValue = Convert.ToInt32(expressValue.Value) }; attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (underlyingType == typeof(double) || underlyingType == typeof(float)) { var decimalValue = new AttributeDecimalValueType { DecimalValue = (double)expressValue.Value, DecimalValueSpecified = true }; attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else if (underlyingType == typeof(string)) { var stringValue = new AttributeStringValueType { StringValue = ifcValue.ToString() }; attributeValueType.Item = stringValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeStringValue; } else if (underlyingType == typeof(bool) || underlyingType == typeof(bool?)) { var boolValue = new BooleanValueType(); if (expressValue.Value != null && (bool)expressValue.Value) { var theBool = (bool)expressValue.Value; boolValue.BooleanValue = theBool; boolValue.BooleanValueSpecified = true; } attributeValueType.Item = boolValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeBooleanValue; } else { attributeValueType = null; } return(attributeValueType); }
public void SetType(AttributeValueType type) { this.Types = (int)type; }
public bool IncludeType(AttributeValueType type) { return((this.Types & (int)type) > 0); }
/// <summary> /// Handles the selections. /// </summary> /// <param name="complexDataQuery">The complex data query.</param> /// <param name="whereType">Type of the where.</param> /// <param name="complexDataQuerySelections"></param> /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxSemmanticException"> /// Invalid structure type for component and /// </exception> private static void HandleSelections(IComplexDataQuery complexDataQuery, DataParametersAndType whereType, IEnumerable<IComplexDataQuerySelection> complexDataQuerySelections, IParameterBuilder builder) { foreach (IComplexDataQuerySelection complexDataQuerySelection in complexDataQuerySelections) { builder.Reset(); // Dimension Values inside an OR -or- AND clause foreach (IComplexComponentValue complexComponentValue in complexDataQuerySelection.Values) { var component = complexDataQuery.DataStructure.GetComponent(complexDataQuerySelection.ComponentId); if (component == null) { throw new SdmxSemmanticException(string.Format("Component with ID {0} does not exist in the DSD {1}", complexDataQuerySelection.ComponentId, complexDataQuery.DataStructure)); } switch (component.StructureType.EnumType) { case SdmxStructureEnumType.Dimension: case SdmxStructureEnumType.MeasureDimension: { var dimensionValueType = new DimensionValueType { ID = complexDataQuerySelection.ComponentId }; SetOperatorAndValue(component, complexComponentValue, dimensionValueType); builder.AddDimension(dimensionValueType); } break; case SdmxStructureEnumType.DataAttribute: { var attributeValueType = new AttributeValueType { ID = complexDataQuerySelection.ComponentId }; SetOperatorAndValue(component, complexComponentValue, attributeValueType); builder.AddAttribute(attributeValueType); } break; default: throw new SdmxSemmanticException(string.Format("Invalid structure type for component ID : {1} Type {0} ", component.StructureType.EnumType, component.Urn)); } } builder.PopulateAndParameter(whereType); } }
/// <summary> /// Adds the attribute. /// </summary> /// <param name="attributeValueType"> /// Type of the attribute value. /// </param> public void AddAttribute(AttributeValueType attributeValueType) { this._dataParametersOrType.AttributeValue.Add(attributeValueType); }
public void AddType(AttributeValueType type) { this.Types |= (int)type; }