Esempio n. 1
0
		internal static void CloseHandle(FileHandlingCacheEntry e)
		{
			try
			{
				e.fs.RealClose();
				e.fs=null;
			}
			catch
			{
			}
			FileHandlingCache.Remove(e);
		}
Esempio n. 2
0
		internal static FileStream NewFileStream(
			string path,
			FileMode mode,
			FileAccess access,
			FileShare share
			)
		{
//			TextWriter tw = new StreamWriter("filelog.txt",true);
//			tw.WriteLine("Open "+path);
//			tw.Close();
//			return new FileStream2(path,mode,access,share);
			foreach(FileHandlingCacheEntry e in FileHandlingCache)
			{
				if(e.filename==path)
				{
					if((e.fm==mode)&&(e.fs.CanSeek))
					{
						e.uses++;
						e.fs.Position=0;
						return e.fs;
					}
					else
					{
						CloseHandle(e);
						break;
					}
				}
			}
			if(FileHandlingCache.Count>Limit)
			{
				int trys = Limit-FileHandlingCache.Count;
				for(int t=0;t<trys;t++)
				{
					FileHandlingCacheEntry se = null;
					foreach(FileHandlingCacheEntry e in FileHandlingCache)
					{
						if(e.uses==0)
						{
							se=e;
							break;
						}
					}
					if(se!=null)
						CloseHandle(se);
				}
			}
			FileStream2 fs = new FileStream2(path,mode,FileAccess.ReadWrite,FileShare.None);
			FileHandlingCacheEntry en = new FileHandlingCacheEntry(path,fs,mode);
			fs.e=en;
			FileHandlingCache.Add( en );
			return fs;
		}