Пример #1
0
        public void GenerateStronglyTypedResourceResxDesignerAllResourcesTest()
        {
            var str = new StronglyTypedResources("c:\temp\resourceTest");
            var res = str.CreateResxDesignerClassesFromAllDatabaseResources("ResourceExport", @"c:\temp\resourceTest");

            Console.WriteLine(res);
        }
        public bool CreateClass(string filename = null, string nameSpace = null)
        {
        #if OnlineDemo
            throw new ApplicationException(WebUtils.GRes("FeatureDisabled"));
        #endif
            var config = DbResourceConfiguration.Current;

            StronglyTypedResources strongTypes =
                new StronglyTypedResources(Context.Request.PhysicalApplicationPath);

            if (string.IsNullOrEmpty(filename))
            {
                filename = HttpContext.Current.Server.MapPath(config.StronglyTypedGlobalResource);
            }

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

            strongTypes.CreateClassFromAllDatabaseResources(nameSpace, filename);

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

            return(true);
        }
Пример #3
0
        public void GenerateStronglyTypedResourceClassFilteredTest()
        {
            var str = new StronglyTypedResources(@"c:\temp");
            var res = str.CreateClassFromAllDatabaseResources("ResourceExport", @"resources.cs", new string[] { "Resources" });

            Console.WriteLine(res);
        }
Пример #4
0
        public void GenerateStronglyTypedDesignerClassFromResxFile()
        {
            var str = new StronglyTypedResources(@"c:\temp", configuration);
            var res = str.CreateClassFromAllDatabaseResources("ResourceExport", @"resources.cs", new[] { "Resources" });

            Console.WriteLine(res);
        }
        public void GenerateStronglyTypedResourceResxDesignerFilteredTest()
        {
            var str = new StronglyTypedResources("c:\temp");
            var res = str.CreateResxDesignerClassesFromAllDatabaseResources("ResourceExport", @"c:\temp\resourceTest", new string[] { "Resources" });

            Console.WriteLine(res);
        }
Пример #6
0
        public bool CreateClass(string filename = null, string nameSpace = null)
        {
            var config = DbResourceConfiguration.Current;

            StronglyTypedResources strongTypes = new StronglyTypedResources(m_webHostEnvironment.ContentRootPath);

            if (string.IsNullOrEmpty(filename))
            {
                filename = Path.Combine(m_webHostEnvironment.ContentRootPath, config.StronglyTypedGlobalResource);
            }

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

            // create all resources into this file and namespace
            strongTypes.CreateClassFromAllDatabaseResources(nameSpace, filename);

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

            return(true);
        }
Пример #7
0
        public void GenerateStronglyTypedResourceResxDesignerFilteredTest()
        {
            var str = new StronglyTypedResources(@"c:\temp", configuration);
            var res = str.CreateResxDesignerClassesFromAllDatabaseResources("ResourceExport", @"c:\temp\resourceTest",
                                                                            new[] { "Resources" });

            Console.WriteLine(res);
        }
        public void GenerateStronglyTypedDesignerClassFromResxFile()
        {
            string filename = @"c:\temp\resourceTest\LocalizationForm.resx";
            string designerFile = Path.ChangeExtension(filename, "designer.cs");
            if (File.Exists(designerFile))
                File.Delete(designerFile);

            var str = new StronglyTypedResources(@"c:\temp\resourceTest");
            str.CreateResxDesignerClassFromResxFile(filename,"LocalizationAdmin","Westwind.Globalization.Sample");

            Assert.IsTrue(File.Exists(designerFile));

        }
        public void GenerateStronglyTypedDesignerClassFromResxFile()
        {
            string filename     = @"c:\temp\resourceTest\LocalizationForm.resx";
            string designerFile = Path.ChangeExtension(filename, "designer.cs");

            if (File.Exists(designerFile))
            {
                File.Delete(designerFile);
            }

            var str = new StronglyTypedResources(@"c:\temp\resourceTest");

            str.CreateResxDesignerClassFromResxFile(filename, "LocalizationAdmin", "Westwind.Globalization.Sample");

            Assert.IsTrue(File.Exists(designerFile));
        }
        public bool CreateClass(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(Context.Request.PhysicalApplicationPath);

            if (string.IsNullOrEmpty(filename))
            {
                filename = HttpContext.Current.Server.MapPath(config.StronglyTypedGlobalResource);
            }

            else if (filename.StartsWith("~"))
            {
                filename = Context.Server.MapPath(filename);
            }

            filename = filename.Replace("/", "\\").Replace("\\\\", "\\");

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


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

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

                if (resourceSets == null || resourceSets.Length < 1)
                {
                    resourceSets = GetResourceSets().ToArray();
                }

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

                    var str = new StronglyTypedResources(null);
                    str.CreateResxDesignerClassFromResxFile(file, resource, nameSpace, false);
                }
            }

            return(true);
        }
        public bool CreateClass(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(Context.Request.PhysicalApplicationPath);

            if (string.IsNullOrEmpty(filename))
                filename = HttpContext.Current.Server.MapPath(config.StronglyTypedGlobalResource);

            else if (filename.StartsWith("~"))
                filename = Context.Server.MapPath(filename);

            filename = filename.Replace("/", "\\").Replace("\\\\", "\\");

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


            if (!string.IsNullOrEmpty(strongTypes.ErrorMessage))
                throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "StronglyTypedGlobalResourcesFailed"));

            if (classType != "Resx")
                strongTypes.CreateClassFromAllDatabaseResources(nameSpace, filename, resourceSets);
            else
            {
                string outputBasePath = filename;
                
                if (resourceSets == null || resourceSets.Length < 1)
                    resourceSets = GetResourceSets().ToArray();

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

                    var str = new StronglyTypedResources(null);

                    str.CreateResxDesignerClassFromResxFile(file, resource,
                        DbResourceConfiguration.Current.ResourceBaseNamespace, false);
                }
            }

            return true;
        }
        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);
        }
        public bool CreateClass([FromBody] CreateClassParams parms)
        {
#if OnlineDemo
            throw new WestwindException("Feature disabled");
#endif
//            throw new NotImplementedException();

            // { filename: "~/properties/resources.cs, nameSpace: "WebApp1", resourceSets: ["rs1","rs2"],classType: "DbRes|Resx"]
            var filename  = parms.FileName;
            var nameSpace = parms.NameSpace;
            var classType = parms.ClassType;

            var resourceSets = parms.ResourceSets;


            var strongTypes =
                new StronglyTypedResources(hostingEnvironment.ContentRootPath, configuration);

            if (string.IsNullOrEmpty(filename))
            {
                filename = Path.Combine(hostingEnvironment.ContentRootPath, configuration.StronglyTypedGlobalResource);
            }

            else if (filename.StartsWith("~"))
            {
                filename = Path.Combine(hostingEnvironment.ContentRootPath, filename);
            }

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


            if (!string.IsNullOrEmpty(strongTypes.ErrorMessage))
            {
                throw new WestwindException("Strongly typed global resources failed: " + strongTypes.ErrorMessage);
            }

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

                if (resourceSets == null || resourceSets.Length < 1)
                {
                    resourceSets = GetResourceSets().ToArray();
                }

                foreach (var resource in resourceSets)
                {
                    var file = Path.Combine(outputBasePath, resource + ".resx");

                    if (!hostingEnvironment.ContentRootFileProvider.GetFileInfo(file).Exists)
                    {
                        continue;
                    }

                    var str = new StronglyTypedResources(null, configuration);

                    str.CreateResxDesignerClassFromResxFile(file, resource,
                                                            configuration.ResourceBaseNamespace, false);
                }
            }

            return(true);
        }
        public bool CreateClass(string filename = null, string nameSpace = null)
        {
        #if OnlineDemo
            throw new ApplicationException(WebUtils.GRes("FeatureDisabled"));
        #endif
            var config = DbResourceConfiguration.Current;

            StronglyTypedResources strongTypes =
                new StronglyTypedResources(Context.Request.PhysicalApplicationPath);

            if (string.IsNullOrEmpty(filename))
                filename = HttpContext.Current.Server.MapPath(config.StronglyTypedGlobalResource);

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

            strongTypes.CreateClassFromAllDatabaseResources(nameSpace, filename);
            
            if (!string.IsNullOrEmpty(strongTypes.ErrorMessage))
                throw new ApplicationException(WebUtils.GRes(STR_RESOURCESET, "StronglyTypedGlobalResourcesFailed"));

            return true;
        }