示例#1
0
        private static void SetTargetCore(DependencyPropertyChangedEventArgs e, DependencyObject d, bool setContext)
        {
            if (e.NewValue == e.OldValue)
            {
                return;
            }

            var target       = e.NewValue;
            var containerKey = e.NewValue as string;//todo containerKey is null for classes

            if (containerKey != null)
            {
                target = IoC.GetInstance(null, containerKey);
            }
#if WINFORMS || WEBGUI
            if (setContext && d.Object is IHaveDataContext)
            {
                Log.Info("Setting DC of {0} to {1}.", d, target);
                ((IHaveDataContext)d.Object).DataContext = target;
            }
#else
            if (setContext && d is FrameworkElement)
            {
                Log.Info("Setting DC of {0} to {1}.", d, target);
                ((FrameworkElement)d).DataContext = target;
            }
#endif

            Log.Info("Attaching message handler {0} to {1}.", target, d);
            Message.SetHandler(d, target);
        }
示例#2
0
        /// <summary>
        /// Invokes the action.
        /// </summary>
        /// <param name="eventArgs">The parameter to the action. If the action does not require a parameter, the parameter may be set to a null reference.</param>
        public void Invoke(object eventArgs)
        {
            Log.Info("Invoking {0}.", this);

            if (context == null)
            {
                UpdateContext();
            }

            if (context.Target == null || context.View == null)
            {
                PrepareContext(context);
                if (context.Target == null)
                {
                    var ex = new Exception(string.Format("No target found for method {0}.",
                                                         context.Message.MethodName));
                    Log.Error(ex);

                    if (!ThrowsExceptions)
                    {
                        return;
                    }
                    throw ex;
                }

                if (!UpdateAvailabilityCore())
                {
                    return;
                }
            }

            if (context.Method == null)
            {
                var ex =
                    new Exception(string.Format("Method {0} not found on target of type {1}.",
                                                context.Message.MethodName, context.Target.GetType()));
                Log.Error(ex);

                if (!ThrowsExceptions)
                {
                    return;
                }
                throw ex;
            }

            context.EventArgs = eventArgs;

            if (EnforceGuardsDuringInvocation && context.CanExecute != null && !context.CanExecute())
            {
                return;
            }

            InvokeAction(context);
            context.EventArgs = null;
        }
示例#3
0
 private static void SetContentPropertyCore(object targetLocation, object view)
 {
     try
     {
         if (view is IHaveDataContext)
         {
             Log.Info("Setting DC of {0} to {1}.", view, targetLocation);
             ((IHaveDataContext)view).DataContext = targetLocation;
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
示例#4
0
        void IActivate.Activate()
        {
            if (IsActive)
            {
                return;
            }

            var initialized = false;

            if (!IsInitialized)
            {
                IsInitialized = initialized = true;
                OnInitialize();
            }

            IsActive = true;
            Log.Info("Activating {0}.", this);
            OnActivate();

            Activated(this, new ActivationEventArgs
            {
                WasInitialized = initialized
            });
        }
示例#5
0
        /// <summary>
        /// Executes a coroutine.
        /// </summary>
        /// <param name="coroutine">The coroutine to execute.</param>
        /// <param name="context">The context to execute the coroutine within.</param>
        /// /// <param name="callback">The completion callback for the coroutine.</param>
        public static void BeginExecute(IEnumerator <IResult> coroutine, ActionExecutionContext context = null,
                                        EventHandler <ResultCompletionEventArgs> callback = null)
        {
            Log.Info("Executing coroutine.");

            var enumerator = CreateParentEnumerator(coroutine);

            IoC.BuildUp(enumerator);

            if (callback != null)
            {
                ExecuteOnCompleted(enumerator, callback);
            }

            ExecuteOnCompleted(enumerator, Completed);
            enumerator.Execute(context ?? new ActionExecutionContext());
        }