protected override PathAccess FetchPathAccess(string pathName) { // Read it from the file system. string f = Path.Combine(basePath, pathName); // If it doesn't exist, generate an error if (!File.Exists(f)) throw new ApplicationException("Path '" + pathName + "' not found input this root service."); // If it does exist, does the .deleted file exist indicating this root // path was removed, if (File.Exists(Path.Combine(basePath, pathName + ".deleted"))) throw new ApplicationException("Path '" + pathName + "' did exist but was deleted."); // Read the summary data for this path. string summaryFile = Path.Combine(basePath, pathName + ".summary"); Util.Properties p = new Util.Properties(); using (FileStream fileStream = new FileStream(summaryFile, FileMode.Open, FileAccess.Read)) { p.Load(fileStream); } string pathType = p.GetProperty("path_type"); // Format it into a PathAccess object, FileStream accessStream = new FileStream(f, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 1024, FileOptions.WriteThrough); return new PathAccess(accessStream, pathName, pathType); }
public void Save(ConfigSource config, Stream output) { if (!output.CanWrite) throw new ArgumentException("The output stream cannot be written.", "output"); Util.Properties properties = new Util.Properties(); SetChildValues(properties, "", config); properties.Store(output, null); }
public void Load(ConfigSource config, Stream input) { if (!input.CanRead) throw new ArgumentException("Cannot read from the stream.", "input"); Util.Properties properties = new Util.Properties(); properties.Load(input); foreach(KeyValuePair<object, object> pair in properties) { config.SetValue((string)pair.Key, (string)pair.Value); } }
protected override void CreatePath(string pathName, string pathTypeName) { string f = Path.Combine(basePath, pathName); FileInfo fileInfo = new FileInfo(f); if (fileInfo.Exists) throw new ApplicationException("Path file for '" + pathName + "' exists on this root service."); // Create the root file using (fileInfo.Create()) { // immediately call Dispose on the stream... } // Create a summary file for storing information about the path string summaryFile = Path.Combine(basePath, pathName + ".summary"); Util.Properties p = new Util.Properties(); p.SetProperty("path_type", pathTypeName); using (FileStream fileStream = new FileStream(summaryFile, FileMode.CreateNew, FileAccess.Write)) { p.Store(fileStream, null); } }
public Protocol(string host, int port, Util.Properties props, string prefix, bool isSsl) { bool connected = false; // did constructor succeed? try { } finally { /* * If we get here because an exception was thrown, we need * to disconnect to avoid leaving a connected socket that * no one will be able to use because this object was never * completely constructed. */ if (!connected) { disconnect(); } } }
protected override void OnStart() { try { // Read the manager service address from the properties file, Util.Properties p = new Util.Properties(); // Contains the root properties, string propFile = Path.Combine(basePath, "00.properties"); if (File.Exists(propFile)) { using (FileStream fin = new FileStream(propFile, FileMode.Open, FileAccess.Read)) { p.Load(fin); } } // Fetch the manager service property, string v = p.GetProperty("manager_address"); if (v != null) { ManagerAddress = ServiceAddresses.ParseString(v); } } catch (IOException e) { throw new ApplicationException("IO Error: " + e.Message); } }