Example #1
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);
        }
        protected override void AddTemplateParameters(IDictionary <string, object> templateParameters)
        {
            base.AddTemplateParameters(templateParameters);
            CodeType      codeType = base.Model.ModelType.CodeType;
            ModelMetadata codeModelModelMetadatum = new CodeModelModelMetadata(codeType);

            if ((int)codeModelModelMetadatum.PrimaryKeys.Length == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The entity type '{0}' has no key defined. Define a key for this entity type.", codeType.Name));
            }
            templateParameters.Add("ModelMetadata", codeModelModelMetadatum);
            List <CodeType> codeTypes = new List <CodeType>()
            {
                codeType
            };

            templateParameters.Add("RequiredNamespaces", base.GetRequiredNamespaces(codeTypes));
            templateParameters.Add("ModelTypeNamespace", (codeType.Namespace != null ? codeType.Namespace.FullName : string.Empty));
            templateParameters.Add("ModelTypeName", codeType.Name);
            templateParameters.Add("UseAsync", base.Model.IsAsyncSelected);
            IEntityFrameworkService service = base.Context.ServiceProvider.GetService <IEntityFrameworkService>();
            string pluralizedWord           = service.GetPluralizedWord(codeType.Name, CultureInfo.InvariantCulture);

            templateParameters.Add("EntitySetName", pluralizedWord);
            CodeDomProvider codeDomProvider = ValidationUtil.GenerateCodeDomProvider(ProjectExtensions.GetCodeLanguage(base.Model.ActiveProject));
            string          str             = codeDomProvider.CreateEscapedIdentifier(codeType.Name.ToLowerInvariantFirstChar());
            string          str1            = codeDomProvider.CreateEscapedIdentifier(pluralizedWord.ToLowerInvariantFirstChar());

            templateParameters.Add("ModelVariable", str);
            templateParameters.Add("EntitySetVariable", str1);
            templateParameters.Add("ODataModificationMessage", "The WebApiConfig class may require additional changes to add a route for this controller. Merge these statements into the Register method of the WebApiConfig class as applicable. Note that OData URLs are case sensitive.");

            templateParameters.Add("IsLegacyOdataVersion", base.Framework.IsODataLegacy(base.Context));
        }
        protected override FrameworkDependencyStatus GenerateConfiguration()
        {
            object obj  = null;
            object obj1 = null;

            base.Context.Items.TryGetProperty <object>("MVC_IsODataAssemblyReferenced", out obj);
            base.Context.Items.TryGetProperty <object>("MVC_IsWebApiAssemblyReferenced", out obj1);
            bool flag  = !(bool)obj;
            bool flag1 = !(bool)obj1;
            bool flag2 = base.TryCreateGlobalAsax();

            if (flag2 && flag)
            {
                return(FrameworkDependencyStatus.FromReadme(ODataReadMe.CreateReadMeText()));
            }
            if (!flag2)
            {
                string empty = string.Empty;
                if (flag)
                {
                    empty = string.Concat(empty, ODataReadMe.CreateReadMeText());
                }
                if (flag1)
                {
                    WebApiReadMe webApiReadMe = new WebApiReadMe(ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject), base.Context.ActiveProject.Name, base.AppStartFileNames);
                    empty = string.Concat(empty, webApiReadMe.CreateReadMeText());
                }
                if (!string.IsNullOrEmpty(empty))
                {
                    return(FrameworkDependencyStatus.FromReadme(empty));
                }
            }
            return(FrameworkDependencyStatus.InstallSuccessful);
        }
Example #4
0
        private static bool IsApplicableProject(CodeGenerationContext context)
        {
            FrameworkName targetFramework;
            bool          flag;

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if ((object)ProjectLanguage.CSharp == (object)ProjectExtensions.GetCodeLanguage(context.ActiveProject) || (object)ProjectLanguage.VisualBasic == (object)ProjectExtensions.GetCodeLanguage(context.ActiveProject))
            {
                targetFramework = null;
                try
                {
                    targetFramework = ProjectExtensions.GetTargetFramework(context.ActiveProject);
                    goto Label0;
                }
                catch
                {
                    flag = false;
                }
                return(flag);
            }
            return(false);

Label0:
            if (targetFramework != null && targetFramework.Identifier == ".NETFramework" && targetFramework.Version >= new Version(4, 5))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        protected void GenerateWebConfig(bool isBundleConfigPresent)
        {
            IDictionary <string, object> templateParametersForWebConfig = AddDependencyUtil.GetTemplateParametersForWebConfig(isBundleConfigPresent, base.Context);
            string codeFileExtension = ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject).CodeFileExtension;
            string str = Path.Combine("Views", "web");
            string textTemplatePath = base.FilesLocatorService.GetTextTemplatePath("web", this.SearchFolders, codeFileExtension);

            base.ActionsService.AddFileFromTemplate(base.Context.ActiveProject, str, textTemplatePath, templateParametersForWebConfig, true);
        }
Example #6
0
        protected override FrameworkDependencyStatus GenerateConfiguration()
        {
            if (base.TryCreateGlobalAsax())
            {
                return(FrameworkDependencyStatus.InstallSuccessful);
            }
            WebApiReadMe webApiReadMe = new WebApiReadMe(ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject), base.Context.ActiveProject.Name, base.AppStartFileNames);

            return(FrameworkDependencyStatus.FromReadme(webApiReadMe.CreateReadMeText()));
        }
Example #7
0
        protected override void CreateStaticFilesAndFolders()
        {
            base.CreateStaticFilesAndFolders();
            string viewFileExtension = MvcProjectUtil.GetViewFileExtension(ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject));
            string str = Path.Combine("Views", "Shared");

            base.ActionsService.AddFolder(base.Context.ActiveProject, str);
            string str1 = Path.ChangeExtension("Error", viewFileExtension);

            base.ActionsService.AddFile(base.Context.ActiveProject, Path.Combine(str, str1), base.FilesLocatorService.GetStaticFilePath(str1, this.SearchFolders), true);
        }
Example #8
0
        private void SelectLayout(object unused)
        {
            string          masterPageVbHtmlFilter;
            string          str;
            ProjectLanguage codeLanguage = ProjectExtensions.GetCodeLanguage(this.Model.ActiveProject);

            masterPageVbHtmlFilter = ResourcesExt.MasterPageCsHtmlFilter;
            if (this.DialogHost.TrySelectFile(this.Model.ActiveProject, ResourcesExt.LayoutPageSelectorHeading, masterPageVbHtmlFilter, "WebStackScaffolding_LayoutPageFile", out str))
            {
                this.LayoutPageFile = str;
            }
        }
Example #9
0
        private void SelectLayout(object unused)
        {
            string          masterPageVbHtmlFilter;
            string          str;
            ProjectLanguage codeLanguage = ProjectExtensions.GetCodeLanguage(this.Model.ActiveProject);

            masterPageVbHtmlFilter = "Layout Pages (*.cshtml)|*.cshtml";

            if (this.DialogHost.TrySelectFile(this.Model.ActiveProject, "Select a Layout Page", masterPageVbHtmlFilter, "WebStackScaffolding_LayoutPageFile", out str))
            {
                this.LayoutPageFile = str;
            }
        }
Example #10
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);
                }
            }
        }
Example #11
0
        private void AddTemplates(HashSet <ViewTemplate> templates, string directory, bool isModelRequired)
        {
            if (!Directory.Exists(directory))
            {
                return;
            }
            string str = string.Concat(".", ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject).CodeFileExtension, ".t4");

            foreach (string str1 in Directory.EnumerateFiles(directory, string.Concat("*", str)))
            {
                string fileName = Path.GetFileName(str1);
                string str2     = fileName.Substring(0, fileName.LastIndexOf(str, StringComparison.OrdinalIgnoreCase));
                templates.Add(new ViewTemplate(str2, isModelRequired));
            }
        }
        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)));
        }
        protected virtual IDictionary <string, object> AddTemplateParameters(CodeType dbContextType, ModelMetadata modelMetadata)
        {
            if (dbContextType == null)
            {
                throw new ArgumentNullException("dbContextType");
            }
            if (modelMetadata == null)
            {
                throw new ArgumentNullException("modelMetadata");
            }
            if (string.IsNullOrEmpty(base.Model.ControllerName))
            {
                throw new InvalidOperationException("The controller name is invalid.");
            }
            IDictionary <string, object> strs = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            CodeType codeType = base.Model.ModelType.CodeType;

            strs.Add("ModelMetadata", modelMetadata);
            strs.Add("ModelTypeNamespace", (codeType.Namespace != null ? codeType.Namespace.FullName : string.Empty));
            List <CodeType> codeTypes = new List <CodeType>()
            {
                codeType,
                dbContextType
            };

            strs.Add("RequiredNamespaces", base.GetRequiredNamespaces(codeTypes));
            strs.Add("ModelTypeName", codeType.Name);
            strs.Add("ContextTypeName", dbContextType.Name);
            strs.Add("UseAsync", base.Model.IsAsyncSelected);
            CodeDomProvider codeDomProvider = ValidationUtil.GenerateCodeDomProvider(ProjectExtensions.GetCodeLanguage(base.Model.ActiveProject));
            string          str             = codeDomProvider.CreateEscapedIdentifier(base.Model.ModelType.ShortTypeName.ToLowerInvariantFirstChar());

            strs.Add("ModelVariable", str);
            strs.Add("EntitySetVariable", modelMetadata.EntitySetName.ToLowerInvariantFirstChar());
            if (base.Model.IsViewGenerationSupported)
            {
                bool flag = OverpostingProtection.IsOverpostingProtectionRequired(codeType);
                strs.Add("IsOverpostingProtectionRequired", flag);
                if (flag)
                {
                    strs.Add("OverpostingWarningMessage", OverpostingProtection.WarningMessage);
                    strs.Add("BindAttributeIncludeText", OverpostingProtection.GetBindAttributeIncludeText(modelMetadata));
                }
            }
            return(strs);
        }
Example #14
0
        private void GenerateT4File(string templateName, string outputFileName, string path)
        {
            IDictionary <string, object> strs = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
            {
                { "Namespace", ProjectExtensions.GetDefaultNamespace(this.Context.ActiveProject) }
            };

            foreach (KeyValuePair <string, string> appStartFileName in this.AppStartFileNames)
            {
                strs.Add(appStartFileName.Key, appStartFileName.Value);
            }
            string codeFileExtension = ProjectExtensions.GetCodeLanguage(this.Context.ActiveProject).CodeFileExtension;
            string str = Path.Combine(path, outputFileName);
            string textTemplatePath = this.FilesLocatorService.GetTextTemplatePath(templateName, this.SearchFolders, codeFileExtension);

            this.ActionsService.AddFileFromTemplate(this.Context.ActiveProject, str, textTemplatePath, strs, true);
        }
Example #15
0
        protected HashSet <string> GetRequiredNamespaces(IEnumerable <CodeType> codeTypes)
        {
            string fullName;

            if (codeTypes == null)
            {
                throw new ArgumentNullException("codeTypes");
            }
            SortedSet <string> strs = ControllerScaffolder <TFramework> .CreateHashSetBasedOnCodeLanguage(ProjectExtensions.GetCodeLanguage(base.Context.ActiveProject));

            strs.Add(base.Model.ControllerNamespace);
            foreach (CodeType codeType in codeTypes)
            {
                if (codeType.Namespace == null)
                {
                    fullName = null;
                }
                else
                {
                    fullName = codeType.Namespace.FullName;
                }
                string str = fullName;
                if (string.IsNullOrEmpty(str))
                {
                    if (string.Equals(codeType.FullName, codeType.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    int    num  = codeType.FullName.LastIndexOf(string.Concat(".", codeType.Name), StringComparison.Ordinal);
                    string str1 = codeType.FullName.Remove(num);
                    strs.Add(str1);
                }
                else
                {
                    strs.Add(str);
                }
            }
            strs.Remove(base.Model.ControllerNamespace);
            return(new HashSet <string>(strs));
        }
        public string GenerateDefaultDataContextTypeName()
        {
            Project         activeProject          = base.ActiveProject;
            string          defaultModelsNamespace = MvcProjectUtil.GetDefaultModelsNamespace(ProjectExtensions.GetDefaultNamespace(activeProject));
            CodeDomProvider codeDomProvider        = ValidationUtil.GenerateCodeDomProvider(ProjectExtensions.GetCodeLanguage(activeProject));
            string          str = codeDomProvider.CreateValidIdentifier(ProjectExtensions.GetDefaultNamespace(activeProject).Replace(".", string.Empty));

            this.DataContextName = string.Concat(defaultModelsNamespace, ".", str, MvcProjectUtil.DataContextSuffix);
            return(this.DataContextName);
        }
 public string GetErrorIfInvalidIdentifier(string text)
 {
     return(ValidationUtil.GetErrorIfInvalidIdentifier(text, ProjectExtensions.GetCodeLanguage(this.ActiveProject)));
 }