ConfigSaver Object




 

  ConfigSaver
 IncludeChildren

 SaveToFile
 Cancel

 PropertyErrorEvent
 PropertyErrorEventHandler
 PropertyStatusEvent
 PropertyStatusEventHandler

 

Visual Basic

Syntax

Class ConfigSaver

Sample Code

 
' Save the entire Controller configuration, including child objects.
'
' Handle PropertyStatus events in order to display progress 
' and exclude Can and CanNode objects from being saved.
'
' Handle PropertyError events in order to display errors.
Public Sub SaveController()
    Dim controller As Mpx.Controller = New Mpx.Controller(0)
    Dim saver As Mpx.ConfigSaver = New Mpx.ConfigSaver()

    ' Have the OnSavePropertyError method handle 
    ' PropertyError(events)
    AddHandler saver.PropertyErrorEvent, 
     AddressOf OnSavePropertyError

    ' Have the OnSavePropertyStatus method handle 
    ' PropertyStatus events
    AddHandler saver.PropertyStatusEvent, 
     AddressOf OnSavePropertyStatus

    Try
        saver.SaveToFile(controller, "controllerConfig.xml")
    Catch exc As System.Exception
        If Not (exc.InnerException Is Nothing) Then
            exc = exc.InnerException
        End If
        System.Console.WriteLine(exc.Message)
        System.Console.WriteLine(exc.StackTrace)
    End Try

End Sub


Sample Application

 

C#

Syntax

class ConfigSaver

Sample Code

 

// Save the entire Controller configuration, including child objects.
//
// Handle ConfigSavePropertyStatus events in order to display
// progress and exclude Can and CanNode objects from being saved.
//
// Handle PropertyError events in order to display errors.

public void SaveController()
{
   Mpx.Controller controller = new Mpx.Controller(0);
   Mpx.ConfigSaver saver = new Mpx.ConfigSaver();

   // Have the OnSavePropertyError method handle PropertyError events
   saver.PropertyErrorEvent += OnSavePropertyError;

   // Have the OnSavePropertyStatus method handle
   // ConfigSavePropertyStatus events

   saver.PropertyStatusEvent += OnSavePropertyStatus;

   saver.SaveToFile(controller, "controllerConfig.xml");
}

See Also

Serialization Overview | ConfigSaveErrorCode | ConfigSavePropertyErrorEventArgs | ConfigSavePropertyStatusEventArgs