Esempio n. 1
0
 public void Call(string command, IPendingServiceCallback callback, params object[] arguments)
 {
     try
     {
         TypeHelper._Init();
         Uri            requestUri = new Uri(this._gatewayUrl);
         HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUri);
         request.ContentType     = "application/x-amf";
         request.Method          = "POST";
         request.CookieContainer = this._netConnection.CookieContainer;
         AMFMessage amfMessage = new AMFMessage((ushort)this._netConnection.ObjectEncoding);
         AMFBody    body       = new AMFBody(command, callback.GetHashCode().ToString(), arguments);
         amfMessage.AddBody(body);
         foreach (KeyValuePair <string, AMFHeader> pair in this._netConnection.Headers)
         {
             amfMessage.AddHeader(pair.Value);
         }
         PendingCall call  = new PendingCall(command, arguments);
         RequestData state = new RequestData(request, amfMessage, call, callback);
         request.BeginGetRequestStream(new AsyncCallback(this.BeginRequestFlashCall), state);
     }
     catch (Exception exception)
     {
         this._netConnection.RaiseNetStatus(exception);
     }
 }
Esempio n. 2
0
        public void Call <T>(string endpoint, string destination, string source, string operation, Responder <T> responder, params object[] arguments)
        {
            if (_netConnection.ObjectEncoding == ObjectEncoding.AMF0)
            {
                throw new NotSupportedException("AMF0 not supported for Flex RPC");
            }
            try {
                TypeHelper._Init();

                RemotingMessage remotingMessage = new RemotingMessage();
                remotingMessage.clientId    = Guid.NewGuid().ToString("D");
                remotingMessage.destination = destination;
                remotingMessage.messageId   = Guid.NewGuid().ToString("D");
                remotingMessage.timestamp   = 0;
                remotingMessage.timeToLive  = 0;
                remotingMessage.SetHeader(MessageBase.EndpointHeader, endpoint);
                remotingMessage.SetHeader(MessageBase.FlexClientIdHeader, _netConnection.ClientId ?? "nil");
                //Service stuff
                remotingMessage.source    = source;
                remotingMessage.operation = operation;
                remotingMessage.body      = arguments;

                FlexInvoke       invoke      = new FlexInvoke();
                PendingCall      pendingCall = new PendingCall(null, new object[] { remotingMessage });
                ResponderHandler handler     = new ResponderHandler(responder);
                pendingCall.RegisterCallback(handler);
                invoke.ServiceCall = pendingCall;
                invoke.InvokeId    = _connection.InvokeId;
                _connection.RegisterPendingCall(invoke.InvokeId, pendingCall);
                Write(invoke);
            } catch (Exception ex) {
                _netConnection.RaiseNetStatus(ex);
            }
        }
Esempio n. 3
0
        // =====================================================================

        /// <summary>
        ///
        /// </summary>
        /// <param name="responder"></param>
        /// <param name="options"></param>
        public void renderSink(Responder <RenderingWidget> responder,
                               RenderOptions options)
        {
            PendingCall call = new PendingCall(responder);

            renderSinkInternal(call, options);
        }
Esempio n. 4
0
        public void Call(string command, IPendingServiceCallback callback, params object[] arguments)
        {
            try
            {
                TypeHelper._Init();

                Uri uri = new Uri(_gatewayUrl);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.ContentType = ContentType.AMF;
                request.Method = "POST";
            #if !(SILVERLIGHT)
                request.CookieContainer = _netConnection.CookieContainer;
            #endif
                AMFMessage amfMessage = new AMFMessage((ushort)_netConnection.ObjectEncoding);
                AMFBody amfBody = new AMFBody(command, callback.GetHashCode().ToString(), arguments);
                amfMessage.AddBody(amfBody);
                foreach (KeyValuePair<string, AMFHeader> entry in _netConnection.Headers)
                {
                    amfMessage.AddHeader(entry.Value);
                }
                PendingCall call = new PendingCall(command, arguments);
                AmfRequestData amfRequestData = new AmfRequestData(request, amfMessage, call, callback, null);
                request.BeginGetRequestStream(BeginRequestFlashCall, amfRequestData);
            }
            catch (Exception ex)
            {
                _netConnection.RaiseNetStatus(ex);
            }
        }
        static FlexInvoke DecodeFlexInvoke(ByteBuffer stream)
        {
            int        version  = stream.ReadByte();
            RtmpReader reader   = new RtmpReader(stream);
            string     action   = reader.ReadData() as string;
            int        invokeId = System.Convert.ToInt32(reader.ReadData());
            object     cmdData  = reader.ReadData();

            object[] parameters = Call.EmptyArguments;
            if (stream.HasRemaining)
            {
#if !(NET_1_1)
                List <object> paramList = new List <object>();
#else
                ArrayList paramList = new ArrayList();
#endif
                while (stream.HasRemaining)
                {
                    object obj = reader.ReadData();
                    paramList.Add(obj);
                }
                parameters = paramList.ToArray();
            }

            /*
             * int dotIndex = action == null ? -1 : action.LastIndexOf(".");
             * string serviceName = (action == -1) ? null : action.Substring(0, dotIndex);
             * string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);
             */
            PendingCall call   = new PendingCall(null, action, parameters);
            FlexInvoke  invoke = new FlexInvoke(invokeId, cmdData);
            invoke.ServiceCall = call;
            return(invoke);
        }
Esempio n. 6
0
        void ProcessReturn(uint callId, BufferView data)
        {
            PendingCall callInfo = FetchPendingCall(callId);

            if (callInfo == null)
            {
                // Received a timeouted (or invalid) answer
                ProtocolError();
                return;
            }

            // Read the incoming data
            object inflatedData;

            try {
                inflatedData = InflateData.Inflate(data, callInfo.Call.ReturnFormat);
            } catch {
                ProtocolError();
                return;
            }

            // Clear the timeout
            if (callInfo.Interval != null)
            {
                callInfo.Interval.Stop();
            }

            // Call the callback
            if (callInfo.OnReturn != null)
            {
                callInfo.OnReturn(this, inflatedData);
            }
        }
Esempio n. 7
0
 public RequestData(HttpWebRequest request, AMFMessage amfMessage, PendingCall call, IPendingServiceCallback callback)
 {
     this._call       = call;
     this._request    = request;
     this._amfMessage = amfMessage;
     this._callback   = callback;
 }
        public void AsyncCallbackTest()
        {
            bool          isCallbackDone = false;
            AsyncCallback callback       = ar => isCallbackDone = true;

            var pendingCall = new PendingCall(0, "", "", callback, this);

            pendingCall.ReceiveResult(
                new RpcMessage.Result {
                CallResult = new RpcMessage.Parameter {
                    IntParam = 42
                }
            });

            client.Setup(c =>
                         c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <AsyncCallback>(),
                                It.IsAny <object>())).Returns(pendingCall);

            dynamic      serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            IAsyncResult asyncResult  = serviceProxy.BeginTestMethod("param", 42.0f, callback, this);

            Assert.That(asyncResult.AsyncState, Is.EqualTo(this));
            asyncResult.AsyncWaitHandle.WaitOne(); //not necessary, just because i can
            int result = serviceProxy.EndTestMethod(asyncResult);

            Assert.That(isCallbackDone);
            Assert.That(asyncResult.IsCompleted);
            Assert.That(result, Is.EqualTo(42));
            client.Verify(c => c.Call("TestServiceName", "TestMethod", new object[] { "param", 42.0f }, callback, this));
        }
Esempio n. 9
0
        public void CallTest()
        {
            PendingCall pendingCall = client.Call("ServiceName", "MethodName", null, null, null);

            controller.Verify(c => c.Send(It.Is <RpcMessage>(m => m.Id == pendingCall.Id &&
                                                             m.CallMessage.Service == "ServiceName" && m.CallMessage.Method == "MethodName" &&
                                                             m.CallMessage.ExpectsResult)));
        }
Esempio n. 10
0
 public AmfRequestData(HttpWebRequest request, AMFMessage amfMessage, PendingCall call, IPendingServiceCallback callback, object responder)
 {
     _call = call;
     _responder = responder;
     _request = request;
     _amfMessage = amfMessage;
     _callback = callback;
 }
Esempio n. 11
0
        public void Invoke(string method, object[] parameters, IPendingServiceCallback callback)
        {
            IPendingServiceCall serviceCall = new PendingCall(method, parameters);

            if (callback != null)
            {
                serviceCall.RegisterCallback(callback);
            }
            this.Invoke(serviceCall);
        }
Esempio n. 12
0
 public void ResultReceived(IPendingServiceCall call)
 {
     if ("createStream".Equals(call.ServiceMethodName))
     {
         RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
         object[]       args       = new object[3] {
             _name, _start, _length
         };
         PendingCall pendingCall = new PendingCall("play", args);
         connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(this.StreamId));
     }
 }
Esempio n. 13
0
        void TimeoutCallback(object sender, ElapsedEventArgs e)
        {
            PendingCall callInfo = FetchPendingCall((Timer)sender);

            if (callInfo != null)
            {
                if (callInfo.OnException != null)
                {
                    callInfo.OnException(this, 0, null);
                }
            }
        }
Esempio n. 14
0
        public void CallResultMissingFailedTest()
        {
            var pendingCall = new PendingCall(0, "", "", null, null);
            pendingCall.ReceiveResult(new RpcMessage.Result());

            client.Setup(c =>
                c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object[]>(), It.IsAny<AsyncCallback>(),
                    It.IsAny<object>())).Returns(pendingCall);

            dynamic serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            int x = serviceProxy.TestMethod(10, "Hello", 1.0f);
        }
 public void ResultReceived(IPendingServiceCall call)
 {
     if ("createStream".Equals(call.ServiceMethodName))
     {
         RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
         object[]       args       = new object[2] {
             _name, _mode
         };
         PendingCall pendingCall = new PendingCall("publish", args);
         pendingCall.RegisterCallback(new PublishResultCallBack());
         connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(_stream.StreamId));
     }
 }
Esempio n. 16
0
        public void CallResultMissingFailedTest()
        {
            var pendingCall = new PendingCall(0, "", "", null, null);

            pendingCall.ReceiveResult(new RpcMessage.Result());

            client.Setup(c =>
                         c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <AsyncCallback>(),
                                It.IsAny <object>())).Returns(pendingCall);

            dynamic serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            int     x            = serviceProxy.TestMethod(10, "Hello", 1.0f);
        }
Esempio n. 17
0
        private static Notify DecodeNotifyOrInvoke(Notify notify, ByteBuffer stream, RtmpHeader header)
        {
            long       position = stream.Position;
            RtmpReader reader   = new RtmpReader(stream);
            string     str      = reader.ReadData() as string;

            if (!(notify is Invoke))
            {
                stream.Position = position;
                return(notify);
            }
            if ((header == null) || (header.StreamId == 0))
            {
                double num2 = (double)reader.ReadData();
                notify.InvokeId = (int)num2;
            }
            object[] args = new object[0];
            if (stream.HasRemaining)
            {
                List <object> list = new List <object>();
                object        item = reader.ReadData();
                if (item is IDictionary)
                {
                    notify.ConnectionParameters = item as IDictionary;
                }
                else if (item != null)
                {
                    list.Add(item);
                }
                while (stream.HasRemaining)
                {
                    list.Add(reader.ReadData());
                }
                args = list.ToArray();
            }
            int    length = str.LastIndexOf(".");
            string name   = (length == -1) ? null : str.Substring(0, length);
            string method = (length == -1) ? str : str.Substring(length + 1, (str.Length - length) - 1);

            if (notify is Invoke)
            {
                PendingCall call = new PendingCall(name, method, args);
                (notify as Invoke).ServiceCall = call;
            }
            else
            {
                Call call2 = new Call(name, method, args);
                notify.ServiceCall = call2;
            }
            return(notify);
        }
Esempio n. 18
0
 private void BeginResponseFlashCall(IAsyncResult ar)
 {
     try
     {
         RequestData asyncState = ar.AsyncState as RequestData;
         if (asyncState != null)
         {
             HttpWebResponse response = (HttpWebResponse)asyncState.Request.EndGetResponse(ar);
             if (response != null)
             {
                 Stream responseStream = response.GetResponseStream();
                 if (responseStream != null)
                 {
                     AMFMessage message = new AMFDeserializer(responseStream).ReadAMFMessage();
                     AMFBody    bodyAt  = message.GetBodyAt(0);
                     for (int i = 0; i < message.HeaderCount; i++)
                     {
                         AMFHeader headerAt = message.GetHeaderAt(i);
                         if (headerAt.Name == "RequestPersistentHeader")
                         {
                             this._netConnection.AddHeader(headerAt.Name, headerAt.MustUnderstand, headerAt.Content);
                         }
                     }
                     PendingCall call = asyncState.Call;
                     call.Result = bodyAt.Content;
                     if (bodyAt.Target.EndsWith("/onStatus"))
                     {
                         call.Status = 0x13;
                     }
                     else
                     {
                         call.Status = 2;
                     }
                     asyncState.Callback.ResultReceived(call);
                 }
                 else
                 {
                     this._netConnection.RaiseNetStatus("Could not aquire ResponseStream");
                 }
             }
             else
             {
                 this._netConnection.RaiseNetStatus("Could not aquire HttpWebResponse");
             }
         }
     }
     catch (Exception exception)
     {
         this._netConnection.RaiseNetStatus(exception);
     }
 }
Esempio n. 19
0
        /**
         * Private helpers
         * =====================================================================
         */

        private void renderSinkInternal(PendingCall call, RenderOptions options)
        {
            int            callId   = _callIdGenerator++;
            ManualRenderer renderer = new ManualRenderer(_platformHandle, onRendererPreDispose);

            call.manualRenderer   = renderer;
            _pendingCalls[callId] = call;
            ADLRenderRequest nReq = RenderOptions.toNative(options);

            nReq.invalidateCallback = renderer.getInvalidateClbck();
            Console.Error.WriteLine("Requesting SDK to start rendering sink");
            NativeAPI.adl_render_sink(_renderResponder, _platformHandle,
                                      new IntPtr(callId), ref nReq);
        }
Esempio n. 20
0
 public void Call(string endpoint, string destination, string source, string operation, IPendingServiceCallback callback, params object[] arguments)
 {
     if (this._netConnection.ObjectEncoding == ObjectEncoding.AMF0)
     {
         throw new NotSupportedException("AMF0 not supported for Flex RPC");
     }
     try
     {
         TypeHelper._Init();
         Uri            requestUri = new Uri(this._gatewayUrl);
         HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUri);
         request.ContentType     = "application/x-amf";
         request.Method          = "POST";
         request.CookieContainer = this._netConnection.CookieContainer;
         AMFMessage      amfMessage = new AMFMessage((ushort)this._netConnection.ObjectEncoding);
         RemotingMessage message2   = new RemotingMessage {
             clientId    = Guid.NewGuid().ToString("D"),
             destination = destination,
             messageId   = Guid.NewGuid().ToString("D"),
             timestamp   = 0L,
             timeToLive  = 0L
         };
         message2.SetHeader("DSEndpoint", endpoint);
         if (this._netConnection.ClientId == null)
         {
             message2.SetHeader("DSId", "nil");
         }
         else
         {
             message2.SetHeader("DSId", this._netConnection.ClientId);
         }
         message2.source    = source;
         message2.operation = operation;
         message2.body      = arguments;
         foreach (KeyValuePair <string, AMFHeader> pair in this._netConnection.Headers)
         {
             amfMessage.AddHeader(pair.Value);
         }
         AMFBody body = new AMFBody(null, null, new object[] { message2 });
         amfMessage.AddBody(body);
         PendingCall call  = new PendingCall(source, operation, arguments);
         RequestData state = new RequestData(request, amfMessage, call, callback);
         request.BeginGetRequestStream(new AsyncCallback(this.BeginRequestFlexCall), state);
     }
     catch (Exception exception)
     {
         this._netConnection.RaiseNetStatus(exception);
     }
 }
Esempio n. 21
0
        public void Properties()
        {
            var resultData = new RpcResultStub();

            var p = new PendingCall();

            Assert.That(p.Status, Is.EqualTo(PendingCallStatus.AwaitingResult));
            Assert.That(p.Result, Is.Null);

            p.Status = PendingCallStatus.Received;
            p.Result = resultData;

            Assert.That(p.Status, Is.EqualTo(PendingCallStatus.Received));
            Assert.That(p.Result, Is.SameAs(resultData));
        }
Esempio n. 22
0
        public void Call(string endpoint, string destination, string source, string operation, IPendingServiceCallback callback, params object[] arguments)
        {
            if (_netConnection.ObjectEncoding == ObjectEncoding.AMF0)
            {
                throw new NotSupportedException("AMF0 not supported for Flex RPC");
            }
            try
            {
                TypeHelper._Init();

                Uri            uri     = new Uri(_gatewayUrl);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.ContentType = ContentType.AMF;
                request.Method      = "POST";
#if !(SILVERLIGHT)
                request.CookieContainer = _netConnection.CookieContainer;
#endif
                AMFMessage amfMessage = new AMFMessage((ushort)_netConnection.ObjectEncoding);

                RemotingMessage remotingMessage = new RemotingMessage();
                remotingMessage.clientId    = Guid.NewGuid().ToString("D");
                remotingMessage.destination = destination;
                remotingMessage.messageId   = Guid.NewGuid().ToString("D");
                remotingMessage.timestamp   = 0;
                remotingMessage.timeToLive  = 0;
                remotingMessage.SetHeader(MessageBase.EndpointHeader, endpoint);
                remotingMessage.SetHeader(MessageBase.FlexClientIdHeader, _netConnection.ClientId ?? "nil");
                //Service stuff
                remotingMessage.source    = source;
                remotingMessage.operation = operation;
                remotingMessage.body      = arguments;

                foreach (KeyValuePair <string, AMFHeader> entry in _netConnection.Headers)
                {
                    amfMessage.AddHeader(entry.Value);
                }
                AMFBody amfBody = new AMFBody(null, null, new object[] { remotingMessage });
                amfMessage.AddBody(amfBody);

                PendingCall    call           = new PendingCall(source, operation, arguments);
                AmfRequestData amfRequestData = new AmfRequestData(request, amfMessage, call, callback, null);
                request.BeginGetRequestStream(BeginRequestFlexCall, amfRequestData);
            }
            catch (Exception ex)
            {
                _netConnection.RaiseNetStatus(ex);
            }
        }
Esempio n. 23
0
 public void Receive <T>(Responder <T> responder)
 {
     try
     {
         TypeHelper._Init();
         Invoke           invoke      = new Invoke();
         PendingCall      pendingCall = new PendingCall(null, null);
         ResponderHandler handler     = new ResponderHandler(responder);
         pendingCall.RegisterCallback(handler);
         _connection.RegisterPendingReceive(pendingCall);
     }
     catch (Exception ex)
     {
         _netConnection.RaiseNetStatus(ex);
     }
 }
Esempio n. 24
0
 public void Call <T>(string command, Responder <T> responder, params object[] arguments)
 {
     try {
         TypeHelper._Init();
         Invoke           invoke      = new Invoke();
         PendingCall      pendingCall = new PendingCall(command, arguments);
         ResponderHandler handler     = new ResponderHandler(responder);
         pendingCall.RegisterCallback(handler);
         invoke.ServiceCall = pendingCall;
         invoke.InvokeId    = _connection.InvokeId;
         _connection.RegisterPendingCall(invoke.InvokeId, pendingCall);
         Write(invoke);
     } catch (Exception ex) {
         _netConnection.RaiseNetStatus(ex);
     }
 }
Esempio n. 25
0
 public override void ConnectionOpened(RtmpConnection connection)
 {
     try {
         // Send "connect" call to the server
         RtmpChannel channel     = connection.GetChannel(3);
         PendingCall pendingCall = new PendingCall("connect", _connectArguments);
         Invoke      invoke      = new Invoke(pendingCall);
         invoke.ConnectionParameters = _connectionParameters;
         invoke.InvokeId             = connection.InvokeId;
         pendingCall.RegisterCallback(this);
         connection.RegisterPendingCall(invoke.InvokeId, pendingCall);
         channel.Write(invoke);
     } catch (Exception ex) {
         _netConnection.RaiseNetStatus(ex);
     }
 }
Esempio n. 26
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client       = new Mock <RpcClient>(new Mock <RpcController>().Object);

            pendingSquareCall = new PendingCall(0, null, null, null, null);
            var squareResultMessage = new RpcMessage.Result();

            squareResultMessage.CallResult          = new RpcMessage.Parameter();
            squareResultMessage.CallResult.IntParam = 42;
            pendingSquareCall.ReceiveResult(squareResultMessage);

            client.Setup(c => c.Call("ISampleService", "GetSquare", It.IsAny <RpcMessage.Parameter[]>(),
                                     It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(pendingSquareCall);
        }
Esempio n. 27
0
        void ProcessException(uint callId, uint type, BufferView data)
        {
            PendingCall callInfo = FetchPendingCall(callId);

            if (callInfo == null)
            {
                // Received a timeouted (or invalid) answer
                ProtocolError();
                return;
            }
            if (!callInfo.Call.HasException(type))
            {
                // Received an invalid exception type
                ProtocolError();
                return;
            }

            // Get exception definition
            Registry.RegisteredException exception = Registry.GetException(type);
            if (exception == null)
            {
                ProtocolError();
                return;
            }

            // Read the incoming data
            object inflatedData;

            try {
                inflatedData = InflateData.Inflate(data, exception.DataFormat);
            } catch {
                ProtocolError();
                return;
            }

            // Clear the timeout
            if (callInfo.Interval != null)
            {
                callInfo.Interval.Stop();
            }

            // Call the callback
            if (callInfo.OnException != null)
            {
                callInfo.OnException(this, (int)type, inflatedData);
            }
        }
Esempio n. 28
0
        public void Init()
        {
            client = new Mock <RpcClient>(new Mock <RpcController>().Object);

            var pendingCall = new PendingCall(0, "", "", null, null);

            pendingCall.ReceiveResult(
                new RpcMessage.Result {
                CallResult = new RpcMessage.Parameter {
                    IntParam = 42
                }
            });

            client.Setup(c =>
                         c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <AsyncCallback>(),
                                It.IsAny <object>())).Returns(pendingCall);
        }
Esempio n. 29
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client = new Mock<RpcClient>(new Mock<RpcController>().Object);

            Type proxyType = proxyBuilder.Build(typeof(ISampleService));
            service = (ISampleService)Activator.CreateInstance(proxyType, client.Object);

            pendingCall = new PendingCall(0, null, null, null, null);
            resultMessage = new RpcMessage.Result();
            resultMessage.CallResult = new RpcMessage.Parameter();
            pendingCall.ReceiveResult(resultMessage);

            client.Setup(c => c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<RpcMessage.Parameter[]>(),
                It.IsAny<AsyncCallback>(), It.IsAny<object>()))
                .Returns(pendingCall);
        }
Esempio n. 30
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client       = new Mock <RpcClient>(new Mock <RpcController>().Object);

            Type proxyType = proxyBuilder.Build(typeof(ISampleService));

            service = (ISampleService)Activator.CreateInstance(proxyType, client.Object);

            pendingCall              = new PendingCall(0, null, null, null, null);
            resultMessage            = new RpcMessage.Result();
            resultMessage.CallResult = new RpcMessage.Parameter();
            pendingCall.ReceiveResult(resultMessage);

            client.Setup(c => c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <RpcMessage.Parameter[]>(),
                                     It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(pendingCall);
        }
Esempio n. 31
0
		/// <summary>
		/// Sends status notification.
		/// </summary>
		/// <param name="status">Status object.</param>
		public void SendStatus(StatusASO status) {
			bool andReturn = !status.code.Equals(StatusASO.NS_DATA_START);
			Invoke invoke;
			if (andReturn) {
				PendingCall call = new PendingCall(null, "onStatus", new object[] { status });
				invoke = new Invoke();
				invoke.InvokeId = 1;
				invoke.ServiceCall = call;
			} else {
				Call call = new Call(null, "onStatus", new object[] { status });
				invoke = (Invoke)new Notify();
				invoke.InvokeId = 1;
				invoke.ServiceCall = call;
			}
			// We send directly to the corresponding stream as for
			// some status codes, no stream has been created and thus
			// "getStreamByChannelId" will fail.
			Write(invoke, _connection.GetStreamIdForChannel(_channelId));
		}
Esempio n. 32
0
 public override void ConnectionOpened(RtmpConnection connection)
 {
     try
     {
         RtmpChannel channel     = connection.GetChannel(3);
         PendingCall serviceCall = new PendingCall("connect", this._connectArguments);
         FluorineFx.Messaging.Rtmp.Event.Invoke message = new FluorineFx.Messaging.Rtmp.Event.Invoke(serviceCall)
         {
             ConnectionParameters = this._connectionParameters,
             InvokeId             = connection.InvokeId
         };
         serviceCall.RegisterCallback(this);
         connection.RegisterPendingCall(message.InvokeId, serviceCall);
         channel.Write(message);
     }
     catch (Exception exception)
     {
         this._netConnection.RaiseNetStatus(exception);
     }
 }
Esempio n. 33
0
        public void SendStatus(StatusASO status)
        {
            Invoke invoke;

            if (!status.code.Equals("NetStream.Data.Start"))
            {
                PendingCall call = new PendingCall(null, "onStatus", new object[] { status });
                invoke = new Invoke {
                    InvokeId    = 1,
                    ServiceCall = call
                };
            }
            else
            {
                Call call2 = new Call(null, "onStatus", new object[] { status });
                invoke             = (Invoke) new Notify();
                invoke.InvokeId    = 1;
                invoke.ServiceCall = call2;
            }
            this.Write(invoke, this._connection.GetStreamIdForChannel(this._channelId));
        }
Esempio n. 34
0
        public void AsyncCallbackTest()
        {
            bool isCallbackDone = false;
            AsyncCallback callback = ar => isCallbackDone = true;

            var pendingCall = new PendingCall(0, "", "", callback, this);
            pendingCall.ReceiveResult(
                new RpcMessage.Result { CallResult = new RpcMessage.Parameter { IntParam = 42 } });

            client.Setup(c =>
                c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object[]>(), It.IsAny<AsyncCallback>(),
                    It.IsAny<object>())).Returns(pendingCall);

            dynamic serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            IAsyncResult asyncResult = serviceProxy.BeginTestMethod("param", 42.0f, callback, this);
            Assert.That(asyncResult.AsyncState, Is.EqualTo(this));
            asyncResult.AsyncWaitHandle.WaitOne(); //not necessary, just because i can
            int result = serviceProxy.EndTestMethod(asyncResult);

            Assert.That(isCallbackDone);
            Assert.That(asyncResult.IsCompleted);
            Assert.That(result, Is.EqualTo(42));
            client.Verify(c => c.Call("TestServiceName", "TestMethod", new object[] { "param", 42.0f }, callback, this));
        }
Esempio n. 35
0
 // =====================================================================
 /// <summary>
 /// 
 /// </summary>
 /// <param name="responder"></param>
 /// <param name="options"></param>
 public void renderSink(Responder<RenderingWidget> responder,
     RenderOptions options)
 {
     PendingCall call = new PendingCall(responder);
     renderSinkInternal(call, options);
 }
Esempio n. 36
0
 public void manualRenderSink(Responder<ManualRenderer> responder, RenderOptions options)
 {
     PendingCall call = new PendingCall(responder);
     renderSinkInternal(call, options);
 }
Esempio n. 37
0
 /**
  * Private helpers
  * =====================================================================
  */
 private void renderSinkInternal(PendingCall call, RenderOptions options)
 {
     int callId = _callIdGenerator++;
     ManualRenderer renderer = new ManualRenderer(_platformHandle, onRendererPreDispose);
     call.manualRenderer = renderer;
     _pendingCalls[callId] = call;
     CDORenderRequest nReq = RenderOptions.toNative(options);
     nReq.invalidateCallback = renderer.getInvalidateClbck();
     Console.Error.WriteLine("Requesting SDK to start rendering sink");
     NativeAPI.cdo_render_sink(_renderResponder, _platformHandle,
         new IntPtr(callId), ref nReq);
 }
Esempio n. 38
0
        public void Init()
        {
            client = new Mock<RpcClient>(new Mock<RpcController>().Object);

            var pendingCall = new PendingCall(0, "", "", null, null);
            pendingCall.ReceiveResult(
                new RpcMessage.Result { CallResult = new RpcMessage.Parameter { IntParam = 42 } });

            client.Setup(c =>
                c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object[]>(), It.IsAny<AsyncCallback>(),
                    It.IsAny<object>())).Returns(pendingCall);
        }
Esempio n. 39
0
		/// <summary>
		/// Begins an asynchronous operation to invoke a service by name with parameters and callback.
		/// </summary>
		/// <param name="asyncCallback">The AsyncCallback delegate.</param>
		/// <param name="method">Method name.</param>
		/// <param name="parameters">Invocation parameters passed to the method.</param>
		/// <param name="callback">Callback used to handle return values.</param>
		/// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
		/// <remarks>
		/// <para>
		/// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginInvoke method.
		/// </para>
		/// <para>
		/// Your callback method should invoke the EndInvoke method. When your application calls BeginInvoke, the system will use a separate thread to execute the specified callback method, and will block on EndInvoke until the client is invoked successfully or throws an exception.
		/// </para>
		/// </remarks>
		public IAsyncResult BeginInvoke(AsyncCallback asyncCallback, string method, object[] parameters, IPendingServiceCallback callback) {
			IPendingServiceCall call = new PendingCall(method, parameters);
			if (callback != null)
				call.RegisterCallback(callback);
			return BeginInvoke(asyncCallback, call);
		}
Esempio n. 40
0
		/// <summary>
		/// Invoke method with parameters and callback.
		/// </summary>
		/// <param name="method">Method name.</param>
		/// <param name="parameters">Invocation parameters passed to the method.</param>
		/// <param name="callback">Callback used to handle return values.</param>
		public void Invoke(string method, object[] parameters, IPendingServiceCallback callback) {
			IPendingServiceCall call = new PendingCall(method, parameters);
			if (callback != null)
				call.RegisterCallback(callback);
			Invoke(call);
		}
Esempio n. 41
0
 public void ResultReceived(IPendingServiceCall call)
 {
     if ("createStream".Equals(call.ServiceMethodName))
     {
         RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
         object[] args = new object[3] { _name, _start, _length };
         PendingCall pendingCall = new PendingCall("play", args);
         connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(this.StreamId));
     }
 }
Esempio n. 42
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client = new Mock<RpcClient>(new Mock<RpcController>().Object);

            pendingSquareCall = new PendingCall(0, null, null, null, null);
            var squareResultMessage = new RpcMessage.Result();
            squareResultMessage.CallResult = new RpcMessage.Parameter();
            squareResultMessage.CallResult.IntParam = 42;
            pendingSquareCall.ReceiveResult(squareResultMessage);

            client.Setup(c => c.Call("ISampleService", "GetSquare", It.IsAny<RpcMessage.Parameter[]>(),
                It.IsAny<AsyncCallback>(), It.IsAny<object>()))
                .Returns(pendingSquareCall);
        }
		static FlexInvoke DecodeFlexInvoke(ByteBuffer stream)
		{
			int version = stream.ReadByte();
			RtmpReader reader = new RtmpReader(stream);
            string action = reader.ReadData() as string;
			int invokeId = System.Convert.ToInt32(reader.ReadData());
			object cmdData = reader.ReadData();

            object[] parameters = Call.EmptyArguments;
            if (stream.HasRemaining)
            {
#if !(NET_1_1)
                List<object> paramList = new List<object>();
#else
            ArrayList paramList = new ArrayList();
#endif
                while (stream.HasRemaining)
                {
                    object obj = reader.ReadData();
                    paramList.Add(obj);
                }
                parameters = paramList.ToArray();
            }
            /*
            int dotIndex = action == null ? -1 : action.LastIndexOf(".");
            string serviceName = (action == -1) ? null : action.Substring(0, dotIndex);
            string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);
            */
            PendingCall call = new PendingCall(null, action, parameters);
            FlexInvoke invoke = new FlexInvoke(invokeId, cmdData);
            invoke.ServiceCall = call;
			return invoke;
		}
		static Notify DecodeNotifyOrInvoke(Notify notify, ByteBuffer stream, RtmpHeader header)
		{
			long start = stream.Position;
			RtmpReader reader = new RtmpReader(stream);
			string action = reader.ReadData() as string;

			if(!(notify is Invoke))
			{
				//Don't decode "NetStream.send" requests
				stream.Position = start;
                notify.Data = ByteBuffer.Allocate(stream.Remaining);
                notify.Data.Put(stream);
				//notify.setData(in.asReadOnlyBuffer());
				return notify;
			}

			if(header == null || header.StreamId == 0) 
			{
				double invokeId = (double)reader.ReadData();
				notify.InvokeId = (int)invokeId;
			}

            object[] parameters = Call.EmptyArguments;
			if(stream.HasRemaining)
			{
#if !(NET_1_1)
                List<object> paramList = new List<object>();
#else
                ArrayList paramList = new ArrayList();
#endif
                object obj = reader.ReadData();

				if (obj is IDictionary)
				{
					// for connect we get a map
					notify.ConnectionParameters = obj as IDictionary;
				} 
				else if (obj != null) 
				{
					paramList.Add(obj);
				}

				while(stream.HasRemaining)
				{
					paramList.Add(reader.ReadData());
				}
				parameters = paramList.ToArray();
			}

			int dotIndex = action.LastIndexOf(".");
			string serviceName = (dotIndex == -1) ? null : action.Substring(0, dotIndex);
            string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);

			if (notify is Invoke)
			{
				PendingCall call = new PendingCall(serviceName, serviceMethod, parameters);
                notify.ServiceCall = call;
			} 
			else 
			{
				Call call = new Call(serviceName, serviceMethod, parameters);
				notify.ServiceCall = call;
			}
			return notify;
		}