Beispiel #1
0
 void clientPipes_DataReceived(object sender, PipeEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived.Invoke(sender, e.String);
     }
 }
 private void ReceiveObject(PipeEventArgs args)
 {
     Console.WriteLine("Recived data.");
     try
     {
         MyDataModel deserializedObject;
         using (MemoryStream stream = new MemoryStream(args.Data))
         {
             deserializedObject = Serializer.Deserialize <MyDataModel>(stream);
         }
         Console.WriteLine("Object successfuly received.");
         Console.WriteLine(string.Format("Deserialized object's field value equals: {0}", deserializedObject.test));
         Console.WriteLine(string.Format("Object is now incremented to {0} " +
                                         "and is sent back to server.", ++deserializedObject.test));
         using (MemoryStream stream = new MemoryStream())
         {
             Serializer.Serialize(stream, deserializedObject);
             _clientPipe.WriteBytes(stream.ToArray());
         }
     }
     catch (Exception ex)
     {
         Console.Write(string.Format("Exeption occured: {0}", ex.Message));
     }
 }
Beispiel #3
0
        public static void AppMessageRecieveHandler(object sender, PipeEventArgs arguments)
        {
            string messageFromServer = arguments.String;

            if (!string.IsNullOrEmpty(messageFromServer))
            {
                Host.SendMessage(JsonConvert.DeserializeObject <JObject>(messageFromServer));
            }
        }
Beispiel #4
0
        public void Ctor_WithByteArrayArgument_HasByteData()
        {
            // Arrange
            string seedString = "Hello World!";

            byte[] expected = System.Text.Encoding.UTF8.GetBytes(seedString);
            int    len      = expected.Length;

            // Act
            var args = new PipeEventArgs(expected);

            // Assert
            CollectionAssert.AreEqual(expected, args.Data);
            Assert.AreEqual("byte[12]", args.ToString());
            Assert.AreEqual(len, args.Length);
        }
        private void onDataRead(object sender, PipeEventArgs e)
        {
            var     jsonSerializedPipeCommand = Encoding.UTF8.GetString(e.Data);
            var     pipeCommand      = JsonConvert.DeserializeObject <PipeCommand>(jsonSerializedPipeCommand);
            dynamic parsedParameters = JsonConvert.DeserializeObject(pipeCommand.CommandParameters.ToString());

            if (pipeCommand.CommandType == PipeCommandTypes.InvalidRequest)
            {
                var invalidRequestParameters = JsonConvert.DeserializeObject <InvalidRequestParameters>(pipeCommand.CommandParameters.ToString());
                processCommandResponse(invalidRequestParameters.OriginalRequest.CommandType, invalidRequestParameters.Convert());
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.RequestAccepted)
            {
                var requestAcceptedParameters = JsonConvert.DeserializeObject <RequestAcceptedParameters>(pipeCommand.CommandParameters.ToString());
                processCommandResponse(requestAcceptedParameters.CommandType, requestAcceptedParameters.Convert());
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.RequestRefused)
            {
                var requestRefusedParameters = JsonConvert.DeserializeObject <RequestRefusedParameters>(pipeCommand.CommandParameters.ToString());
                processCommandResponse(requestRefusedParameters.CommandType, requestRefusedParameters.Convert());
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.NegotiationResponse)
            {
                negotiationResponse = JsonConvert.DeserializeObject <NegotiationResponseParameters>(pipeCommand.CommandParameters.ToString());
                negotiationResponseReceived.Set();
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.ContentUpdateRequestFromMQ)
            {
                var contentUpdateRequest = JsonConvert.DeserializeObject <ContentUpdateRequestFromMQParameters>(pipeCommand.CommandParameters.ToString()).Convert();
                CallbackHandler.QueueContentUpdateRequest(contentUpdateRequest);
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.ChangeHighlightRequestFromMQ)
            {
                var changeHighlightRequest = JsonConvert.DeserializeObject <ChangeHighlightRequestFromMQParameters>(pipeCommand.CommandParameters.ToString()).Convert();
                CallbackHandler.QueueChangeHighlightRequest(changeHighlightRequest);
            }
            else if (pipeCommand.CommandType == PipeCommandTypes.PreviewPartIdUpdateRequestFromMQ)
            {
                var previewPartIdUpdateRequest = JsonConvert.DeserializeObject <PreviewPartIdUpdateRequestFromMQParameters>(pipeCommand.CommandParameters.ToString()).Convert();
                CallbackHandler.QueuePreviewPartIdUpdateRequest(previewPartIdUpdateRequest);
            }
        }
 internal void DataReceived(PipeEventArgs args)
 {
     _args = args;
     ev.Raise();
 }
Beispiel #7
0
        public void DataRecievedHandler(ServerPipe serverPipe, PipeEventArgs arguments)
        {
            var         commandJsonString = arguments.String;
            BaseCommand baseCommand       = JsonConvert.DeserializeObject <BaseCommand>(commandJsonString);

            if (baseCommand == null)
            {
                return;
            }
            switch (baseCommand.Command)
            {
            case ZC_Command.CONFIRM_CONNECT_HOST:
            {
                ConfirmConnectedHost response = JsonConvert.DeserializeObject <ConfirmConnectedHost>(commandJsonString);
                if (response != null && response.IsSuccess)
                {
                    Profile selectedObject = profile;

                    List <string> ByPassListPattern = selectedObject.ByPassProxySites.Select(p =>
                        {
                            return($"*{p}*");
                        }).ToList();


                    SetProfileRequest request = new SetProfileRequest()
                    {
                        Command = ZC_Command.SET_PROFILE_REQUEST,
                        Profile = new BrowserProfile()
                        {
                            Id                  = selectedObject.Id,
                            Email               = selectedObject.Email,
                            CPU                 = selectedObject.CPU,
                            Battery             = selectedObject.Battery,
                            EnableAudioApi      = selectedObject.EnableAudioApi,
                            EnablePlugins       = selectedObject.EnablePlugins,
                            EnableMediaPlugins  = selectedObject.EnableMediaPlugins,
                            Fonts               = selectedObject.Fonts,
                            RandomTimersEnabled = selectedObject.RandomTimersEnabled,
                            UserAgent           = selectedObject.UserAgent,
                            Screen              = selectedObject.Screen,
                            HistoryLength       = selectedObject.HistoryLength,
                            WebGL               = selectedObject.WebGL,
                            FakeClientRects     = true,
                            Canvas              = selectedObject.Canvas,
                            EnableNetwork       = selectedObject.EnableNetwork,
                            Language            = selectedObject.Language,
                            GeoIpEnabled        = selectedObject.GeoIpEnabled,
                            ProxyEnabled        = selectedObject.ProxyEnabled,
                            Proxies             = selectedObject.Proxies.Where(p => p.Enabled).ToList(),
                            ByPassProxySites    = ByPassListPattern,
                        }
                    };

                    serverPipe.WriteString(JsonConvert.SerializeObject(request));
                }
                break;
            }

            case ZC_Command.NOTIFICATION:
            {
                Notification response = JsonConvert.DeserializeObject <Notification>(commandJsonString);
                if (response != null && response.IsSuccess)
                {
                    Notification request = new Notification()
                    {
                        Type      = NotificationType.INFOR,
                        IsSuccess = true,
                        Message   = "Hello from zchanger application"
                    };

                    serverPipe.WriteString(JsonConvert.SerializeObject(request));
                }
                break;
            }

            case ZC_Command.DISCONNECT:
            {
                DissposeHostConnection(serverPipe.Id);
                break;
            }
            }
        }
Beispiel #8
0
        protected void OnDataReceived(object sender, PipeEventArgs e)
        {
            var ms = new MemoryStream(e.Data);

            OnMessage?.Invoke(Deserialize(ms));
        }