From d468089d3d013b5994832e8b168f005fe0936f32 Mon Sep 17 00:00:00 2001 From: Ash Beitz <8304894+ashbeitz@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:21:25 -0800 Subject: [PATCH] Improved seat massager sample --- .../src/dtdl-validator/DtdlValidator.cs | 8 +------- .../ModelsRepositoryClientExtensions.cs | 2 +- samples/seat_massager/common/src/lib.rs | 9 ++++----- .../provider/src/request_impl.rs | 20 ++++++++++--------- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/dtdl-tools/src/dtdl-validator/DtdlValidator.cs b/dtdl-tools/src/dtdl-validator/DtdlValidator.cs index 36913fa0..afcba2f4 100644 --- a/dtdl-tools/src/dtdl-validator/DtdlValidator.cs +++ b/dtdl-tools/src/dtdl-validator/DtdlValidator.cs @@ -37,7 +37,7 @@ static string ConvertToDTMI(string dtdlFilePath, string dtdlDirPath, string exte // Strip off the directory path and the extension. string dtmiPath = dtdlFilePath.Substring(dtdlDirPath.Length + 1, dtdlFilePath.Length - dtdlDirPath.Length - extension.Length - 2); // Replace each directory separator with a colon and the hyphen with a semicolon. - string dtmi = dtmiPath.Replace('/', ':').Replace('-', ';'); + string dtmi = dtmiPath.Replace(Path.DirectorySeparatorChar, ':').Replace('-', ';'); return dtmi; } @@ -92,12 +92,6 @@ static int ValidateDtdl(DirectoryInfo dtdlDirectory, String extension) } failureOccured = true; } - catch (ResolutionException ex) - { - Console.WriteLine($"{file} - failed"); - Console.WriteLine($" {ex.ToString()}"); - failureOccured = true; - } catch (Exception ex) { Console.WriteLine($"{file} - failed"); diff --git a/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs b/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs index 03a195ac..118f0e47 100644 --- a/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs +++ b/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs @@ -14,7 +14,7 @@ internal static class ModelsRepositoryClientExtensions /// /// The models repository client. /// - /// The cancellation topken. + /// The cancellation token. /// The model definitions for the provided DTMIs. public static async IAsyncEnumerable ParserDtmiResolverAsync( this ModelsRepositoryClient modelRepoClient, IReadOnlyCollection dtmis, diff --git a/samples/seat_massager/common/src/lib.rs b/samples/seat_massager/common/src/lib.rs index a749f979..0834e09b 100644 --- a/samples/seat_massager/common/src/lib.rs +++ b/samples/seat_massager/common/src/lib.rs @@ -6,11 +6,11 @@ use serde_derive::{Deserialize, Serialize}; /// A targeted payload. /// The targeting details helps on the receiver's side to dispatch the request. -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct TargetedPayload { /// The instance id for the target entity. pub instance_id: String, - /// The path within the target enttity to member that we are targetting. + /// The path within the target entity to member that we are targeting. pub member_path: String, /// The operation to be performed on the target entity's member. pub operation: String, @@ -18,11 +18,10 @@ pub struct TargetedPayload { pub payload: String, } - -/// Status codes and messages. +/// Status codes and messages. pub mod status { pub mod ok { pub const CODE: i32 = 200; pub const MESSAGE: &str = "Ok"; } -} \ No newline at end of file +} diff --git a/samples/seat_massager/provider/src/request_impl.rs b/samples/seat_massager/provider/src/request_impl.rs index fdf22be4..9e7e112d 100644 --- a/samples/seat_massager/provider/src/request_impl.rs +++ b/samples/seat_massager/provider/src/request_impl.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT use digital_twin_model::sdv_v2 as sdv; -use log::{debug, info, warn}; +use log::{debug, error, info, warn}; use parking_lot::Mutex; use samples_protobuf_data_access::async_rpc::v1::request::{ request_server::Request, AskRequest, AskResponse, NotifyRequest, NotifyResponse, @@ -41,14 +41,15 @@ impl Request for RequestImpl { info!("respond_uri: {respond_uri}"); info!("ask_id: {ask_id}"); - let targetted_payload_json: TargetedPayload = serde_json::from_str(&payload).unwrap(); - info!("instance_id: {}", targetted_payload_json.instance_id); - info!("member_path: {}", targetted_payload_json.member_path); - info!("operation: {}", targetted_payload_json.operation); - info!("inner payload: {}", targetted_payload_json.payload); + let targeted_payload_json: TargetedPayload = serde_json::from_str(&payload).unwrap(); + + info!("instance_id: {}", targeted_payload_json.instance_id); + info!("member_path: {}", targeted_payload_json.member_path); + info!("operation: {}", targeted_payload_json.operation); + info!("inner payload: {}", targeted_payload_json.payload); let request_payload_json: serde_json::Value = - serde_json::from_str(&targetted_payload_json.payload) + serde_json::from_str(&targeted_payload_json.payload) .map_err(|error| tonic::Status::invalid_argument(error.to_string()))?; let type_id_json: serde_json::Value = request_payload_json.get("@type").unwrap().clone(); @@ -63,7 +64,7 @@ impl Request for RequestImpl { tokio::spawn(async move { let client_result = RespondClient::connect(respond_uri).await; if let Err(error_message) = client_result { - warn!("Unable to connect due to {error_message}"); + error!("Unable to connect due to {error_message}"); return; } let mut client = client_result.unwrap(); @@ -84,7 +85,8 @@ impl Request for RequestImpl { tonic::Request::new(AnswerRequest { ask_id, payload: response_payload_json }); let response = client.answer(answer_request).await; if let Err(status) = response { - warn!("Answer failed: {status:?}"); + error!("Answer failed: {status:?}"); + return; } });