Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 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"
     };
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
 public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     foreach (var p in eventArgs.Parameters)
     {
         if (null == p.Value)
         {
             throw new ArgumentNullException(p.Name);
         }
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 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"
         }
     }
     ;
 }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        ///--------------------------------------------------------------------------------
        /// <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);
            }
        }
Ejemplo n.º 11
0
        ///--------------------------------------------------------------------------------
        /// <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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 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()
             );
     }
 }
Ejemplo n.º 14
0
 ///--------------------------------------------------------------------------------
 /// <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);
     }
 }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
 public void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     AfterMethodInvocationCount++;
 }
Ejemplo n.º 17
0
 /// <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();
 }
Ejemplo n.º 19
0
 public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     Console.WriteLine("Before " + eventArgs.MemberName);
 }
Ejemplo n.º 20
0
 /// <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";
 }
Ejemplo n.º 22
0
        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()
         );
     }
 }
Ejemplo n.º 25
0
 public void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     BeforeMethodInvocationCount++;
 }
 public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     eventArgs.Target.As<MockLogMixin>().AddLogMessage(
         "OnBeforeMethod: " + eventArgs.MemberName);
 }
Ejemplo n.º 27
0
 public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     BeforeMethodInvocationCount++;
 }
Ejemplo n.º 28
0
 public void OnAfterMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     AfterMethodInvocationCount++;
 }
Ejemplo n.º 29
0
        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>")))));
 }
Ejemplo n.º 31
0
 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"
         };
 }
Ejemplo n.º 34
0
        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);
        }
Ejemplo n.º 35
0
 public override void OnBeforeMethodInvocation(object sender, MethodEventArgs eventArgs)
 {
     Console.WriteLine("Before " + eventArgs.MemberName);
 }