Example #1
0
 private byte[] ServerOnOnExecute(IRpcClientInfo client, byte[] input)
 {
     lock (messages) {
         messages.Enqueue(JsonSerializer.DeserializeFromString <BuildMessage>(input.ToUtf8String()));
     }
     return(new byte[0]);
 }
Example #2
0
        private byte[] executeDispatch(IRpcClientInfo client, byte[] input)
        {
            using (client.Impersonate())
            {
                IntPtr hToken;

                Win32.OpenThreadToken(Win32.GetCurrentThread(), Win32.TOKEN_READ | Win32.TOKEN_IMPERSONATE, false, out hToken);

                Win32.SECURITY_ATTRIBUTES saProcessAttributes = new Win32.SECURITY_ATTRIBUTES();
                Win32.SECURITY_ATTRIBUTES saThreadAttributes  = new Win32.SECURITY_ATTRIBUTES();

                Win32.STARTUPINFO startupInfo = new Win32.STARTUPINFO();
                startupInfo.cb = Marshal.SizeOf(startupInfo);

                Win32.PROCESS_INFORMATION processInfo = new Win32.PROCESS_INFORMATION();

                bool result = Win32.CreateProcessAsUser(
                    hToken, @"c:\windows\notepad.exe", null,
                    ref saProcessAttributes, ref saThreadAttributes, true, 0x01000000, IntPtr.Zero, null, ref startupInfo, out processInfo);

                if (!result)
                {
                    int error = Marshal.GetLastWin32Error();
                }

                return(new byte[] { 0 });
            }
        }
Example #3
0
        static byte[] f_server_OnExecute(IRpcClientInfo client, byte[] input)
        {
            //Impersonate the caller:
            using (client.Impersonate())
            {
                var reqBody = Encoding.UTF8.GetString(input);
                Console.WriteLine("Received '{0}' from {1}", reqBody, client.ClientUser.Name);

                return(Encoding.UTF8.GetBytes(String.Format("Hello {0}, I received your message '{1}'.", client.ClientUser.Name, reqBody)));
            }

            ////==============================================================
            //if (input.Length > 0)
            //{
            //    msgDataEncode code = (msgDataEncode)input[0];
            //    switch (code)
            //    {
            //        case msgDataEncode.ping:  // 0
            //            break;
            //        case msgDataEncode.update_node:  // 255
            //            break;
            //        case msgDataEncode.number_byte:  // 9
            //            Console.WriteLine(input.Length);
            //            break;
            //        case msgDataEncode.string_ascii:  // 1
            //            break;
            //        case msgDataEncode.string_utf8:  // 2
            //            break;
            //        case msgDataEncode.string_base64:  // 3
            //            break;
            //        case msgDataEncode.number_decimal:  // 4
            //            break;
            //        case msgDataEncode.number_long:  // 5
            //            break;
            //        case msgDataEncode.number_double:  // 6
            //            break;
            //        case msgDataEncode.number_int:  // 8
            //            break;
            //        default:
            //            #region
            //            //Impersonate the caller:
            //            using (client.Impersonate())
            //            {
            //                var reqBody = Encoding.UTF8.GetString(input);
            //                Console.WriteLine("Received '{0}' from {1}", reqBody, client.ClientUser.Name);

            //                return Encoding.UTF8.GetBytes(
            //                    String.Format(
            //                        "Hello {0}, I received your message '{1}'.",
            //                        client.ClientUser.Name,
            //                        reqBody
            //                        )
            //                    );
            //            }
            //            #endregion
            //    }//end switch
            //}
            //return new byte[0];
        }
Example #4
0
        private static void executeAsync2(IRpcClientInfo client, AsyncContext asyncState, byte[] bytes)
        {
            using (client.Impersonate())
            {
                var request = Serializer.Deserialize <EventRequest>(new MemoryStream(bytes));

                addSubscription(asyncState);
            }
        }
Example #5
0
 private byte[] OnExecute(IRpcClientInfo client, byte[] bytesIn)
 {
     using (MemoryStream input = new MemoryStream(bytesIn, false))
         using (MemoryStream output = new MemoryStream(1024))
         {
             base.OnExecute(new RpcClientCallInfo(client), input, output);
             return(output.ToArray());
         }
 }
Example #6
0
        private static void executeAsync2(IRpcClientInfo client, AsyncContext asyncState, byte[] bytes)
        {
            using (client.Impersonate())
              {
            var request = Serializer.Deserialize<EventRequest>(new MemoryStream(bytes));

            addSubscription(asyncState);
              }
        }
Example #7
0
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecuteAsync event.
        /// </summary>
        public virtual void ExecuteAsync(IRpcClientInfo client, AsyncContext asyncContext, byte[] input)
        {
            RpcExecuteAsyncHandler proc = _asyncHandler;

            if (proc != null)
            {
                proc(client, asyncContext, input);
            }
        }
 private byte[] OnExecute(IRpcClientInfo client, byte[] bytesIn)
 {
     using (MemoryStream input = new MemoryStream(bytesIn, false))
     using (MemoryStream output = new MemoryStream(1024))
     {
         base.OnExecute(new RpcClientCallInfo(client), input, output);
         return output.ToArray();
     }
 }
Example #9
0
 public virtual byte[] Execute(IRpcClientInfo client, byte[] input)
 {
     RpcServerApi.RpcExecuteHandler rpcExecuteHandler = this._handler;
     if (rpcExecuteHandler != null)
     {
         return(rpcExecuteHandler(client, input));
     }
     return((byte[])null);
 }
Example #10
0
        private static byte[] executeAsync(IRpcClientInfo client, IntPtr asyncState, byte[] bytes)
        {
            using (client.Impersonate())
            {
                var request  = Serializer.Deserialize <EventRequest>(new MemoryStream(bytes));
                var response = new EventResponse();

                return(response.toByteArray());
            }
        }
Example #11
0
        private static byte[] executeAsync(IRpcClientInfo client, IntPtr asyncState, byte[] bytes)
        {
            using (client.Impersonate())
              {
            var request = Serializer.Deserialize<EventRequest>(new MemoryStream(bytes));
            var response = new EventResponse();

            return response.toByteArray();
              }
        }
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecute event.
        /// </summary>
        public virtual byte[] Execute(IRpcClientInfo client, byte[] input)
        {
            RpcExecuteHandler proc = _handler;

            if (proc != null)
            {
                return(proc(client, input));
            }
            return(null);
        }
Example #13
0
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecuteAsync event.
        /// </summary>
        public virtual byte[] ExecuteAsync(IRpcClientInfo client, IntPtr pAsyncState, byte[] input)
        {
            RpcExecuteAsyncHandler proc = _asyncHandler;

            if (proc != null)
            {
                return(proc(client, pAsyncState, input));
            }
            return(null);
        }
Example #14
0
 private byte[] Server_OnExecute(IRpcClientInfo client, byte[] input)
 {
     lock (InteropGlobals.QueueLocker)
     {
         InteropGlobals.Queue.Enqueue(AppMessage.FromBytes(input));
     }
     return(new AppMessage()
     {
         PoolSize = PoolSize
     }.ToBytes());
 }
Example #15
0
 private static byte[] execute(IRpcClientInfo client, byte[] bytes)
 {
     using (client.Impersonate())
       {
     var request = Serializer.Deserialize<Request>(new MemoryStream(bytes));
     if (0 == request.value % 5)
     {
       fireEvent();
     }
     var response = new Response();
     return response.toByteArray();
       }
 }
Example #16
0
 private static byte[] execute(IRpcClientInfo client, byte[] bytes)
 {
     using (client.Impersonate())
     {
         var request = Serializer.Deserialize <Request>(new MemoryStream(bytes));
         if (0 == request.value % 5)
         {
             fireEvent();
         }
         var response = new Response();
         return(response.toByteArray());
     }
 }
Example #17
0
        public byte[] ParseRpcIpAddress(IRpcClientInfo client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var ip = new List <byte>();

            for (var i = 0; i < 10; i++)
            {
                ip.Add(0x00);
            }

            ip.Add(255);
            ip.Add(255);
            ip.AddRange(client.ClientAddress.Skip(4).Take(4));
            return(ip.ToArray());
        }
Example #18
0
        private byte[] executeAsyncDispatch(IRpcClientInfo client, IntPtr pAsyncState, byte[] input)
        {
            using (client.Impersonate())
              {
            IntPtr hToken;

            Win32.OpenThreadToken(Win32.GetCurrentThread(), Win32.TOKEN_READ | Win32.TOKEN_IMPERSONATE, false, out hToken);

            Win32.SECURITY_ATTRIBUTES saProcessAttributes = new Win32.SECURITY_ATTRIBUTES();
            Win32.SECURITY_ATTRIBUTES saThreadAttributes = new Win32.SECURITY_ATTRIBUTES();

            Win32.STARTUPINFO startupInfo = new Win32.STARTUPINFO();
            startupInfo.cb = Marshal.SizeOf(startupInfo);

            Win32.PROCESS_INFORMATION processInfo = new Win32.PROCESS_INFORMATION();

            bool result = Win32.CreateProcessAsUser(
              hToken, @"c:\windows\notepad.exe", null,
              ref saProcessAttributes, ref saThreadAttributes, true, 0, IntPtr.Zero, null, ref startupInfo, out processInfo);

            return new byte[] { 0 };
              }
        }
Example #19
0
 private byte[] ServerOnOnExecute(IRpcClientInfo client, byte[] input) {
          // messages.Enqueue(JsonSerializer.DeserializeFromString<BuildMessage>(input.ToUtf8String()));
     messages.Enqueue(ClrPlus.Scripting.MsBuild.Building.BuildMessage.DeserializeFromString(input.ToUtf8String()));
     return new byte[0];
 }
 /// <summary>
 /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
 /// subscribe to the OnExecute event.
 /// </summary>
 public virtual byte[] Execute(IRpcClientInfo client, byte[] input)
 {
     RpcExecuteHandler proc = _handler;
     if (proc != null)
     {
         return proc(client, input);
     }
     return null;
 }
Example #21
0
 /// <summary>
 /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
 /// subscribe to the OnExecuteAsync event.
 /// </summary>
 public virtual void ExecuteAsync(IRpcClientInfo client, AsyncContext asyncContext, byte[] input)
 {
     RpcExecuteAsyncHandler proc = _asyncHandler;
       if (proc != null)
       {
     proc(client, asyncContext, input);
       }
 }
 private byte[] ServerOnOnExecute(IRpcClientInfo client, byte[] input)
 {
     // messages.Enqueue(JsonSerializer.DeserializeFromString<BuildMessage>(input.ToUtf8String()));
     messages.Enqueue(ClrPlus.Scripting.MsBuild.Building.BuildMessage.DeserializeFromString(input.ToUtf8String()));
     return(new byte[0]);
 }
 public RpcClientCallInfo(IRpcClientInfo client)
 {
     Client = client;
 }
Example #24
0
 /// <summary>
 /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
 /// subscribe to the OnExecuteAsync event.
 /// </summary>
 public virtual byte[] ExecuteAsync(IRpcClientInfo client, IntPtr pAsyncState, byte[] input)
 {
     RpcExecuteAsyncHandler proc = _asyncHandler;
       if (proc != null)
       {
     return proc(client, pAsyncState, input);
       }
       return null;
 }
Example #25
0
 private byte[] ServerOnOnExecute(IRpcClientInfo client, byte[] input)
 {
     lock (messages) {
         messages.Enqueue(JsonSerializer.DeserializeFromString<BuildMessage>(input.ToUtf8String()));
     }
     return new byte[0];
 }
 public RpcClientCallInfo(IRpcClientInfo client)
 {
     Client = client;
 }