public override File422 CreateFile(string fileName) { File422 memFile = null; if (!StdFSHelper.ContainsPathCharacters(fileName) || string.IsNullOrEmpty(fileName)) { //check if exists already if ((memFile = GetFile(fileName)) != null) { using (Stream s = memFile.OpenReadWrite()) { if (s != null) { //this 0's out the memory stream. s.SetLength(0); } } } else { memFile = new MemFSFile(fileName, this); _childFiles.Add(memFile); } } return(memFile); }
static void Main(string[] args) { MemoryFileSystem mfs = new MemoryFileSystem(); MemFSDir root = (MemFSDir)mfs.GetRoot(); MemFSFile testing = (MemFSFile)root.CreateFile("test.txt"); MemoryStream stream = (MemoryStream)testing.OpenReadWrite(); string test = "This is a test string!"; byte[] buf = Encoding.ASCII.GetBytes(test); stream.Write(buf, 0, buf.Length); stream.Close(); MemoryStream stream2 = (MemoryStream)testing.OpenReadOnly(); int numBytes = stream2.Read(buf, 0, buf.Length); string test2 = Encoding.ASCII.GetString(buf); MemFSDir test1 = (MemFSDir)root.CreateDir("test1"); MemFSDir subTest1 = (MemFSDir)test1.CreateDir("subTest1"); MemFSFile file = (MemFSFile)subTest1.CreateFile("test.txt"); test1.CreateDir("subTest2"); root.CreateDir("test2"); root.CreateDir("test3"); }
public override File422 CreateFile(string name) { if (!ValidateName(name)) { return(null); } foreach (File422 file in files) { if (file.Name == name) { return(null); } } foreach (Dir422 dir in dirs) { if (dir.Name == name) { return(null); } } File422 newFile = new MemFSFile(this, name); files.Add(newFile); return(newFile); }
public override File422 CreateFile(string name) { MemFSFile file = new MemFSFile(name, this); files.Add(file); return(file); }
public trackingMemStream(bool write, MemFSFile originFile) //constructor class { actualStream = new MemoryStream(); originFile.data.CopyTo(actualStream); actualStream.Position = 0; canWrite = write; file = originFile; position = 0; }
public override File422 CreateFile(string name) { MemFSFile newFile = new MemFSFile(name, this); if (_fileList == null) { _fileList = new List <File422>(); } _fileList.Add(newFile); return(newFile); }
public override File422 CreateFile(string name) { File422 file = GetFile(name); if (file == null) { file = new MemFSFile(name, this); _files.Add(file); } return(file); }
public override File422 CreateFile(string name) { if (!ValidateName(name)) { return(null); } File422 newFile = new MemFSFile(this, name); files.Add(newFile); return(newFile); }
public override File422 CreateFile(string fileName) { if (fileName.Contains("\\") || fileName.Contains("/") || fileName == string.Empty || fileName == null) { return(null); } MemFSFile file = new MemFSFile(fileName, this); m_files.Add(file); return(file); }
public override File422 CreateFile(string fileName) { if (string.IsNullOrEmpty(fileName) || !Utilities.isValidFileName(fileName)) { return(null); } var toAdd = new MemFSFile(fileName, this); m_files.Add(toAdd); return(toAdd); }
// Create new file in this directory. public override File422 CreateFile(string fileName) { if (Utility.PathCharPresent(fileName)) { return(null); } foreach (var file in this.files) { if (file.Name == fileName) { return(file); } } File422 new_file = new MemFSFile(fileName, this); this.files.Add((MemFSFile)new_file); return(new_file); }
internal void OnFileAccessed(object sender, FileAccessEventArgs e) { MemFSFile file = sender as MemFSFile; /**if (file == null) * { * // Ensure that the object being sent is a MemFSFile * throw new InvalidDataException("Object must be a MemFSFile object."); * }*/ lock (m_lock) { if (e.fileOperation == FileAccessEventArgs.FileOperation.Open) { // The file has been opened somewhere. // The mode that it was opened it does not matter from the directory's perspective. if (m_listOfOpenFiles.ContainsKey(file)) { m_listOfOpenFiles[file]++; } else { m_listOfOpenFiles[file] = 1; } } else { // The file has been closed somewhere. m_listOfOpenFiles[file]--; if (m_listOfOpenFiles[file] == 0) { int outVal; // This file is no longer open anywhere. // Remove this handle and discard it from the opened files collection, then file.FileAccessed -= OnFileAccessed; m_listOfOpenFiles.TryRemove(file, out outVal); } } } }
public override File422 CreateFile(string fileName) { if (fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { return(null); } foreach (var f in _files) { if (f.Name == fileName) { // found file var T = f as MemFSFile; T.Size(0); return(f); } } MemFSFile temp = new MemFSFile(Path.Combine(_path, fileName), this); _files.Add(temp); return(temp); }
public override File422 CreateFile(string name) { bool contains = false; foreach (MemFSFile f in Files) { if (f.Name == name) { contains = true; } } if (contains) { return(null); } MemFSFile newFile = new MemFSFile(name, this); Files.Add(newFile); return(newFile); }