using System.CodeDom.Compiler;
using System.Collections;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Web.Hosting;
using System.Web.Util;
-#if NET_2_0
-using System.Collections.Generic;
-#endif
-
namespace System.Web.UI {
internal class ServerSideScript
{
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public abstract class TemplateParser : BaseParser
{
-#if NET_2_0
[Flags]
internal enum OutputCacheParsedParams
{
VaryByControl = 0x0040,
VaryByContentEncodings = 0x0080
}
-#endif
string inputFile;
string text;
ArrayList dependencies;
ArrayList assemblies;
Hashtable anames;
-#if NET_2_0
string[] binDirAssemblies;
Dictionary <string, bool> namespacesCache;
Dictionary <string, bool> imports;
List <string> interfaces;
List <ServerSideScript> scripts;
-#else
- Hashtable imports;
- ArrayList interfaces;
- ArrayList scripts;
-#endif
Type baseType;
bool baseTypeIsGlobal = true;
string className;
bool output_cache;
int oc_duration;
string oc_header, oc_custom, oc_param, oc_controls;
-#if NET_2_0
string oc_content_encodings, oc_cacheprofile, oc_sqldependency;
bool oc_nostore;
OutputCacheParsedParams oc_parsed_params = 0;
-#endif
bool oc_shared;
OutputCacheLocation oc_location;
-#if NET_2_0
+
// Kludge needed to support pre-parsing of the main directive (see
// AspNetGenerator.GetRootBuilderType)
internal int allowedMainDirectives = 0;
List <UnknownAttributeDescriptor> unknownMainAttributes;
Stack <string> includeDirs;
List <string> registeredTagNames;
-#else
- Stack includeDirs;
- Assembly srcAssembly;
-#endif
ILocation directiveLocation;
int appAssemblyIndex = -1;
internal TemplateParser ()
{
-#if NET_2_0
imports = new Dictionary <string, bool> (StringComparer.Ordinal);
-#else
- imports = new Hashtable ();
- imports.Add ("System", true);
- imports.Add ("System.Collections", true);
- imports.Add ("System.Collections.Specialized", true);
- imports.Add ("System.Configuration", true);
- imports.Add ("System.Text", true);
- imports.Add ("System.Text.RegularExpressions", true);
- imports.Add ("System.Web", true);
- imports.Add ("System.Web.Caching", true);
- imports.Add ("System.Web.Security", true);
- imports.Add ("System.Web.SessionState", true);
- imports.Add ("System.Web.UI", true);
- imports.Add ("System.Web.UI.WebControls", true);
- imports.Add ("System.Web.UI.HtmlControls", true);
-#endif
LoadConfigDefaults ();
assemblies = new ArrayList ();
-#if NET_2_0
CompilationSection compConfig = CompilationConfig;
foreach (AssemblyInfo info in compConfig.Assemblies) {
if (info.Assembly != "*")
AddAssemblyByName (info.Assembly);
}
-#else
- CompilationConfiguration compConfig = CompilationConfig;
-
- foreach (string a in compConfig.Assemblies)
- AddAssemblyByName (a);
- if (compConfig.AssembliesInBin)
- AddAssembliesInBin ();
-#endif
language = compConfig.DefaultLanguage;
implicitLanguage = true;
protected abstract Type CompileIntoType ();
-#if NET_2_0
internal void AddControl (Type type, IDictionary attributes)
{
AspGenerator generator = AspGenerator;
imports.Add (ns, true);
}
}
-#endif
internal void RegisterCustomControl (string tagPrefix, string tagName, string src)
{
string realpath = null;
bool fileExists = false;
-
-#if NET_2_0
VirtualFile vf = null;
VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
VirtualPath vp = new VirtualPath (src, BaseVirtualDir);
if (vf != null)
realpath = MapPath (vf.VirtualPath);
}
-#else
- realpath = MapPath (src);
- fileExists = File.Exists (realpath);
-#endif
+
if (!fileExists)
ThrowParseFileNotFound (src);
if (String.Compare (realpath, inputFile, false, Helpers.InvariantCulture) == 0)
return;
-#if NET_2_0
string vpath = vf.VirtualPath;
-#else
- string vpath = VirtualPathUtility.Combine (BaseVirtualDir, src);
- if (VirtualPathUtility.IsAbsolute (vpath))
- vpath = VirtualPathUtility.ToAppRelative (vpath);
-#endif
try {
-#if NET_2_0
RegisterTagName (tagPrefix + ":" + tagName);
RootBuilder.Foundry.RegisterFoundry (tagPrefix, tagName, vpath);
-#else
- Type type = null;
- ArrayList other_deps = new ArrayList ();
- type = UserControlParser.GetCompiledType (vpath, realpath, other_deps, Context);
- foreach (string s in other_deps)
- AddDependency (s);
- AddAssembly (type.Assembly, true);
- RootBuilder.Foundry.RegisterFoundry (tagPrefix, tagName, type);
-#endif
AddDependency (vpath);
} catch (ParseException pe) {
if (this is UserControlParser)
internal virtual void AddDirective (string directive, Hashtable atts)
{
-#if NET_2_0
var pageParserFilter = PageParserFilter;
-#endif
if (String.Compare (directive, DefaultDirectiveName, true, Helpers.InvariantCulture) == 0) {
-#if NET_2_0
bool allowMainDirective = allowedMainDirectives > 0;
-#else
- bool allowMainDirective = false;
-#endif
+
if (mainAttributes != null && !allowMainDirective)
ThrowParseException ("Only 1 " + DefaultDirectiveName + " is allowed");
-#if NET_2_0
+
allowedMainDirectives--;
if (mainAttributes != null)
return;
if (pageParserFilter != null)
pageParserFilter.PreprocessDirective (directive.ToLower (Helpers.InvariantCulture), atts);
-#endif
mainAttributes = atts;
ProcessMainAttributes (mainAttributes);
return;
- }
-#if NET_2_0
- else if (pageParserFilter != null)
+ } else if (pageParserFilter != null)
pageParserFilter.PreprocessDirective (directive.ToLower (Helpers.InvariantCulture), atts);
-#endif
int cmp = String.Compare ("Assembly", directive, true, Helpers.InvariantCulture);
if (cmp == 0) {
ThrowParseException ("The 'duration' attribute must be set " +
"to a positive integer value");
break;
-#if NET_2_0
+
case "sqldependency":
oc_sqldependency = (string) entry.Value;
break;
oc_content_encodings = (string) entry.Value;
oc_parsed_params |= OutputCacheParsedParams.VaryByContentEncodings;
break;
-#endif
+
case "varybyparam":
oc_param = (string) entry.Value;
if (String.Compare (oc_param, "none", true, Helpers.InvariantCulture) == 0)
break;
case "varybyheader":
oc_header = (string) entry.Value;
-#if NET_2_0
oc_parsed_params |= OutputCacheParsedParams.VaryByHeader;
-#endif
break;
case "varybycustom":
oc_custom = (string) entry.Value;
-#if NET_2_0
oc_parsed_params |= OutputCacheParsedParams.VaryByCustom;
-#endif
break;
case "location":
if (!(this is PageParser))
try {
oc_location = (OutputCacheLocation) Enum.Parse (
typeof (OutputCacheLocation), (string) entry.Value, true);
-#if NET_2_0
oc_parsed_params |= OutputCacheParsedParams.Location;
-#endif
} catch {
ThrowParseException ("The 'location' attribute is case sensitive and " +
"must be one of the following values: Any, Client, " +
}
break;
case "varybycontrol":
-#if ONLY_1_1
- if (this is PageParser)
- goto default;
-#endif
oc_controls = (string) entry.Value;
-#if NET_2_0
oc_parsed_params |= OutputCacheParsedParams.VaryByControl;
-#endif
break;
case "shared":
if (this is PageParser)
return type;
}
-#if !NET_2_0
- void AddAssembliesInBin ()
- {
- Assembly asm;
- foreach (string s in HttpApplication.BinDirectoryAssemblies) {
- try {
- asm = Assembly.LoadFrom (s);
- assemblies.Add (asm.Location);
- } catch (BadImageFormatException) {
- // ignore silently
- }
- }
- }
-#endif
-
internal virtual void AddInterface (string iface)
{
- if (interfaces == null) {
-#if NET_2_0
+ if (interfaces == null)
interfaces = new List <string> ();
-#else
- interfaces = new ArrayList ();
-#endif
- }
if (!interfaces.Contains (iface))
interfaces.Add (iface);
if (namesp == null || namesp.Length == 0)
return;
- if (imports == null) {
-#if NET_2_0
+ if (imports == null)
imports = new Dictionary <string, bool> (StringComparer.Ordinal);
-#else
- imports = new Hashtable ();
-#endif
- }
if (imports.ContainsKey (namesp))
return;
imports.Add (namesp, true);
-#if NET_2_0
AddAssemblyForNamespace (namesp);
-#endif
}
-#if NET_2_0
void AddAssemblyForNamespace (string namesp)
{
if (binDirAssemblies == null)
return false;
}
-#endif
internal virtual void AddSourceDependency (string filename)
{
internal virtual void ProcessMainAttributes (Hashtable atts)
{
directiveLocation = new System.Web.Compilation.Location (Location);
-
-#if NET_2_0
CompilationSection compConfig;
-#else
- CompilationConfiguration compConfig;
-#endif
compConfig = CompilationConfig;
atts.Remove ("Description"); // ignored
-#if NET_1_1
atts.Remove ("CodeBehind"); // ignored
-#endif
atts.Remove ("AspCompat"); // ignored
debug = GetBool (atts, "Debug", compConfig.Debug);
linePragmasOn = GetBool (atts, "LinePragmas", true);
string inherits = GetString (atts, "Inherits", null);
-#if NET_2_0
string srcRealPath = null;
// In ASP 2, the source file is actually integrated with
// Single-Page model.
SetBaseType (inherits);
}
-#else
- string src = GetString (atts, "Src", null);
- if (src != null)
- srcAssembly = GetAssemblyFromSource (src);
-
- if (inherits != null)
- SetBaseType (inherits);
-#endif
if (src != null) {
if (VirtualPathUtility.IsAbsolute (src))
src = VirtualPathUtility.ToAppRelative (src);
className = GetString (atts, "ClassName", null);
if (className != null) {
-#if NET_2_0
string [] identifiers = className.Split ('.');
for (int i = 0; i < identifiers.Length; i++)
if (!CodeGenerator.IsValidLanguageIndependentIdentifier (identifiers [i]))
ThrowParseException (String.Format ("'{0}' is not a valid "
+ "value for attribute 'classname'.", className));
-#else
- if (!CodeGenerator.IsValidLanguageIndependentIdentifier (className))
- ThrowParseException (String.Format ("'{0}' is not a valid "
- + "value for attribute 'classname'.", className));
-#endif
}
-#if NET_2_0
if (this is TemplateControlParser)
metaResourceKey = GetString (atts, "meta:resourcekey", null);
}
return;
}
-#endif
+
if (atts.Count > 0)
ThrowParseException ("Unknown attribute: " + GetOneKey (atts));
}
-#if NET_2_0
void RegisterTagName (string tagName)
{
if (registeredTagNames == null)
UnknownAttributeDescriptor desc = new UnknownAttributeDescriptor (mi, value);
unknownMainAttributes.Add (desc);
}
-#endif
internal void SetBaseType (string type)
{
parent = null;
if (parent == null) {
-#if NET_2_0
parent = LoadType (type);
-#else
- parent = null;
- if (srcAssembly != null)
- parent = srcAssembly.GetType (type);
-
- if (parent == null)
- parent = LoadType (type);
-#endif
if (parent == null)
ThrowParseException ("Cannot find type " + type);
ThrowParseException ("The parent type '" + type + "' does not derive from " + DefaultBaseType);
}
-#if NET_2_0
var pageParserFilter = PageParserFilter;
if (pageParserFilter != null && !pageParserFilter.AllowBaseType (parent))
throw new HttpException ("Base type '" + parent + "' is not allowed.");
-#endif
baseType = parent;
}
internal void PushIncludeDir (string dir)
{
- if (includeDirs == null) {
-#if NET_2_0
+ if (includeDirs == null)
includeDirs = new Stack <string> (1);
-#else
- includeDirs = new Stack (1);
-#endif
- }
includeDirs.Push (dir);
}
AddSourceDependency (vpath);
CompilerResults result;
-
-#if NET_2_0
string tmp;
CompilerParameters parameters;
CodeDomProvider provider = BaseCompiler.CreateProvider (HttpContext.Current, language, out parameters, out tmp);
abuilder.AddAssemblyReference (BuildManager.GetReferencedAssemblies () as List <Assembly>);
abuilder.AddCodeFile (realPath);
result = abuilder.BuildAssembly (new VirtualPath (vpath));
-#else
- result = CachingCompiler.Compile (language, realPath, realPath, assemblies, Debug);
-#endif
+
if (result.NativeCompilerReturnValue != 0) {
using (StreamReader reader = new StreamReader (realPath)) {
throw new CompilationException (realPath, result.Errors, reader.ReadToEnd ());
get { return linePragmasOn; }
}
-#if NET_2_0
internal byte[] MD5Checksum {
get { return md5checksum; }
set { md5checksum = value; }
return pageParserFilterType;
}
}
-#endif
internal Type DefaultBaseType {
get {
set { inputFile = value; }
}
-#if NET_2_0
internal bool IsPartial {
get { return (!srcIsLegacy && src != null); }
}
{
get { return unknownMainAttributes; }
}
-#endif
internal string Text {
get { return text; }
set { baseTypeIsGlobal = value; }
}
-#if NET_2_0
static long autoClassCounter = 0;
-#endif
internal string EncodeIdentifier (string value)
{
if (className != null)
return className;
-#if NET_2_0
string physPath = HttpContext.Current.Request.PhysicalApplicationPath;
string inFile;
if (StrUtils.StartsWith (inFile, physPath))
className = inputFile.Substring (physPath.Length).ToLower (Helpers.InvariantCulture);
else
-#endif
className = Path.GetFileName (inputFile);
className = EncodeIdentifier (className);
return className;
}
}
-#if NET_2_0
internal List <ServerSideScript> Scripts {
get {
if (scripts == null)
internal List <string> Interfaces {
get { return interfaces; }
}
-#else
- internal ArrayList Scripts {
- get {
- if (scripts == null)
- scripts = new ArrayList ();
-
- return scripts;
- }
- }
-
- internal Hashtable Imports {
- get { return imports; }
- }
-
- internal ArrayList Interfaces {
- get { return interfaces; }
- }
-#endif
internal ArrayList Assemblies {
get {
internal RootBuilder RootBuilder {
get {
-#if NET_2_0
if (rootBuilder != null)
return rootBuilder;
AspGenerator generator = AspGenerator;
if (generator != null)
rootBuilder = generator.RootBuilder;
-#endif
+
return rootBuilder;
}
set { rootBuilder = value; }
get { return oc_duration; }
}
-#if NET_2_0
internal OutputCacheParsedParams OutputCacheParsedParameters {
get { return oc_parsed_params; }
}
get { return null; }
set { /* no-op */ }
}
-#endif
internal string OutputCacheVaryByHeader {
get { return oc_header; }
get { return oc_param; }
}
-#if NET_2_0
internal List <string> RegisteredTagNames {
get { return registeredTagNames; }
}
get;
set;
}
-#else
- internal PagesConfiguration PagesConfig {
- get { return PagesConfiguration.GetInstance (Context); }
- }
-#endif
}
}
\ No newline at end of file