protected async Task Send(string action, string targetComponent)
        {
            JsonObject data = new JsonObject();

            data.AddValue(nameof(FixedNames.Action), action);
            data.AddValue(nameof(FixedNames.Sender), this.controllerName);
            data.AddValue(nameof(FixedNames.Target), targetComponent);
            await SendRaw(data).ConfigureAwait(false);
        }
Example #2
0
            public JsonValue Serialize(object obj, JsonMapper mapper)
            {
                CustomClass2 data = obj as CustomClass2;

                JsonObject result = new JsonObject();

                result.AddValue("ID", new JsonValue(data.ID));
                result.AddValue("Age", new JsonValue(data.Age));
                return(result);
            }
 public async Task Send(ControllerBase sender, JsonObject data)
 {
     data.AddValue(nameof(FixedNames.Sender), sender.controllerName);
     data.AddValue(nameof(FixedNames.Target), sender.targetComponentName);
     OnJsonDataSend?.Invoke(sender, data);
     if (socketClient.ConnectionStatus == ConnectionStatus.Connected)
     {
         await socketClient.Send(Guid.Empty, data).ConfigureAwait(false);
     }
 }
Example #4
0
 private async void GripperSlider_Moved(object sender, Controls.SliderEventArgs e)
 {
     if (ControllerHandler.ConnectionStatus == ConnectionStatus.Connected)
     {
         JsonObject command = new JsonObject();
         command.AddValue("Target", "Gripper");
         command.AddValue("Action", "Set");
         command.AddValue("Position", Map(-100, 100, 0, 100, e.Distance));
         await landingPageController.SendRequest(command, true);
     }
 }
        public async Task SetCaptureFormat(ImageFormat imageFormat)
        {
            JsonObject imageFormatJson = new JsonObject();

            imageFormatJson.AddValue("Action", "SetCurrentFormat");
            imageFormatJson.AddValue("SubType", imageFormat.Format);
            imageFormatJson.AddValue("Width", imageFormat.Width);
            imageFormatJson.AddValue("Height", imageFormat.Height);
            imageFormatJson.AddValue("BitRate", imageFormat.JsonFormat.GetNamedNumber("Bitrate"));

            await Send(imageFormatJson).ConfigureAwait(false);

            currentImageFormat = imageFormat;
        }
        public async Task RequestCurrentFormat()
        {
            JsonObject imageCapture = new JsonObject();

            imageCapture.AddValue("Action", "GetCurrentFormat");
            await Send(imageCapture).ConfigureAwait(false);
        }
        public async Task CaptureDeviceImage()
        {
            JsonObject imageCapture = new JsonObject();

            imageCapture.AddValue("Action", "Capture");
            await Send(imageCapture).ConfigureAwait(false);
        }
        public async Task RequestSupportedFormats(string type = null, string subType = null)
        {
            JsonObject imageCapture = new JsonObject();

            imageCapture.AddValue("Action", "ListFormats");
            if (!string.IsNullOrEmpty(type))
            {
                imageCapture.AddValue("Type", type);
            }
            if (!string.IsNullOrEmpty(subType))
            {
                imageCapture.AddValue("SubType", subType);
            }

            await Send(imageCapture).ConfigureAwait(false);
        }
Example #9
0
        public void WriteJsonValue()
        {
            string     expectedBody = "{\"ID\":1,\"Age\":31}";
            JsonObject body         = new JsonObject();

            body.AddValue("ID", new JsonValue(1));
            body.AddValue("Age", new JsonValue(31));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public async Task CaptureDeviceImage()
        {
            JsonObject imageCapture = new JsonObject();

            imageCapture.AddValue("Action", "Capture");
            await ControllerHandler.Send(this, imageCapture).ConfigureAwait(false);
        }
        public JsonValue Serialize(object obj, JsonMapper mapper)
        {
            Invitation invitation = (Invitation)obj;

            JsonObject result = new JsonObject();

            result.AddValue("subject", new JsonValue(invitation.Subject));
            result.AddValue("body", new JsonValue(invitation.Body));

            JsonObject recipients = new JsonObject();
            JsonArray  people     = new JsonArray();
            JsonObject person     = new JsonObject();

            if (invitation.Recipient.ID != null)
            {
                person.AddValue("_path", new JsonValue("/people/" + invitation.Recipient.ID));
            }
            else
            {
                person.AddValue("_path", new JsonValue("/people/email=" + invitation.Recipient.Email));
                person.AddValue("first-name", new JsonValue(invitation.Recipient.FirstName));
                person.AddValue("last-name", new JsonValue(invitation.Recipient.LastName));
            }
            JsonObject personValue = new JsonObject();

            personValue.AddValue("person", person);
            people.AddValue(personValue);
            recipients.AddValue("values", people);
            result.AddValue("recipients", recipients);

            JsonObject itemContent = new JsonObject();
            JsonObject request     = new JsonObject();

            request.AddValue("connect-type", new JsonValue("friend"));
            if (invitation.Recipient.AuthToken != null)
            {
                string[]   authToken     = invitation.Recipient.AuthToken.Split(':');
                JsonObject authorization = new JsonObject();
                authorization.AddValue("name", new JsonValue(authToken[0]));
                authorization.AddValue("value", new JsonValue(authToken[1]));
                request.AddValue("authorization", authorization);
            }
            itemContent.AddValue("invitation-request", request);
            result.AddValue("item-content", itemContent);

            return(result);
        }
        public async Task Send(ControllerBase sender, string action)
        {
            JsonObject data = new JsonObject();

            data.AddValue(nameof(FixedNames.Action), action);

            await Send(sender, data).ConfigureAwait(false);
        }
 public async Task Send(string sender, JsonObject data)
 {
     data.AddValue(nameof(FixedNames.Sender), sender);
     OnJsonDataSend?.Invoke(sender, data);
     if (socketClient.ConnectionStatus == ConnectionStatus.Connected)
     {
         await socketClient.Send(Guid.Empty, data).ConfigureAwait(false);
     }
 }
        public void PostJsonValueForMessage()
        {
            template.MessageConverters.Add(new SpringJsonHttpMessageConverter());

            JsonObject user = new JsonObject();

            user.AddValue("Name", new JsonValue("Lisa Baia"));

            HttpResponseMessage result = template.PostForMessage("user", user);

            Assert.AreEqual(new Uri(new Uri(uri), "/user/3"), result.Headers.Location, "Invalid location");
            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode, "Invalid status code");
            Assert.AreEqual("User id '3' created with 'Lisa Baia'", result.StatusDescription, "Invalid status description");
        }
        public JsonValue Serialize(object obj, JsonMapper mapper)
        {
            Message message = (Message)obj;

            JsonObject result = new JsonObject();
            result.AddValue("subject", new JsonValue(message.Subject));
            result.AddValue("body", new JsonValue(message.Body));

            JsonObject recipients = new JsonObject();
            JsonArray people = new JsonArray();
            foreach (string id in message.RecipientIds)
            {
                JsonObject person = new JsonObject();
                person.AddValue("_path", new JsonValue("/people/" + id));

                JsonObject personValue = new JsonObject();
                personValue.AddValue("person", person);
                people.AddValue(personValue);
            }
            recipients.AddValue("values", people);
            result.AddValue("recipients", recipients);

            return result;
        }
Example #16
0
 public void AddValue(string name, object value)
 {
     dataObject.AddValue(name, value);
 }
Example #17
0
        private JsonObject MediaPropertiesToJson(IMediaEncodingProperties mediaProperties)
        {
            JsonObject properties = new JsonObject();

            if (mediaProperties is VideoEncodingProperties)
            {
                VideoEncodingProperties videoProperties = mediaProperties as VideoEncodingProperties;
                properties.AddValue(nameof(videoProperties.Bitrate), videoProperties.Bitrate);
                properties.AddValue(nameof(videoProperties.FrameRate), $"{videoProperties.FrameRate.Denominator}/{videoProperties.FrameRate.Numerator}");
                properties.AddValue(nameof(videoProperties.Height), videoProperties.Height);
                properties.AddValue(nameof(videoProperties.ProfileId), videoProperties.ProfileId);
                properties.AddValue(nameof(videoProperties.PixelAspectRatio), $"{videoProperties.PixelAspectRatio.Denominator}:{videoProperties.PixelAspectRatio.Numerator}");
                properties.AddValue(nameof(videoProperties.Subtype), videoProperties.Subtype);
                properties.AddValue(nameof(videoProperties.Type), videoProperties.Type);
                properties.AddValue(nameof(videoProperties.Width), videoProperties.Width);
            }
            else if (mediaProperties is ImageEncodingProperties)
            {
                ImageEncodingProperties imageProperties = mediaProperties as ImageEncodingProperties;
                properties.AddValue(nameof(imageProperties.Height), imageProperties.Height);
                properties.AddValue(nameof(imageProperties.Subtype), imageProperties.Subtype);
                properties.AddValue(nameof(imageProperties.Type), imageProperties.Type);
                properties.AddValue(nameof(imageProperties.Width), imageProperties.Width);
            }
            return(properties);
        }
 protected async Task Send(JsonObject data)
 {
     data.AddValue(nameof(FixedNames.Sender), this.controllerName);
     data.AddValue(nameof(FixedNames.Target), this.targetComponentName);
     await SendRaw(data).ConfigureAwait(false);
 }