From 845b302fc780d564d8234cb79a1d87ffa391b0f4 Mon Sep 17 00:00:00 2001 From: SatishRaj4377 <158574671+SatishRaj4377@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:17:50 +0530 Subject: [PATCH 1/3] WF-905069-UG_Update_For_DataContractSerializer_Support_Hotfix --- .../Serialization/Diagram-Serialization.md | 165 ++++++++++++++++++ .../Serialization/Palette-Serialization.md | 54 ++++++ 2 files changed, 219 insertions(+) create mode 100644 WindowsForms/Diagram/Serialization/Diagram-Serialization.md create mode 100644 WindowsForms/Diagram/Serialization/Palette-Serialization.md diff --git a/WindowsForms/Diagram/Serialization/Diagram-Serialization.md b/WindowsForms/Diagram/Serialization/Diagram-Serialization.md new file mode 100644 index 000000000..dd7848445 --- /dev/null +++ b/WindowsForms/Diagram/Serialization/Diagram-Serialization.md @@ -0,0 +1,165 @@ +--- +layout: post +title: Diagram Serialization in Windows Forms Diagram control | Syncfusion +description: Learn about Diagram Serialization support in Syncfusion Windows Forms Diagram control and more details. +platform: windowsforms +control: Diagram +documentation: ug +--- + +# Serialization in Windows Forms Diagram +Serialization is the process of converting the state of Diagram objects into a byte stream, allowing them to be recreated later when needed. These streams can be stored in a database, a file, or in memory. The reverse process is known as Deserialization. + +## Save +In the Diagram, [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The features provided by `DataContractSerializer` apply to Diagram serialization, supporting the saving of the diagram to a stream while preserving all its properties. + +### Saving Diagram via Filename + +{% tabs %} +{% highlight c# %} + +SaveFileDialog saveFileDialog = new SaveFileDialog(); +saveFileDialog.Filter = @"XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +if (saveFileDialog.ShowDialog(this) == DialogResult.OK) +{ + // Save Diagram via file path + diagram1.SaveXml(this.saveFileDialog.FileName); + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +### Saving Diagram via Stream + +{% tabs %} +{% highlight c# %} + +SaveFileDialog saveFileDialog = new SaveFileDialog(); +saveFileDialog.Filter = @"XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +if (saveFileDialog.ShowDialog(this) == DialogResult.OK) +{ + // Save Diagram via file stream + using (Stream stream = File.Open(saveFileDialog.FileName, FileMode.CreateNew)) + { + diagram1.SaveXml(stream); + } + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +## Load +On Deserialization, the saved stream is used to load the Diagram’s nodes and connectors into the current view. This allows you to continue working on the previously saved Diagram by loading the appropriate stream. + +### Loading Diagram from File Path +{% tabs %} +{% highlight c# %} + +OpenFileDialog openFileDialog = new OpenFileDialog(); +openFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +openFileDialog.DefaultExt = "*.xml"; +openFileDialog.Title = "Open Diagram"; +if (openFileDialog.ShowDialog(this) == DialogResult.OK) +{ + string filePath = openFileDialog.FileName; + + // Load Diagram from file path + diagram1.LoadXml(filePath); + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +### Loading Diagram from Stream +{% tabs %} +{% highlight c# %} + +OpenFileDialog openFileDialog = new OpenFileDialog(); +openFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +openFileDialog.DefaultExt = "*.xml"; +openFileDialog.Title = "Open Diagram"; +if (openFileDialog.ShowDialog(this) == DialogResult.OK) +{ + string filePath = openFileDialog.FileName; + + // Load Diagram from file stream + using (Stream myStream = openFileDialog.OpenFile()) + { + diagram1.LoadXml(myStream); + } + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +### Loading Diagram from file with Exception Handling +{% tabs %} +{% highlight c# %} + +OpenFileDialog openFileDialog = new OpenFileDialog(); +openFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +openFileDialog.DefaultExt = "*.xml"; +openFileDialog.Title = "Open Diagram"; +if (openFileDialog.ShowDialog(this) == DialogResult.OK) +{ + string filePath = openFileDialog.FileName; + + // Load Diagram from File with Exception Handling + diagram1.LoadXml(filePath, out Exception exception); + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +### Loading Diagram from Stream with Exception Handling +{% tabs %} +{% highlight c# %} + +OpenFileDialog openFileDialog = new OpenFileDialog(); +openFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +openFileDialog.DefaultExt = "*.xml"; +openFileDialog.Title = "Open Diagram"; +if (openFileDialog.ShowDialog(this) == DialogResult.OK) +{ + string filePath = openFileDialog.FileName; + + // Load Diagram from Stream with Exception Handling + using (Stream myStream = openFileDialog.OpenFile()) + { + diagram1.LoadXml(myStream, out Exception ex); + } + + this.diagram1.Refresh(); +} + +{% endhighlight %} +{% endtabs %} + +## Is the Diagram's Model Modified? +[Modified](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html#Syncfusion_Windows_Forms_Diagram_Model_Modified) property of the Diagram's [Model](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html) is a boolean that indicates whether the `Model` has been updated. It tracks all changes made to the `Model`, including the addition of nodes and other modifications to the Diagram elements. + +{% tabs %} +{% highlight c# %} +if (diagram1 != null && diagram1.Model.Modified) +{ + MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show( + "Do you want to save the Diagram?", + "SfDiagram", + MessageBoxButton.YesNo); + if (messageBoxResult == MessageBoxResult.Yes) + { + SaveDiagram(); + } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/WindowsForms/Diagram/Serialization/Palette-Serialization.md b/WindowsForms/Diagram/Serialization/Palette-Serialization.md new file mode 100644 index 000000000..b6cb978f2 --- /dev/null +++ b/WindowsForms/Diagram/Serialization/Palette-Serialization.md @@ -0,0 +1,54 @@ +--- +layout: post +title: Palette Serialization in Windows Forms Diagram control | Syncfusion +description: Learn about Palette Serialization support in Syncfusion Windows Forms Diagram control and more details. +platform: windowsforms +control: Diagram +documentation: ug +--- + +# Palette Serialization in Windows Forms Diagram + +Palette serialization allows users to save and load the state of the palette, including all its symbols and their properties, making it easier to persist the palette across sessions or share it between applications. + +### Saving Palette + +In a Palette, the [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The functionalities provided by `DataContractSerializer` are applicable to palette serialization. It supports saving the palette to an XML file, including all its symbols. The Palette's state is fully preserved during the serialization process. + +{% tabs %} +{% highlight c# %} + +SaveFileDialog saveFileDialog = new SaveFileDialog(); +saveFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +if (saveFileDialog.ShowDialog(this) == DialogResult.OK) +{ + SymbolPalette currentSymbolPalette = paletteGroupBar1.CurrentSymbolPalette; + string strSavePath = saveFileDialog.FileName; + if (currentSymbolPalette != null) + { + currentSymbolPalette.SavePalette(strSavePath); + } +} + +{% endhighlight %} +{% endtabs %} + + +### Loading Palettes Using DataContractSerializer + +Loading a palette from an XML file involves deserializing the XML data back into the palette object, ensuring all symbols and their properties are restored accurately. + +{% tabs %} +{% highlight c# %} + +OpenFileDialog openFileDialog = new OpenFileDialog(); +openFileDialog.Filter = "XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; +if (openFileDialog.ShowDialog(this) == DialogResult.OK) +{ + string strFileName = openFileDialog.FileName; + paletteGroupBar1.LoadPalette(strFileName); +} + +{% endhighlight %} +{% endtabs %} + From af2659cac58f5b7e7fc9467072260c95f9212e2c Mon Sep 17 00:00:00 2001 From: Prakash Perumal <63277969+prakashperumal1892@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:22:10 +0530 Subject: [PATCH 2/3] WF-905069: Updated UG content --- .../Serialization/Diagram-Serialization.md | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/WindowsForms/Diagram/Serialization/Diagram-Serialization.md b/WindowsForms/Diagram/Serialization/Diagram-Serialization.md index dd7848445..542fe0a42 100644 --- a/WindowsForms/Diagram/Serialization/Diagram-Serialization.md +++ b/WindowsForms/Diagram/Serialization/Diagram-Serialization.md @@ -8,12 +8,14 @@ documentation: ug --- # Serialization in Windows Forms Diagram -Serialization is the process of converting the state of Diagram objects into a byte stream, allowing them to be recreated later when needed. These streams can be stored in a database, a file, or in memory. The reverse process is known as Deserialization. + +Serialization is the process of converting the state of diagram objects into a byte stream, allowing them to be recreated later. These streams can be stored in a database, a file, or memory. The reverse process is known as deserialization. ## Save -In the Diagram, [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The features provided by `DataContractSerializer` apply to Diagram serialization, supporting the saving of the diagram to a stream while preserving all its properties. -### Saving Diagram via Filename +In the diagram, [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The features provided by `DataContractSerializer` apply to diagram serialization, supporting saving the diagram to a stream while preserving all its properties. + +### Saving a Diagram via Filename {% tabs %} {% highlight c# %} @@ -22,7 +24,7 @@ SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = @"XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { - // Save Diagram via file path + // Save the diagram to a file path diagram1.SaveXml(this.saveFileDialog.FileName); this.diagram1.Refresh(); @@ -31,7 +33,7 @@ if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -### Saving Diagram via Stream +### Saving a Diagram via Stream {% tabs %} {% highlight c# %} @@ -40,7 +42,7 @@ SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = @"XML Diagram (*.xml)|*.xml|All files (*.*)|*.*"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { - // Save Diagram via file stream + // Save the diagram to a file stream using (Stream stream = File.Open(saveFileDialog.FileName, FileMode.CreateNew)) { diagram1.SaveXml(stream); @@ -53,9 +55,11 @@ if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {% endtabs %} ## Load -On Deserialization, the saved stream is used to load the Diagram’s nodes and connectors into the current view. This allows you to continue working on the previously saved Diagram by loading the appropriate stream. -### Loading Diagram from File Path +Deserialization uses the saved stream to load the diagram's nodes and connectors into the current view. This allows you to continue working on the previously saved diagram by loading the appropriate stream. + +### Loading a Diagram from a File Path + {% tabs %} {% highlight c# %} @@ -67,7 +71,7 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string filePath = openFileDialog.FileName; - // Load Diagram from file path + // Load the diagram from the file path diagram1.LoadXml(filePath); this.diagram1.Refresh(); @@ -76,7 +80,8 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -### Loading Diagram from Stream +### Loading a Diagram from a Stream + {% tabs %} {% highlight c# %} @@ -88,7 +93,7 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string filePath = openFileDialog.FileName; - // Load Diagram from file stream + // Load the diagram from a file stream using (Stream myStream = openFileDialog.OpenFile()) { diagram1.LoadXml(myStream); @@ -100,7 +105,8 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -### Loading Diagram from file with Exception Handling +### Loading a Diagram from a File with Exception Handling + {% tabs %} {% highlight c# %} @@ -112,7 +118,7 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string filePath = openFileDialog.FileName; - // Load Diagram from File with Exception Handling + // Load the diagram from the file path with exception handling diagram1.LoadXml(filePath, out Exception exception); this.diagram1.Refresh(); @@ -121,7 +127,8 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -### Loading Diagram from Stream with Exception Handling +### Loading a Diagram from a Stream with Exception Handling + {% tabs %} {% highlight c# %} @@ -133,7 +140,7 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string filePath = openFileDialog.FileName; - // Load Diagram from Stream with Exception Handling + // Load the diagram from the stream with exception handling using (Stream myStream = openFileDialog.OpenFile()) { diagram1.LoadXml(myStream, out Exception ex); @@ -145,8 +152,9 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -## Is the Diagram's Model Modified? -[Modified](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html#Syncfusion_Windows_Forms_Diagram_Model_Modified) property of the Diagram's [Model](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html) is a boolean that indicates whether the `Model` has been updated. It tracks all changes made to the `Model`, including the addition of nodes and other modifications to the Diagram elements. +## Checking if the Diagram's Model is Modified + +The [Modified](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html#Syncfusion_Windows_Forms_Diagram_Model_Modified) property of the Diagram's [Model](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Diagram.Model.html) is a boolean value indicating whether the diagram has any unsaved changes. It tracks all changes made to the diagram, including node additions and other modifications to the diagram elements. {% tabs %} {% highlight c# %} @@ -162,4 +170,4 @@ if (diagram1 != null && diagram1.Model.Modified) } } {% endhighlight %} -{% endtabs %} \ No newline at end of file +{% endtabs %} From 7c5c4231b775e2c71442419740f82c2cfaf6480e Mon Sep 17 00:00:00 2001 From: Prakash Perumal <63277969+prakashperumal1892@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:23:03 +0530 Subject: [PATCH 3/3] WF-905069: Updated UG content --- .../Diagram/Serialization/Palette-Serialization.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/WindowsForms/Diagram/Serialization/Palette-Serialization.md b/WindowsForms/Diagram/Serialization/Palette-Serialization.md index b6cb978f2..e2c5ffa94 100644 --- a/WindowsForms/Diagram/Serialization/Palette-Serialization.md +++ b/WindowsForms/Diagram/Serialization/Palette-Serialization.md @@ -9,11 +9,11 @@ documentation: ug # Palette Serialization in Windows Forms Diagram -Palette serialization allows users to save and load the state of the palette, including all its symbols and their properties, making it easier to persist the palette across sessions or share it between applications. +Palette serialization allows users to save and load the state of a palette, including all its symbols and their properties. This makes it easier to persist the palette across sessions or share it between applications. -### Saving Palette +### Saving a Palette -In a Palette, the [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The functionalities provided by `DataContractSerializer` are applicable to palette serialization. It supports saving the palette to an XML file, including all its symbols. The Palette's state is fully preserved during the serialization process. +In a palette, the [DataContractSerializer](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=net-8.0) is used for serialization. The functionalities provided by `DataContractSerializer` apply to palette serialization, supporting saving the palette to an XML file while preserving all symbols. The palette's state is fully maintained during serialization. {% tabs %} {% highlight c# %} @@ -36,7 +36,7 @@ if (saveFileDialog.ShowDialog(this) == DialogResult.OK) ### Loading Palettes Using DataContractSerializer -Loading a palette from an XML file involves deserializing the XML data back into the palette object, ensuring all symbols and their properties are restored accurately. +Loading a palette from an XML file involves deserializing the XML data back into a palette object, ensuring that all symbols and their properties are accurately restored. {% tabs %} {% highlight c# %} @@ -51,4 +51,3 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) {% endhighlight %} {% endtabs %} -