コード例 #1
0
        /// <summary>
        /// Imports Resources recursively from a non-Web project
        /// </summary>
        /// <param name="basePhysicalPath">The physical path to the directory</param>
        /// <param name="baseNamespace">The base namespace in the project to prefix InternalResourceSets with</param>
        /// <returns></returns>
        public bool ImportWinResources(string basePhysicalPath)
        {
            if (basePhysicalPath == null)
            {
                basePhysicalPath = BasePhysicalPath;
            }

            // basePhysicalPath = basePhysicalPath.ToLower();
            if (!basePhysicalPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                basePhysicalPath += Path.DirectorySeparatorChar;
            }

            // We need to create a Web relative path (ie. admin/myresources.resx)
            string relPath = basePhysicalPath.Replace(BasePhysicalPath, "");

            relPath = DbResourceUtils.NormalizePath(relPath);

            // Import the base path first
            ImportDirectoryResources(basePhysicalPath, relPath);

            // Recurse into child folders
            string[] directories;
            try
            {
                directories = Directory.GetDirectories(basePhysicalPath);
            }
            catch
            {
                return(false);
            }

            foreach (string dirString in directories)
            {
                DirectoryInfo directory = new DirectoryInfo(dirString);

                string dir = directory.Name;

                if (dir == "" || ("|bin|obj|.git|.svn|_svn|app_code|app_themes|app_data|migrations|node_modules|bower_components|".Contains("|" + dir.ToLower() + "|")))
                {
                    continue;
                }

                ImportWinResources(basePhysicalPath + dir + Path.DirectorySeparatorChar);
            }

            return(true);
        }
        public bool ImportResxResources(string inputBasePath = null)
        {
#if OnlineDemo
            throw new ApplicationException(WebUtils.GRes("FeatureDisabled"));
#endif

            if (string.IsNullOrEmpty(inputBasePath))
            {
                inputBasePath = DbResourceConfiguration.Current.ResxBaseFolder;
            }

            if (inputBasePath.Contains("~"))
            {
                inputBasePath = Request.MapPath(inputBasePath, basePath: Host.ContentRootPath);
            }

            inputBasePath = DbResourceUtils.NormalizePath(inputBasePath);

            DbResXConverter converter = new DbResXConverter(inputBasePath);

            bool res = false;

            if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms)
            {
                res = converter.ImportWebResources(inputBasePath);
            }
            else
            {
                res = converter.ImportWinResources(inputBasePath);
            }

            if (!res)
            {
                new ApplicationException(DbIRes.T("ResourceImportFailed", STR_RESOURCESET));
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Returns the path the resource file withouth the resx and localeId extension
        /// </summary>
        /// <param name="resourceSet"></param>
        /// <param name="LocalResources"></param>
        /// <returns></returns>
        public string FormatResourceSetPath(string resourceSet)
        {
            string path;

            if (string.IsNullOrEmpty(BasePhysicalPath) &&
                DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.Project)
            {
                path = DbResourceConfiguration.Current.ResxBaseFolder;
                if (path.StartsWith("~"))
                {
                    path = DbResourceUtils.NormalizePath(path.Replace("~", BasePhysicalPath));
                }
            }
            else
            {
                path = BasePhysicalPath;
            }

            resourceSet = Path.Combine(path, resourceSet);


            if (IsLocalResourceSet(resourceSet) && !resourceSet.Contains("App_LocalResources"))
            {
                string pathOnly = Path.GetDirectoryName(resourceSet);
                string fileOnly = Path.GetFileName(resourceSet);

                resourceSet = Path.Combine(pathOnly, "App_LocalResources", fileOnly);
            }

            FileInfo fi = new FileInfo(resourceSet);

            if (!fi.Directory.Exists)
            {
                fi.Directory.Create();
            }

            return(resourceSet);
        }
        public bool CreateClass([FromBody] dynamic parms)
        {
#if OnlineDemo
            throw new ApplicationException(WebUtils.GRes("FeatureDisabled"));
#endif
            var config = DbResourceConfiguration.Current;

            // { filename: "~/properties/resources.cs, nameSpace: "WebApp1", resourceSets: ["rs1","rs2"],classType: "DbRes|Resx"]
            string filename  = parms["fileName"];
            string nameSpace = parms["namespace"];
            string classType = parms["classType"];
            JArray rs        = parms["resourceSets"] as JArray;

            string[] resourceSets = null;
            if (rs != null)
            {
                resourceSets = rs.ToObject <string[]>();
                if (resourceSets != null && resourceSets.Length == 1 && string.IsNullOrEmpty(resourceSets[0]))
                {
                    resourceSets = null;
                }
            }


            StronglyTypedResources strongTypes =
                new StronglyTypedResources(Request.MapPath("~/", basePath: Host.ContentRootPath));

            if (string.IsNullOrEmpty(filename))
            {
                filename = Request.MapPath(config.StronglyTypedGlobalResource, basePath: Host.ContentRootPath);
            }

            else if (filename.StartsWith("~"))
            {
                filename = Request.MapPath(filename, basePath: Host.ContentRootPath);
            }

            filename = DbResourceUtils.NormalizePath(filename);

            if (string.IsNullOrEmpty(nameSpace))
            {
                nameSpace = config.ResourceBaseNamespace;
            }

            if (!string.IsNullOrEmpty(strongTypes.ErrorMessage))
            {
                throw new ApplicationException(DbIRes.T("StronglyTypedGlobalResourcesFailed", STR_RESOURCESET));
            }

            if (classType != "Resx")
            {
                strongTypes.CreateClassFromAllDatabaseResources(nameSpace, filename, resourceSets);
            }
            else
            {
                string outputBasePath = filename;

                if (resourceSets == null || resourceSets.Length < 1)
                {
                    resourceSets = Manager.GetAllResourceSets(ResourceListingTypes.AllResources).ToArray();
                }

                foreach (var resource in resourceSets)
                {
                    string file = Path.Combine(outputBasePath, resource + ".resx");
                    if (!System.IO.File.Exists(file))
                    {
                        continue;
                    }


                    var str = new StronglyTypedResources(null);
#if NETFULL
                    // Use automated generation
                    str.CreateResxDesignerClassFromResxFile(file, resource, nameSpace, false);
#else
                    // Manual code generation
                    str.CreateResxDesignerClassFromResourceSet(resource, nameSpace, resource, file);
#endif
                }
            }

            return(true);
        }