/// <summary> /// Reads the config from a file /// </summary> /// <param name="filename">file to read from</param> /// <param name="role">The role of the configured element.</param> /// <returns>Config object read</returns> public static GConnectionDialogFormConfig Read(string filename, AlchemiRole role) { string file = Utils.GetFilePath(filename, role, false); GConnectionDialogFormConfig c; //handle missing file exception / serialization exception etc... and create a default config. try { //open for read-only using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (fs.Length > 0) { BinaryFormatter bf = new BinaryFormatter(); c = (GConnectionDialogFormConfig)bf.Deserialize(fs); } else { c = new GConnectionDialogFormConfig(file); } } c.EndPointConfig = Alchemi.Core.EndPointUtils.EndPointConfiguration.GetConfiguration(role); } catch (Exception ex) { logger.Debug("Error reading config from " + file + ", getting default config.", ex); c = new GConnectionDialogFormConfig(file); } return(c); }
/// <summary> /// Reads the config from a file /// </summary> /// <param name="filename">file to read from</param> /// <param name="role">The role of the configured element.</param> /// <returns>Config object read</returns> public static GConnectionDialogFormConfig Read(string filename, AlchemiRole role) { string file = Utils.GetFilePath(filename, role, false); GConnectionDialogFormConfig c; //handle missing file exception / serialization exception etc... and create a default config. try { //open for read-only using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (fs.Length > 0) { BinaryFormatter bf = new BinaryFormatter(); c = (GConnectionDialogFormConfig)bf.Deserialize(fs); } else { c = new GConnectionDialogFormConfig(file); } } c.EndPointConfig = Alchemi.Core.EndPointUtils.EndPointConfiguration.GetConfiguration(role); } catch (Exception ex) { logger.Debug("Error reading config from " + file + ", getting default config.", ex); c = new GConnectionDialogFormConfig(file); } return c; }