コード例 #1
0
 void InvalidateRibbonForViewModel(IRibbonViewModel viewModel)
 {
     if (viewModel.RibbonUi == null) return;
     foreach (var targets in notifyChangeTargetLookup[viewModel.GetType()])
     {
         viewModel.RibbonUi.InvalidateControl(targets.Value);
     }
 }
コード例 #2
0
        public void Invoke(IRibbonControl control, Expression <Action> caller, params object[] parameters)
        {
            try
            {
                var            methodName     = caller.GetMethodName();
                CallbackTarget callbackTarget =
                    vstoContribContext.TagToCallbackTargetLookup[control.Tag + methodName];

                var view = (object)control.Context;
                IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(view);
                VstoContribLog.Debug(l => l("Ribbon callback {0} being invoked on {1} (View: {2}, ViewModel: {3})",
                                            methodName, control.Id, view.ToLogFormat(), viewModelInstance.ToLogFormat()));

                Type         type     = viewModelInstance.GetType();
                PropertyInfo property = type.GetProperty(callbackTarget.Method);

                if (property != null)
                {
                    type.InvokeMember(callbackTarget.Method,
                                      BindingFlags.SetProperty,
                                      null,
                                      viewModelInstance,
                                      new[]
                    {
                        parameters.Single()
                    });
                }
                else
                {
                    type.InvokeMember(callbackTarget.Method,
                                      BindingFlags.InvokeMethod,
                                      null,
                                      viewModelInstance,
                                      new[]
                    {
                        control
                    }
                                      .Concat(parameters)
                                      .ToArray());
                }
            }
            catch (TargetInvocationException e)
            {
                var innerEx = e.InnerException;
                PreserveStackTrace(innerEx);
                if (vstoContribContext.ErrorHandlers.Count == 0)
                {
                    Trace.TraceError(innerEx.ToString());
                }

                var handled = vstoContribContext.ErrorHandlers.Any(errorHandler => errorHandler.Handle(innerEx));

                if (!handled)
                {
                    throw innerEx;
                }
            }
        }
コード例 #3
0
 void InvalidateRibbonForViewModel(IRibbonViewModel viewModel)
 {
     if (viewModel.RibbonUi == null)
     {
         return;
     }
     foreach (var targets in notifyChangeTargetLookup[viewModel.GetType()])
     {
         viewModel.RibbonUi.InvalidateControl(targets.Value);
     }
 }
コード例 #4
0
        public void Invoke(IRibbonControl control, Expression <Action> caller, params object[] parameters)
        {
            try
            {
                CallbackTarget callbackTarget =
                    vstoContribContext.TagToCallbackTargetLookup[control.Tag + caller.GetMethodName()];

                IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(control.Context);

                Type         type     = viewModelInstance.GetType();
                PropertyInfo property = type.GetProperty(callbackTarget.Method);

                if (property != null)
                {
                    type.InvokeMember(callbackTarget.Method,
                                      BindingFlags.SetProperty,
                                      null,
                                      viewModelInstance,
                                      new[]
                    {
                        parameters.Single()
                    });
                }
                else
                {
                    type.InvokeMember(callbackTarget.Method,
                                      BindingFlags.InvokeMethod,
                                      null,
                                      viewModelInstance,
                                      new[]
                    {
                        control
                    }
                                      .Concat(parameters)
                                      .ToArray());
                }
            }
            catch (TargetInvocationException e)
            {
                var innerEx = e.InnerException;
                PreserveStackTrace(innerEx);
                if (vstoContribContext.ErrorHandlers.Count == 0)
                {
                    Trace.TraceError(innerEx.ToString());
                }

                var handled = vstoContribContext.ErrorHandlers.Any(errorHandler => errorHandler.Handle(innerEx));

                if (!handled)
                {
                    throw innerEx;
                }
            }
        }
コード例 #5
0
        public object InvokeGet(IRibbonControl control, Expression <Action> caller, params object[] parameters)
        {
            if (control.Context == null)
            {
                return(null);
            }

            var            methodName     = caller.GetMethodName();
            CallbackTarget callbackTarget = vstoContribContext.TagToCallbackTargetLookup[control.Tag + methodName];

            var view = (object)control.Context;
            IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(view);

            VstoContribLog.Debug(l => l("Ribbon callback {0} being invoked on {1} (View: {2}, ViewModel: {3})",
                                        methodName, control.Id, view.ToLogFormat(), viewModelInstance.ToLogFormat()));

            Type         type     = viewModelInstance.GetType();
            PropertyInfo property = type.GetProperty(callbackTarget.Method);

            if (property != null)
            {
                return(type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.GetProperty,
                                         null,
                                         viewModelInstance,
                                         null));
            }

            try
            {
                return(type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.InvokeMethod,
                                         null,
                                         viewModelInstance,
                                         new[]
                {
                    control
                }
                                         .Concat(parameters)
                                         .ToArray()));
            }
            catch (MissingMethodException)
            {
                throw new InvalidOperationException(
                          string.Format("Expecting method with signature: {0}.{1}(IRibbonControl control)",
                                        type.Name,
                                        callbackTarget.Method));
            }
        }
コード例 #6
0
        public object InvokeGet(IRibbonControl control, Expression <Action> caller, params object[] parameters)
        {
            CallbackTarget callbackTarget = vstoContribContext.TagToCallbackTargetLookup[control.Tag + caller.GetMethodName()];

            IRibbonViewModel viewModelInstance = ribbonViewModelResolver.ResolveInstanceFor(control.Context);

            Type         type     = viewModelInstance.GetType();
            PropertyInfo property = type.GetProperty(callbackTarget.Method);

            if (property != null)
            {
                return(type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.GetProperty,
                                         null,
                                         viewModelInstance,
                                         null));
            }

            try
            {
                return(type.InvokeMember(callbackTarget.Method,
                                         BindingFlags.InvokeMethod,
                                         null,
                                         viewModelInstance,
                                         new[]
                {
                    control
                }
                                         .Concat(parameters)
                                         .ToArray()));
            }
            catch (MissingMethodException)
            {
                throw new InvalidOperationException(
                          string.Format("Expecting method with signature: {0}.{1}(IRibbonControl control)",
                                        type.Name,
                                        callbackTarget.Method));
            }
        }