Example #1
0
        /// <summary>
        /// Generate a new <see cref="InProcessAgent"/>, associated with <paramref name="obj"/>.
        /// </summary>
        /// <param name="obj">The object to assocated the <see cref="InProcessAgent"/> with.</param>
        /// <returns>A new <see cref="InProcessAgent"/>.</returns>
        public static InProcessAgent NewIPCAgent(Object obj)
        {
            var x = new InProcessAgent(obj.GetType());

            directory.Add(obj, x);
            return(x);
        }
Example #2
0
        /// <summary>
        /// Intercepts all method calls.
        /// </summary>
        /// <param name="args"></param>
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if (IsOutOfProcess) //if we're running out of process,
            {
                args.Proceed(); //just do what the code says.
                return;
            }

            InProcessAgent ipcAgent;

            //if the method we're processing is marked with [Initializer],
            if (MethodMarkedWith(args.Method, typeof(InitializerAttribute)))
            {
                ipcAgent = InProcessAgent.NewIPCAgent(args.Instance);                  // Start a new external process
                ipcAgent.Construct(args.Instance.GetType(), args.Arguments.ToArray()); //initialise the class on the other end.
                return;
            }

            //find the already existing InProcessAgent.
            ipcAgent = InProcessAgent.GetIPCAgent(args.Instance);

            if (MethodIsDispose(args.Method)) //If this method is the Dispose() Method,
            {
                // AND we've marked the Dispose() method with [KillExternalProcess],
                if (MethodMarkedWith(args.Method, typeof(KillExternalProcessAttribute)))
                {
                    ipcAgent.Dispose(DisposeMethod.KillDispose); //Kill the external process impolitely.
                }
                else //otherwise
                {
                    ipcAgent.Dispose(DisposeMethod.PoliteDispose); //Politely ask the external process to exit.
                }
                return;
            }
            // If we're not intialising or disposing, simply tell the external process to run the command.
            args.ReturnValue = ipcAgent.Call(args.Method, args.Arguments.ToArray());
        }
Example #3
0
 /// <summary>
 /// Generate a new <see cref="InProcessAgent"/>, associated with <paramref name="obj"/>.
 /// </summary>
 /// <param name="obj">The object to assocated the <see cref="InProcessAgent"/> with.</param>
 /// <returns>A new <see cref="InProcessAgent"/>.</returns>
 public static InProcessAgent NewIPCAgent(Object obj)
 {
     var x = new InProcessAgent(obj.GetType());
     directory.Add(obj, x);
     return x;
 }