/// <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> /// Returns the configuration read from the xml file: "Alchemi.Manager.config.xml" /// </summary> /// <param name="aRole">For what alchemi node is the EndPointConfiguration beeing used.</param> /// <param name="configFileName">What is the name of the config file.</param> /// <returns>Configuration object</returns> public static EndPointConfiguration GetConfiguration(AlchemiRole aRole, string configFileName) { string configFile = Utils.GetFilePath(configFileName, aRole, true); EndPointConfiguration temp = DeSlz(configFile); temp.ConfigFileName = configFileName; temp.ConfigFile = configFile; return(temp); }
/// <summary> /// Gets the location (including full path) of the given file name. /// This returns a path in the users' application-data directory, of the form: /// <![CDATA[ /// <users-app-data-dir>\Alchemi\<module-name>\filename /// ]]> /// </summary> /// <param name="filename">name of the file or directory whose location is to be resolved</param> /// <param name="name">name of the calling Alchemi module</param> /// <param name="createIfNeeded">Creates the parent directories if needed.</param> /// <returns></returns> public static string GetFilePath(string filepath, AlchemiRole name, bool createIfNeeded) { string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string[] paths = new string[] { dataDir, "Alchemi", name.ToString(), filepath }; return(GetAbsPath(paths, createIfNeeded)); }
/// <summary> /// Write the config to file /// </summary> public void Write(AlchemiRole aRole) { //string file = Utils.GetFilePath(Default_Config_File, AlchemiRole.Owner, true); try { using (Stream s = new FileStream(_Filename, FileMode.Create)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(s, this); s.Close(); } EndPointConfig.ResetEndPointFileName(aRole); EndPointConfig.Slz(); } catch (Exception ex) { //ignore. if we have a call to "write" here again, we might end up in a //infinite loop! } }
/// <summary> /// Gets the location (including full path) of the given file name. /// This returns a path in the users' application-data directory, of the form: /// <![CDATA[ /// <users-app-data-dir>\Alchemi\<module-name>\filename /// ]]> /// </summary> /// <param name="filename">name of the file or directory whose location is to be resolved</param> /// <param name="name">name of the calling Alchemi module</param> /// <param name="createIfNeeded">Creates the parent directories if needed.</param> /// <returns></returns> public static string GetFilePath(string filepath, AlchemiRole name, bool createIfNeeded) { string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string[] paths = new string[] { dataDir, "Alchemi", name.ToString(), filepath }; return GetAbsPath(paths, createIfNeeded); }
/// <summary> /// Default constructor. ConfigFileName is set to "Alchemi.EndPoint.config.xml" /// </summary> /// <param name="aRole">For what alchemi node is the EndPointConfiguration beeing used.</param> public EndPointConfiguration(AlchemiRole aRole) { ConfigFile = Utils.GetFilePath(ConfigFileName, aRole, true); }
/// <summary> /// Sets the name of the config file to be used. /// </summary> /// <param name="aRole">For what alchemi node is the EndPointConfiguration beeing used.</param> public void ResetEndPointFileName(AlchemiRole aRole) { ConfigFile = Utils.GetFilePath(ConfigFileName, aRole, true); }
/// <summary> /// Write the config to file /// </summary> public void Write(AlchemiRole aRole) { //string file = Utils.GetFilePath(Default_Config_File, AlchemiRole.Owner, true); try { using (Stream s = new FileStream(_Filename, FileMode.Create)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(s, this); s.Close(); } EndPointConfig.ResetEndPointFileName(aRole); EndPointConfig.Slz(); } catch(Exception ex) { //ignore. if we have a call to "write" here again, we might end up in a //infinite loop! } }
/// <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> /// Constructor. /// </summary> /// <param name="aRole">For what alchemi node is the EndPointConfiguration beeing used.</param> /// <param name="configFileName">What is the name of the config file.</param> public EndPointConfiguration(AlchemiRole aRole, string configFileName) { ConfigFileName = configFileName; ConfigFile = Utils.GetFilePath(ConfigFileName, aRole, true); }
/// <summary> /// Returns the configuration read from the xml file: "Alchemi.Manager.config.xml" /// </summary> /// <param name="aRole">For what alchemi node is the EndPointConfiguration beeing used.</param> /// <param name="configFileName">What is the name of the config file.</param> /// <returns>Configuration object</returns> public static EndPointConfiguration GetConfiguration(AlchemiRole aRole, string configFileName) { string configFile = Utils.GetFilePath(configFileName, aRole, true); EndPointConfiguration temp = DeSlz(configFile); temp.ConfigFileName = configFileName; temp.ConfigFile = configFile; return temp; }