Ejemplo n.º 1
0
        public void Edit(Project project)
        {
            string str = Path.Combine(ProjectExtensions.GetFullPath(project), "web.config");

            if (project.DTE.SourceControl.IsItemUnderSCC(str) && !project.DTE.SourceControl.IsItemCheckedOut(str) && !project.DTE.SourceControl.CheckOutItem(str))
            {
                return;
            }
            IEditorInterfaces orOpenDocument = this.VisualStudio.Editor.GetOrOpenDocument(str);

            Marshal.ThrowExceptionForHR(orOpenDocument.VsTextBuffer.Reload(1));
            ITextBuffer textBuffer = orOpenDocument.TextBuffer;

            using (ITextEdit textEdit = textBuffer.CreateEdit())
            {
                string editedText = this.GetEditedText(textEdit.Snapshot.GetText());
                if (editedText != null)
                {
                    textEdit.Replace(new Span(0, textBuffer.CurrentSnapshot.Length), editedText);
                    textEdit.Apply();
                    this.VisualStudio.Editor.FormatDocument(str);
                    Document document = project.DTE.Documents.Item(str);
                    document.Save("");
                }
            }
        }
Ejemplo n.º 2
0
        protected void CreateAppStartFiles(string configFileName, string productNamespace)
        {
            string str = configFileName;
            int    num = 2;

            while (true)
            {
                Project  activeProject = this.Context.ActiveProject;
                CodeType codeType      = this.CodeTypeService.GetCodeType(activeProject, string.Concat(ProjectExtensions.GetDefaultNamespace(activeProject), ".", configFileName));
                string   str1          = string.Concat(configFileName, ".", ProjectExtensions.GetCodeLanguage(this.Context.ActiveProject).CodeFileExtension);
                string   str2          = Path.Combine(ProjectExtensions.GetFullPath(this.Context.ActiveProject), "App_Start", str1);
                if (!File.Exists(Path.Combine(ProjectExtensions.GetFullPath(this.Context.ActiveProject), "App_Start", str1)) && codeType == null)
                {
                    this.AppStartFileNames.Add(str, configFileName);
                    this.GenerateT4File(str, configFileName, "App_Start");
                    return;
                }
                if (codeType != null && !codeType.Name.StartsWith("BundleConfig", StringComparison.OrdinalIgnoreCase) && CodeTypeFilter.IsProductNamespaceImported(codeType, productNamespace))
                {
                    this.AppStartFileNames.Add(str, configFileName);
                    return;
                }
                if (codeType != null && codeType.Name.StartsWith("BundleConfig", StringComparison.OrdinalIgnoreCase) && AddDependencyUtil.IsSearchTextPresent(str2, "ScriptBundle(\"~/bundles/jquery\")"))
                {
                    break;
                }
                configFileName = string.Concat(str, num);
                num++;
            }
            this.AppStartFileNames.Add(str, configFileName);
        }
Ejemplo n.º 3
0
 private bool IsGlobalAsaxPresent()
 {
     if ((this.CodeTypeService.GetCodeType(this.Context.ActiveProject, "Global") != null || this.CodeTypeService.GetCodeType(this.Context.ActiveProject, "MvcApplication") != null ? true : this.CodeTypeService.GetCodeType(this.Context.ActiveProject, "WebApiApplication") != null))
     {
         return(true);
     }
     return(File.Exists(Path.Combine(ProjectExtensions.GetFullPath(this.Context.ActiveProject), string.Empty, "Global.asax")));
 }
 public static string GetProjectTemplateRoot(Project project)
 {
     if (project == null)
     {
         throw new ArgumentNullException("project");
     }
     return(Path.Combine(ProjectExtensions.GetFullPath(project), "CodeTemplates"));
 }
Ejemplo n.º 5
0
        public virtual void UpdateConfiguration(CodeGenerationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            Project activeProject = context.ActiveProject;
            string  str           = Path.Combine(ProjectExtensions.GetFullPath(activeProject), "web.config");

            this.VisualStudioIntegration.Editor.GetOrOpenDocument(str);
        }
Ejemplo n.º 6
0
        public void EnsureLayoutPageAndDependenciesCreated(string areaName, string areaRelativePath, bool isBundleConfigPresent)
        {
            string str;
            string viewFileExtension = MvcProjectUtil.GetViewFileExtension(ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject));
            string str1 = Path.ChangeExtension("_ViewStart", viewFileExtension);

            str = (!string.IsNullOrEmpty(areaRelativePath) ? Path.Combine(areaRelativePath, "Views") : "Views");
            if (!File.Exists(Path.Combine(ProjectExtensions.GetFullPath(base.Context.ActiveProject), str, str1)))
            {
                string codeFileExtension = ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject).CodeFileExtension;
                string textTemplatePath  = base.FilesLocatorService.GetTextTemplatePath("_ViewStart", this.SearchFolders, codeFileExtension);
                ICodeGeneratorActionsService actionsService = base.ActionsService;
                Project activeProject            = base.Context.ActiveProject;
                string  str2                     = Path.Combine(str, "_ViewStart");
                Dictionary <string, object> strs = new Dictionary <string, object>()
                {
                    { "AreaName", areaName }
                };
                actionsService.AddFileFromTemplate(activeProject, str2, textTemplatePath, strs, true);
                string str3 = Path.ChangeExtension("_Layout", viewFileExtension);
                string str4 = Path.Combine(str, "Shared");
                if (!File.Exists(Path.Combine(ProjectExtensions.GetFullPath(base.Context.ActiveProject), str4, str3)))
                {
                    textTemplatePath = base.FilesLocatorService.GetTextTemplatePath("_Layout", this.SearchFolders, codeFileExtension);
                    ICodeGeneratorActionsService codeGeneratorActionsService = base.ActionsService;
                    Project project = base.Context.ActiveProject;
                    string  str5    = Path.Combine(str4, "_Layout");
                    Dictionary <string, object> strs1 = new Dictionary <string, object>()
                    {
                        { "IsBundleConfigPresent", isBundleConfigPresent },
                        { "JQueryVersion", this.Repository.GetPackageVersion(base.Context, NuGetPackages.JQueryNuGetPackageId) },
                        { "ModernizrVersion", this.Repository.GetPackageVersion(base.Context, NuGetPackages.ModernizrNuGetPackageId) }
                    };
                    codeGeneratorActionsService.AddFileFromTemplate(project, str5, textTemplatePath, strs1, true);
                    if (!base.Context.Items.ContainsProperty("MVC_IsLayoutPageCreated"))
                    {
                        base.Context.Items.AddProperty("MVC_IsLayoutPageCreated", true);
                    }
                    textTemplatePath = base.FilesLocatorService.GetTextTemplatePath("Site", this.SearchFolders, codeFileExtension);
                    Version assemblyVersion = ProjectReferences.GetAssemblyVersion(base.Context.ActiveProject, AssemblyVersions.MvcAssemblyName);
                    ICodeGeneratorActionsService actionsService1 = base.ActionsService;
                    Project activeProject1            = base.Context.ActiveProject;
                    string  str6                      = Path.Combine("Content", "Site");
                    Dictionary <string, object> strs2 = new Dictionary <string, object>()
                    {
                        { "MvcVersion", assemblyVersion }
                    };
                    actionsService1.AddFileFromTemplate(activeProject1, str6, textTemplatePath, strs2, true);
                }
            }
        }
        public static string GetProjectRelativePath(this ProjectItem projectItem)
        {
            Project containingProject = projectItem.ContainingProject;
            string  str      = null;
            string  fullPath = ProjectExtensions.GetFullPath(containingProject);

            fullPath = MvcProjectUtil.EnsureTrailingBackSlash(fullPath);
            string fullPath1 = ProjectExtensions.GetFullPath(projectItem);

            if (!string.IsNullOrEmpty(fullPath) && !string.IsNullOrEmpty(fullPath1))
            {
                str = CoreScaffoldingUtil.MakeRelativePath(fullPath1, fullPath);
            }
            return(str);
        }
        public static bool IsBundleConfigPresent(CodeGenerationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            Project activeProject    = context.ActiveProject;
            string  defaultNamespace = ProjectExtensions.GetDefaultNamespace(activeProject);

            if (context.ServiceProvider.GetService <ICodeTypeService>().GetCodeType(activeProject, string.Concat(defaultNamespace, ".BundleConfig")) != null)
            {
                return(true);
            }
            string str = string.Concat("BundleConfig.", ProjectExtensions.GetCodeLanguage(activeProject).CodeFileExtension);

            return(File.Exists(Path.Combine(ProjectExtensions.GetFullPath(activeProject), "App_Start", str)));
        }
Ejemplo n.º 9
0
 protected override void CreateStaticFilesAndFolders()
 {
     base.CreateStaticFilesAndFolders();
     base.ActionsService.AddFolder(base.Context.ActiveProject, "Models");
     if (!base.Context.Items.ContainsProperty("MVC_IsControllersFolderCreated") && !Directory.Exists(Path.Combine(ProjectExtensions.GetFullPath(base.Context.ActiveProject), "Controllers")))
     {
         base.Context.Items.AddProperty("MVC_IsControllersFolderCreated", true);
     }
     base.ActionsService.AddFolder(base.Context.ActiveProject, "Controllers");
     base.ActionsService.AddFolder(base.Context.ActiveProject, "Views");
 }