/// <summary> /// Saves the current DXConfiguration /// </summary> private void SaveDXConfiguration() { Stream stream = null; try { Cursor = Cursors.WaitCursor; string configFile = m_server.ServerName + ".dxconfig"; // create the configuartion file. stream = new FileStream(configFile, FileMode.Create, FileAccess.Write, FileShare.None); // populate the user settings object. DXConfiguration configuration = new DXConfiguration(); configuration.Target = m_target; // serialize the user settings object. new BinaryFormatter().Serialize(stream, configuration); } catch { // ignore errors. } finally { // close the stream. if (stream != null) { stream.Close(); } Cursor = Cursors.Default; } }
/// <summary> /// Loads the configuration for the current server. /// </summary> private bool LoadDXConfiguration() { Stream stream = null; try { Cursor = Cursors.WaitCursor; string configFile = m_server.ServerName + ".dxconfig"; // open configuration file. stream = new FileStream(configFile, FileMode.Open, FileAccess.Read, FileShare.Read); // deserialize the server object. DXConfiguration configuration = (DXConfiguration) new BinaryFormatter().Deserialize(stream); // overrided the current settings. if (configuration != null) { configuration.Target.Connect(); m_target = configuration.Target; SelectTargetCTRL.Initialize(new OpcUrl[] { m_target.Url }, 0, OpcSpecification.OPC_DA_30); } // load succeeded. return(true); } catch (Exception) { // ignore errors. return(false); } finally { // close the stream. if (stream != null) { stream.Close(); } Cursor = Cursors.Default; } }