protected void AddFilesToProject(string[] filenames, string primaryFile) { EnvDTE.ProjectItem parent = this.ProjectItem; EnvDTE.ProjectItem item = null; if (parent != null) { var filelist = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (var file in filenames) { filelist[Path.GetFileName(file)] = file; } for (int i = 1; item == null && i <= parent.ProjectItems.Count; i++) { EnvDTE.ProjectItem child = parent.ProjectItems.Item(i); if (!filelist.Remove(child.Name)) { child.Remove(); } } if (primaryFile != null) { filelist.Remove(primaryFile); } foreach (string file in filelist.Values) { parent.ProjectItems.AddFromFile(file); } } }
public static void DeleteItems(this IVsProject project, List <string> paths) { project.EnsureIsCheckout(); foreach (string path in paths) { EnvDTE.ProjectItem item = project.GetProjectItem(path); if (item != null) { if (File.Exists(path)) { item.Delete(); } else { item.Remove(); } } } var sliceCompileDependencies = paths.Select( p => { return(Path.Combine(Path.GetDirectoryName(p), string.Format("SliceCompile.{0}.d", Path.GetFileNameWithoutExtension(p)))); }).Distinct().ToList(); foreach (var path in sliceCompileDependencies) { if (File.Exists(path)) { try { File.Delete(path); } catch (IOException) { } } } }
public static void DeleteItems(List <string> paths) { foreach (string path in paths) { EnvDTE.ProjectItem item = FindProjectItem(path); if (item != null) { item.Remove(); } if (File.Exists(path)) { try { File.Delete(path); } catch (IOException) { // can happen if the file is being used by other process } } } }
/// <summary> /// Open your QuantConnect project in Visual Studio /// </summary> /// <param name="selectedProject"></param> /// <param name="api"></param> /// <param name="projectName"></param> public static bool OpenProject(int selectedProject, string projectName, Action enableForm) { // Don't let user open the same project he's working in if (selectedProject == ProjectID) { DialogResult dialogResult = MessageBox.Show("You are currently working on this project.", "Invalid Operation", MessageBoxButtons.OK); } ProjectID = selectedProject; ProjectName = CleanInput(projectName); // Check if file already exists if (!ExistingFileChecker(ProjectName, ProjectID)) { return(false); } Async.Add(new APIJob(APICommand.OpenProject, (files, errors) => { List <File> projectFiles = (List <File>)files; // Create Solution Solution4 soln = (Solution4)QCPluginPackage.ApplicationObject.Solution; soln.Create(Directory + ProjectID + " - " + ProjectName, ProjectName + ".sln"); // Create Project soln.AddFromTemplate(Directory + @"QCTemplate\csQCTemplate.vstemplate", Directory + ProjectID + " - " + ProjectName, ProjectName, false); // Add Files to Project: foreach (EnvDTE.Project proj in soln.Projects) { foreach (var file in proj.ProjectItems) { EnvDTE.ProjectItem item = file as EnvDTE.ProjectItem; if (item.Name == "Class1.cs") { item.Remove(); } } foreach (var file in projectFiles) { System.IO.File.WriteAllText(Directory + ProjectID + " - " + ProjectName + @"\" + file.Name, file.Code); //Add files to project: try { proj.ProjectItems.AddFromFile(Directory + ProjectID + " - " + ProjectName + @"\" + file.Name); } catch (SystemException ex) { MessageBox.Show("ERROR: " + ex); } } //Add References var vsProject = proj.Object as VSProject; if (vsProject == null) { continue; } var commonDLL = Directory + @"QCAlgorithm-master\QuantConnect.Algorithm\bin\Debug\QuantConnect.Common.dll"; if (!System.IO.File.Exists(commonDLL)) { //Download and unzip: API.DownloadQCAlgorithm(Directory); } //Safe to add reference: vsProject.References.Add(commonDLL); vsProject.References.Add(Directory + @"QCAlgorithm-master\QuantConnect.Algorithm\bin\Debug\MathNet.Numerics.dll"); vsProject.References.Add(Directory + @"QCAlgorithm-master\QuantConnect.Algorithm\bin\Debug\QuantConnect.Algorithm.dll"); vsProject.References.Add(Directory + @"QCAlgorithm-master\QuantConnect.Algorithm\bin\Debug\QuantConnect.Algorithm.Interface.dll"); } //Save & open solution soln.SaveAs(Directory + ProjectID + " - " + ProjectName + @"\" + ProjectName + ".sln"); ProjectLoaded = true; if (enableForm != null) { enableForm(); } }, selectedProject)); return(true); }