private Configuration.Chunk FindSectionChunk(string name, ref string valueName) { // First check that the resource is really here. if (documentHandle.IsValid) { if (documentHandle.Resource.RootChunk != null) { if (documentHandle.Resource.RootChunk.Name == "Registry") { // Really search for it. string[] parts = name.Split(new char[] { '.' }); if (parts.Length > 1) { string[] sectionParts = new string[parts.Length - 1]; for (int i = 0; i < parts.Length - 1; i++) { sectionParts[i] = parts[i]; } valueName = parts[parts.Length - 1]; Configuration.Chunk currentChunk = documentHandle.Resource.RootChunk; // Now recurse. for (int i = 0; i < sectionParts.Length; i++) { currentChunk = currentChunk[sectionParts[i]]; if (currentChunk == null) { break; } } return(currentChunk); } } } } else { log.Warning("Registry file not found."); if (documentHandle.Url != string.Empty) { log.Info("Creating new registry file [{0}]", documentHandle.Url); // Create an empty document. Configuration.XmlDocument newDocument = new Configuration.XmlDocument(); newDocument.RootChunk = new Configuration.Chunk("Registry"); // Write it out. newDocument.Write(documentHandle.Url); } } return(null); }
public override bool Read(System.IO.Stream stream) { Xml.XmlDocument xmlDocument = new Xml.XmlDocument(); try { xmlDocument.Load(stream); this.RootChunk = ReadStep(xmlDocument.DocumentElement); if (this.RootChunk != null) { return(true); } } catch (Xml.XmlException e) { log.Warning(e.ToString()); } return(false); }
public System.IO.Stream Open(string url, bool write) { log.Debug("Trying to open file [{0}] write: {1}", url, write); // Find matching archive. if (!write) { if (!Exists(url)) { log.Warning("Trying to open [{0}] for reading, file does not exist.", url); return(null); } } if (Url.IsFilename(url)) { string relativeUrl = url; Archive foundArchive = FindArchive(url, ref relativeUrl); if (foundArchive != null) { System.IO.Stream stream = foundArchive.Open(relativeUrl, write); if (stream != null) { log.Debug("File [{0}] successfully opened for write: {1}", url, write); } return(stream); } else { log.Info("No archive found for url: [{0}][{1}]", url, relativeUrl); } } else { log.Info("[{0}] is not a file url.", url); } return(null); }
public override System.IO.Stream Open(string fileName, bool write) { try { if (write) { FileStream file = new FileStream(GetPath(fileName), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); return(file); } else { FileStream file = new FileStream(GetPath(fileName), FileMode.Open, FileAccess.Read, FileShare.Read); return(file); } } catch (System.IO.FileNotFoundException e) { log.Warning("File not found [{0}]", e.FileName); return(null); } }