/// <summary> /// Internal use only /// </summary> /// <param name="arguments"></param> /// <param name="instance"></param> /// <param name="name"></param> /// <returns></returns> public static object?OnMethodCalled(List <object?> arguments, object instance, string name) { var type = instance.GetType(); var factory = type.GetPrivateFieldInfo(ProxyFactoryFieldName).GetValue(instance) as EmptyProxyFactory ?? throw new InvalidOperationException($"{ProxyFactoryFieldName} is null"); var allArgumentsNotNull = arguments.All(argument => argument != null); var methodInfo = type.GetMethodInfo(name, allArgumentsNotNull // ReSharper disable once RedundantEnumerableCastCall ? arguments.Cast <object>().Select(argument => argument.GetType()).ToArray() : null); var args = new MethodEventArgs(arguments, methodInfo, factory) { ReturnObject = CreateReturnObject(methodInfo), }; factory.MethodCalled?.Invoke(instance, args); factory.AsyncMethodCalled?.Invoke(instance, args)?.Wait(); if (args.Exception != null) { throw args.Exception; } return(args.ReturnObject); }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.CancellationToken = new CancellationToken { Cancel = true, ReturnValue = "Interceptor" }; }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.CancellationToken = new CancellationToken { Cancel = true, ReturnValue = "Interceptor" }; }
private void ExecuteMethodImplementation( Type returnType, string methodName, IEnumerable <Parameter> parameters, Action <MemberEventArgs> callMethodInvocationDelegate, Action <MemberEventArgs> invocationComplete = null) { var eventArgs = new MethodEventArgs { Target = _target, Mixin = _mixin, MemberName = methodName, ReturnType = returnType, Parameters = parameters }; foreach (var interceptor in Interceptors) { interceptor.OnBeforeMethodInvocation( this, eventArgs); if (null != eventArgs.CancellationToken && eventArgs.CancellationToken.Cancel) { if (null != invocationComplete) { invocationComplete(eventArgs); } return; } } callMethodInvocationDelegate(eventArgs); foreach (var interceptor in Interceptors) { interceptor.OnAfterMethodInvocation( this, eventArgs); if (null != eventArgs.CancellationToken && eventArgs.CancellationToken.Cancel) { if (null != invocationComplete) { invocationComplete(eventArgs); } return; } } if (null != invocationComplete) { invocationComplete(eventArgs); } }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { foreach (var p in eventArgs.Parameters) { if (null == p.Value) { throw new ArgumentNullException(p.Name); } } }
private void ExecuteMethodImplementation( Type returnType, string methodName, IEnumerable <Parameter> parameters, Action <MemberEventArgs> callMethodInvocationDelegate, Action <MemberEventArgs> invocationComplete = null) { var eventArgs = new MethodEventArgs { Target = _target, Mixin = _mixin, MemberName = methodName, ReturnType = returnType, Parameters = parameters }; if (FireInterceptorEvent( eventArgs, (i, e) => i.OnBeforeMethodInvocation(this, eventArgs), invocationComplete)) { return; } try { callMethodInvocationDelegate(eventArgs); } catch (Exception exc) { eventArgs.MemberInvocationException = exc; if (FireInterceptorEvent( eventArgs, (i, e) => i.OnAfterMethodInvocation(this, eventArgs), invocationComplete)) { return; } else { throw; } } FireInterceptorEvent( eventArgs, (i, e) => i.OnAfterMethodInvocation(this, eventArgs), invocationComplete); if (null != invocationComplete) { invocationComplete(eventArgs); } }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine( "LoggingAspect: [{0}.{1}] called with Parameters: {2}", eventArgs.Target.GetType().FullName, eventArgs.MemberName, string.Join(",", eventArgs.Parameters.Select(x => string.Format("({0}: {1})", x.Name, (x.Value ?? "<null>"))))); }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { if (null != eventArgs.MemberInvocationException && eventArgs.MemberName == "Method") { eventArgs.CancellationToken = new CancellationToken { Cancel = true, ReturnValue = "Intercepted" } } ; }
private void AddMethod(object sender, MethodEventArgs e) { String methodInformation = ""; IDictionary id = new Dictionary <String, String>(e.methodInformation); DateTime dateTime = DateTime.Now; foreach (DictionaryEntry de in id) { methodInformation += de.Key + ": " + de.Value + "\n"; } methodList.Add(new Method(e.methodPath + " (" + dateTime.TimeOfDay + ")", methodInformation)); }
///-------------------------------------------------------------------------------- /// <summary>This method applies method deletes.</summary> ///-------------------------------------------------------------------------------- public void ProcessDeleteMethodPerformed(MethodEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Method != null) { foreach (MethodViewModel item in Methods.ToList <MethodViewModel>()) { if (item.Method.MethodID == data.Method.MethodID) { // remove item from tabs, if present WorkspaceEventArgs message = new WorkspaceEventArgs(); message.ItemID = item.Method.MethodID; Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message); // delete children for (int i = item.Items.Count - 1; i >= 0; i--) { if (item.Items[i] is ParameterViewModel) { ParameterViewModel child = item.Items[i] as ParameterViewModel; ParameterEventArgs childMessage = new ParameterEventArgs(); childMessage.Parameter = child.Parameter; childMessage.MethodID = item.Method.MethodID; childMessage.Solution = Solution; childMessage.WorkspaceID = child.WorkspaceID; item.ProcessDeleteParameterPerformed(childMessage); } } // delete item isItemMatch = true; Methods.Remove(item); Entity.MethodList.Remove(item.Method); Items.Remove(item); Entity.ResetModified(true); OnUpdated(this, null); break; } } if (isItemMatch == false) { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method processes the new method command.</summary> ///-------------------------------------------------------------------------------- public void ProcessNewMethodCommand() { MethodEventArgs message = new MethodEventArgs(); message.Method = new Method(); message.Method.MethodID = Guid.NewGuid(); message.Method.EntityID = Entity.EntityID; message.Method.Entity = Entity; message.EntityID = Entity.EntityID; message.Method.Solution = Solution; message.Solution = Solution; message.WorkspaceID = WorkspaceID; Mediator.NotifyColleagues <MethodEventArgs>(MediatorMessages.Command_EditMethodRequested, message); }
private async Task <bool> HttpServer_BeginRequest(HttpContext context, CancellationToken cancellationToken) { var request = context.Request; var response = context.Response; Core.Log.LibVerbose("Request received from {0}:{1} to {2} {3}", request.RemoteAddress, request.RemotePort, request.Method, request.RawUrl); var clientId = Guid.NewGuid(); var ccEvent = ClientConnectEventArgs.Retrieve(clientId); OnClientConnect?.Invoke(this, ccEvent); ClientConnectEventArgs.Store(ccEvent); context.Response.ContentType = Serializer.MimeTypes[0]; var responseBuffer = default(MultiArray <byte>); if (context.Request.Method == HttpMethod.GET && EnableGetDescriptors && OnGetDescriptorsRequest != null) { var eArgs = ServerDescriptorsEventArgs.Retrieve(); OnGetDescriptorsRequest(this, eArgs); responseBuffer = Serializer.Serialize(eArgs.Descriptors); ServerDescriptorsEventArgs.Store(eArgs); } if (context.Request.Method == HttpMethod.POST && !(OnMethodCallAsync is null)) { Counters.IncrementBytesReceived(context.Request.PostData.Length); var messageRq = Serializer.Deserialize <RPCRequestMessage>(context.Request.PostData); var eArgs = MethodEventArgs.Retrieve(clientId, messageRq, cancellationToken); await OnMethodCallAsync.InvokeAsync(this, eArgs).ConfigureAwait(false); if (eArgs.Response != null) { responseBuffer = Serializer.Serialize(eArgs.Response); OnResponseSent?.Invoke(this, eArgs.Response); } MethodEventArgs.Store(eArgs); } await responseBuffer.CopyToAsync(response.OutputStream).ConfigureAwait(false); Counters.IncrementBytesSent(responseBuffer.Count); return(true); }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { if (null != eventArgs.MemberInvocationException) { Console.WriteLine( "LoggingAspect: [{0}.{1}] threw an Exception: [{2}]", eventArgs.Target.GetType().FullName, eventArgs.MemberName, eventArgs.MemberInvocationException.Message); } else { Console.WriteLine( "LoggingAspect: [{0}.{1}] completed by returning [{2}]", eventArgs.Target.GetType().FullName, eventArgs.MemberName, (null == eventArgs.ReturnType) ? "<void>" : (null == eventArgs.ReturnValue) ? "<null>" : eventArgs.ReturnValue.ToString() ); } }
///-------------------------------------------------------------------------------- /// <summary>This method applies method updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditMethodPerformed(MethodEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Method != null) { foreach (MethodViewModel item in Methods) { if (item.Method.MethodID == data.Method.MethodID) { isItemMatch = true; item.Method.TransformDataFromObject(data.Method, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new Method data.Method.Entity = Entity; MethodViewModel newItem = new MethodViewModel(data.Method, Solution); newItem.Updated += new EventHandler(Children_Updated); Methods.Add(newItem); Entity.MethodList.Add(newItem.Method); Solution.MethodList.Add(newItem.Method); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
private void HttpServer_OnBeginRequest(HttpContext context, ref bool handled, CancellationToken cancellationToken) { var request = context.Request; var response = context.Response; Core.Log.LibVerbose("Request received from {0}:{1} to {2} {3}", request.RemoteAddress, request.RemotePort, request.Method, request.RawUrl); var clientId = Guid.NewGuid(); OnClientConnect?.Invoke(this, new ClientConnectEventArgs(clientId)); context.Response.ContentType = Serializer.MimeTypes[0]; var responseBuffer = default(SubArray <byte>); if (context.Request.Method == HttpMethod.GET && EnableGetDescriptors && OnGetDescriptorsRequest != null) { var eArgs = new ServerDescriptorsEventArgs(); OnGetDescriptorsRequest(this, eArgs); responseBuffer = Serializer.Serialize(eArgs.Descriptors); } if (context.Request.Method == HttpMethod.POST && OnMethodCall != null) { Counters.IncrementBytesReceived(context.Request.PostData.Length); var messageRq = Serializer.Deserialize <RPCRequestMessage>(context.Request.PostData); var eArgs = new MethodEventArgs(clientId, messageRq, cancellationToken); OnMethodCall(this, eArgs); if (eArgs.Response != null) { responseBuffer = Serializer.Serialize(eArgs.Response); OnResponseSent?.Invoke(this, eArgs.Response); } } response.Write(responseBuffer.Array, responseBuffer.Offset, responseBuffer.Count); Counters.IncrementBytesSent(responseBuffer.Count); handled = true; }
public void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { AfterMethodInvocationCount++; }
/// <summary> /// Fired before a method is invoked. /// </summary> /// <param name="sender"> /// The Mixin host container. /// </param> /// <param name="eventArgs"> /// Contains references to the Target and Mixin class as well /// as the method that is executing. /// </param> /// <remarks> /// Set the <see cref="MemberEventArgs.CancellationToken"/> to prevent /// the method from invoking. /// </remarks> public virtual void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { }
private void OnMethodClicked(object sender, MethodEventArgs e) { InvokeSelectedMethod(); }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine("Before " + eventArgs.MemberName); }
/// <summary> /// Fired after a method is invoked. /// </summary> /// <param name="sender"> /// The Mixin host container. /// </param> /// <param name="eventArgs"> /// Contains references to the Target and Mixin class as well /// as the method that is executing including the return value. /// </param> /// <remarks> /// Set the <see cref="MemberEventArgs.CancellationToken"/> to overwrite /// the return value. /// </remarks> public virtual void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.ReturnValue += "_Interceptor"; }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine("After " + eventArgs.MemberName); eventArgs.ReturnValue = eventArgs.ReturnValue + " - Now with Aspects!"; }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { foreach(var p in eventArgs.Parameters) if (null == p.Value) throw new ArgumentNullException(p.Name); }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { if (null != eventArgs.MemberInvocationException) { Console.WriteLine( "LoggingAspect: [{0}.{1}] threw an Exception: [{2}]", eventArgs.Target.GetType().FullName, eventArgs.MemberName, eventArgs.MemberInvocationException.Message); } else { Console.WriteLine( "LoggingAspect: [{0}.{1}] completed by returning [{2}]", eventArgs.Target.GetType().FullName, eventArgs.MemberName, (null == eventArgs.ReturnType) ? "<void>" : (null == eventArgs.ReturnValue) ? "<null>" : eventArgs.ReturnValue.ToString() ); } }
public void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { BeforeMethodInvocationCount++; }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.Target.As<MockLogMixin>().AddLogMessage( "OnBeforeMethod: " + eventArgs.MemberName); }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { BeforeMethodInvocationCount++; }
public void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { AfterMethodInvocationCount++; }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine("After " + eventArgs.MemberName); eventArgs.ReturnValue = eventArgs.ReturnValue + " - Now with Aspects!"; }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine( "LoggingAspect: [{0}.{1}] called with Parameters: {2}", eventArgs.Target.GetType().FullName, eventArgs.MemberName, string.Join(",", eventArgs.Parameters.Select(x => string.Format("({0}: {1})", x.Name, (x.Value ?? "<null>"))))); }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.ReturnValue += "_Interceptor"; }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { eventArgs.Target.As <MockLogMixin>().AddLogMessage( "OnAfterMethod: " + eventArgs.MemberName); }
public override void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs) { if (null != eventArgs.MemberInvocationException && eventArgs.MemberName == "Method") eventArgs.CancellationToken = new CancellationToken { Cancel = true, ReturnValue = "Intercepted" }; }
protected override void OnItemSelectionChanged(ListViewItemSelectionChangedEventArgs e) { ItemInfo info = e.Item.Tag as ItemInfo; if (selected == info) { return; } if ((info != null) && (this.MethodSelected != null) && e.IsSelected) { ThrownException te = null; MethodItem me = info.Data as MethodItem; Method caller = me.CalledBy; Method method = me.Method; ////if (info.Parent != null) ////{ //// if (me.Exception == null) //// { //// if (info.PreviousChild != null) //// { //// MethodItem previousMe = info.PreviousChild.Data as MethodItem; //// if (previousMe != null) //// { //// caller = previousMe.Method; //// } //// } //// else //// { //// ItemInfo parentInfo = info.Parent.Item.Tag as ItemInfo; //// if (parentInfo != null) //// { //// MethodItem parentMe = parentInfo.Data as MethodItem; //// if (parentMe != null) //// { //// caller = parentMe.Method; //// } //// } //// } //// } ////} Method m = null; if (me.Exception != null) { caller = method; method = null; } MethodEventArgs ea = new MethodEventArgs(method, caller, me.Exception); this.MethodSelected(this, ea); } base.OnItemSelectionChanged(e); }
public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs) { Console.WriteLine("Before " + eventArgs.MemberName); }