public ProjectFile CreateFile(string name) { if (!Helpers.ValidFilename(name)) { throw new Exception("Invalid directory name \"" + name + "\""); } //does the file already exist? ProjectFile buffer = GetFile(name); if (DirectoryExists(name)) { return(null); } if (buffer != null) { return(buffer); } //make sure that the physical directory that contains //the physical file exists. string parentDirectory = new DirectoryInfo(PhysicalLocation).FullName; if (!Directory.Exists(parentDirectory)) { Directory.CreateDirectory(parentDirectory); } Monitor.Enter(p_SyncLock); //create it buffer = new ProjectFile(name, Project); buffer.AssignNewID(); buffer.p_ParentID = InstanceID; //create the physical file on disk File.WriteAllText(buffer.PhysicalLocation, ""); //add it to the file list Array.Resize(ref p_ChildFiles, p_ChildFiles.Length + 1); p_ChildFiles[p_ChildFiles.Length - 1] = buffer.InstanceID; Project.RegisterEntity(buffer, false); //clean up Monitor.Exit(p_SyncLock); Project.Save(); return(buffer); }
public ProjectFile CreateFile(string name) { if (!Helpers.ValidFilename(name)) { throw new Exception("Invalid directory name \"" + name + "\""); } //does the file already exist? ProjectFile buffer = GetFile(name); if (DirectoryExists(name)) { return null; } if (buffer != null) { return buffer; } //make sure that the physical directory that contains //the physical file exists. string parentDirectory = new DirectoryInfo(PhysicalLocation).FullName; if (!Directory.Exists(parentDirectory)) { Directory.CreateDirectory(parentDirectory); } Monitor.Enter(p_SyncLock); //create it buffer = new ProjectFile(name, Project); buffer.AssignNewID(); buffer.p_ParentID = InstanceID; //create the physical file on disk File.WriteAllText(buffer.PhysicalLocation, ""); //add it to the file list Array.Resize(ref p_ChildFiles, p_ChildFiles.Length + 1); p_ChildFiles[p_ChildFiles.Length - 1] = buffer.InstanceID; Project.RegisterEntity(buffer, false); //clean up Monitor.Exit(p_SyncLock); Project.Save(); return buffer; }