Esempio n. 1
0
 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]));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
        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]));
        }
Esempio n. 7
0
        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);
                                                 });
            }
        }
Esempio n. 8
0
 public bool CanHandle(InvokeContext callContext)
 {
     return callContext.Name.Equals("Attach");
 }
Esempio n. 9
0
 public bool CanHandle(InvokeContext callContext)
 {
     return true;
 }
Esempio n. 10
0
 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])));
 }
Esempio n. 11
0
 public override void Action(InvokeContext context)
 {
     Console.WriteLine("log end!");
 }
Esempio n. 12
0
 public bool CanHandle(InvokeContext callContext)
 {
     return callContext.Name.InvariantEquals("Add");
 }
Esempio n. 13
0
 public bool CanHandle(InvokeContext callContext)
 {
     return callContext.Name.Contains("And");
 }
Esempio n. 14
0
 public bool CanHandle(InvokeContext callContext)
 {
     return callContext.Name.Equals("AddResource");
 }
Esempio n. 15
0
 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));
 }
Esempio n. 16
0
 public bool CanHandle(InvokeContext callContext)
 {
     return callContext.Name.StartsWithAnyOf("Bind", "OneWayBind");
 }
Esempio n. 17
0
 public bool CanHandle(InvokeContext ctx)
 {
     return ctx.Name.StartsWith("Static");
 }
Esempio n. 18
0
 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));
 }
Esempio n. 19
0
        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);
                    }
                }
            }
        }