예제 #1
0
        private void GenerateBusiness(ProjectItem projectItem, Solution2 solution2, Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (project.Name.EndsWith("Business") || project.Name.EndsWith("Bll"))
            {
                CommonHelpers.CreateFoldersIfNotExists(project, new string[] { "Abstract", "Concrete" });

                foreach (ProjectItem item in project.ProjectItems)
                {
                    var projectTemplate          = solution2.GetProjectItemTemplate("Interface", "CSharp");
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(projectItem.Name);
                    var fileParameters           = new CreateFileParameters
                    {
                        FileNameWithoutExtension = fileNameWithoutExtension,
                        ProjectItem     = item,
                        ProjectName     = project.Name,
                        ProjectTemplate = projectTemplate
                    };
                    if (item.Name == "Abstract")
                    {
                        BusinessFileService.CreateBusinessAbstract(fileParameters);
                    }
                    if (item.Name == "Concrete")
                    {
                        BusinessFileService.CreateBusinessConcrete(fileParameters);
                    }
                    if (item.Name == "DependencyResolvers")
                    {
                        foreach (ProjectItem iocFolder in item.ProjectItems)
                        {
                            BusinessFileService.RegisterAddedFilesToIoc(iocFolder, fileParameters.FileNameWithoutExtension);
                        }
                    }
                }
            }
        }
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            string title   = "CreateRelatedObjects";

            EnvDTE.DTE           dte;
            EnvDTE.SelectedItems selectedItems;
            EnvDTE.ProjectItem   projectItem;
            EnvDTE80.Solution2   solution2;
            dte           = SyncServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE ?? throw new ArgumentNullException();
            solution2     = (Solution2)dte.Solution;
            selectedItems = dte.SelectedItems;
            if (selectedItems.Count > 1)
            {
                message = "Can't Support multiple creation yet.";
                VsShellUtilities.ShowMessageBox((IServiceProvider)ServiceProvider, message, title, OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            if (selectedItems == null)
            {
                message = "There isn't any item selected";
                VsShellUtilities.ShowMessageBox((IServiceProvider)ServiceProvider, message, title, OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }
            foreach (EnvDTE.SelectedItem selectedItem in selectedItems)
            {
                projectItem = selectedItem.ProjectItem as ProjectItem;
                if (!IsIEntityImplementation(projectItem))
                {
                    message = "Object must be Implemented from IEntity in order to generate";
                    VsShellUtilities.ShowMessageBox((IServiceProvider)ServiceProvider, message, title,
                                                    OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    return;
                }

                if (projectItem != null)
                {
                    foreach (EnvDTE.Project project in dte.Solution.Projects)
                    {
                        if (project.Name.EndsWith("DataAccess") || project.Name.EndsWith("Dal"))
                        {
                            if (!DoesProjectFolderExists(project.FullName, "Abstract"))
                            {
                                project.ProjectItems.AddFolder("Abstract");
                            }

                            if (!DoesProjectFolderExists(project.FullName, "Concrete\\EntityFramework"))
                            {
                                project.ProjectItems.AddFolder("Concrete\\EntityFramework");
                            }

                            foreach (EnvDTE.ProjectItem item in project.ProjectItems)
                            {
                                var projectTemplate          = solution2.GetProjectItemTemplate("Interface", "CSharp");
                                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(projectItem.Name);
                                var fileParameters           = new CreateFileParameters
                                {
                                    ProjectItem              = item,
                                    ProjectTemplate          = projectTemplate,
                                    ProjectName              = project.Name,
                                    FileNameWithoutExtension = fileNameWithoutExtension,
                                };
                                if (item.Name == "Abstract")
                                {
                                    DataAccessFileService.CreateDalAbstract(fileParameters);
                                }
                                if (item.Name == "Concrete")
                                {
                                    foreach (ProjectItem concrete in item.ProjectItems)
                                    {
                                        if (concrete.Name == "EntityFramework")
                                        {
                                            fileParameters.ProjectItem = concrete;
                                            DataAccessFileService.CreateDalConcrete(fileParameters);
                                        }
                                    }
                                }
                            }
                        }

                        if (project.Name.EndsWith("Business") || project.Name.EndsWith("Bll"))
                        {
                            if (!DoesProjectFolderExists(project.FullName, "Abstract"))
                            {
                                project.ProjectItems.AddFolder("Abstract");
                            }

                            if (!DoesProjectFolderExists(project.FullName, "Concrete"))
                            {
                                project.ProjectItems.AddFolder("Concrete");
                            }

                            foreach (EnvDTE.ProjectItem item in project.ProjectItems)
                            {
                                var projectTemplate          = solution2.GetProjectItemTemplate("Interface", "CSharp");
                                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(projectItem.Name);
                                var fileParameters           = new CreateFileParameters
                                {
                                    FileNameWithoutExtension = fileNameWithoutExtension,
                                    ProjectItem     = item,
                                    ProjectName     = project.Name,
                                    ProjectTemplate = projectTemplate
                                };
                                if (item.Name == "Abstract")
                                {
                                    BusinessFileService.CreateBusinessAbstract(fileParameters);
                                }
                                if (item.Name == "Concrete")
                                {
                                    BusinessFileService.CreateBusinessConcrete(fileParameters);
                                }
                            }
                        }
                    }
                }
            }
        }