Exemple #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Solution3 sol3 = _app.Solution as Solution3;
                if (sol3 == null || string.IsNullOrEmpty(sol3.FileName))
                {
                    MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                    return;
                }
                string saveDir = this.txtSaveDir.Text.Trim();
                if (string.IsNullOrEmpty(saveDir) || Directory.Exists(saveDir) == false)
                {
                    MsgBox.ShowTip("请选择项目保存位置");
                    return;
                }
                string rootDir = this.txtRootDir.Text.Trim();
                rootDir = rootDir.TrimEnd('.');
                if (string.IsNullOrEmpty(rootDir))
                {
                    MsgBox.ShowTip("根名字空间不能为空");
                    return;
                }
                bool isExistFolder = false;
                for (int j = 1; j < sol3.Projects.Count; j++)
                {
                    Project proj = sol3.Projects.Item(j);
                    if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder)
                    {
                        continue;
                    }
                    if (sol3.Projects.Item(j).Name.Equals(rootDir, StringComparison.CurrentCultureIgnoreCase))
                    {
                        isExistFolder = true;
                        break;
                    }
                }
                if (isExistFolder == false)
                {
                    Project solFolder = sol3.AddSolutionFolder(rootDir);
                }
                List <Project> existProjs = ProjectUtility.GetAllProjects(_app);
                for (int i = 0; i < this.richTextBox1.Lines.Length; i++)
                {
                    string subDir = this.richTextBox1.Lines[i].Trim();
                    subDir = subDir.TrimStart('.').TrimEnd('.');
                    if (string.IsNullOrEmpty(subDir))
                    {
                        continue;
                    }
                    subDir = rootDir + "." + subDir;

                    string projPath = Path.Combine(saveDir, subDir + "\\" + subDir + ".csproj");
                    bool   isExist  = false;
                    for (int k = 0; k < existProjs.Count; k++)
                    {
                        if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (isExist == false)
                    {
                        if (File.Exists(projPath))
                        {
                            DialogResult rlt = MsgBox.ShowOkCancel("项目保存位置下已经存在:" + subDir + ",是否需要加载?");
                            if (rlt == DialogResult.OK)
                            {
                                sol3.AddFromFile(projPath, false);
                            }
                            continue;
                        }
                        string  templatePath = sol3.GetProjectTemplate("ClassLibrary.zip", "CSharp");
                        Project proj         = sol3.AddFromTemplate(templatePath, Path.Combine(saveDir, subDir), subDir, true);
                    }
                    else
                    {
                        MsgBox.ShowTip(subDir + "已经存在");
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Exemple #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Solution3 sol3 = _app.Solution as Solution3;
                if (sol3 == null || string.IsNullOrEmpty(sol3.FileName))
                {
                    MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                    return;
                }
                List <Project> existProjs = ProjectUtility.GetAllProjects(_app);
                for (int i = 0; i < this.treeView1.Nodes.Count; i++)
                {
                    TreeNode rootNode = this.treeView1.Nodes[i];
                    if (rootNode.Checked && rootNode.Nodes.Count > 0)
                    {
                        string foldName      = rootNode.Tag as string;
                        bool   isExistFolder = false;
                        for (int j = 1; j < sol3.Projects.Count; j++)
                        {
                            Project proj = sol3.Projects.Item(j);
                            if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder)
                            {
                                continue;
                            }
                            if (sol3.Projects.Item(j).Name.Equals(foldName, StringComparison.CurrentCultureIgnoreCase))
                            {
                                isExistFolder = true;
                                break;
                            }
                        }
                        if (isExistFolder == false)
                        {
                            Project solFolder = sol3.AddSolutionFolder(rootNode.Tag as string);
                        }
                        for (int j = 0; j < rootNode.Nodes.Count; j++)
                        {
                            if (rootNode.Nodes[j].Checked)
                            {
                                string projPath = rootNode.Nodes[j].Tag as string;
                                bool   isExist  = false;
                                for (int k = 0; k < existProjs.Count; k++)
                                {
                                    if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        isExist = true;
                                        break;
                                    }
                                }
                                if (isExist == false)
                                {
                                    Project proj = sol3.AddFromFile(projPath, false);
                                }
                                else
                                {
                                    MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载");
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < rootNode.Nodes.Count; j++)
                        {
                            if (rootNode.Nodes[j].Checked)
                            {
                                string projPath = rootNode.Nodes[j].Tag as string;
                                bool   isExist  = false;
                                for (int k = 0; k < existProjs.Count; k++)
                                {
                                    if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        isExist = true;
                                        break;
                                    }
                                }
                                if (isExist == false)
                                {
                                    Project proj = sol3.AddFromFile(projPath, false);
                                }
                                else
                                {
                                    MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载");
                                }
                            }
                        }
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        private void Generate(string slnName)
        {
            Solution3 sln = (DTEObject.Solution as Solution3);

            sln.Create(currentSlnPath, slnName);

            CopyExternalBinFolder(currentSlnPath);

            // Create solution folder
            Project sfProj = sln.AddSolutionFolder(ExternalBinDirectoryName);

            foreach (string file in Directory.GetFiles(ExternalBinPath))
            {
                sfProj.ProjectItems.AddFromFile(file);
            }

            // Create *.Domain Project
            string classLibProjTemplatePath =
                sln.GetProjectTemplate("ClassLibrary.zip", "CSharp");
            string domainProjName = slnName + "." + "Domain";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, domainProjName),
                                domainProjName, false);
            Project   domainProj   = GetProjectByName(sln, domainProjName);
            VSProject vsDomainProj = domainProj.Object as VSProject;

            vsDomainProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));

            // Create *.Persistence Project
            string persistProjName = slnName + "." + "Persistence";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, persistProjName),
                                persistProjName, false);
            Project   persistProj   = GetProjectByName(sln, persistProjName);
            VSProject vsPersistProj = persistProj.Object as VSProject;

            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataAccess.dll"));
            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataMapper.dll"));
            vsPersistProj.References.AddProject(domainProj);

            // Create *.Service Project
            string serviceProjName = slnName + "." + "Service";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, serviceProjName),
                                serviceProjName, false);
            Project   serviceProj   = GetProjectByName(sln, serviceProjName);
            VSProject vsServiceProj = serviceProj.Object as VSProject;

            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataAccess.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "Castle.DynamicProxy.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "log4net.dll"));
            vsServiceProj.References.AddProject(domainProj);
            vsServiceProj.References.AddProject(persistProj);

            // Create *.Presentation Project
            string presentProjName = slnName + "." + "Presentation";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, presentProjName),
                                presentProjName, false);
            Project   presentProj   = GetProjectByName(sln, presentProjName);
            VSProject vsPresentProj = presentProj.Object as VSProject;

            vsPresentProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsPresentProj.References.AddProject(domainProj);
            vsPresentProj.References.AddProject(serviceProj);

            // Create *.Web Project
            string webProjTemplatePath =
                sln.GetProjectTemplate("WebApplicationProject.zip", "CSharp");
            string webProjName = slnName + "." + "Web";

            sln.AddFromTemplate(webProjTemplatePath, Path.Combine(currentSlnPath, webProjName),
                                webProjName, false);
            Project   webProj   = GetProjectByName(sln, webProjName);
            VSProject vsWebProj = webProj.Object as VSProject;

            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "Castle.DynamicProxy.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.Logging.Log4Net.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "log4net.dll"));
            vsWebProj.References.AddProject(domainProj);
            vsWebProj.References.AddProject(presentProj);

            webProj.ProjectItems.AddFolder("css", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("images", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("Maps", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("UserControls", Constants.vsProjectItemKindPhysicalFolder);

            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\dao.config"));
            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\providers.config"));
            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\SqlMap.config"));

            sln.SaveAs(slnName);
        }