Beispiel #1
0
        public static Project AddProject(this Solution4 solution, string destination, string projectName, string templateName)
        {
            var projectPath  = Path.Combine(destination, projectName);
            var templatePath = solution.GetProjectTemplate(templateName, "CSharp");

            solution.AddFromTemplate(templatePath, projectPath, projectName, false);

            return(solution.GetProject(projectName));
        }
Beispiel #2
0
        public void Add(Solution4 solution, string projectType, string templateProjectName, string projectName)
        {
            try
            {
                var solutionFileInfo = new FileInfo(solution.FullName);
                var solutionName = solutionFileInfo.Name.Replace(".sln", string.Empty);
                projectName = String.Format("{0}.{1}", solutionName, projectName);
                var projectDirectoryName = string.Format("{0}/{1}", solutionFileInfo.DirectoryName, projectName);

                var templateProjectPath = solution.GetProjectTemplate(projectType, Constants.Language);

                //Add a project
                var project = solution.AddFromTemplate(templateProjectPath, projectDirectoryName, projectName);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Beispiel #3
0
        private void AddProjectTemplate()
        {
            int  retry   = 100;
            bool success = false;

            while (!success && retry > 0)
            {
                try
                {
                    _solution.AddFromTemplate(TemplatePath, IntDir, _projectName, false);

                    success = true;
                }
#if DEBUG
                catch (Exception ex)
#else
                catch
#endif
                {
                    success = false;
                    retry--;

                    if (retry > 0)
                    {
                        System.Threading.Thread.Sleep(150);

#if DEBUG
                        Log.LogMessage(MessageImportance.High, "Exception: " + ex.ToString());
#endif
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #4
0
        public static string GenerateSolution()
        {
            DTE2   dte;
            object obj;
            string outputfolder = "";

            try
            {
                if (SolutionGenerator.SelectedType == CompType.Addon)
                {
                    SolutionGenerator.TemplateFileName = "CSharpAddon.zip";
                }
                else // interpreter
                {
                    SolutionGenerator.TemplateFileName = "CSharpInterpreter.zip";
                }

                // Prefer latest VS
                System.Type type = null;
                if (type == null)
                {
                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.14.0");
                }
                if (type == null)
                {
                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.12.0");
                }
                if (type == null)
                {
                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
                }
                if (type == null)
                {
                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
                }

                obj = Activator.CreateInstance(type, true);
                dte = (DTE2)obj;
                Solution4 sln = (Solution4)dte.Solution;

                outputfolder = Path.Combine(TargetFolder, SolutionName);
                string solutionName = SolutionName + ".sln";

                if (Directory.Exists(outputfolder))
                {
                    Directory.Delete(outputfolder, true);
                }

                // Unpack the sufficent template project
                Stream TemplateStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Templates." + SolutionGenerator.TemplateFileName);
                FileStream FileWriter = new FileStream(Path.Combine(SolutionGenerator.ProjectTemplateLocation, SolutionGenerator.TemplateFileName), FileMode.Create);
                using (TemplateStream)
                    using (FileWriter)
                    {
                        TemplateStream.CopyTo(FileWriter);
                    }

                sln.Create(outputfolder, solutionName);

                string TemplatePath = sln.GetProjectTemplate(SolutionGenerator.TemplateFileName, "CSharp");
                sln.AddFromTemplate(TemplatePath, outputfolder, SolutionName, false);
                var project       = sln.Projects.Item(1);
                var dotNetVersion = new FrameworkName(".NETFramework", new Version(4, 0));
                var fullname      = dotNetVersion.FullName;
                project.Properties.Item("TargetFrameworkMoniker").Value = dotNetVersion.FullName;
                sln.Close();
            }
            finally
            {
                obj = dte = null;
            }
            return(outputfolder);
        }
        /// <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);
        }