private static void Validate(ListNode listNode) { if (listNode.Metadata.HasFlag(BindingMetadataFlags.Item) && listNode.Metadata.Parent.Composition?.Add == null) { throw BindingException.FromMetadata(listNode.Metadata.Parent, $"List add method not found."); } }
public static void Validate(AggregateNode aggregateNode) { if (aggregateNode.Item == null) { return; } foreach (MetadataNode node in aggregateNode.Item.Tree().Skip(1)) { if (!node.Metadata.HasFlag(BindingMetadataFlags.Writable)) { throw BindingException.FromProperty(node.Identity.Name, $"Property is read-only."); } if (node.ListIndex == null) { ValidateConstructor(node); } if (node.ListIndex == null && node.HasFlag(NodeFlags.Dynamic)) { ValidateDynamic(node); } } }
public void TraceBindingError(BindingException ex) { log.Trace(MethodBase.GetCurrentMethod().Name); if (ReportFileInstance.CurrentStep != null) { ReportFileInstance.CurrentStep.Status = TestResultStatus.Skipped; ReportFileInstance.CurrentStep.ErrorMessageString = ex.ToString(); // ReportFileInstance.WriteToXml(TestResultsDirectory); } ReportFileInstance.CurrentStep = null; }
private static void ValidateConstructor(MetadataNode node) { NewExpression constructor = node.Metadata.Composition?.Construct; if (constructor == null) { throw BindingException.FromProperty(node.Identity.Name, $"No default constructor defined."); } else if (!node.Metadata.Type.IsAssignableFrom(constructor.Type)) { throw BindingException.FromProperty(node.Identity.Name, $"No conversion exists between constructor type '{constructor.Type.GetSanitizedName()}' and property type '{node.Metadata.Type.GetSanitizedName()}'."); } }
private Expression GetValueReaderProxy(IBindingValueInfo valueInfo) { Expression value = valueInfo.Value; if (value.Type != typeof(object) && value.Type != typeof(string)) { throw BindingException.Create(valueInfo.Metadata, $"Cannot deserialize JSON from type '{value.Type.GetSanitizedName()}'."); } Expression nullCheck = null; if (valueInfo.CanBeDbNull) { nullCheck = Expression.TypeIs(value, typeof(DBNull)); } if (valueInfo.CanBeNull) { Expression isNull = Expression.ReferenceEqual(value, Expression.Constant(null, value.Type)); nullCheck = nullCheck == null ? isNull : Expression.AndAlso(nullCheck, isNull); } if (value.Type == typeof(object)) { value = Expression.Convert(value, typeof(string)); } Expression targetValue; if (valueInfo.TargetType == typeof(JsonDocument)) { targetValue = this.GetParseDocumentExpression(valueInfo.Metadata, value); } else if (valueInfo.TargetType == typeof(JsonElement)) { targetValue = this.GetParseElementExpression(valueInfo.Metadata, value); } else { targetValue = this.GetDeserializeExpression(valueInfo.Metadata, value, valueInfo.Helper); } if (nullCheck != null) { return(Expression.Condition(nullCheck, Expression.Default(targetValue.Type), targetValue)); } return(targetValue); }
static bool ShowInternal(Exception e) { BindingException mte = (e as BindingException); bool error = true; if (mte != null) { error = mte.Error; if (!error && GetWarningLevel(mte.Code) == WarningLevel.Disable) { return(false); } Console.Out.WriteLine(mte.ToString()); if (Verbosity > 1) { Exception ie = e.InnerException; if (ie != null) { if (Verbosity > 3) { Console.Error.WriteLine("--- inner exception"); Console.Error.WriteLine(ie); Console.Error.WriteLine("---"); } else { Console.Error.WriteLine("\t{0}", ie.Message); } } } if (Verbosity > 2) { Console.Error.WriteLine(e.StackTrace); } } else { Console.Out.WriteLine("error BI0000: Unexpected error - Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new"); Console.Out.WriteLine(e.ToString()); Console.Out.WriteLine(Environment.StackTrace); } return(error); }
private void AddChildKey(ListResult result, TargetWriter writer) { IList <IReference> references = this.GetChildReferences(writer.Source.Metadata).ToList(); KeyReader childKey = references.Select(r => this.FindChildKey(writer.Source, r)).NotNull().FirstOrDefault(); if (childKey != null && this.IsValidJoinKey(childKey, throwOnInvalid: true)) { this.InitializeKey(childKey); } if (childKey == null && this.RequiresReference(writer.Source.Metadata)) { throw BindingException.NoReferenceFound(writer.Source.Metadata); } writer.List = this.GetListTarget(result, writer.Source.Metadata, childKey); writer.Join = this.GetJoinTarget(result, childKey); }
private Expression GetValueReaderProxy(IBindingValueInfo valueInfo) { Expression value = valueInfo.Value; if (value.Type != typeof(object) && value.Type != typeof(string)) { throw BindingException.FromMetadata(valueInfo.Metadata, $"Cannot deserialize JSON from type '{value.Type.GetSanitizedName()}'."); } Expression nullCheck = null; if (valueInfo.CanBeDbNull) { nullCheck = Expression.TypeIs(value, typeof(DBNull)); } if (valueInfo.CanBeNull) { Expression isNull = Expression.ReferenceEqual(value, Expression.Constant(null, value.Type)); if (nullCheck == null) { nullCheck = isNull; } else { nullCheck = Expression.AndAlso(nullCheck, isNull); } } if (value.Type == typeof(object)) { value = Expression.Convert(value, typeof(string)); } Expression jsonValue = this.GetJsonDeserializer(valueInfo.Metadata, value, valueInfo.Helper); if (nullCheck != null) { return(Expression.Condition(nullCheck, Expression.Default(jsonValue.Type), jsonValue)); } return(jsonValue); }
public static void Validate(MetadataNode itemNode) { foreach (MetadataNode node in itemNode.Tree()) { if (!node.Metadata.HasFlag(BindingMetadataFlags.Item) && !node.Metadata.HasFlag(BindingMetadataFlags.Writable)) { throw BindingException.FromProperty(node.Identity.Name, $"Property is read-only."); } if (node.Column == null) { ValidateConstructor(node); } if (node.Column == null && node.HasFlag(NodeFlags.Dynamic)) { ValidateDynamic(node); } } }
static bool ShowInternal(Exception e) { BindingException mte = (e as BindingException); bool error = true; if (mte != null) { error = mte.Error; Console.Out.WriteLine(mte.ToString()); if (Verbosity > 1) { Exception ie = e.InnerException; if (ie != null) { if (Verbosity > 3) { Console.Error.WriteLine("--- inner exception"); Console.Error.WriteLine(ie); Console.Error.WriteLine("---"); } else { Console.Error.WriteLine("\t{0}", ie.Message); } } } if (Verbosity > 2) { Console.Error.WriteLine(e.StackTrace); } } else { Console.Out.WriteLine("error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com"); Console.Out.WriteLine(e.ToString()); Console.Out.WriteLine(Environment.StackTrace); } return(error); }
private bool IsValidJoinKey(KeyReader joinKey, bool throwOnInvalid = false) { IReferenceKey parentKey = joinKey.Reference.FindParentKey(); IReferenceKey childKey = joinKey.Reference.FindChildKey(); foreach (var(childValue, parentValue) in childKey.Properties.Zip(parentKey.Properties)) { Type parentType = parentValue.Type.GetKeyType(); Type childType = childValue.Type.GetKeyType(); if (parentType != childType && throwOnInvalid) { throw BindingException.InvalidReference(joinKey.Reference); } else if (parentType != childType) { return(false); } } return(true); }
public void TraceBindingError(BindingException ex) { if (CurrentStepId != null) { var request = new FinishTestItemRequest { Status = Status.Failed, EndTime = DateTime.UtcNow, Issue = new Issue { Type = IssueType.AutomationBug, Comment = ex.Message } }; var errorRequest = new AddLogItemRequest { TestItemId = CurrentStepId, Level = LogLevel.Error, Time = DateTime.UtcNow, Text = ex.ToString() }; Bridge.Service.AddLogItem(errorRequest); if (BeforeStepFinished != null) { BeforeStepFinished(this, new TestItemFinishedEventArgs(Bridge.Service, request)); } var message = Bridge.Service.FinishTestItem(CurrentStepId, request).Info; if (AfterStepFinished != null) { AfterStepFinished(this, new TestItemFinishedEventArgs(Bridge.Service, request, message)); } CurrentStepId = null; Bridge.Context.TestId = null; } }
public void TraceBindingError(BindingException ex) { traceListener.WriteToolOutput("binding error: {0}", ex.Message); }
public void TraceBindingError(BindingException ex) { throw new NotImplementedException(); }
public BufferConverter Compile(MetadataIdentity metadata, ColumnMetadata columnInfo) { IBindingMetadata binding = metadata.Lookup <IBindingMetadata>(); ParameterExpression inputParam = Expression.Parameter(typeof(object)); ParameterExpression helperParam = Expression.Parameter(typeof(object)); ParameterExpression helperVariable = this.GetHelperVariable(binding); Expression value = inputParam; if (binding != null) { Type sourceType = null; if (columnInfo != null) { BindingColumnInfo bindingColumnInfo = new BindingColumnInfo() { Column = columnInfo, CanBeNull = true, Metadata = binding, }; sourceType = binding.Value?.Read(bindingColumnInfo)?.ReturnType; } BindingValueInfo valueInfo = new BindingValueInfo() { CanBeNull = true, CanBeDbNull = true, Metadata = binding, Value = value, SourceType = sourceType, TargetType = binding.Type, Helper = helperVariable, }; try { value = binding.Value?.Convert?.Invoke(valueInfo) ?? inputParam; } catch (BindingException) { throw; } catch (Exception ex) { throw BindingException.InvalidCast(binding, ex); } } value = this.GetObjectExpression(value); if (helperVariable != null) { Expression typedParam = Expression.Convert(helperParam, helperVariable.Type); Expression assignHelper = Expression.Assign(helperVariable, typedParam); value = Expression.Block(new[] { helperVariable }, assignHelper, value); } BufferInternalConverter innerFunc = Expression.Lambda <BufferInternalConverter>(value, inputParam, helperParam).Compile(); object helperObject = binding?.Helper?.Object; return(value => innerFunc(value, helperObject)); }
public void TraceBindingError(BindingException ex) { Console.WriteLine("TraceBindingError: {0}", ex); }
private ListTarget GetListTarget(ListResult result, IBindingMetadata metadata, KeyReader joinKey) { int bufferIndex = this.Buffer.GetListIndex(metadata, joinKey?.Reference); metadata = joinKey?.Target ?? metadata; ListTarget target = result.Targets.FirstOrDefault(t => t.Index == bufferIndex); if (target != null) { return(target); } target = new ListTarget() { Index = bufferIndex, Variable = this.GetListVariable(metadata, joinKey), }; if (joinKey == null && metadata.HasFlag(BindingMetadataFlags.Item)) { target.NewList = target.NewTarget = metadata.Parent.Composition?.Construct ?? throw BindingException.InvalidConstructor(metadata.Parent); target.AddMethod = metadata.Parent.Composition.Add; } if (joinKey != null) { target.NewTarget = Expression.New(target.Variable.Type); } if (target.NewTarget != null) { result.Targets.Add(target); } return(target); }
private ParameterExpression GetListVariable(IBindingMetadata metadata, KeyReader joinKey) { if (joinKey != null) { Type dictType = typeof(Dictionary <,>).MakeGenericType(joinKey.KeyType, typeof(ElasticArray)); return(this.GetNamedVariable(dictType, metadata.Identity)); } else if (metadata.HasFlag(BindingMetadataFlags.Item)) { Type listType = metadata.Parent.Composition?.Construct?.Type ?? throw BindingException.InvalidConstructor(metadata.Parent); return(this.GetNamedVariable(listType, metadata.Identity)); } return(null); }