Exemplo n.º 1
0
        /// <summary>
        /// Applies all <see cref="Binding"/>s listed in a specific <see cref="IBindingContainer"/>.
        /// </summary>
        /// <param name="bindingContainer">The list of <see cref="Binding"/>s to be performed.</param>
        /// <param name="implementation">The implementation to be made available via the <see cref="Binding"/>s.</param>
        /// <param name="startInfo">The process launch environment to apply the <see cref="Binding"/>s to.</param>
        /// <exception cref="ImplementationNotFoundException">The <paramref name="implementation"/> is not cached yet.</exception>
        /// <exception cref="ExecutorException">A <see cref="Command"/> contained invalid data.</exception>
        /// <exception cref="IOException">A problem occurred while writing a file.</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to a file is not permitted.</exception>
        private void ApplyBindings(IBindingContainer bindingContainer, ImplementationSelection implementation, ProcessStartInfo startInfo)
        {
            // Do not apply bindings more than once
            if (!_appliedBindingContainers.Add(bindingContainer))
            {
                return;
            }

            if (bindingContainer.Bindings.Count == 0)
            {
                return;
            }

            // Don't use bindings for PackageImplementations
            if (implementation.ID.StartsWith(ExternalImplementation.PackagePrefix))
            {
                return;
            }

            new PerTypeDispatcher <Binding>(ignoreMissing: true)
            {
                (EnvironmentBinding environmentBinding) => ApplyEnvironmentBinding(environmentBinding, implementation, startInfo),
                //(OverlayBinding overlayBinding) => ApplyOverlayBinding(overlayBinding, implementation, startInfo),
                (ExecutableInVar executableInVar) => ApplyExecutableInVar(executableInVar, implementation, startInfo),
                (ExecutableInPath executableInPath) => ApplyExecutableInPath(executableInPath, implementation, startInfo)
            }.Dispatch(bindingContainer.Bindings);
        }
Exemplo n.º 2
0
        public bool TryGetChildren(
            IBindingContainer bindingContainer,
            DetectedConstructorArgument constructorArgument,
            out IReadOnlyList <ExtenderAndTypePair> result
            )
        {
            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            if (constructorArgument is null)
            {
                throw new ArgumentNullException(nameof(constructorArgument));
            }

            var rresult = new List <ExtenderAndTypePair>();

            if (constructorArgument.Type is null)
            {
                throw new DpdtException(
                          DpdtExceptionTypeEnum.InternalError,
                          $"constructorArgument.Type is null somehow"
                          );
            }

            BindingContainerGroup?group;

            if (!Groups.TryGetValue(constructorArgument.Type, out group))
            {
                var unwrappedType = constructorArgument.GetUnwrappedType();

                if (!Groups.TryGetValue(unwrappedType, out group))
                {
                    result = new List <ExtenderAndTypePair>();
                    return(false);
                }
            }

            if (group is null)
            {
                throw new DpdtException(
                          DpdtExceptionTypeEnum.InternalError,
                          $"Something wrong with the {nameof(BindingExtenderBox)}"
                          );
            }

            foreach (var childBindingContainer in group.BindingExtenders)
            {
                rresult.Add(
                    new ExtenderAndTypePair(
                        childBindingContainer,
                        constructorArgument
                        )
                    );
            }

            result = rresult;
            return(rresult.Count > 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a Binder
        /// </summary>
        /// <remarks>
        /// Specifying which binder to use can be acheived by placing a BindingOptionsControl on the page or
        /// using the BindingStateMode config key. BindingOptionsControl takes precedence. A default ViewStateBinder
        /// is used in the absence of the above.
        /// </remarks>
        /// <param name="bindingContainer"></param>
        /// <returns></returns>
        public static BinderBase CreateBinder(IBindingContainer bindingContainer)
        {
            //Create a binder based on:
            //A) The binder specified by a binding options control
            BinderBase binder = null;

            if (!TryGetBinderFromOptionsControl(bindingContainer, out binder))
            {
                //B) The binder specified in the config
                if (!TryGetBinderFromConfig(bindingContainer, out binder))
                {
                    //C) the default binder is created.
                    binder = CreateBinder(bindingContainer, DEFAULT_STATE_MODE);
                }
            }

            //Set the update source trigger on:
            UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.PostBack;

            //A) The updateSourceTrigger specified by a binding options control
            if (!TryGetUpdateSourceTriggerOptionsControl(bindingContainer, out updateSourceTrigger))
            {
                //B) The updateSourceTrigger specified in the config
                TryGetUpdateSourceTriggerFromConfig(bindingContainer, out updateSourceTrigger);
            }

            binder.UpdateSourceTrigger = updateSourceTrigger;

            return(binder);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes binding manager and data bindings if necessary.
        /// </summary>
        private void InitializeBindingManager()
        {
            IDictionary sharedState = this.SharedState;

            string key = GetBindingManagerKey();

            this.bindingManager = sharedState[key] as BaseBindingManager;
            if (this.bindingManager == null)
            {
                lock (sharedState.SyncRoot)
                {
                    this.bindingManager = sharedState[key] as BaseBindingManager;
                    if (this.bindingManager == null)
                    {
                        try
                        {
                            this.bindingManager = CreateBindingManager();
                            if (bindingManager == null)
                            {
                                throw new ArgumentNullException("bindingManager",
                                                                "CreateBindingManager() must not return null");
                            }
                            InitializeDataBindings();
                        }
                        catch
                        {
                            this.bindingManager = null;
                            throw;
                        }
                        sharedState[key] = this.bindingManager;
                        this.OnDataBindingsInitialized(EventArgs.Empty);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static bool TryGetBindingOptionsControl(IBindingContainer bindingContainer, out BindingOptionsControl bindingOptionsControl)
        {
            bool result = false;

            bindingOptionsControl = null;

            Page page = bindingContainer as Page;

            if (page == null)
            {
                throw new InvalidOperationException("This method binding extension can only be used within the context of an asp.net page");
            }

            IBindingTarget  target                = new WebformControl(page);
            IControlService controlService        = GetControlService(bindingContainer);
            WebformControl  wrappedOptionsControl = controlService.FindControlRecursive(target, typeof(BindingOptionsControl)) as WebformControl;

            if (wrappedOptionsControl != null)
            {
                bindingOptionsControl = wrappedOptionsControl.Control as BindingOptionsControl;

                if (bindingOptionsControl != null)
                {
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create and execute a programmatic binding
        /// </summary>
        /// <param name="bindingContainer"></param>
        /// <param name="control">The control that should be bound</param>
        /// <param name="targetProperty">The property on the control to which to bind</param>
        /// <param name="bindingOptions">Binding options including the path to the data source</param>
        public static void CreateBinding(this IBindingContainer bindingContainer, Control control, string targetProperty, Options bindingOptions)
        {
            object       value = BindingHelpers.Bind(control, bindingOptions, targetProperty);
            PropertyInfo pInfo = control.GetType().GetProperty(targetProperty);

            pInfo.SetValue(control, value, null);
        }
Exemplo n.º 7
0
        public void Activate(IBindingContainer bindingContainer, PropertyExpression targetPropertyExpression)
        {
            if (bindingContainer == null)
            {
                throw new ArgumentNullException("bindingContainer");
            }
            if (!bindingContainer.Bindings.Contains(this))
            {
                throw new InvalidOperationException(Resources.BindingMustBeActivatedInOwningContainer);
            }

            if (Interlocked.CompareExchange(ref _activated, 1, 0) != 0)
            {
                throw new InvalidOperationException(Resources.AlreadyActivated);
            }

            _container = bindingContainer;
            _targetPropertyExpression = targetPropertyExpression;

            if (TargetPropertyExpression == null)
            {
                //no target property expression was provided when activating, so ask the base class to create one
                TargetPropertyExpression = AttemptCreateTargetPropertyExpression();
            }

            if (TargetPropertyExpression != null && (Mode == BindingMode.TwoWay || Mode == BindingMode.OneWayToSource))
            {
                //listen for changes in the target
                TargetPropertyExpression.ValueChanged += TargetPropertyExpressionValueChanged;
            }

            OnActivated();
        }
    public override void InstallBindings(IBindingContainer container)
    {
        container.Bind <IInitializable>().ToInstance(this);

        // Purchase store // TODO IVAN
        //container.Bind<IStoreProductSource>().ToGetter<ConfigModel>((Config) => Config.Store);
    }
Exemplo n.º 9
0
        public BinderBase(IBindingContainer bindingContainer, IDataStorageService dataStorageService, IControlService controlService)
        {
            this.bindingContainer   = bindingContainer;
            this.dataStorageService = dataStorageService;
            this.controlService     = controlService;

            bindingContainer.Load += new EventHandler(bindingContainer_Load);
        }
Exemplo n.º 10
0
    public override void InstallBindings(IBindingContainer container)
    {
        container.Bind <IGameErrorHandler>().ToSingle <CustomErrorHandler>();
        container.Bind <IPlayerData>().ToSingle <PlayerDataProvider>();

#if ADMIN_PANEL
        container.BindAdminPanelConfigurer <AdminPanelGame>();
#endif
    }
        public void SetupForTest()
        {
            mockContainer      = MockRepository.GenerateMock <IServiceProviderBindingContainer>();
            dataStorageService = new ViewStateStorageService(new StateBag());
            controlService     = MockRepository.GenerateMock <IControlService>();

            //object under test
            binder = new ViewStateBinder(mockContainer, dataStorageService, controlService);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Bind to a command
        /// </summary>
        /// <remarks>
        /// Binding via an options object is supported to allow for a more natural syntax between data and command bindings
        /// </remarks>
        /// <param name="control"></param>
        /// <param name="bindingOptions">Options for binding. Only the Path property is utilised for command bindings.
        /// </param>
        public static string BindCommand(this object control, Options bindingOptions)
        {
            Control           ctrl             = control as Control;
            IBindingContainer bindingContainer = ctrl.Page as IBindingContainer;
            BinderBase        binder           = CreateBinder(bindingContainer);

            binder.ExecuteCommandBind(new WebformControl(ctrl), bindingOptions);

            return("return true");
        }
Exemplo n.º 13
0
        private void ApplyBinding(BindingDef binding, IBindingContainer bindingContainer)
        {
            TargetProperty property = binding.ResolveAsTarget(this.bindingContainer);

            if (property != null)
            {
                object value = property.Value;
                SetProperty(binding, value);
            }
        }
        public BindingContainerExtender(
            IBindingContainer bindingContainer
            )
        {
            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            BindingContainer = bindingContainer;
        }
Exemplo n.º 15
0
        private bool CheckForItselfOrAnyChildIsConditional(
            ref HashSet <IBindingContainer> used,
            BindingExtenderBox bindingContainerBox,
            IBindingContainer bindingContainer
            )
        {
            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            if (used is null)
            {
                throw new ArgumentNullException(nameof(used));
            }

            if (bindingContainerBox is null)
            {
                throw new ArgumentNullException(nameof(bindingContainerBox));
            }

            if (used.Contains(bindingContainer))
            {
                //found cycle, skip this subtree as circular
                return(false);
            }
            used.Add(bindingContainer);

            if (bindingContainer.IsConditional)
            {
                return(true);
            }

            if (bindingContainerBox.TryGetChildren(bindingContainer, true, out var pairs))
            {
                foreach (var pair in pairs)
                {
                    var used2 = new HashSet <IBindingContainer>(used);
                    if (CheckForItselfOrAnyChildIsConditional(
                            ref used2,
                            bindingContainerBox,
                            pair.BindingExtender.BindingContainer
                            ))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Provide all children of the specific binding container.
        /// </summary>
        /// <param name="bindingContainer">A binding container whose children we want to retrieve.</param>
        /// <param name="tolerateMissingChildren">Should this method tolerate unknown (unresolvable) children?</param>
        /// <param name="result">Found children.</param>
        /// <returns>true if children has been found.</returns>
        public bool TryGetChildren(
            IBindingContainer bindingContainer,
            bool tolerateMissingChildren,
            out IReadOnlyList <ExtenderAndTypePair> result
            )
        {
            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            var rresult = new List <ExtenderAndTypePair>();

            foreach (var ca in bindingContainer.ConstructorArguments.Where(ca => !ca.DefineInBindNode))
            {
                if (ca.Type is null)
                {
                    throw new DpdtException(
                              DpdtExceptionTypeEnum.InternalError,
                              $"constructorArgument.Type is null somehow"
                              );
                }

                if (Groups.TryGetValue(ca.Type, out var group))
                {
                    foreach (var childBindingContainer in group.BindingExtenders)
                    {
                        rresult.Add(
                            new ExtenderAndTypePair(
                                childBindingContainer,
                                ca
                                )
                            );
                    }
                }
                else
                {
                    //for at least one constructor argument there is no bindings
                    //(probably it's a binding misconfiguration or these bindings are in parent cluster)
                    if (!tolerateMissingChildren)
                    {
                        result = new List <ExtenderAndTypePair>();
                        return(false);
                    }
                }
            }

            result = rresult;
            return(true);
        }
Exemplo n.º 17
0
        private bool CheckForHasUnresolvedChildren(
            ref HashSet <IBindingContainer> used,
            BindingExtenderBox box,
            IBindingContainer bindingContainer
            )
        {
            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            if (used is null)
            {
                throw new ArgumentNullException(nameof(used));
            }

            if (box is null)
            {
                throw new ArgumentNullException(nameof(box));
            }

            if (used.Contains(bindingContainer))
            {
                //found cycle, skip this subtree as circular
                return(false);
            }
            used.Add(bindingContainer);

            if (!box.TryGetChildren(bindingContainer, false, out var pairs))
            {
                //at least one child does not found
                return(true);
            }

            foreach (var pair in pairs)
            {
                var used2 = new HashSet <IBindingContainer>(used);
                if (CheckForHasUnresolvedChildren(
                        ref used2,
                        box,
                        pair.BindingExtender.BindingContainer
                        ))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Deactivates this <c>BindingBase</c> so that it can be activated again.
        /// </summary>
        internal void Deactivate()
        {
            if (Interlocked.Exchange(ref _activated, 0) == 1)
            {
                _container = null;

                if (TargetPropertyExpression != null)
                {
                    TargetPropertyExpression.ValueChanged -= TargetPropertyExpressionValueChanged;
                    TargetPropertyExpression = null;
                }

                OnDeactivated();
            }
        }
Exemplo n.º 19
0
        private static IDataStorageService GetDataStorageService(IBindingContainer bindingContainer)
        {
            IDataStorageService      dataStorageService = null;
            IBindingServicesProvider serviceProvider    = bindingContainer as IBindingServicesProvider;

            if (serviceProvider != null)
            {
                dataStorageService = serviceProvider.DataStorageService;
            }
            else
            {
                dataStorageService = new ViewStateStorageService(bindingContainer.GetStateBag());
            }

            return(dataStorageService);
        }
Exemplo n.º 20
0
        private static IControlService GetControlService(IBindingContainer bindingContainer)
        {
            IControlService          controlService  = null;
            IBindingServicesProvider serviceProvider = bindingContainer as IBindingServicesProvider;

            if (serviceProvider != null)
            {
                controlService = serviceProvider.ControlService;
            }
            else
            {
                controlService = new WebformsControlService();
            }

            return(controlService);
        }
Exemplo n.º 21
0
        private static bool TryGetUpdateSourceTriggerOptionsControl(IBindingContainer bindingContainer, out UpdateSourceTrigger updateSourceTrigger)
        {
            bool result = false;

            updateSourceTrigger = UpdateSourceTrigger.PostBack;

            BindingOptionsControl bindingOptionsControl = null;

            if (TryGetBindingOptionsControl(bindingContainer, out bindingOptionsControl))
            {
                updateSourceTrigger = bindingOptionsControl.UpdateSourceTrigger;
                result = true;
            }

            return(result);
        }
Exemplo n.º 22
0
        private static bool TryGetBinderFromOptionsControl(IBindingContainer bindingContainer, out BinderBase binder)
        {
            bool result = false;

            binder = null;

            BindingOptionsControl bindingOptionsControl = null;

            if (TryGetBindingOptionsControl(bindingContainer, out bindingOptionsControl))
            {
                binder = CreateBinder(bindingContainer, bindingOptionsControl.StateMode);
                result = true;
            }

            return(result);
        }
Exemplo n.º 23
0
        public static IEnumerable <Requirements> ToBindingRequirements([NotNull] this IBindingContainer bindingContainer, [NotNull] FeedUri interfaceUri)
        {
            #region Sanity checks
            if (bindingContainer == null)
            {
                throw new ArgumentNullException("bindingContainer");
            }
            if (interfaceUri == null)
            {
                throw new ArgumentNullException("interfaceUri");
            }
            #endregion

            return(bindingContainer.Bindings.OfType <ExecutableInBinding>()
                   .Select(x => new Requirements(interfaceUri, x.Command ?? Command.NameRun)));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Create a binder and explicitly specify the StateMode
        /// </summary>
        /// <param name="bindingContainer"></param>
        /// <param name="stateMode"></param>
        /// <returns></returns>
        public static BinderBase CreateBinder(IBindingContainer bindingContainer, StateMode stateMode)
        {
            BinderBase          binder             = null;
            IDataStorageService dataStorageService = GetDataStorageService(bindingContainer);

            if (stateMode == StateMode.Recreate)
            {
                binder = new StatelessBinder(bindingContainer, dataStorageService, new WebformsControlService());
            }
            else
            {
                binder = new ViewStateBinder(bindingContainer, new ViewStateStorageService(bindingContainer.GetStateBag()), new WebformsControlService());
            }

            return(binder);
        }
Exemplo n.º 25
0
        private static bool TryGetUpdateSourceTriggerFromConfig(IBindingContainer bindingContainer, out UpdateSourceTrigger updateSourceTrigger)
        {
            bool result = false;

            updateSourceTrigger = UpdateSourceTrigger.PostBack;
            string updateSourceTriggerStr = WebConfigurationManager.AppSettings[UPDATE_SOURCE_TRIGGER_KEY];

            if (!string.IsNullOrEmpty(updateSourceTriggerStr))
            {
                if (updateSourceTrigger.TryParse(updateSourceTriggerStr))
                {
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 26
0
        public void ApplyBinding(IBindingContainer container = null)
        {
            IsValid(false);

            if (container != null && !container.Bindings.Contains(this))
            {
                container.Bindings.Add(this);
            }

            Control.DataContext = Element;

            Control.BindDataContext(
                (IndirectBinding <T>)ControlBinding,
                (IndirectBinding <T>)ElementBinding,
                DualBindingMode.TwoWay
                );
        }
Exemplo n.º 27
0
        /// <summary>
        /// Applies all <see cref="Binding"/>s listed in a specific <see cref="IBindingContainer"/>.
        /// </summary>
        /// <param name="bindingContainer">The list of <see cref="Binding"/>s to be performed.</param>
        /// <param name="implementation">The implementation to be made available via the <see cref="Binding"/>s.</param>
        /// <param name="startInfo">The process launch environment to apply the <see cref="Binding"/>s to.</param>
        /// <exception cref="ImplementationNotFoundException">The <paramref name="implementation"/> is not cached yet.</exception>
        /// <exception cref="ExecutorException">A <see cref="Command"/> contained invalid data.</exception>
        /// <exception cref="IOException">A problem occurred while writing a file.</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to a file is not permitted.</exception>
        private void ApplyBindings(IBindingContainer bindingContainer, ImplementationSelection implementation, ProcessStartInfo startInfo)
        {
            // Do not apply bindings more than once
            if (!_appliedBindingContainers.Add(bindingContainer)) return;

            if (bindingContainer.Bindings.Count == 0) return;

            // Don't use bindings for PackageImplementations
            if (implementation.ID.StartsWith(ExternalImplementation.PackagePrefix)) return;

            new PerTypeDispatcher<Binding>(ignoreMissing: true)
            {
                (EnvironmentBinding environmentBinding) => ApplyEnvironmentBinding(environmentBinding, implementation, startInfo),
                //(OverlayBinding overlayBinding) => ApplyOverlayBinding(overlayBinding, implementation, startInfo),
                (ExecutableInVar executableInVar) => ApplyExecutableInVar(executableInVar, implementation, startInfo),
                (ExecutableInPath executableInPath) => ApplyExecutableInPath(executableInPath, implementation, startInfo)
            }.Dispatch(bindingContainer.Bindings);
        }
Exemplo n.º 28
0
        private static bool TryGetBinderFromConfig(IBindingContainer bindingContainer, out BinderBase binder)
        {
            bool result = false;

            binder = null;
            string stateModeStr = WebConfigurationManager.AppSettings[STATE_MODE_KEY];

            if (!string.IsNullOrEmpty(stateModeStr))
            {
                StateMode stateModeEnum = StateMode.Persist;
                if (stateModeEnum.TryParse(stateModeStr))
                {
                    binder = CreateBinder(bindingContainer, stateModeEnum);
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Bind and specify options for the bind.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="bindingOptions"></param>
        /// <returns></returns>
        public static object Bind(object control, Options bindingOptions, string propertyName)
        {
            Control        ctrl           = control as Control;
            WebformControl wrappedControl = new WebformControl(ctrl);

            IBindingContainer bindingContainer = ctrl.Page as IBindingContainer;
            BinderBase        binder           = CreateBinder(bindingContainer);

            object bindingResult = null;

            if (ctrl != null && bindingContainer != null)
            {
                IDataItemContainer dataItemContainer = ctrl.NamingContainer as IDataItemContainer;

                if (dataItemContainer != null)
                {
                    WebformControl <IDataItemContainer> wrappedContainer = new WebformControl <IDataItemContainer>((Control)dataItemContainer);

                    if (string.IsNullOrEmpty(propertyName))
                    {
                        bindingResult = binder.ExecuteBind(wrappedControl, wrappedContainer, bindingOptions);
                    }
                    else
                    {
                        bindingResult = binder.ExecuteBind(wrappedControl, wrappedContainer, bindingOptions, propertyName);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(propertyName))
                    {
                        bindingResult = binder.ExecuteBind(wrappedControl, bindingOptions);
                    }
                    else
                    {
                        bindingResult = binder.ExecuteBind(wrappedControl, bindingOptions, propertyName);
                    }
                }
            }

            return(bindingResult);
        }
Exemplo n.º 30
0
        public void AppendOrFailIfExists(
            IBindingContainer bindingContainer,
            bool idempotent
            )
        {
            if (_used.Contains(bindingContainer))
            {
                var cycleList = new List <IBindingContainer>(_usedInList);
                cycleList.Add(bindingContainer);

                throw new CycleFoundException(
                          cycleList,
                          _idempotent
                          );
            }

            _used.Add(bindingContainer);
            _usedInList.Add(bindingContainer);
            _idempotent &= idempotent;
        }
Exemplo n.º 31
0
        private FactoryProduct GenerateFactoryBody(
            IBindingContainer bindingContainer
            )
        {
            var methodsToImplement = ScanForMethodsToImplement(bindingContainer);

            return(new FactoryProduct(
                       bindingContainer.BindToType,
                       $@"
namespace DpdtInject.Tests.Factory.Simple0
{{
    public partial class AFactory : IAFactory
    {{
        public IA Create()
        {{
            return new A();
        }}
    }}
}}
"));
        }
Exemplo n.º 32
0
        /// <summary>
        /// Initializes binding manager and data bindings if necessary.
        /// </summary>
        private void InitializeBindingManager()
        {
            IDictionary sharedState = this.SharedState;

            string key = GetBindingManagerKey();
            this.bindingManager = sharedState[key] as BaseBindingManager;
            if (this.bindingManager == null)
            {
                // access to shared state must be synchronized
                lock (this.SharedState.SyncRoot)
                {
                    this.bindingManager = sharedState[key] as BaseBindingManager;
                    if (this.bindingManager == null)
                    {
                        Trace.Write( traceCategory, "Initialize Data Bindings" );
                        this.bindingManager = CreateBindingManager();
                        if (this.bindingManager == null)
                        {
                            throw new ArgumentNullException( "bindingManager",
                                                            "CreateBindingManager() must not return null" );
                        }
                        InitializeDataBindings();
                        sharedState[key] = this.bindingManager;
                        OnDataBindingsInitialized( EventArgs.Empty );
                    }
                }
            }
        }
Exemplo n.º 33
0
 static Bindings()
 {
     Container = new BindingContainer(ViewModelDefaults.ModelResolver, ViewModelDefaults.ReflectionCache,
         new TestModule());
 }
Exemplo n.º 34
0
        public void Activate(IBindingContainer bindingContainer, PropertyExpression targetPropertyExpression)
        {
            if (bindingContainer == null)
                throw new ArgumentNullException("bindingContainer");
            if (!bindingContainer.Bindings.Contains(this))
                throw new InvalidOperationException(Resources.BindingMustBeActivatedInOwningContainer);

            if (Interlocked.CompareExchange(ref _activated, 1, 0) != 0)
            {
                throw new InvalidOperationException(Resources.AlreadyActivated);
            }

            _container = bindingContainer;
            _targetPropertyExpression = targetPropertyExpression;

            if (TargetPropertyExpression == null)
            {
                //no target property expression was provided when activating, so ask the base class to create one
                TargetPropertyExpression = AttemptCreateTargetPropertyExpression();
            }

            if (TargetPropertyExpression != null && (Mode == BindingMode.TwoWay || Mode == BindingMode.OneWayToSource))
            {
                //listen for changes in the target
                TargetPropertyExpression.ValueChanged += TargetPropertyExpressionValueChanged;
            }

            OnActivated();
        }
Exemplo n.º 35
0
 public void Activate(IBindingContainer bindingContainer)
 {
     Activate(bindingContainer, null);
 }
Exemplo n.º 36
0
        /// <summary>
        /// Initializes binding manager and data bindings if necessary.
        /// </summary>
        private void InitializeBindingManager()
        {
            IDictionary sharedState = this.SharedState;

            string key = GetBindingManagerKey();
            this.bindingManager = sharedState[key] as BaseBindingManager;
            if (this.bindingManager == null)
            {
                lock (sharedState.SyncRoot)
                {
                    this.bindingManager = sharedState[key] as BaseBindingManager;
                    if (this.bindingManager == null)
                    {
                        try
                        {
                            this.bindingManager = CreateBindingManager();
                            if (bindingManager == null)
                            {
                                throw new ArgumentNullException( "bindingManager",
                                                                "CreateBindingManager() must not return null" );
                            }
                            InitializeDataBindings();
                        }
                        catch
                        {
                            this.bindingManager = null;
                            throw;
                        }
                        sharedState[key] = this.bindingManager;
                        this.OnDataBindingsInitialized( EventArgs.Empty );
                    }
                }
            }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Deactivates this <c>BindingBase</c> so that it can be activated again.
        /// </summary>
        internal void Deactivate()
        {
            if (Interlocked.Exchange(ref _activated, 0) == 1)
            {
                _container = null;

                if (TargetPropertyExpression != null)
                {
                    TargetPropertyExpression.ValueChanged -= TargetPropertyExpressionValueChanged;
                    TargetPropertyExpression = null;
                }

                OnDeactivated();
            }
        }