示例#1
0
 public bool IsDependencyInstalled(CodeGenerationContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     return(ProjectReferences.IsAssemblyReferenced(context.ActiveProject, AssemblyVersions.MvcAssemblyName));
 }
示例#2
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);
                }
            }
        }
示例#3
0
        internal static void GetPackageFileNameForPackage(CodeGenerationContext context, IEnumerable <IVsPackageMetadata> installedPackages, string packageId, string assemblyReferenceName, Version minSupportedAssemblyReferenceVersion, ref string packageFileName)
        {
            Version assemblyVersion;

            if (ProjectReferences.IsAssemblyReferenced(context.ActiveProject, assemblyReferenceName))
            {
                IVsPackageMetadata variable = (
                    from package in installedPackages
                    where string.Equals(packageId, package.Id, StringComparison.OrdinalIgnoreCase)
                    select package).FirstOrDefault <IVsPackageMetadata>();
                if (variable == null || !SemanticVersionParser.TryParse(variable.VersionString, out assemblyVersion))
                {
                    assemblyVersion = ProjectReferences.GetAssemblyVersion(context.ActiveProject, assemblyReferenceName);
                }
                if (assemblyVersion >= minSupportedAssemblyReferenceVersion && assemblyVersion <= PackageVersions._latestKnownPackageVersion)
                {
                    packageFileName = PackageVersions.GetPackageVersionsFileName(assemblyVersion);
                }
            }
        }
示例#4
0
        private IDictionary <string, object> AddViewTemplateParameters(ModelMetadata modelMetadata, CodeGenerationContext context)
        {
            if (modelMetadata == null)
            {
                throw new ArgumentNullException("modelMetadata");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (string.IsNullOrEmpty(base.Model.ViewName))
            {
                throw new InvalidOperationException("The view name is invalid.");
            }
            IDictionary <string, object> strs = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
            {
                { "ModelMetadata", modelMetadata },
                { "ViewName", base.Model.ViewName },
                { "LayoutPageFile", base.Model.LayoutPageFile ?? string.Empty },
                { "IsPartialView", base.Model.IsPartialViewSelected },
                { "IsLayoutPageSelected", base.Model.IsLayoutPageSelected },
                { "ReferenceScriptLibraries", base.Model.IsReferenceScriptLibrariesSelected },
                { "IsBundleConfigPresent", AddDependencyUtil.IsBundleConfigPresent(context) },
                { "JQueryVersion", base.Repository.GetPackageVersion(base.Context, NuGetPackages.JQueryNuGetPackageId) }
            };
            Version assemblyVersion = ProjectReferences.GetAssemblyVersion(base.Context.ActiveProject, AssemblyVersions.MvcAssemblyName);

            strs.Add("MvcVersion", assemblyVersion);
            if (base.Model.ModelType != null)
            {
                CodeType codeType = base.Model.ModelType.CodeType;
                strs.Add("ViewDataTypeName", codeType.FullName);
                strs.Add("ViewDataTypeShortName", codeType.Name);
                strs.Add("ViewDataType", codeType);
            }
            else
            {
                strs.Add("ViewDataTypeName", string.Empty);
            }
            return(strs);
        }
        public static IDictionary <string, object> GetTemplateParametersForWebConfig(bool isBundleConfigPresent, CodeGenerationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            string defaultNamespace           = ProjectExtensions.GetDefaultNamespace(context.ActiveProject);
            Dictionary <string, object> strs  = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            HashSet <string>            strs1 = new HashSet <string>(StringComparer.Ordinal);

            if (isBundleConfigPresent)
            {
                strs1.Add("System.Web.Optimization");
            }
            strs1.Add(defaultNamespace);
            strs.Add("RequiredNamespaces", strs1);
            Version assemblyVersion = ProjectReferences.GetAssemblyVersion(context.ActiveProject, AssemblyVersions.MvcAssemblyName);

            strs["MvcVersion"] = assemblyVersion;
            return(strs);
        }