public override Object Clone() { NodeValue clone = (NodeValue)base.Clone(); //Note: We purposely don't clone types, so we can always do identity checking return(clone); }
public ResourceInstanceSimpleProperty(string propertyName, NodeValue nodeValue, bool createDollarValue) : base(propertyName) { PropertyValue = nodeValue.ClrValue; ClrType = nodeValue.Type.ClrType; CreateDollarValue = createDollarValue; // TODO: make this random UseTickCountForJsonDateTime = false; //AstoriaTestProperties.Random.Next(2) == 0; }
public ResourceInstanceSimpleProperty CreateResourceSimpleInstanceProperty(NodeValue nodeValue) { if (this.IsNavigation == true) { throw new InvalidOperationException("Needs to be a simple property"); } ResourceInstanceSimpleProperty resourceInstanceSimpleProperty = new ResourceInstanceSimpleProperty(this.Name, nodeValue); return(resourceInstanceSimpleProperty); }
public override bool IsApproxValueComparable(NodeValue nodeValue) { if (nodeValue.ClrValue is T) { return(IsApproxValueComparable((T)nodeValue.ClrValue)); } else { throw new ArgumentException("Invalid type used"); } }
public static ResourceInstanceKey ConstructResourceInstanceKey(KeyExpression keyExpression) { List <ResourceInstanceSimpleProperty> keyProperties = new List <ResourceInstanceSimpleProperty>(); for (int i = 0; i < keyExpression.Properties.Count(); i++) { NodeProperty p = keyExpression.Properties.ElementAt(i); NodeValue nodeVal = keyExpression.Values.ElementAt(i); keyProperties.Add(new ResourceInstanceSimpleProperty(p.Name, nodeVal.ClrValue)); } ResourceInstanceKey instanceKey = new ResourceInstanceKey(keyExpression.ResourceContainer, keyExpression.ResourceType, keyProperties.ToArray()); return(instanceKey); }
public static ResourceInstanceProperty CreateProperty(ResourceProperty rp, bool createDollarValueVersion) { if (createDollarValueVersion == true && rp.IsComplexType) { throw new ArgumentException("Cannot do a $Value of a ComplexType"); } if (rp.IsComplexType) { return(new ResourceInstanceComplexProperty(rp.Type.Name, rp.Name, CreateComplexResourceInstance((ComplexType)rp.Type))); } else if (!rp.IsNavigation) { NodeValue nodeValue = Resource.CreateValue(rp); return(new ResourceInstanceSimpleProperty(rp.Name, nodeValue, createDollarValueVersion)); } else { throw new ArgumentException("Property has to be a complex type or simple property"); } }
public static ComplexResourceInstance CreateComplexResourceInstance(ComplexType type) { List <ResourceInstanceProperty> instanceProperties = new List <ResourceInstanceProperty>(); foreach (ResourceProperty childProperty in type.Properties) { ResourceInstanceProperty resourceInstanceProperty = null; if (childProperty.IsComplexType) { resourceInstanceProperty = new ResourceInstanceComplexProperty(childProperty.Type.Name, childProperty.Name, CreateComplexResourceInstance((ComplexType)childProperty.Type)); } else { NodeValue nodeValue = Resource.CreateValue(childProperty); resourceInstanceProperty = new ResourceInstanceSimpleProperty(childProperty.Name, nodeValue); } instanceProperties.Add(resourceInstanceProperty); } ComplexResourceInstance complexInstance = new ComplexResourceInstance(type.Name, instanceProperties.ToArray()); return(complexInstance); }
public bool IsApproxKeyValue() { if (_isApproxKeyValue == null) { _isApproxKeyValue = false; List <ResourceProperty> approxPrecisionKeys = new List <ResourceProperty>(); bool approxPrecisionFound = false; //If any of the key primitive types sometimes have inaccurate precision (ie: float) //Remove from collection, only want valid keys out of here foreach (ResourceProperty keyProp in this.Properties) { if ((keyProp.Type as PrimitiveType).IsApproxPrecision) { approxPrecisionFound = true; } } if (approxPrecisionFound) { for (int i = 0; i < this.Properties.Length; i++) { NodeValue val = this.Values[i]; ResourceProperty rp = this.Properties[i] as ResourceProperty; if ((rp.Type as PrimitiveType).IsApproxPrecision) { bool isApproxComparable = (rp.Type as PrimitiveType).IsApproxValueComparable(val); if (!isApproxComparable) { _isApproxKeyValue = true; break; } } } } } return(_isApproxKeyValue.Value); }
//Static public static ConstantExpression Constant(NodeValue value) { return new ConstantExpression(value); }
//Static public static ConstantExpression Constant(NodeValue value) { return(new ConstantExpression(value)); }
public NameValuePair(string name, NodeValue value) : base(name) { _value = value; }
public ResourceInstanceSimpleProperty(string propertyName, NodeValue nodeValue) : this(propertyName, nodeValue, false) { }
//Constructor public ConstantExpression(NodeValue value) : base(null) { _value = value; }
private static ResourceInstanceKey TryCreateUniqueResourceInstanceKey(ResourceContainer container, ResourceType resType, KeyExpressions relatedForeignKeys) { Workspace workspace = container.Workspace; List <ResourceInstanceSimpleProperty> keyProperties = new List <ResourceInstanceSimpleProperty>(); Dictionary <ResourceProperty, ResourceProperty> foreignKeyMap = resType.Key.Properties.OfType <ResourceProperty>() .Where(p => p.ForeignKeys.Any()) .ToDictionary(p => p, p => p.ForeignKeys.First().PrimaryKey.Properties.OfType <ResourceProperty>().First()); Dictionary <string, ResourceProperty> reverseForeignKeyMap = new Dictionary <string, ResourceProperty>(); foreach (KeyValuePair <ResourceProperty, ResourceProperty> pair in foreignKeyMap) { reverseForeignKeyMap[pair.Value.Name] = pair.Key; } Dictionary <ResourceProperty, object> propertyValues = new Dictionary <ResourceProperty, object>(); List <ResourceProperty> constrainedProperties = new List <ResourceProperty>(); foreach (ResourceProperty property in resType.Key.Properties.OfType <ResourceProperty>()) { if (foreignKeyMap.ContainsKey(property)) { constrainedProperties.Add(property); } else { NodeValue obj = (property.Type as PrimitiveType).CreateRandomValueForFacets(property.Facets); propertyValues[property] = obj.ClrValue; } } foreach (ResourceProperty currentProperty in constrainedProperties) { if (propertyValues.ContainsKey(currentProperty)) { continue; } ResourceProperty foreignProperty = foreignKeyMap[currentProperty]; ResourceContainer foreignContainer = container.FindDefaultRelatedContainer(foreignProperty.ResourceType); KeyExpression foreignKey = relatedForeignKeys.Where(k => k.ResourceContainer == foreignContainer).FirstOrDefault(); if (foreignKey == null) { KeyExpressions foreignKeys = workspace.GetAllExistingKeysOfType(foreignContainer, foreignProperty.ResourceType); while (foreignKey == null && foreignKeys.Any()) { foreignKey = foreignKeys.Choose(); // ensure that for every property in the key, it matches any local values for (int i = 0; i < foreignKey.Properties.Length; i++) { string keyPropertyName = foreignKey.Properties[i].Name; ResourceProperty localProperty; if (reverseForeignKeyMap.TryGetValue(keyPropertyName, out localProperty)) { object keyValue = foreignKey.Values[i].ClrValue; object localValue; if (propertyValues.TryGetValue(localProperty, out localValue)) { if (localValue != keyValue) { foreignKeys.Remove(foreignKey); foreignKey = null; break; } } } } } if (foreignKey == null) { AstoriaTestLog.FailAndThrow("Could not find an appropriate foreign key"); } relatedForeignKeys.Add(foreignKey); } for (int i = 0; i < foreignKey.Properties.Length; i++) { NodeProperty p = foreignKey.Properties[i]; if (p.Name == foreignProperty.Name) { propertyValues[currentProperty] = foreignKey.Values[i].ClrValue; } else if (p.ForeignKeys.Count() > 0) { string foreign = p.ForeignKeys.First().PrimaryKey.Properties.OfType <ResourceProperty>().First().Name; ResourceProperty localProperty; if (reverseForeignKeyMap.TryGetValue(foreign, out localProperty)) { propertyValues[localProperty] = foreignKey.Values[i].ClrValue; } } } } foreach (ResourceProperty property in resType.Key.Properties.OfType <ResourceProperty>()) { if (!propertyValues.ContainsKey(property)) { propertyValues[property] = (object)null; } } foreach (KeyValuePair <ResourceProperty, object> pair in propertyValues) { keyProperties.Add(new ResourceInstanceSimpleProperty(pair.Key.Facets, pair.Key.Name, pair.Value)); } ResourceInstanceKey resourceInstanceKey = new ResourceInstanceKey(container, resType, keyProperties.ToArray()); return(resourceInstanceKey); }
public static KeyExpression Key(ResourceContainer container, ResourceType type, NodeProperty[] properties, NodeValue[] values) { ConstantExpression[] constants = values.Select(v => Constant(v)).ToArray(); PropertyExpression[] propExps = properties.Select(p => Property(p)).ToArray(); return new KeyExpression(container, type, propExps, constants); }
public virtual bool IsApproxValueComparable(NodeValue nodeValue) { return(true); }
public static NodeFacet ConcurrencyMode(ConcurrencyMode mode) { NodeValue nodeValue = new NodeValue(mode, null); return(new NodeFacet(FacetKind.ConcurrencyMode, nodeValue)); }
//Constructor public NodeFacet(String name, NodeValue value) : base(name) { _value = value; _desc = "Facet"; }
public static NodeFacet UnsafeLinkOperations(params RequestVerb[] operations) { NodeValue nodeValue = new NodeValue(operations.ToList(), null); return(new NodeFacet(FacetKind.UnsafeLinkOperations, nodeValue)); }
public static NodeFacet UnderlyingType(UnderlyingType value) { NodeValue nodeValue = new NodeValue(value, null); return(new NodeFacet(FacetKind.UnderlyingType, nodeValue)); }