public void Handle(InvokeContext ctx) { var propertyName = ctx.Name; var propertyType = ctx.XamlType.GetPropertyType(propertyName); var values = ctx.NormalizeToBuiltXaml(c => c.Values[0]).MustHaveValue(); ctx.AddSetterWith(new SetterContext(propertyName, propertyType, values.Length > 1 ? values : values[0])); }
public void Handle(InvokeContext ctx) { var names = ctx.Name.Split(new string[] { "And" }, StringSplitOptions.RemoveEmptyEntries); var propType = ctx.XamlType.GetPropertyTypeProvider(); names.Zip(ctx.Values, (s, o) => new { PropName = s, Value = o }) .Select(a => new SetterContext(a.PropName, propType(a.PropName), a.Value)) .ForEach(ctx.AddSetterWith); }
public void Handle(InvokeContext ctx) { FailIfXamlNotAFrameworkElement(ctx); var propertyName = ctx.Name.Replace("OneWayBind", "").Replace("Bind", ""); var depProp = ctx.XamlType .FindDependencyProperty(propertyName) .MustHaveValue(new ArgumentException("No DependencyProperty '{0}' found on type '{1}'".Fmt(propertyName, ctx.XamlType.Name))); ctx.AddSetterWith(ctx.NewBindSetterContext(depProp)); }
private static void GuardAgainstSignatureFailures(InvokeContext ctx) { if (ctx.Values.Length < 2 || !ctx.Values[0].CanBeCastTo<DependencyProperty>()) ThrowException(); if (ctx.IsArgumentNameSpecified("path")) return; if (!((DependencyProperty)ctx.Values[0]).IsValidType(ctx.Values[1])) ThrowException(); }
public void Handle(InvokeContext ctx) { GuardAgainstSignatureFailures(ctx); var attachProp = (DependencyProperty)ctx.Values[0]; if (ctx.IsArgumentNameSpecified("path")) ctx.AddSetterWith(ctx.NewBindSetterContext(attachProp)); else { var value = ctx.Values[1]; ctx.AddSetterWith<DependencyObject>(xaml => xaml.SetValue(attachProp, value)); } }
public void Handle(InvokeContext ctx) { FailIfXamlNotAFrameworkElement(ctx); object value = null; ctx.Values[1].Maybe( v => v.Cast<Func<XamlBuilder, Xaml>>() .Get(func => func(ctx.Builder).Create()) .Do(xaml => value = xaml), v => v.Cast<Xaml>() .Get(x => x.Create()) .Do(xaml => value = xaml) ); ctx.AddSetterWith<FrameworkElement>(fw => fw.Resources.Add(ctx.Values[0], value ?? ctx.Values[1])); }
public void Handle(InvokeContext ctx) { FailIfIAddChildIsMissing(ctx); var values = ctx.Values.Select(v => ctx.NormalizeToBuiltXaml(_ => v).MustHaveValue()).Flatten(); foreach (var value in values) { var v = value; ctx.AddSetterWith<IAddChild>(ac => { if (v.CanBeCastTo<string>()) ac.AddText((string) v); else ac.AddChild(v); }); } }
public bool CanHandle(InvokeContext callContext) { return callContext.Name.Equals("Attach"); }
public bool CanHandle(InvokeContext callContext) { return true; }
public void Handle(InvokeContext ctx) { var propertyName = ctx.Name.Replace("Static", ""); var propertyType = ctx.XamlType.GetPropertyType(propertyName); ctx.AddSetterWith(new SetterContext(propertyName, propertyType, new StaticResource(ctx.Values[0]))); }
public override void Action(InvokeContext context) { Console.WriteLine("log end!"); }
public bool CanHandle(InvokeContext callContext) { return callContext.Name.InvariantEquals("Add"); }
public bool CanHandle(InvokeContext callContext) { return callContext.Name.Contains("And"); }
public bool CanHandle(InvokeContext callContext) { return callContext.Name.Equals("AddResource"); }
private static void FailIfIAddChildIsMissing(InvokeContext ctx) { if (!ctx.XamlType.CanBeCastTo<IAddChild>()) throw new NotSupportedException("Type {0} does not support IAddChild interface, hence Add is not supported.".Fmt(ctx.XamlType.Name)); }
public bool CanHandle(InvokeContext callContext) { return callContext.Name.StartsWithAnyOf("Bind", "OneWayBind"); }
public bool CanHandle(InvokeContext ctx) { return ctx.Name.StartsWith("Static"); }
private static void FailIfXamlNotAFrameworkElement(InvokeContext ctx) { if (!ctx.XamlType.CanBeCastTo<FrameworkElement>()) throw new NotSupportedException("Type {0} is not assignable to FrameworkElement, Binding is therefore not supported".Fmt(ctx.XamlType.Name)); }
public async Task Invoke(InvokeContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } object[] customAttributes = (object[])context.Request.Properties["CustomAttributes"]; DatabaseConnection databaseConnection = customAttributes.FirstOrDefault(t => t.GetType() == typeof(DatabaseConnection)) as DatabaseConnection; bool isDatabaseConnectionEnabled = databaseConnection == null ? true : databaseConnection.IsEnabled; if (!isDatabaseConnectionEnabled) { await _next.Invoke(context); } else { var appContext = Application.Current.Context; Transactional transactional = customAttributes.FirstOrDefault(t => t.GetType() == typeof(Transactional)) as Transactional; bool isTransactionEnabled = transactional == null ? false : transactional.IsEnabled; DbConnection connection = GetDbConnection(DbContextOptions.DbProviderName); DatabaseContext ctx = null; if (isTransactionEnabled) { connection.ConnectionString = DbContextOptions.WriteConnectionString; using (ctx = new DatabaseContext(true, connection)) { ctx.DbProviderName = DbContextOptions.DbProviderName; ServiceContext serviceContext = (ServiceContext)context.Request.Properties["ServiceContext"]; serviceContext.AddItem("DatabaseContext", ctx); await _next.Invoke(context); InvokeResult invokeResult = context.Result; if (invokeResult?.Value != null) { dynamic result = invokeResult.Value; if (result.GetType().Name == typeof(ServiceResponse <>).Name) { if (result?.IsSuccess == true) { ctx.Commit(); } else { ctx.Transaction.Rollback(); } } else { ctx.Commit(); } } else { ctx.Transaction.Rollback(); } } } else { connection.ConnectionString = DbContextOptions.ReadConnectionString; using (ctx = new DatabaseContext(false, connection)) { ctx.DbProviderName = DbContextOptions.DbProviderName; ServiceContext serviceContext = (ServiceContext)context.Request.Properties["ServiceContext"]; serviceContext.AddItem("DatabaseContext", ctx); await _next.Invoke(context); } } } }