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; } } }
public void ReloadSceneWithCallbackWithCallback(CallbackTarget cbt, string callbackMethod) { // callbackTarget = cbt; WebGLComm.inst.Debug("Reloading scene callback fn/mthod: " + cbt + ",/" + callbackMethod); SimpleJSON.JSONClass N = new SimpleJSON.JSONClass(); N[SceneManager.callbackKey] = callbackMethod; N[SceneManager.callbackTargetKey] = GetStringFromCalbackTarget(cbt); PlayerPrefs.SetString(prefsKey, N.ToString()); ReloadSceneWithCallback(); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { unchecked { int hash = ((CallbackMethod != null ? CallbackMethod.GetHashCode() : 0) * 397) ^ (CallbackTarget != null ? CallbackTarget.GetHashCode() : 0); hash = (hash * 397) ^ Event.EventDetail.ID; hash = (hash * 397) ^ EllaModel.Instance.GetPublisherId(Event.Publisher); return(hash); } }
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; } } }
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)); } }
string GetStringFromCalbackTarget(CallbackTarget cbt) { switch (cbt) { case CallbackTarget._LevelBuilder: return("_LevelBuilder"); break; case CallbackTarget._WebGLComm: return("_WebGLComm"); break; } return("none"); }
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)); } }