Example #1
0
        Assembly CompileLocal()
        {
            if (String.IsNullOrEmpty(virtualPath))
            {
                return(null);
            }

            Assembly cached = GetCachedLocalResourcesAssembly(virtualPath);

            if (cached != null)
            {
                return(cached);
            }

            string prefix;

            if (virtualPath == "/")
            {
                prefix = "App_LocalResources.root";
            }
            else
            {
                prefix = "App_LocalResources" + virtualPath.Replace('/', '.');
            }

            string assemblyPath = FileUtils.CreateTemporaryFile(TempDirectory,
                                                                prefix,
                                                                "dll",
                                                                OnCreateRandomFile) as string;

            if (assemblyPath == null)
            {
                throw new ApplicationException("Failed to create local resources assembly");
            }

            List <AppResourceFileInfo> files = this.files.Files;

            foreach (AppResourceFileInfo arfi in files)
            {
                GetResourceFile(arfi, true);
            }

            AppResourcesAssemblyBuilder builder = new AppResourcesAssemblyBuilder("App_LocalResources", assemblyPath,
                                                                                  this);

            builder.Build();
            Assembly ret = builder.MainAssembly;

            if (ret != null)
            {
                AddAssemblyToCache(virtualPath, ret);
            }

            return(ret);
        }
Example #2
0
        Assembly CompileGlobal()
        {
            string assemblyPath = FileUtils.CreateTemporaryFile(TempDirectory,
                                                                "App_GlobalResources",
                                                                "dll",
                                                                OnCreateRandomFile) as string;

            if (assemblyPath == null)
            {
                throw new ApplicationException("Failed to create global resources assembly");
            }

            List <string>[] fileGroups = GroupGlobalFiles();
            if (fileGroups == null || fileGroups.Length == 0)
            {
                return(null);
            }

            CodeCompileUnit unit = new CodeCompileUnit();
            CodeNamespace   ns   = new CodeNamespace(null);

            ns.Imports.Add(new CodeNamespaceImport("System"));
            ns.Imports.Add(new CodeNamespaceImport("System.Globalization"));
            ns.Imports.Add(new CodeNamespaceImport("System.Reflection"));
            ns.Imports.Add(new CodeNamespaceImport("System.Resources"));
            unit.Namespaces.Add(ns);

            AppResourcesAssemblyBuilder builder = new AppResourcesAssemblyBuilder("App_GlobalResources", assemblyPath,
                                                                                  this);
            CodeDomProvider provider = builder.Provider;

            Dictionary <string, bool> assemblies = new Dictionary <string, bool> ();

            foreach (List <string> ls in fileGroups)
            {
                DomFromResource(ls [0], unit, assemblies, provider);
            }

            foreach (KeyValuePair <string, bool> de in assemblies)
            {
                unit.ReferencedAssemblies.Add(de.Key);
            }

            builder.Build(unit);
            HttpContext.AppGlobalResourcesAssembly = builder.MainAssembly;

            return(builder.MainAssembly);
        }
		Assembly CompileLocal ()
		{
			if (String.IsNullOrEmpty (virtualPath))
				return null;
			
			Assembly cached = GetCachedLocalResourcesAssembly (virtualPath);
			if (cached != null)
				return cached;
			
			string prefix;
			if (virtualPath == "/")
				prefix = "App_LocalResources.root";
			else
				prefix = "App_LocalResources" + virtualPath.Replace ('/', '.');
			
			string assemblyPath = FileUtils.CreateTemporaryFile (TempDirectory,
									     prefix,
									     "dll",
									     OnCreateRandomFile) as string;
			if (assemblyPath == null)
				throw new ApplicationException ("Failed to create local resources assembly");

			List<AppResourceFileInfo> files = this.files.Files;
			foreach (AppResourceFileInfo arfi in files)
				GetResourceFile (arfi, true);

			AppResourcesAssemblyBuilder builder = new AppResourcesAssemblyBuilder ("App_LocalResources", assemblyPath,
											       this);
			builder.Build ();
			Assembly ret = builder.MainAssembly;
			
			if (ret != null)
				AddAssemblyToCache (virtualPath, ret);

			return ret;
		}
		Assembly CompileGlobal ()
		{
			string assemblyPath = FileUtils.CreateTemporaryFile (TempDirectory,
									     "App_GlobalResources",
									     "dll",
									     OnCreateRandomFile) as string;

			if (assemblyPath == null)
				throw new ApplicationException ("Failed to create global resources assembly");
			
			List <string>[] fileGroups = GroupGlobalFiles ();
			if (fileGroups == null || fileGroups.Length == 0)
				return null;
			
			CodeCompileUnit unit = new CodeCompileUnit ();
			CodeNamespace ns = new CodeNamespace (null);
			ns.Imports.Add (new CodeNamespaceImport ("System"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Globalization"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Reflection"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Resources"));
			unit.Namespaces.Add (ns);

			AppResourcesAssemblyBuilder builder = new AppResourcesAssemblyBuilder ("App_GlobalResources", assemblyPath,
											       this);
			CodeDomProvider provider = builder.Provider;
			
			Dictionary <string,bool> assemblies = new Dictionary<string,bool> ();
			foreach (List<string> ls in fileGroups)
				DomFromResource (ls [0], unit, assemblies, provider);
			
			foreach (KeyValuePair<string,bool> de in assemblies)
				unit.ReferencedAssemblies.Add (de.Key);
			
			builder.Build (unit);
			HttpContext.AppGlobalResourcesAssembly = builder.MainAssembly;
			
			return builder.MainAssembly;
		}