示例#1
0
        bool CollectFiles(string dir, AppCodeAssembly aca)
        {
            bool haveFiles = false;

            AppCodeAssembly curaca = aca;

            foreach (string f in Directory.GetFiles(dir))
            {
                aca.AddFile(f);
                haveFiles = true;
            }

            foreach (string d in Directory.GetDirectories(dir))
            {
                foreach (AppCodeAssembly a in assemblies)
                {
                    if (a.SourcePath == d)
                    {
                        curaca = a;
                        break;
                    }
                }
                if (CollectFiles(d, curaca))
                {
                    haveFiles = true;
                }
                curaca = aca;
            }
            return(haveFiles);
        }
示例#2
0
        // FIXME: there should be some validation of syntactic correctness of the member/class name
        // for the groups/properties. For now it's left to the compiler to report errors.
        //
        // CodeGenerator.IsValidLanguageIndependentIdentifier (id) - use that
        //
        bool ProcessCustomProfile(ProfileSection ps, AppCodeAssembly defasm)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            CodeNamespace   ns   = new CodeNamespace(null);

            unit.Namespaces.Add(ns);
            defasm.AddUnit(unit);

            ns.Imports.Add(new CodeNamespaceImport("System"));
            ns.Imports.Add(new CodeNamespaceImport("System.Configuration"));
            ns.Imports.Add(new CodeNamespaceImport("System.Web"));
            ns.Imports.Add(new CodeNamespaceImport("System.Web.Profile"));

            RootProfilePropertySettingsCollection props = ps.PropertySettings;

            if (props == null)
            {
                return(true);
            }

            SortedList <string, string> groupProperties = new SortedList <string, string> ();
            string groupName;

            foreach (ProfileGroupSettings pgs in props.GroupSettings)
            {
                groupName = MakeGroupName(pgs.Name);
                groupProperties.Add(groupName, pgs.Name);
                BuildProfileClass(ps, groupName, pgs.PropertySettings, ns,
                                  "System.Web.Profile.ProfileGroupBase", true, null);
            }

            string baseType = ps.Inherits;

            if (String.IsNullOrEmpty(baseType))
            {
                baseType = "System.Web.Profile.ProfileBase";
            }
            else
            {
                string[] parts = baseType.Split(new char[] { ',' });
                if (parts.Length > 1)
                {
                    baseType = parts [0].Trim();
                }
            }

            bool baseIsGlobal;

            if (baseType.IndexOf('.') != -1)
            {
                baseIsGlobal = true;
            }
            else
            {
                baseIsGlobal = false;
            }

            BuildProfileClass(ps, "ProfileCommon", props, ns, baseType, baseIsGlobal, groupProperties);
            return(true);
        }
示例#3
0
        bool ProcessAppCodeDir(string appCode, AppCodeAssembly defasm)
        {
            // First process the codeSubDirectories
            CompilationSection cs = (CompilationSection)WebConfigurationManager.GetWebApplicationSection("system.web/compilation");

            if (cs != null)
            {
                string aname;
                for (int i = 0; i < cs.CodeSubDirectories.Count; i++)
                {
                    aname = String.Concat("App_SubCode_", cs.CodeSubDirectories[i].DirectoryName);
                    assemblies.Add(new AppCodeAssembly(
                                       aname,
                                       Path.Combine(appCode, cs.CodeSubDirectories[i].DirectoryName)));
                }
            }

            return(CollectFiles(appCode, defasm));
        }
示例#4
0
        public void Compile()
        {
            if (_alreadyCompiled)
            {
                return;
            }

            string         appCode           = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Code");
            ProfileSection ps                = WebConfigurationManager.GetWebApplicationSection("system.web/profile") as ProfileSection;
            bool           haveAppCodeDir    = Directory.Exists(appCode);
            bool           haveCustomProfile = HaveCustomProfile(ps);

            if (!haveAppCodeDir && !haveCustomProfile)
            {
                return;
            }

            AppCodeAssembly defasm = new AppCodeAssembly("App_Code", appCode);

            assemblies.Add(defasm);

            bool haveCode = false;

            if (haveAppCodeDir)
            {
                haveCode = ProcessAppCodeDir(appCode, defasm);
            }
            if (haveCustomProfile)
            {
                if (ProcessCustomProfile(ps, defasm))
                {
                    haveCode = true;
                }
            }

            if (!haveCode)
            {
                return;
            }

            HttpRuntime.EnableAssemblyMapping(true);
            string[] binAssemblies = HttpApplication.BinDirectoryAssemblies;

            foreach (AppCodeAssembly aca in assemblies)
            {
                aca.Build(binAssemblies);
            }
            _alreadyCompiled           = true;
            DefaultAppCodeAssemblyName = Path.GetFileNameWithoutExtension(defasm.OutputAssemblyName);

            RunAppInitialize();

            if (haveCustomProfile && providerTypeName != null)
            {
                if (Type.GetType(providerTypeName, false) == null)
                {
                    foreach (Assembly asm in BuildManager.TopLevelAssemblies)
                    {
                        if (asm == null)
                        {
                            continue;
                        }

                        if (asm.GetType(providerTypeName, false) != null)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }

                Exception noTypeException = null;
                Type      ptype           = null;

                try {
                    ptype = HttpApplication.LoadTypeFromBin(providerTypeName);
                } catch (Exception ex) {
                    noTypeException = ex;
                }

                if (ptype == null)
                {
                    throw new HttpException(String.Format("Profile provider type not found: {0}", providerTypeName), noTypeException);
                }
            }
        }
示例#5
0
		bool CollectFiles (string dir, AppCodeAssembly aca)
		{
			bool haveFiles = false;
			
			AppCodeAssembly curaca = aca;
			foreach (string f in Directory.GetFiles (dir)) {
				aca.AddFile (f);
				haveFiles = true;
			}
			
			foreach (string d in Directory.GetDirectories (dir)) {
				foreach (AppCodeAssembly a in assemblies)
					if (a.SourcePath == d) {
						curaca = a;
						break;
					}
				if (CollectFiles (d, curaca))
					haveFiles = true;
				curaca = aca;
			}
			return haveFiles;
		}
示例#6
0
		public void Compile ()
		{
			if (_alreadyCompiled)
				return;
			
			string appCode = Path.Combine (HttpRuntime.AppDomainAppPath, "App_Code");
			ProfileSection ps = WebConfigurationManager.GetWebApplicationSection ("system.web/profile") as ProfileSection;
			bool haveAppCodeDir = Directory.Exists (appCode);
			bool haveCustomProfile = HaveCustomProfile (ps);
			
			if (!haveAppCodeDir && !haveCustomProfile)
				return;

			AppCodeAssembly defasm = new AppCodeAssembly ("App_Code", appCode);
			assemblies.Add (defasm);

			bool haveCode = false;
			if (haveAppCodeDir)
				haveCode = ProcessAppCodeDir (appCode, defasm);
			if (haveCustomProfile)
				if (ProcessCustomProfile (ps, defasm))
					haveCode = true;

			if (!haveCode)
				return;
			
			HttpRuntime.EnableAssemblyMapping (true);
			string[] binAssemblies = HttpApplication.BinDirectoryAssemblies;
			
			foreach (AppCodeAssembly aca in assemblies)
				aca.Build (binAssemblies);
			_alreadyCompiled = true;
			DefaultAppCodeAssemblyName = Path.GetFileNameWithoutExtension (defasm.OutputAssemblyName);

			RunAppInitialize ();
			
			if (haveCustomProfile && providerTypeName != null) {
				if (Type.GetType (providerTypeName, false) == null) {
					foreach (Assembly asm in BuildManager.TopLevelAssemblies) {
						if (asm == null)
							continue;
						
						if (asm.GetType (providerTypeName, false) != null)
							return;
					}
				} else
					return;

				Exception noTypeException = null;
				Type ptype = null;
				
				try {
					ptype = HttpApplication.LoadTypeFromBin (providerTypeName);
				} catch (Exception ex) {
					noTypeException = ex;
				}

				if (ptype == null)
					throw new HttpException (String.Format ("Profile provider type not found: {0}", providerTypeName), noTypeException);
			}
		}
示例#7
0
		// FIXME: there should be some validation of syntactic correctness of the member/class name
		// for the groups/properties. For now it's left to the compiler to report errors.
		//
		// CodeGenerator.IsValidLanguageIndependentIdentifier (id) - use that
		//
		bool ProcessCustomProfile (ProfileSection ps, AppCodeAssembly defasm)
		{
			CodeCompileUnit unit = new CodeCompileUnit ();
			CodeNamespace ns = new CodeNamespace (null);
			unit.Namespaces.Add (ns);
			defasm.AddUnit (unit);
			
			ns.Imports.Add (new CodeNamespaceImport ("System"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Configuration"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Web"));
			ns.Imports.Add (new CodeNamespaceImport ("System.Web.Profile"));
			
			RootProfilePropertySettingsCollection props = ps.PropertySettings;
			if (props == null)
				return true;

			SortedList<string, string> groupProperties = new SortedList<string, string> ();
			string groupName;
			foreach (ProfileGroupSettings pgs in props.GroupSettings) {
				groupName = MakeGroupName (pgs.Name);
				groupProperties.Add (groupName, pgs.Name);
				BuildProfileClass (ps, groupName, pgs.PropertySettings, ns,
						   "System.Web.Profile.ProfileGroupBase", true, null);
			}
			
			string baseType = ps.Inherits;
			if (String.IsNullOrEmpty (baseType))
				baseType = "System.Web.Profile.ProfileBase";
			else {
				string[] parts = baseType.Split (new char[] {','});
				if (parts.Length > 1)
					baseType = parts [0].Trim ();
			}
			
			bool baseIsGlobal;
			if (baseType.IndexOf ('.') != -1)
				baseIsGlobal = true;
			else
				baseIsGlobal = false;
			
			BuildProfileClass (ps, "ProfileCommon", props, ns, baseType, baseIsGlobal, groupProperties);
			return true;
		}
示例#8
0
		bool ProcessAppCodeDir (string appCode, AppCodeAssembly defasm)
		{
			// First process the codeSubDirectories
			CompilationSection cs = (CompilationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/compilation");
			
			if (cs != null) {
				string aname;
				for (int i = 0; i < cs.CodeSubDirectories.Count; i++) {
					aname = String.Concat ("App_SubCode_", cs.CodeSubDirectories[i].DirectoryName);
					assemblies.Add (new AppCodeAssembly (
								aname,
								Path.Combine (appCode, cs.CodeSubDirectories[i].DirectoryName)));
				}
			}
			
			return CollectFiles (appCode, defasm);
		}