Skip to main content

ferroui_remote_protocol/
design_messages.rs

1use crate::{bson_class, ferro_remote_message_guid};
2
3#[derive(Clone, Debug, Default, PartialEq)]
4pub struct UpdateXamlMessage {
5    pub xaml: Option<String>,
6    pub assembly_path: Option<String>,
7    pub xaml_file_project_path: Option<String>,
8}
9
10ferro_remote_message_guid!(UpdateXamlMessage, "9AEC9A2E-6315-4066-B4BA-E9A9EFD0F8CC");
11bson_class!(UpdateXamlMessage as "UpdateXamlMessage" {
12    "Xaml" => xaml: Option<String>,
13    "AssemblyPath" => assembly_path: Option<String>,
14    "XamlFileProjectPath" => xaml_file_project_path: Option<String>,
15});
16
17#[derive(Clone, Debug, Default, PartialEq)]
18pub struct UpdateXamlResultMessage {
19    pub error: Option<String>,
20    pub handle: Option<String>,
21    pub exception: Option<ExceptionDetails>,
22}
23
24ferro_remote_message_guid!(UpdateXamlResultMessage, "B7A70093-0C5D-47FD-9261-22086D43A2E2");
25bson_class!(UpdateXamlResultMessage as "UpdateXamlResultMessage" {
26    "Error" => error: Option<String>,
27    "Handle" => handle: Option<String>,
28    "Exception" => exception: Option<ExceptionDetails>,
29});
30
31#[derive(Clone, Debug, Default, PartialEq)]
32pub struct StartDesignerSessionMessage {
33    pub session_id: Option<String>,
34}
35
36ferro_remote_message_guid!(StartDesignerSessionMessage, "854887CF-2694-4EB6-B499-7461B6FB96C7");
37bson_class!(StartDesignerSessionMessage as "StartDesignerSessionMessage" {
38    "SessionId" => session_id: Option<String>,
39});
40
41#[derive(Clone, Debug, Default, PartialEq)]
42pub struct ExceptionDetails {
43    pub exception_type: Option<String>,
44    pub message: Option<String>,
45    pub line_number: Option<i32>,
46    pub line_position: Option<i32>,
47}
48
49impl ExceptionDetails {
50    /// `new ExceptionDetails()`.
51    pub fn new() -> ExceptionDetails {
52        ExceptionDetails::default()
53    }
54
55    /// `new ExceptionDetails(Exception e)`.
56    ///
57    /// Deviation (DEVIATIONS.md, Remote protocol): the original reads the
58    /// name of the class of the exception by reflection, unwraps a
59    /// `TargetInvocationException` and takes the line and the position from
60    /// an `XmlException`. An error of Rust has no class name to read and this
61    /// library does not know the error types of the markup crates, so the
62    /// caller states the three: the name of the error type, the error (its
63    /// text is the message) and, for an error of a document, its line and
64    /// position.
65    pub fn from_exception(
66        exception_type: &str,
67        e: &dyn std::error::Error,
68        line_info: Option<(i32, i32)>,
69    ) -> ExceptionDetails {
70        ExceptionDetails {
71            exception_type: Some(exception_type.to_string()),
72            message: Some(e.to_string()),
73            line_number: line_info.map(|(line_number, _)| line_number),
74            line_position: line_info.map(|(_, line_position)| line_position),
75        }
76    }
77}
78
79bson_class!(ExceptionDetails as "ExceptionDetails" {
80    "ExceptionType" => exception_type: Option<String>,
81    "Message" => message: Option<String>,
82    "LineNumber" => line_number: Option<i32>,
83    "LinePosition" => line_position: Option<i32>,
84});