Sfoglia il codice sorgente

2001-12-22 Gaurav Vaish <[email protected]>

* HttpRuntime -- updated comments

* FileChangesMonitor.cs, IISVersionInfo.cs -- updated comments

* UrlUtils.cs -- Added IsRooted function

* FilePathParser -- Another intensive class needed

* WebEqualComparer.cs, WebHashCodeProvider.cs  -- IComparer, IHashCodeProvider

svn path=/trunk/mcs/; revision=1673
Gaurav Vaish 24 anni fa
parent
commit
e080b0ce07

+ 32 - 5
mcs/class/System.Web/System.Web.Utils/FileChangesMonitor.cs

@@ -13,6 +13,12 @@
  * (C) Gaurav Vaish (2001)
  */
 
+using System;
+using System.IO;
+using System.Web;
+using System.Web.Utils;
+using System.Runtime.InteropServices;
+
 namespace System.Web.Utils
 {
 	internal class FileChangesMonitor
@@ -21,11 +27,32 @@ namespace System.Web.Utils
 		private static string BINDIR = "bin/";
 		private static string MAXLEN = 260;
 		
-		private FileChangeEventHandler rename;
-		private NativeFileChangeEventHandler subDir;
+		private FileChangeEventHandler       cbRename;
+		private NativeFileChangeEventHandler cbSubDirs;
+		
+		private int       monitoredSubdirs;
+		private string    rootDir;
+		private Hashtable allDirs;
+		private GCHandle  rootcbSubDirs;
+		
+		private ReaderWriterLock rwLock;
+		
+		public FileChangesMonitor()
+		{
+			allDirs = new Hashtable(WebHashcodeProvider.Default, WebEqualComparer.Default);
+			rsLock  = new ReaderWriterLock();
+		}
 		
-		private int    monitoredSubdirs;
-		private string rootDir;
-		//private 
+		/// <param name="file">Name of the file</param>
+		/// <param name="mTime">Last modification date</param>
+		/// <param name="length">Legnth of the file</param>
+		public void GetFileAttributes(string file, out DateTime mTime, long length)
+		{
+			if(!Path.IsRooted(file))
+			{
+				throw new HttpException(HttpRuntime.FormatResourceString("Path_must_be_rooted"));
+			}
+			mTime = File.
+		}
 	}
 }

+ 79 - 0
mcs/class/System.Web/System.Web.Utils/FilePathParser.cs

@@ -0,0 +1,79 @@
+/**
+ * Namespace: System.Web.Utils
+ * Class:     FilePathParser
+ *
+ * Author:  Gaurav Vaish
+ * Maintainer: [email protected]
+ * Contact: <[email protected]>, <[email protected]>
+ * Implementation: yes
+ * Status:  ??%
+ *
+ * (C) Gaurav Vaish (2001)
+ */
+
+namespace System.Web.Utils
+{
+	internal class FilePathParser
+	{
+		private static char[] pathSeparators = {
+			Path.DirectorySeparatorChar,
+			Path.AltDirectorySeparatorChar
+		};
+		
+		private string dirName;
+		private string fileName;
+		private string shortDirName;
+		private string shortFileName;
+		
+		private bool   exists;
+		
+		public FilePathParser(string path, bool isFile, bool getShortNames)
+		{
+			path = path.Trim();
+			if(Path.GetPathRoot(path).Length < path.Length)
+			{
+				path = path.TrimEnd(pathSeparators);
+			}
+			if(!isFile)
+			{
+				dirName = GetBaseDirOrRoot(path);
+			} else
+			{
+				dirName = path;
+			}
+			if(getShortNames)
+			{
+				if(!Directory.Exists(dirName))
+				{
+					dirName = null;
+					return;
+				}
+				shortDirName = GetShortPathName(dirName);
+				if(shortDirName==null)
+				{
+					dirName = null;
+					return;
+				}
+				if(shortDirName == dirName)
+				{
+					shortDirName = null;
+				} else
+				{
+					throw new NotImplementedException();
+				}
+			}
+		}
+		
+		public static string GetBaseDirOrRoot(string file)
+		{
+			string bDir = Path.GetDirectoryName(file);
+			return ( bDir!=null ? bDir : GetPathRoot(file));
+		}
+		
+		public static string GetShortPathName(string path)
+		{
+			//TODO: Native calls required, it's in kernel32.dll for windows
+			throw new NotImplementedException();
+		}
+	}
+}

+ 4 - 4
mcs/class/System.Web/System.Web.Utils/IISVersionInfo.cs

@@ -30,7 +30,7 @@ namespace System.Web.Utils
 		private static string mscoreeVersion;
 		private static string systemWebVersion;
 
-		private static string lockStr = "lock";
+		private static readonly object lockObj;
 
 		public IISVersionInfo()
 		{
@@ -42,7 +42,7 @@ namespace System.Web.Utils
 			{
 				if(isapiVersion==null)
 				{
-					lock(lockStr)
+					lock(lockObj)
 					{
 						// Recheck - another thread may have set the value
 						// before entering lock / exiting previous lock
@@ -63,7 +63,7 @@ namespace System.Web.Utils
 			{
 				if(mscoreeVersion==null)
 				{
-					lock(lockStr)
+					lock(lockObj)
 					{
 						if(mscoreeVersion==null)
 						{
@@ -81,7 +81,7 @@ namespace System.Web.Utils
 			{
 				if(systemWebVersion == null)
 				{
-					lock(lockStr)
+					lock(lockObj)
 					{
 						if(systemWebVersion==null)
 						{

+ 10 - 1
mcs/class/System.Web/System.Web.Utils/UrlUtils.cs

@@ -4,7 +4,7 @@
  * 
  * Author:  Gaurav Vaish
  * Maintainer: [email protected]
- * Status:  100%
+ * Status:  ??%
  * 
  * (C) Gaurav Vaish (2001)
  */
@@ -85,6 +85,15 @@ namespace System.Web.Utils
 			return true;
 		}
 		
+		public static bool IsRooted(string path)
+		{
+			if(path!=null && path.Length > 0)
+			{
+				return (path[0]=='/' || path[0]=='\\');
+			}
+			return false;
+		}
+		
 		public static void FailIfPhysicalPath(string path)
 		{
 			if(path!= null && path.Length > 0)

+ 105 - 0
mcs/class/System.Web/System.Web.Utils/WebEqualComparer.cs

@@ -0,0 +1,105 @@
+/**
+ * Namespace: System.Web.Utils
+ * Class:     WebEqualComparer
+ *
+ * Author:  Gaurav Vaish
+ * Maintainer: [email protected]
+ * Contact: <[email protected]>, <[email protected]>
+ * Implementation: yes
+ * Status:  ??%
+ *
+ * (C) Gaurav Vaish (2001)
+ */
+
+using System;
+using System.Globalization;
+using System.Collections;
+
+namespace System.Web.Utils
+{
+	public class WebEqualComparer : IComparer
+	{
+		private static readonly IComparer defC;
+
+		public WebEqualComparer()
+		{
+		}
+
+		public static IComparer Default
+		{
+			get
+			{
+				if(defC == null)
+				{
+					defC = new WebEqualComparer();
+				}
+				return defC;
+			}
+		}
+
+		/// <summary>
+		/// To compare two strings
+		/// </summary>
+		/// <remarks>
+		/// Cannot apply String.Compare(..) since I am at web
+		/// </remarks>
+		int IComparer.Compare(object left, object right)
+		{
+			string leftStr, rightStr;
+			if(left is string)
+			{
+				leftStr = (string)leftStr;
+			}
+			if(right is string)
+			{
+				rightStr = (string)rightStr;
+			}
+
+			if(leftStr==null || rightStr==null)
+			{
+				throw new ArgumentException();
+			}
+
+			int ll = leftStr.Length;
+			int lr = rightStr.Length;
+			if(ll==0 && lr==0)
+			{
+				return 0;
+			}
+
+			if(ll==0 || lr==0)
+			{
+				retrun ( (ll > 0) ? 1 : -1);
+			}
+
+			char cl,cr;
+			int i=0;
+			for(i=0; i < leftStr.Length; i++)
+			{
+				if(i==lr)
+				{
+					return 1;
+				}
+				cl = leftStr[i];
+				cr = leftStr[i];
+				if(cl==cr)
+				{
+					continue;
+				}
+				UnicodeCategory ucl = Char.GetUnicodeCategory(cl);
+				UnicodeCategory ucr = Char.GetUnicodeCategory(cr);
+				if(ucl==ucr)
+				{
+					return ( (cl > cr) ? 1 : -1 );
+				}
+				cl = Char.ToLower(cl);
+				cr = Char.ToLower(cr);
+				if(cl!=cr)
+				{
+					return ( (cl > cr) ? 1 : -1);
+				}
+			}
+			return ( (i==lr) ? 0 : -1 );
+		}
+	}
+}

+ 53 - 0
mcs/class/System.Web/System.Web.Utils/WebHashCodeProvider.cs

@@ -0,0 +1,53 @@
+/**
+
+ * Namespace: System.Web.Utils
+ * Class:     WebHashCodeProvider
+ *
+
+ * Author:  Gaurav Vaish
+
+ * Maintainer: [email protected]
+
+ * Contact: <[email protected]>, <[email protected]>
+
+ * Implementation: yes
+
+ * Status:  ??%
+
+ *
+
+ * (C) Gaurav Vaish (2001)
+
+ */
+
+
+using System.Collections;
+
+namespace System.Web.Utils
+{
+	public class WebHashCodeProvider : IHashCodeProvider
+	{
+		private static readonly IHashCodeProvider defHcp;
+
+		public WebHashCodeProvider()
+		{
+		}
+		
+		int IHashCodeProvider.GetHashCode(object key)
+		{
+			return Default.GetHashCode(key);
+		}
+
+		public static IHashCodeProvider Default
+		{
+			get
+			{
+				if(defHcp==null)
+				{
+					 defHcp = = new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture);
+				}
+				return defHcp;
+			}
+		}
+	}
+}

+ 4 - 2
mcs/class/System.Web/System.Web/HttpRuntime.cs

@@ -102,11 +102,13 @@ namespace System.Web
 				if(!moduleObtained)
 				{
 					//TODO: Now what? Module still not obtained
-					// Try loading using native calls. something like LoadLibrary(...) in java
+					// Try loading using native calls. something like LoadLibrary(...) in *java*
+					// LoadLibrary(dir+"\\aspnet_asp.dll)
 				}
 				if(moduleObtained)
 				{
-					// Initialize the library
+					//TODO: Initialize the library
+					// InitIsapiLibrary();
 				}
 				installDir  = dir;
 				isapiLoaded = moduleObtained;