protected MessageHandlerFunc GetMessageHandler(IBindingContext context, MethodInfo method)
        {
            var allowBinding = false;

            MiddlewareHelper.Go(bindingMiddleware,
                                (handler, next) => handler.Handle(context, next),
                                () =>
            {
                allowBinding = true;
            });

            if (!allowBinding)
            {
                return(null);
            }

            if (context.MessageClass == null)
            {
                throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} does not resolve to a message class");
            }


            var invalidBindings = context.Parameters.Where(p => !p.HasBinding).ToList();

            // ReSharper disable once InvertIf
            if (invalidBindings.Count > 0)
            {
                var parameterNames = string.Join(", ", invalidBindings.Select(p => p.Info.Name));
                throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} has unknown parameters: {parameterNames}");
            }

            var resultHandler = ((IBindingResultAccess)context.Result).GetHandler();

            return(WrapMethod(method, context.Parameters.Select(p => ((IBindingParameterAccess)p).GetBinding()), resultHandler));
        }
Esempio n. 2
0
        public object Bind(Type type, IBindingContext context)
        {
            var instance = Activator.CreateInstance(type);
            Bind(type, instance, context);

            return instance;
        }
        protected override void Start()
        {
            VariableViewModel viewModel = new VariableViewModel()
            {
                Username = "******",
                Email    = "*****@*****.**",
                Remember = true
            };

            viewModel.Color  = this.variables.Get <Color>("color");
            viewModel.Vector = this.variables.Get <Vector3>("vector");

            IBindingContext bindingContext = this.BindingContext();

            bindingContext.DataContext = viewModel;

            /* databinding */
            BindingSet <VariableExample, VariableViewModel> bindingSet = this.CreateBindingSet <VariableExample, VariableViewModel>();

            bindingSet.Bind(this.variables.Get <InputField>("username")).For(v => v.text, v => v.onEndEdit).To(vm => vm.Username).TwoWay();
            bindingSet.Bind(this.variables.Get <InputField>("email")).For(v => v.text, v => v.onEndEdit).To(vm => vm.Email).TwoWay();
            bindingSet.Bind(this.variables.Get <Toggle>("remember")).For(v => v.isOn, v => v.onValueChanged).To(vm => vm.Remember).TwoWay();
            bindingSet.Bind(this.variables.Get <Button>("submit")).For(v => v.onClick).To(vm => vm.OnSubmit);
            bindingSet.Build();
        }
Esempio n. 4
0
 static public void FallBack(this IBindingContext me, IBindingContext other)
 {
     me.FallBack((name, key, extras) =>
     {
         return(other.Unsafe.TryGet(name, key, extras));
     });
 }
Esempio n. 5
0
        public void PopulateProperty(Type type, PropertyInfo property, IBindingContext context)
        {
            var propertyBinder = _propertyBinders.BinderFor(property);

            context.Logger.ChosePropertyBinder(property, propertyBinder);
            propertyBinder.Bind(property, context);
        }
Esempio n. 6
0
 /// <summary>
 /// Not yet implemented
 /// </summary>
 private static string ScriptAsDelete(
     IBindingContext bindingContext,
     ConnectionInfo connInfo,
     ObjectMetadata metadata)
 {
     return(null);
 }
 public void Bind(PropertyInfo property, IBindingContext context)
 {
     property.ForAttribute<BindingAttribute>(att =>
     {
         att.Bind(property, context);
     });
 }
Esempio n. 8
0
 private void populate(Type type, IBindingContext context)
 {
     _typeCache.ForEachProperty(type, prop =>
     {
         _propertyBinders.BinderFor(prop).Bind(prop, context);
     });
 }
        public static object GetViewForViewModel(this IDataTemplate template, IBindingContext context, object viewModel, Func<object, object> getConvertView, params object[] args)
        {
            if (template != null)
            {
                var cell = getConvertView(template.Id);
                if (cell != null && template.ViewType != null)
                {
                    if (!template.ViewType.IsAssignableFrom(cell.GetType()))
                    {
                        cell = null;
                    }
                }

                if (cell == null)
                {
                    cell = template.CreateView(args);
                }

                template.InitializeView(cell);
                context.Bindings.ClearBindings(cell);
                template.BindViewModel(context, viewModel, cell);
                return cell;
            }

            return null;
        }
Esempio n. 10
0
 public override void Bind(PropertyInfo property, IBindingContext context)
 {
     context.Service<IRequestHeaders>().Value<string>(_headerName, val =>
     {
         property.SetValue(context.Object, val, null);
     });
 }
Esempio n. 11
0
        public virtual void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var text2DRenderer = context.GetComponentData <Text2DRenderer>(entity);
            var text2DStyle    = context.GetComponentData <Text2DStyle>(entity);

            var text = context.GetUnityComponent <TText>(entity);

            if (context.HasComponent <TextString>(entity))
            {
                var textString = context.GetBufferRO <TextString>(entity).Reinterpret <char>().AsString();
                text.text = textString;
            }
            else
            {
                text.text = string.Empty;
            }

            text.fontStyle   = FontStyles.Normal;
            text.lineSpacing = 1;
            text.richText    = false;
            text.alignment   = Fonts.GetTextAlignmentFromPivot(text2DRenderer.pivot);
            var c = text2DStyle.color;

            text.color              = new Color(c.r, c.g, c.b, c.a);;
            text.fontSize           = text2DStyle.size * SizeFactor;
            text.isOrthographic     = true;
            text.enableWordWrapping = false;

            Transfer(entity, text, context);
        }
Esempio n. 12
0
 protected override void Transfer(Entity entity, TextMeshProUGUI text, IBindingContext context)
 {
     base.Transfer(entity, text, context);
     try
     {
         if (context.HasComponent <Text2DAutoFit>(entity))
         {
             var autoFit = context.GetComponentData <Text2DAutoFit>(entity);
             text.enableAutoSizing   = true;
             text.fontSizeMin        = autoFit.minSize * SizeFactor;
             text.fontSizeMax        = autoFit.maxSize * SizeFactor;
             text.enableWordWrapping = false;
         }
         else
         {
             text.enableAutoSizing   = false;
             text.enableWordWrapping = false;
         }
     }
     finally
     {
         Canvas.ForceUpdateCanvases();
         LayoutRebuilder.ForceRebuildLayoutImmediate(context.GetUnityComponent <RectTransform>(entity).root as RectTransform);
     }
 }
Esempio n. 13
0
        public override void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            base.TransferToUnityComponents(entity, context);
            var rt = context.GetUnityComponent <RectTransform>(entity);

            rt.sizeDelta = Vector2.zero;
        }
Esempio n. 14
0
        public void Handle(IBindingContext context, Action next)
        {
            next();

            if (context.Result.HasHandler)
            {
                return;
            }


            bool isTaskOf;
            Type actualType;

            if (!context.Result.Info.ParameterType.IsTypeOrTaskOf(t => t.IsClass, out isTaskOf, out actualType))
            {
                return;
            }


            if (isTaskOf)
            {
                var handler = GetType().GetMethod("PublishGenericTaskResult", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(actualType);

                context.Result.SetHandler(async(messageContext, value) =>
                {
                    await(Task) handler.Invoke(null, new[] { messageContext, value });
                });
            }
            else
            {
                context.Result.SetHandler((messageContext, value) =>
                                          value == null ? null : Reply(value, messageContext));
            }
        }
Esempio n. 15
0
	public static Game NewGame(IBindingContext context)
	{
		WorldLogicCoordinateTransform transformer = new WorldLogicCoordinateTransform(0.32f,10,10);
		var boardView = context.Get<BoardView> (InnerBindingNames.Empty,10,10,transformer);

		return new Game(boardView);
	}
        public object Bind(Type inputModelType, IBindingContext context)
        {
            //we determine the type by sniffing the ctor arg
            var entityType = inputModelType
                .GetConstructors()
                .Single(x => x.GetParameters().Count() == 1)
                .GetParameters()
                .Single()
                .ParameterType;

            var entity = tryFindExistingEntity(entityType, context)
                ?? createNewEntity(entityType, context);

            var model = (EditEntityModel)Activator.CreateInstance(inputModelType, entity);

            context.BindProperties(model);

            // Get the binding errors from conversion of the EditEntityModel
            context.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Property, FastPackKeys.PARSE_VALUE);
            });

            return model;
        }
Esempio n. 17
0
 public void Bind(PropertyInfo property, IBindingContext context)
 {
     property.ForAttribute <BindingAttribute>(att =>
     {
         att.Bind(property, context);
     });
 }
Esempio n. 18
0
 public override void Bind(PropertyInfo property, IBindingContext context)
 {
     var chain = context.Service<ICurrentChain>();
     var resource = ResourceHash.For(new VaryByResource(chain));
     
     property.SetValue(context.Object, resource, null);
 }
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            var type = property.PropertyType;
            var itemType = type.GetGenericArguments()[0];
            if (type.IsInterface)
            {
                type = _collectionTypeProvider.GetCollectionType(type, itemType);
            }

            object collection = Activator.CreateInstance(type);
            var collectionType = collection.GetType();

            Func<object, bool> addToCollection = obj =>
                {
                    if (obj != null)
                    {
                        var addMethod = _addMethods[collectionType];
                        addMethod.Invoke(collection, new[] {obj});
                        return true;
                    }
                    return false;
                };

            var formatString = property.Name + "[{0}]";

            int index = 0;
            string prefix;
            do
            {
                prefix = formatString.ToFormat(index);
                index++;
            } while (addToCollection(context.BindObject(prefix, itemType)));

            property.SetValue(context.Object, collection, null);
        }
Esempio n. 20
0
 public void TransferFromUnityComponents(Entity entity, IBindingContext context)
 {
     context.SetComponentData(entity, new RectHitBox2D
     {
         box = context.GetUnityComponent <Unity.Tiny.RectHitBox2D>(entity).Box.Convert()
     });
 }
Esempio n. 21
0
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                var requests = context.GetEnumerableRequests(property.Name).ToList();

                // TODO -- need an end to end test on this behavior
                if (!requests.Any())
                {
                    return;
                }

                var data = new T[requests.Count];

                for (int i = 0; i < requests.Count; i++)
                {
                    var requestData = requests[i];

                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(requestData, typeof(T), o =>
                    {
                        data[i] = (T)o;
                    });
                }

                property.SetValue(context.Object, data, null);
            }
Esempio n. 22
0
        public object Bind(Type type, IBindingContext context)
        {
            var model = Activator.CreateInstance(type);
            Bind(type, model, context);

            return model;
        }
Esempio n. 23
0
        /// <summary>
        /// Determines whether or not a request is an Ajax request by searching for a value of the "X-Requested-With" header
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool IsAjaxRequest(this IBindingContext context)
        {
            bool returnValue = false;

            context.Data.ValueAs <object>(XRequestedWithHeader, val => returnValue = val.IsAjaxRequest());
            return(returnValue);
        }
Esempio n. 24
0
        public object Bind(Type type, IBindingContext context)
        {
            object model = Activator.CreateInstance(type);

            context.BindProperties(model);
            return(model);
        }
Esempio n. 25
0
            public CacheKey(IdentifierCollection identifiers, bool ignoreCase, IBindingContext bindingContext, BoundExpressionOptions options)
            {
                Options = options;

                OwnerType = bindingContext.OwnerType;

                var imports = bindingContext.Imports;

                Imports = new Import[imports == null ? 0 : imports.Count];

                if (Imports.Length > 0)
                {
                    imports.CopyTo(Imports, 0);
                }

                IdentifierTypes = new Type[identifiers.Count];

                for (int i = 0; i < identifiers.Count; i++)
                {
                    IdentifierTypes[i] = bindingContext.GetVariableType(
                        identifiers[i].Name,
                        ignoreCase
                        );
                }
            }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelTemperature"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public ModelTemperature(IBindingContext context)
     : base(context)
 {
     context.ThrowIfNull(nameof(context));
     _temperature = context.GetState <ITemperatureSimulationState>();
     Parameters   = context.GetParameterSet <ModelParameters>();
 }
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                if (_conversionPropertyBinder.CanBeParsed(property.PropertyType))
                {
                    bool convertedAsIs = context.Data.ValueAs <string>(property.Name, value => _conversionPropertyBinder.Bind(property, context));
                    if (convertedAsIs)
                    {
                        return;
                    }
                }

                var collection = property.GetValue(context.Object, null) as ICollection <T>;

                if (collection == null)
                {
                    collection = new List <T>();
                    property.SetValue(context.Object, collection, null);
                }

                context.GetEnumerableRequests(property.Name).Each(request =>
                {
                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(request, typeof(T), @object => { collection.Add((T)@object); });
                });
            }
Esempio n. 28
0
        /// <summary>
        /// Script create statements for metadata object
        /// </summary>
        private static string ScriptAsCreate(
            IBindingContext bindingContext,
            ConnectionInfo connInfo,
            ObjectMetadata metadata)
        {
            Scripter         scripter = new Scripter(bindingContext.ServerConnection, connInfo);
            StringCollection results  = null;

            if (metadata.MetadataType == MetadataType.Table)
            {
                results = scripter.GetTableScripts(metadata.Name, metadata.Schema);
            }
            else if (metadata.MetadataType == MetadataType.SProc)
            {
                results = scripter.GetStoredProcedureScripts(metadata.Name, metadata.Schema);
            }
            else if (metadata.MetadataType == MetadataType.View)
            {
                results = scripter.GetViewScripts(metadata.Name, metadata.Schema);
            }

            StringBuilder builder = null;

            if (results != null)
            {
                builder = new StringBuilder();
                foreach (var result in results)
                {
                    builder.AppendLine(result);
                    builder.AppendLine();
                }
            }
            return(builder != null?builder.ToString() : null);
        }
Esempio n. 29
0
        void Start()
        {
            viewModel = new ListViewViewModel();
            for (int i = 0; i < 3; i++)
            {
                viewModel.AddItem();
            }
            viewModel.Items[0].IsSelected = true;

            IBindingContext bindingContext = this.BindingContext();

            bindingContext.DataContext = viewModel;

            BindingSet <ListViewDatabindingExample, ListViewViewModel> bindingSet = this.CreateBindingSet <ListViewDatabindingExample, ListViewViewModel>();

            bindingSet.Bind(this.listView).For(v => v.Items).To(vm => vm.Items).OneWay();
            bindingSet.Bind(this.listView).For(v => v.OnSelectChanged).To <int>(vm => vm.Select).OneWay();

            bindingSet.Bind(this.addButton).For(v => v.onClick).To(vm => vm.AddItem);
            bindingSet.Bind(this.removeButton).For(v => v.onClick).To(vm => vm.RemoveItem);
            bindingSet.Bind(this.clearButton).For(v => v.onClick).To(vm => vm.ClearItem);
            bindingSet.Bind(this.changeIconButton).For(v => v.onClick).To(vm => vm.ChangeItemIcon);

            bindingSet.Build();
        }
Esempio n. 30
0
        public void TransferFromUnityComponents(Entity entity, IBindingContext context)
        {
            var image = context.GetUnityComponent <UnityEngine.UI.Image>(entity);

            context.SetComponentData(entity, new Sprite2DRenderer()
            {
                sprite = context.GetEntity(image.sprite),
                color  = image.color.Convert()
            });

            var rt = context.GetUnityComponent <UnityEngine.RectTransform>(entity);

            var optionsData = new Sprite2DRendererOptions()
            {
                size = rt.rect.size
            };


            if (image.type == UnityEngine.UI.Image.Type.Simple || image.type == UnityEngine.UI.Image.Type.Sliced)
            {
                optionsData.drawMode = DrawMode.Stretch;
            }
            else
            {
                optionsData.drawMode = DrawMode.ContinuousTiling;
            }
            if (context.HasComponent <Sprite2DRendererOptions>(entity))
            {
                context.SetComponentData(entity, optionsData);
            }
            else
            {
                context.AddComponentData(entity, optionsData);
            }
        }
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            if (context.Object == null)
            {
                return;
            }

            Type entityType = context.Object.GetTrueType();

            // If there is no Extends<> for the entity type, do nothing
            if (!ExtensionProperties.HasExtensionFor(entityType))
            {
                return;
            }

            Type extensionType = ExtensionProperties.ExtensionFor(entityType);

            // direct the FubuMVC model binding to resolve an object of the
            // extensionType using "entityType.Name" as the prefix on the form data,
            // and place the newly created object using the specified property
            var childRequest = context.GetSubRequest(property.Name);

            context.BindObject(childRequest, property.PropertyType, o =>
            {
                property.SetValue(context.Object, o, null);
            });
        }
Esempio n. 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Time(IBindingContext context)
            : base(context)
        {
            _bp = context.GetParameterSet <Parameters>();

            // Create derivatives for the numerator and denominator
            _state  = context.GetState <ITimeSimulationState>();
            _method = context.GetState <IIntegrationMethod>();
            if (_bp.Numerator.Length > 1)
            {
                _dNumerator = new IDerivative[_bp.Numerator.Length - 1];
                for (int i = 0; i < _dNumerator.Length; i++)
                {
                    _dNumerator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dNumerator = null;
            }
            if (_bp.Denominator.Length > 1)
            {
                _dDenominator = new IDerivative[_bp.Denominator.Length - 1];
                for (int i = 0; i < _dDenominator.Length; i++)
                {
                    _dDenominator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dDenominator = null;
            }
        }
 private void Update(object source)
 {
     if (_parentContext != null)
     {
         var src = _parentContext.Source;
         if (src != null)
         {
             WeakEventManager.GetBindingContextListener(src).Remove(this);
         }
     }
     if (source == null)
     {
         _parentContext = null;
     }
     else
     {
         _parentContext = GetParentBindingContext(source);
         if (_parentContext != null)
         {
             var src = _parentContext.Source;
             if (src != null)
             {
                 WeakEventManager.GetBindingContextListener(src).Add(this);
             }
         }
     }
 }
Esempio n. 34
0
        /// <inheritdoc/>
        public IWaveform Create(IBindingContext context)
        {
            IIntegrationMethod method = null;
            TimeParameters     tp     = null;

            context?.TryGetState(out method);
            context?.TryGetSimulationParameterSet(out tp);
            double step = 1.0;

            if (!RiseTime.Given || !FallTime.Given)
            {
                if (tp is SpiceMethod sm)
                {
                    step = sm.InitialStep;
                }
                else if (tp != null)
                {
                    step = tp.StopTime / 50.0;
                }
            }
            return(new Instance(method,
                                InitialValue,
                                PulsedValue,
                                Delay,
                                RiseTime.Given ? RiseTime.Value : step,
                                FallTime.Given ? FallTime.Value : step,
                                PulseWidth,
                                Period));
        }
Esempio n. 35
0
        public object Bind(Type type, IBindingContext context)
        {
            var entityType = type.GetConstructors().Single(x => x.GetParameters().Count() == 1).GetParameters().Single().ParameterType;

            // This is our convention.
            var prefix = entityType.Name;
            var prefixedContext = context.PrefixWith(prefix);

            DomainEntity entity = tryFindExistingEntity(context, prefixedContext, entityType) ?? createNewEntity(entityType, prefixedContext);

            var model = (EditEntityModel)Activator.CreateInstance(type, entity);

            // Get the binding errors from conversion of the Entity
            prefixedContext.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            _innerBinder.Bind(type, model, context);

            // Get the binding errors from conversion of the EditEntityModel
            context.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            return model;
        }
Esempio n. 36
0
        public object Bind(Type type, IBindingContext context)
        {
            var entityType = type.GetConstructors().Single(x => x.GetParameters().Count() == 1).GetParameters().Single().ParameterType;

            // This is our convention.
            var prefix          = entityType.Name;
            var prefixedContext = context.PrefixWith(prefix);

            DomainEntity entity = tryFindExistingEntity(context, prefixedContext, entityType) ?? createNewEntity(entityType, prefixedContext);

            var model = (EditEntityModel)Activator.CreateInstance(type, entity);


            // Get the binding errors from conversion of the Entity
            prefixedContext.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            _innerBinder.Bind(type, model, context);

            // Get the binding errors from conversion of the EditEntityModel
            context.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            return(model);
        }
        public static BindingSet <TBehaviour, TSource> CreateBindingSet <TBehaviour, TSource>(this TBehaviour behaviour, TSource dataContext) where TBehaviour : Behaviour
        {
            IBindingContext context = behaviour.BindingContext();

            context.DataContext = dataContext;
            return(new BindingSet <TBehaviour, TSource>(context, behaviour));
        }
 private void SetCubeRed(IBindingContext panel)
 {
     if (instence)
     {
         instence.GetComponent <MeshRenderer> ().material.color = Color.red;
     }
 }
Esempio n. 39
0
 public override void Bind(PropertyInfo property, IBindingContext context)
 {
     context.Service <IRequestHeaders>().Value <string>(_headerName, val =>
     {
         property.SetValue(context.Object, val, null);
     });
 }
Esempio n. 40
0
        public BoundExpression GetOrCreateBoundExpression(IBindingContext binder, BoundExpressionOptions options)
        {
            Require.NotNull(binder, "binder");
            Require.NotNull(options, "options");

            var key = new CacheKey(
                _dynamicExpression.ParseResult.Identifiers,
                !DynamicExpression.IsLanguageCaseSensitive(_dynamicExpression.Language),
                binder,
                options
            );

            lock (_syncRoot)
            {
                BoundExpression boundExpression;

                if (!_cache.TryGetValue(key, out boundExpression))
                {
                    boundExpression = new BoundExpression(
                        _dynamicExpression,
                        key.OwnerType,
                        key.Imports,
                        key.IdentifierTypes,
                        key.Options
                    );

                    _cache.Add(key, boundExpression);
                }

                return boundExpression;
            }
        }
Esempio n. 41
0
        public BoundExpression GetOrCreateBoundExpression(IBindingContext binder, BoundExpressionOptions options)
        {
            Require.NotNull(binder, "binder");
            Require.NotNull(options, "options");

            var key = new CacheKey(
                _dynamicExpression.ParseResult.Identifiers,
                !DynamicExpression.IsLanguageCaseSensitive(_dynamicExpression.Language),
                binder,
                options
                );

            lock (_syncRoot)
            {
                BoundExpression boundExpression;

                if (!_cache.TryGetValue(key, out boundExpression))
                {
                    boundExpression = new BoundExpression(
                        _dynamicExpression,
                        key.OwnerType,
                        key.Imports,
                        key.IdentifierTypes,
                        key.Options
                        );

                    _cache.Add(key, boundExpression);
                }

                return(boundExpression);
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Use a ConnectionInfo item to create a connected binding context
        /// </summary>
        /// <param name="connInfo">Connection info used to create binding context</param>
        /// <param name="overwrite">Overwrite existing context</param>
        public virtual string AddConnectionContext(ConnectionInfo connInfo, string featureName = null, bool overwrite = false)
        {
            if (connInfo == null)
            {
                return(string.Empty);
            }

            // lookup the current binding context
            string connectionKey = GetConnectionContextKey(connInfo);

            if (BindingContextExists(connectionKey))
            {
                if (overwrite)
                {
                    RemoveBindingContext(connectionKey);
                }
                else
                {
                    // no need to populate the context again since the context already exists
                    return(connectionKey);
                }
            }
            IBindingContext bindingContext = this.GetOrCreateBindingContext(connectionKey);

            if (bindingContext.BindingLock.WaitOne())
            {
                try
                {
                    bindingContext.BindingLock.Reset();
                    SqlConnection sqlConn = connectionOpener.OpenSqlConnection(connInfo, featureName);

                    // populate the binding context to work with the SMO metadata provider
                    bindingContext.ServerConnection = new ServerConnection(sqlConn);

                    if (this.needsMetadata)
                    {
                        bindingContext.SmoMetadataProvider         = SmoMetadataProvider.CreateConnectedProvider(bindingContext.ServerConnection);
                        bindingContext.MetadataDisplayInfoProvider = new MetadataDisplayInfoProvider();
                        bindingContext.MetadataDisplayInfoProvider.BuiltInCasing =
                            this.CurrentSettings.SqlTools.IntelliSense.LowerCaseSuggestions.Value
                                ? CasingStyle.Lowercase : CasingStyle.Uppercase;
                        bindingContext.Binder = BinderProvider.CreateBinder(bindingContext.SmoMetadataProvider);
                    }

                    bindingContext.BindingTimeout = ConnectedBindingQueue.DefaultBindingTimeout;
                    bindingContext.IsConnected    = true;
                }
                catch (Exception)
                {
                    bindingContext.IsConnected = false;
                }
                finally
                {
                    bindingContext.BindingLock.Set();
                }
            }

            return(connectionKey);
        }
Esempio n. 43
0
        private DomainEntity createNewEntity(Type entityType, IBindingContext prefixedContext)
        {
            var entity = (DomainEntity)_innerBinder.Bind(entityType, prefixedContext);
            entity.Id = Guid.Empty;
            _entityDefaults.ApplyDefaultsToNewEntity(entity);

            return entity;
        }
        public EmbeddedPipelineBindingContext(IBindingContext parent)
        {
            _parent = Ensure.IsNotNull(parent, nameof(parent));

            _correlationMapping = new Dictionary<Expression, Guid>();
            _expressionMapping = new Dictionary<Expression, Expression>();
            _memberMapping = new Dictionary<MemberInfo, Expression>();
        }
        public object Bind(Type type, IBindingContext context)
        {
            var contentType = context.Data.ValueAs<string>("Content-Type");
            var acceptType = context.Data.ValueAs<string>("Accept");
            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            return currentMimeType;
        }
 public ViewHolderImpl(View itemView, int viewType)
     : base(itemView)
 {
     if (viewType != global::Android.Resource.Layout.SimpleListItem1)
     {
         _bindingContext = BindingServiceProvider.ContextManager.GetBindingContext(itemView);
         _bindingContext.Value = null;
     }
 }
 public void Bind(PropertyInfo property, IBindingContext context)
 {
     var fubuRequest = context.Service<IFubuRequest>();
     var modelType = property.PropertyType;
     if (fubuRequest.Has(modelType))
     {
         property.SetValue(context.Object, fubuRequest.Get(modelType), null);
     }
 }
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            var httpContext = context.Service<HttpContextBase>();
            var ipAddress = httpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrWhiteSpace(ipAddress)) ipAddress = httpContext.Request.ServerVariables["HTTP_X_FORWARDED"];
            if (string.IsNullOrWhiteSpace(ipAddress)) ipAddress = httpContext.Request.UserHostAddress;

            property.SetValue(context.Object, ipAddress, null);
        }
Esempio n. 49
0
 public object Bind(Type type, IBindingContext context)
 {
     var jsonModel = context
                         .Service<IFubuRequest>()
                         .Get<JsonModel>();
     return context
             .Service<IJsonService>()
             .Deserialize(type, jsonModel.Body);
 }
 public void Bind(PropertyInfo property, IBindingContext context)
 {
     context.ForProperty(property, () =>
     {
         ValueConverter converter = _converters.FindConverter(property);
         object value = converter(context);
         property.SetValue(context.Object, value, null);
     });
 }
 public static void PopulatePropertyWithBinder(PropertyInfo property, IBindingContext context,
                                               IPropertyBinder propertyBinder)
 {
     context.Logger.Chose(property, propertyBinder);
     context.ForProperty(property, propertyContext =>
     {
         propertyBinder.Bind(property, context);
     });
 }
Esempio n. 52
0
        public void Bind(Type type, object instance, IBindingContext context)
        {
            var request = context.Service<IFubuRequest>();

            _types.ForEachProperty(type, prop =>
            {
                var value = request.Get(prop.PropertyType);
                prop.SetValue(instance, value, null);
            });
        }
Esempio n. 53
0
        public bool Bind(object instance, PropertyInfo propertyInfo, IBindingContext bindingContext)
        {
            if (!bindingSourceCollection.ContainsKey(bindingContext.GetKey(propertyInfo.Name)))
                return false;

            propertyInfo.SetValue(instance, valueConverterCollection.Convert(propertyInfo.PropertyType,
                                                                             bindingSourceCollection.Get(bindingContext.GetKey(propertyInfo.Name))), new object[0]);

            return true;
        }
Esempio n. 54
0
        public void TryBindModel(Type type, IBindingContext context, Action<BindResult> continuation)
        {
            var binder = _binders.BinderFor(type);

            if (binder != null)
            {
                var result = executeModelBinder(type, binder, context);
                continuation(result);
            }
        }
Esempio n. 55
0
        public object Bind(Type type, IBindingContext context)
        {
            var path = FindPath(context.Service<IRequestData>());
            object instance = Activator.CreateInstance(type, path);

            // Setting additional properties
            // TODO -- have this delegate to a new method on BindingContext instead
            context.BindProperties(instance);

            return instance;
        }
Esempio n. 56
0
        public static SelectExpression BindSelect(PipelineExpression pipeline, IBindingContext bindingContext, LambdaExpression lambda)
        {
            bindingContext.AddExpressionMapping(lambda.Parameters[0], pipeline.Projector);

            var selector = bindingContext.Bind(lambda.Body);

            return new SelectExpression(
                pipeline.Source,
                lambda.Parameters[0].Name,
                selector);
        }
Esempio n. 57
0
        public static WhereExpression BindWhere(PipelineExpression pipeline, IBindingContext bindingContext, LambdaExpression lambda)
        {
            bindingContext.AddExpressionMapping(lambda.Parameters[0], pipeline.Projector);

            var predicate = bindingContext.Bind(lambda.Body);

            return new WhereExpression(
                pipeline.Source,
                lambda.Parameters[0].Name,
                predicate);
        }
Esempio n. 58
0
        public bool Bind(object instance, PropertyInfo propertyInfo, IBindingContext bindingContext)
        {
            using (bindingContext.OpenChildContext(string.Format("{0}_", propertyInfo.Name)))
            {
                var obj = bindingContext.Bind(propertyInfo.PropertyType);
                if (obj == null) return false;

                propertyInfo.SetValue(instance, obj, new object[0]);
                return true;
            }
        }
Esempio n. 59
0
	void Start()
	{
		DontDestroyOnLoad (gameObject);

		var bindingFinder = new ReflectiveBindingFinder (GetType ().Assembly);

		m_masterContext = new ReflectiveBindingContextFactory (bindingFinder).CreateContext();

		m_masterContext.Get<Game> ();

	}
Esempio n. 60
0
        // TODO -- need an integrated test with Connection String providers
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            context.ForProperty(property, () =>
            {
                ValueConverter converter = _cache[property];

                var value = converter(context);

                property.SetValue(context.Object, value, null);
            });
        }