public string[] ComposeProject(string scriptFile) { string scHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR"); foreach (string file in templateProjectFiles) { File.Copy(Path.Combine(scHomeDir, Path.Combine(templateProjectDir, file)), Path.Combine(projectDir, file), true); } scriptParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); SetWorkingDir(Path.GetDirectoryName(scriptFile), Path.Combine(projectDir, templateProjectFile) + ".user"); InsertFile(scriptFile, Path.Combine(projectDir, templateProjectFile)); string[] importerdScripts = scriptParser.SaveImportedScripts(); foreach (string file in importerdScripts) { InsertFile(file, Path.Combine(projectDir, templateProjectFile)); if (Path.GetFileName(file).StartsWith("i_")) //imported modified files have name "i_file_XXXXXX.cs>" { filesToClean[file.ToUpper()] = true; } } CSScriptLibrary.AssemblyResolver asmResolver = new CSScriptLibrary.AssemblyResolver(); string[] referencedNamespaces = scriptParser.ReferencedNamespaces; foreach (string name in referencedNamespaces) { bool ignore = false; foreach (string ignoreName in scriptParser.IgnoreNamespaces) { if (ignore = (name == ignoreName)) { break; } } if (ignore) { continue; } string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs); foreach (string file in asmFiles) { InsertReference(Path.GetFileNameWithoutExtension(file), file, Path.Combine(projectDir, templateProjectFile)); } } foreach (string asm in scriptParser.ReferencedAssemblies) //some assemblies were referenced from code { string asmName = Path.Combine(Path.GetDirectoryName(asm), Path.GetFileNameWithoutExtension(asm)); foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(asmName, SearchDirs)) { InsertReference(Path.GetFileNameWithoutExtension(file), file, Path.Combine(projectDir, templateProjectFile)); } } return(importerdScripts); }
private bool IsProjectChanged() { CSScriptLibrary.ScriptParser newParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); //contains scriptFile + imported CSScriptLibrary.ScriptParser currentParser = VS71IDE.scriptParser; //check if number of source files in project has changed if (currentParser.FilesToCompile.Length != newParser.FilesToCompile.Length) return true; Hashtable htImported = new Hashtable(); foreach (string file in newParser.FilesToCompile) { string key = FileToKey(file); if (key != null) htImported[key] = true; } foreach (string file in currentParser.FilesToCompile) { string key = FileToKey(file); if (key != null && !htImported.ContainsKey(key)) return true; } //check if number of referrenced assemblies in project has changed ArrayList currentAssemblies = new ArrayList(); foreach (string name in currentParser.ReferencedNamespaces) foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs)) currentAssemblies.Add(file); foreach (string file in currentParser.ReferencedAssemblies) currentAssemblies.Add(file); ArrayList newAssemblies = new ArrayList(); foreach (string name in newParser.ReferencedNamespaces) foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs)) newAssemblies.Add(file); foreach (string file in newParser.ReferencedAssemblies) newAssemblies.Add(file); if (newAssemblies.Count != currentAssemblies.Count) return true; newAssemblies.Sort(); currentAssemblies.Sort(); foreach (string file in newAssemblies) if (0 > currentAssemblies.BinarySearch(file)) return true; return false; }
private string[] GetImportedFiles(string scriptFile) { CSScriptLibrary.ScriptParser parser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); return parser.SaveImportedScripts(); }
public void IsolateProject(string scriptFile, string newProjectDir) { if (Directory.Exists(newProjectDir)) { try { Directory.Delete(newProjectDir, true); } catch (Exception e) { throw new Exception("Cannot clean destination folder " + newProjectDir + "\n" + e.Message); } } Directory.CreateDirectory(newProjectDir); string newScriptFile = Path.Combine(newProjectDir, Path.GetFileName(scriptFile)); File.Copy(scriptFile, newScriptFile); string scHomeDir = Environment.GetEnvironmentVariable("CSSCRIPT_DIR"); foreach (string file in templateProjectFiles) { File.Copy(Path.Combine(scHomeDir, Path.Combine(templateProjectDir, file)), Path.Combine(newProjectDir, file), true); } scriptParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); //main script file SetWorkingDir(newProjectDir, Path.Combine(newProjectDir, templateProjectFile) + ".user"); InsertFile(newScriptFile, Path.Combine(newProjectDir, templateProjectFile), false); //imported scripts string[] importerdScripts = scriptParser.SaveImportedScripts(); foreach (string file in importerdScripts) { string fileToInsert = file; if (Path.GetFileName(file).StartsWith("i_")) //rename imported files to their original names { int end = file.LastIndexOf("_"); if (end != -1) { string newFile = Path.GetFileName(file.Substring(0, end).Replace("i_", "") + Path.GetExtension(file)); newFile = Path.Combine(newProjectDir, newFile); if (File.Exists(newFile)) { newFile = GetCopyName(newFile); } File.Move(file, newFile); fileToInsert = newFile; } } else if (file != scriptFile) { string newFile = newFile = Path.Combine(newProjectDir, Path.GetFileName(file)); if (File.Exists(newFile)) { newFile = GetCopyName(newFile); } File.Copy(file, newFile); fileToInsert = newFile; } InsertFile(fileToInsert, Path.Combine(newProjectDir, templateProjectFile), false); } //refernced dlls CSScriptLibrary.AssemblyResolver asmResolver = new CSScriptLibrary.AssemblyResolver(); string[] referencedNamespaces = scriptParser.ReferencedNamespaces; foreach (string name in referencedNamespaces) { string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs); foreach (string file in asmFiles) { string fileToInsert = file; if (file.IndexOf("assembly\\GAC") == -1 && file.IndexOf("assembly/GAC") == -1) //do not copy GAC files { fileToInsert = Path.Combine(newProjectDir, Path.GetFileName(fileToInsert)); File.Copy(file, fileToInsert, true); } InsertReference(Path.GetFileNameWithoutExtension(fileToInsert), Path.GetFileName(fileToInsert), Path.Combine(newProjectDir, templateProjectFile)); } } foreach (string asm in scriptParser.ReferencedAssemblies) //some assemblies were referenced from code { string asmName = Path.Combine(Path.GetDirectoryName(asm), Path.GetFileNameWithoutExtension(asm)); string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(asmName, SearchDirs); foreach (string file in asmFiles) { string fileToInsert = file; if (file.IndexOf("assembly\\GAC") == -1 && file.IndexOf("assembly/GAC") == -1) //do not copy GAC files { fileToInsert = Path.Combine(newProjectDir, Path.GetFileName(fileToInsert)); File.Copy(file, fileToInsert, true); } InsertReference(Path.GetFileNameWithoutExtension(fileToInsert), Path.GetFileName(fileToInsert), Path.Combine(newProjectDir, templateProjectFile)); } } //rename project files string newSolutionFile = Path.Combine(newProjectDir, Path.GetFileNameWithoutExtension(newScriptFile) + Path.GetExtension(solutionFile)); string newProjectFile = Path.Combine(newProjectDir, Path.GetFileNameWithoutExtension(newScriptFile) + Path.GetExtension(templateProjectFile)); File.Move(Path.Combine(newProjectDir, solutionFile), newSolutionFile); File.Move(Path.Combine(newProjectDir, templateProjectFile + ".user"), newProjectFile + ".user"); using (StreamReader sr = new StreamReader(Path.Combine(newProjectDir, templateProjectFile))) using (StreamWriter sw = new StreamWriter(newProjectFile)) sw.Write(sr.ReadToEnd().Replace(Path.GetFileNameWithoutExtension(solutionFile), Path.GetFileNameWithoutExtension(newProjectFile))); File.Delete(Path.Combine(newProjectDir, templateProjectFile)); //repoint solution to the rigt project file string solutionText = ""; using (StreamReader sr = new StreamReader(newSolutionFile)) { solutionText = sr.ReadToEnd(); } solutionText = solutionText.Replace("DebugScript", Path.GetFileNameWithoutExtension(newScriptFile)); using (StreamWriter sw = new StreamWriter(newSolutionFile)) { sw.Write(solutionText); } Console.WriteLine("Script " + Path.GetFileName(scriptFile) + " is isolated to folder: " + new DirectoryInfo(newProjectDir).FullName); }
public string[] ComposeProject(string scriptFile) { string scHomeDir = GetEnvironmentVariable("CSSCRIPT_DIR"); foreach (string file in templateProjectFiles) { File.Copy(Path.Combine(scHomeDir, Path.Combine(templateProjectDir, file)), Path.Combine(projectDir, file), true); } scriptParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); SetWorkingDir(Path.GetDirectoryName(scriptFile), Path.Combine(projectDir, templateProjectFile) + ".user"); InsertFile(scriptFile, Path.Combine(projectDir, templateProjectFile)); string[] importerdScripts = scriptParser.SaveImportedScripts(); foreach (string file in importerdScripts) { InsertFile(file, Path.Combine(projectDir, templateProjectFile)); if (Path.GetFileName(file).StartsWith("i_")) //imported modified files have name "i_file_XXXXXX.cs>" filesToClean[file.ToUpper()] = true; } CSScriptLibrary.AssemblyResolver asmResolver = new CSScriptLibrary.AssemblyResolver(); string[] referencedNamespaces = scriptParser.ReferencedNamespaces; foreach (string name in referencedNamespaces) { bool ignore = false; foreach (string ignoreName in scriptParser.IgnoreNamespaces) if (ignore = (name == ignoreName)) break; if (ignore) continue; string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs); foreach (string file in asmFiles) { InsertReference(Path.GetFileNameWithoutExtension(file), file, Path.Combine(projectDir, templateProjectFile)); } } foreach (string asm in scriptParser.ReferencedAssemblies) //some assemblies were referenced from code { string asmName = Path.Combine(Path.GetDirectoryName(asm), Path.GetFileNameWithoutExtension(asm)); foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(asmName, SearchDirs)) { InsertReference(Path.GetFileNameWithoutExtension(file), file, Path.Combine(projectDir, templateProjectFile)); } } return importerdScripts; }
private string[] GetImportedFiles(string scriptFile) { CSScriptLibrary.ScriptParser parser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); return(parser.SaveImportedScripts()); }
public void IsolateProject(string scriptFile, string newProjectDir) { if (Directory.Exists(newProjectDir)) { try { Directory.Delete(newProjectDir, true); } catch (Exception e) { throw new Exception("Cannot clean destination folder " + newProjectDir + "\n" + e.Message); } } Directory.CreateDirectory(newProjectDir); string newScriptFile = Path.Combine(newProjectDir, Path.GetFileName(scriptFile)); File.Copy(scriptFile, newScriptFile); string scHomeDir = Environment.GetEnvironmentVariable("CSSCRIPT_DIR"); foreach (string file in templateProjectFiles) { File.Copy(Path.Combine(scHomeDir, Path.Combine(templateProjectDir, file)), Path.Combine(newProjectDir, file), true); } scriptParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); //main script file SetWorkingDir(newProjectDir, Path.Combine(newProjectDir, templateProjectFile) + ".user"); InsertFile(newScriptFile, Path.Combine(newProjectDir, templateProjectFile), false); //imported scripts string[] importerdScripts = scriptParser.SaveImportedScripts(); foreach (string file in importerdScripts) { string fileToInsert = file; if (Path.GetFileName(file).StartsWith("i_")) //rename imported files to their original names { int end = file.LastIndexOf("_"); if (end != -1) { string newFile = Path.GetFileName(file.Substring(0, end).Replace("i_", "") + Path.GetExtension(file)); newFile = Path.Combine(newProjectDir, newFile); if (File.Exists(newFile)) { newFile = GetCopyName(newFile); } File.Move(file, newFile); fileToInsert = newFile; } } else if (file != scriptFile) { string newFile = newFile = Path.Combine(newProjectDir, Path.GetFileName(file)); if (File.Exists(newFile)) { newFile = GetCopyName(newFile); } File.Copy(file, newFile); fileToInsert = newFile; } InsertFile(fileToInsert, Path.Combine(newProjectDir, templateProjectFile), false); } //refernced dlls CSScriptLibrary.AssemblyResolver asmResolver = new CSScriptLibrary.AssemblyResolver(); string[] referencedNamespaces = scriptParser.ReferencedNamespaces; foreach (string name in referencedNamespaces) { string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs); foreach (string file in asmFiles) { string fileToInsert = file; if (file.IndexOf("assembly\\GAC") == -1 && file.IndexOf("assembly/GAC") == -1) //do not copy GAC files { fileToInsert = Path.Combine(newProjectDir, Path.GetFileName(fileToInsert)); File.Copy(file, fileToInsert, true); } InsertReference(Path.GetFileNameWithoutExtension(fileToInsert), Path.GetFileName(fileToInsert), Path.Combine(newProjectDir, templateProjectFile)); } } foreach (string asm in scriptParser.ReferencedAssemblies) //some assemblies were referenced from code { string asmName = Path.Combine(Path.GetDirectoryName(asm), Path.GetFileNameWithoutExtension(asm)); string[] asmFiles = CSScriptLibrary.AssemblyResolver.FindAssembly(asmName, SearchDirs); foreach (string file in asmFiles) { string fileToInsert = file; if (file.IndexOf("assembly\\GAC") == -1 && file.IndexOf("assembly/GAC") == -1) //do not copy GAC files { fileToInsert = Path.Combine(newProjectDir, Path.GetFileName(fileToInsert)); File.Copy(file, fileToInsert, true); } InsertReference(Path.GetFileNameWithoutExtension(fileToInsert), Path.GetFileName(fileToInsert), Path.Combine(newProjectDir, templateProjectFile)); } } //rename project files string newSolutionFile = Path.Combine(newProjectDir, Path.GetFileNameWithoutExtension(newScriptFile) + Path.GetExtension(solutionFile)); string newProjectFile = Path.Combine(newProjectDir, Path.GetFileNameWithoutExtension(newScriptFile) + Path.GetExtension(templateProjectFile)); File.Move(Path.Combine(newProjectDir, solutionFile), newSolutionFile); File.Move(Path.Combine(newProjectDir, templateProjectFile + ".user"), newProjectFile + ".user"); using (StreamReader sr = new StreamReader(Path.Combine(newProjectDir, templateProjectFile))) using (StreamWriter sw = new StreamWriter(newProjectFile)) sw.Write(sr.ReadToEnd().Replace(Path.GetFileNameWithoutExtension(solutionFile), Path.GetFileNameWithoutExtension(newProjectFile))); File.Delete(Path.Combine(newProjectDir, templateProjectFile)); //repoint solution to the rigt project file string solutionText = ""; using (StreamReader sr = new StreamReader(newSolutionFile)) { solutionText = sr.ReadToEnd(); } solutionText = solutionText.Replace("DebugScript", Path.GetFileNameWithoutExtension(newScriptFile)); using (StreamWriter sw = new StreamWriter(newSolutionFile)) { sw.Write(solutionText); } Console.WriteLine("Script " + Path.GetFileName(scriptFile) + " is isolated to folder: " + new DirectoryInfo(newProjectDir).FullName); }
private bool IsProjectChanged() { CSScriptLibrary.ScriptParser newParser = new CSScriptLibrary.ScriptParser(scriptFile, SearchDirs); //contains scriptFile + imported CSScriptLibrary.ScriptParser currentParser = VS71IDE.scriptParser; //check if number of source files in project has changed if (currentParser.FilesToCompile.Length != newParser.FilesToCompile.Length) { return(true); } Hashtable htImported = new Hashtable(); foreach (string file in newParser.FilesToCompile) { string key = FileToKey(file); if (key != null) { htImported[key] = true; } } foreach (string file in currentParser.FilesToCompile) { string key = FileToKey(file); if (key != null && !htImported.ContainsKey(key)) { return(true); } } //check if number of referrenced assemblies in project has changed ArrayList currentAssemblies = new ArrayList(); foreach (string name in currentParser.ReferencedNamespaces) { foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs)) { currentAssemblies.Add(file); } } foreach (string file in currentParser.ReferencedAssemblies) { currentAssemblies.Add(file); } ArrayList newAssemblies = new ArrayList(); foreach (string name in newParser.ReferencedNamespaces) { foreach (string file in CSScriptLibrary.AssemblyResolver.FindAssembly(name, SearchDirs)) { newAssemblies.Add(file); } } foreach (string file in newParser.ReferencedAssemblies) { newAssemblies.Add(file); } if (newAssemblies.Count != currentAssemblies.Count) { return(true); } newAssemblies.Sort(); currentAssemblies.Sort(); foreach (string file in newAssemblies) { if (0 > currentAssemblies.BinarySearch(file)) { return(true); } } return(false); }