当前位置: 首页>>代码示例>>C#>>正文


C# FileStream.BeginRead方法代码示例

本文整理汇总了C#中FileStream.BeginRead方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.BeginRead方法的具体用法?C# FileStream.BeginRead怎么用?C# FileStream.BeginRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileStream的用法示例。


在下文中一共展示了FileStream.BeginRead方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static int Main()
    {
        byte [] buf = new byte [1];
        AsyncCallback ac = new AsyncCallback (async_callback);
        IAsyncResult ar;
        int sum0 = 0;

        FileStream s = new FileStream ("async_read.cs",  FileMode.Open);

        s.Position = 0;
        sum0 = 0;
        while (s.Read (buf, 0, 1) == 1)
            sum0 += buf [0];

        s.Position = 0;

        do {
            ar = s.BeginRead (buf, 0, 1, ac, buf);
        } while (s.EndRead (ar) == 1);
        sum -= buf [0];

        Thread.Sleep (100);

        s.Close ();

        Console.WriteLine ("CSUM: " + sum + " " + sum0);
        if (sum != sum0)
            return 1;

        return 0;
    }
开发者ID:robertmichaelwalsh,项目名称:CSharpFrontEnd,代码行数:31,代码来源:async_read.cs

示例2: Main

	static int Main () {
		byte [] buf = new byte [1];
		AsyncCallback ac = new AsyncCallback (async_callback);
		IAsyncResult ar;
		int sum0 = 0;
		int count0 = 0;
		
		FileStream s = new FileStream ("async_read.exe",  FileMode.Open, FileAccess.Read);

		s.Position = 0;
		while (s.Read (buf, 0, 1) == 1) {
			sum0 += buf [0];
			count0 ++;
		}
		
		s.Position = 0;
		
		do {
			buf = new byte [1];
			ar = s.BeginRead (buf, 0, 1, ac, buf);
		} while (s.EndRead (ar) == 1);
		
		Thread.Sleep (100);
		
		s.Close ();

		count0 ++;  // async_callback is invoked for the "finished reading" case too
		Console.WriteLine ("CSUM: " + sum + " " + sum0);
		Console.WriteLine ("Count: " + count + " " + count0);
		if (sum != sum0 || count != count0)
			return 1;
		
		return 0;
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:34,代码来源:async_read.cs

示例3: Load

 public int Load(string filePath)
 {
     byte[] fileData;
     using (FileStream stream = new FileStream (filePath, FileMode.OpenOrCreate)) {
         fileData = new byte[stream.Length];
         stream.BeginRead(fileData, 0, fileData.Length, new System.AsyncCallback(OnLoad), new FageFileState(++_countId, filePath, stream, fileData));
     }
     return _countId;
 }
开发者ID:buzzler,项目名称:titan,代码行数:9,代码来源:FageFileLoader.cs

示例4: runTest


//.........这里部分代码省略.........
             bArrReturn = sr2.ReadBytes(bArr.Length);
             iCountTestcases++;
             if(bArrReturn.Length != bArr.Length) 
             {
                 iCountErrors++;
                 printerr( "Error_1900c! Incorrect number of chars read");
             }
             for(int i = 0 ; i < bArr.Length ; i++) 
             {
                 iCountTestcases++;
                 if(bArrReturn[i] != bArr[i]) 
                 {
                     iCountErrors++;
                     printerr( "Error_298vc_"+i+"! Expected=="+(Int32)bArr[i]+", got=="+(Int32)bArrReturn[i]);
                 }
             }
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_9848v";
         try 
         {
             fs2 = new FileStream(filName, FileMode.Create);
             sw2 = new StreamWriter(fs2);
             for(int i = 0 ; i < chArr.Length ; i++)
                 sw2.Write(chArr[i]);
             sw2.Flush();
             sw2.Close();
             fs2 = new FileStream(filName, FileMode.Open);
             bArr = new Byte[(Int32)fs2.Length];
             fs2.EndRead(fs2.BeginRead(bArr, 0, (Int32)fs2.Length, null, null));
             fs2.Position = 0;
             sr2 = new BinaryReader(fs2);
             bArrReturn = sr2.ReadBytes(bArr.Length);
             iCountTestcases++;
             if(bArrReturn.Length != bArr.Length) 
             {
                 iCountErrors++;
                 printerr( "Error_0901x! Incorrect number of chars read, length=="+bArr.Length);
             }
             for(int i = 0 ; i < bArr.Length ; i++) 
             {
                 iCountTestcases++;
                 if(bArrReturn[i] != bArr[i]) 
                 {
                     iCountErrors++;
                     printerr( "Error_98yv8!_"+i+"! Expected=="+(Int32)bArr[i]+", got=="+(Int32)bArrReturn[i]);
                 }
             }
             sr2.Close();
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_698y7! Unexpected exception thrown, exc=="+exc.ToString());
         }
         Byte[] bytes = BitConverter.GetBytes('\u00FC');
         for(int i = 0 ; i < bytes.Length ; i++) 
             Console.WriteLine(bytes[i]);
         strLoc = "Loc_958hb";
         fs2 = new FileStream(filName, FileMode.Create);
         BinaryWriter bw2 = new BinaryWriter(fs2, Encoding.Unicode);
         bw2.Write("\u00FA\u00FB\u00FC\u00FD\uFFFE");
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co5640readbytes.cs

示例5: runTest


//.........这里部分代码省略.........
         {
             fs2.Read(new Byte[1], 0, 1);
             iCountErrors++;
             printerr( "Error_2000p! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_2000q! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_2000r! Incorrect exception thrown, exc=="+exc.ToString());
         }
         iCountTestcases++;
         try 
         {
             fs2.EndWrite(fs2.BeginWrite(new Byte[]{1}, 0, 1, null, null));
             iCountErrors++;
             printerr( "Error_2000s! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_2000t! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr("Error_2000u! Incorrect exception thrown, exc=="+exc.ToString());
         }
         iCountTestcases++;
         try 
         {
             fs2.EndRead(fs2.BeginRead(new Byte[1], 0, 1, null, null));
             iCountErrors++;
             printerr("Error_2000v! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_2000w! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch( Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_2000x! Incorrect exception thrown, exc=="+exc.ToString());
         } 
         iCountTestcases++;
         try 
         {
             fs2.Flush();
             iCountErrors++;
             printerr( "Error_2000y! Expected exception not thrwon");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_2000z! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_200aa! Incorrect exception thrown, exc=="+exc.ToString());
         }
         iCountTestcases++;
         try 
         {
             fs2.Lock(1,1);
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co5718close.cs

示例6: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     String strLoc = "Loc_000oo";
     int iCountErrors = 0;
     int iCountTestcases = 0;
     try
     {		
         String filName = s_strTFAbbrev+"TestFile";
         Stream fs2;
         IAsyncResult iar;
         Int32 iReturn;
         Byte[] bArr;
         Byte[] bRead;
         if(File.Exists(filName)) 
             File.Delete(filName);
         strLoc = "Loc_100aa";
         iCountTestcases++;
         try 
         {
             fs2 = new FileStream(null, FileMode.Create, FileAccess.Read, FileShare.None, 100, false);
             iCountErrors++;
             printerr( "Error_100bb! Expected exception not thrown");
             fs2.Close();
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo( "Info_100cc! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_100dd Incorrect exception thrown, exc=="+exc.ToString());
         }	
         strLoc = "Loc_300aa";
         fs2 = new FileStream(filName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 100, false);
         bArr = new Byte[1024*100];
         for(int i = 0 ; i < bArr.Length ; i++)
             bArr[i] = (Byte)i;
         fs2.Write(bArr, 0, bArr.Length);
         fs2.Close();
         bRead = new Byte[bArr.Length];
         fs2 = new FileStream(filName, FileMode.Open);
         iar = fs2.BeginRead(bRead, 0, bRead.Length, null, null);
         iReturn = fs2.EndRead(iar);
         iCountTestcases++;
         if(!iar.IsCompleted) 
         {
             iCountErrors++;
             printerr( " Error_300dd! Operation should be complete");
         }
         iCountTestcases++;
         if(!iar.CompletedSynchronously) 
         {
             iCountErrors++;
             printerr( "Error_300cc! Unexpectedly completed ASync");
         }
         iCountTestcases++;
         if(iReturn != bArr.Length) 
         {
             iCountErrors++;
             printerr( "Error_300bb! Expected=="+bArr.Length+", Return=="+iReturn);
         }
         for(int i = 0 ; i < bRead.Length ; i++) 
         {
             iCountTestcases++;
             if(bRead[i] != bArr[i]) 
             {
                 printerr( "Error_300ff_"+i+"! Expected=="+bArr[i]+", got=="+bRead[i]);
                 iCountErrors++;
             }
         }
         fs2.Close();
         strLoc = "Loc_400aa";
         fs2 = new FileStream(filName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 100, true);
         bArr = new Byte[100*1024];
         for(int i = 0 ; i < bArr.Length ; i++)
             bArr[i] = (Byte)i;
         fs2.Write(bArr, 0, bArr.Length);
         fs2.Close();
         bRead = new Byte[bArr.Length];
         fs2 = new FileStream(filName, FileMode.Open);
         iar = fs2.BeginRead(bRead, 0, bRead.Length, null, null);
         iReturn = fs2.EndRead(iar);
         iCountTestcases++;
         if(!iar.IsCompleted) 
         {
             iCountErrors++;
             printerr( "Error_400bb! Operation should be complete");
         } 
         iCountTestcases++;
         if(!iar.CompletedSynchronously) 
         {
             iCountErrors++;
             printerr( "Error_400cc! Unexpectedly completed Synchronously");
         } 
         iCountTestcases++;
         if(iReturn != bArr.Length) 
         {
             iCountErrors++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co9307ctor_str_fm_fa_fs_i_b_str.cs

示例7: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         FileStream fs2;
         Byte[] bArr, bResultArr;
         String fileName = s_strTFAbbrev+"TestFile.tmp";
         AsyncCallback ascb;
         IAsyncResult iar;
         fs2 = new FileStream(fileName, FileMode.Create);
         bArr = new Byte[26];
         for(int i = 0 ; i < 26 ; i++)
             bArr[i] = (Byte)((i%26)+65);
         fs2.Flush();
         fs2.Close();
         strLoc = "Loc_7882h";
         fs2 = new FileStream(fileName, FileMode.Open);
         iCountTestcases++;
         try 
         {
             fs2.BeginRead(null, 0, 0, null, null);
             iCountErrors++;
             printerr( "Error_18983! Expected exception not thrown");
         } 
         catch ( ArgumentNullException aexc) 
         {
             printinfo( "Info_989su! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_9t898! Incorrect exception thrown, exc=="+exc.ToString());
         }
         fs2.Close();
         strLoc = "Loc_1298x";
         for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++)
         {
             fs2 = new FileStream(fileName, FileMode.Open);
             iCountTestcases++;
             bArr = new Byte[]{0,1,2,3};
             try 
             {
                 fs2.BeginRead(bArr, iArrInvalidValues[iLoop], 0, null, null);
                 iCountErrors++;
                 printerr("Error_298tk! Expected exception not thrown");
             } 
             catch (ArgumentOutOfRangeException aexc) 
             {
                 printinfo ( "Info_9888b! Caught expected exception, aexc=="+aexc.Message);
             } 
             catch (Exception exc) 
             {
                 iCountErrors++;
                 printerr( "Error_28g8b! Incorrect exception thrown, exc=="+exc.ToString());
             }
             fs2.Close();
         }
         strLoc = "Loc_77f8h";
         for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++)
         {
             fs2 = new FileStream(fileName, FileMode.Open);
             iCountTestcases++;
             bArr = new Byte[]{0,1,2,3};
             try 
             {
                 fs2.BeginRead(bArr, iArrLargeValues[iLoop], 0, null, null);
                 iCountErrors++;
                 printerr( "Error_9t8g8! Expected exception not thrown");
             } 
             catch (ArgumentException aexc) 
             {
                 printinfo( "Info_t87gy! Caught expected exception, aexc=="+aexc.Message);
             } 
             catch (Exception exc) 
             {
                 iCountErrors++;
                 printerr( "Error_29y8g! Incorrect exception thrown, exc=="+exc.ToString());
             }
             fs2.Close();
         }
         strLoc = "Loc_89t8y";
         for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++)
         {
             fs2 = new FileStream(fileName, FileMode.Open);
             iCountTestcases++;
             bArr = new Byte[]{0,1};
             try 
             {
                 fs2.BeginRead(bArr, 0, iArrInvalidValues[iLoop], null, null);
                 iCountErrors++;
                 printerr( "Error_2868b! Expected exception not thrown");
             } 
             catch (ArgumentOutOfRangeException aexc) 
             {
                 printinfo( "Info_3388g! Caught expected exception, aexc=="+aexc.Message);
             } 
             catch (Exception exc) 
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5584beginread.cs

示例8: BeginProcessRequest

    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        try
        {
            _log.Info("Starting process request...");
            _log.Info("fontname: " + m_sFontName);

            string sNameToDecode;
            if (m_sFontName.Length > gc_sJsExtention.Length && gc_sJsExtention == m_sFontName.Substring(m_sFontName.Length - gc_sJsExtention.Length))
                sNameToDecode = m_sFontName.Substring(0, m_sFontName.Length - gc_sJsExtention.Length);
            else
                sNameToDecode = m_sFontName;
            byte[] data_decode = Odtff_fonts.ZBase32Encoder.Decode(sNameToDecode);
            string sFontNameDecoded = System.Text.Encoding.UTF8.GetString(data_decode);
            _log.Info("fontnameDecoded: " + sFontNameDecoded);

            context.Response.Clear();
            context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(double.Parse(ConfigurationManager.AppSettings["resource.expires"], Constants.mc_oCultureInfo)));
            context.Response.Cache.SetSlidingExpiration(false);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.ContentType = Utils.GetMimeType(sFontNameDecoded);
            string contentDisposition = Utils.GetContentDisposition(context.Request.UserAgent, context.Request.Browser.Browser, context.Request.Browser.Version, m_sFontName);
            context.Response.AppendHeader("Content-Disposition", contentDisposition);

            string sRealFontName = sFontNameDecoded;
            if (gc_sJsExtention == Path.GetExtension(sRealFontName))
                sRealFontName = sRealFontName.Substring(0, sRealFontName.Length - gc_sJsExtention.Length);

            string strFilepath;
            m_mapFontNameToFullPath.TryGetValue(sRealFontName.ToUpper(), out strFilepath);

            FileInfo oFileInfo = new FileInfo(strFilepath);
            if (oFileInfo.Exists)
            {
                DateTime oLastModified = oFileInfo.LastWriteTimeUtc;
                string sETag = oLastModified.Ticks.ToString("x");

                DateTime oDateTimeUtcNow = DateTime.UtcNow;

                if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
                {
                    _log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
                    oLastModified = oDateTimeUtcNow;
                }

                string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
                string sRequestETag = context.Request.Headers["If-None-Match"];
                bool bNoModify = false;
                if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                {
                    bool bRequestETag = true;
                    if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
                        bRequestETag = false;
                    bool bRequestIfModifiedSince = true;
                    if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                    {
                        try
                        {
                            DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
                            if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
                                bRequestIfModifiedSince = false;
                        }
                        catch 
                        {
                            bRequestIfModifiedSince = false;
                        }
                    }
                    if (bRequestETag && bRequestIfModifiedSince)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                        bNoModify = true;
                    }
                }
                if (false == bNoModify)
                {
                    context.Response.Cache.SetETag(sETag);

                    context.Response.Cache.SetLastModified(oLastModified.ToLocalTime());
                    
                    FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true);
                    byte[] aBuffer = new byte[oFileStreamInput.Length];
                    TransportClass oTransportClass = new TransportClass(context, cb, oFileStreamInput, aBuffer, sFontNameDecoded);
                    oFileStreamInput.BeginRead(aBuffer, 0, aBuffer.Length, ReadFileCallback, oTransportClass);
                    bStartAsync = true;
                }
            }
            else
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
        }
        catch(Exception e)
        {
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            
            _log.Error(context.Request.QueryString.ToString());
            _log.Error("Exeption catched in BeginProcessRequest:", e);
        }
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
//.........这里部分代码省略.........
开发者ID:TangramINC,项目名称:DocumentServer,代码行数:101,代码来源:FontService.ashx.cs

示例9: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     int iCountErrors = 0;
     int iCountTestcases = 0;
     try
     {
         String filName = s_strTFAbbrev+"TestFile";
         Stream fs2;
         IAsyncResult iar;
         Byte[] bArr;
         if(File.Exists(filName)) 
             File.Delete(filName);
         strLoc = "Loc_100aa";
         fs2 = new FileStream(filName, FileMode.Create);
         iCountTestcases++;
         try 
         {
             fs2.EndWrite(null);
             iCountErrors++;
             printerr( "Error_100bb! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo( "Info_100cc! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_100dd Incorrect exception thrown, exc=="+exc.ToString());
         }	
         fs2.Close();
         strLoc = "Loc_200aa";
         fs2 = new FileStream(filName, FileMode.Create);
         iar = fs2.BeginRead(new Byte[0], 0, 0, null, null);
         iCountTestcases++;
         try 
         {
             fs2.EndWrite(iar);
             iCountErrors++;
             printerr( "Error_200bb! Expected exception not thrown");
         } 
         catch (ArgumentException aexc) 
         {
             printinfo ("Info_200cc! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_200dd! Incorrect exception thrown, exc=="+exc.ToString());
         }				
         fs2.Close();
         strLoc = "Loc_300aa";
         fs2 = new FileStream(filName, FileMode.Create);
         bArr = new Byte[1024*1000];
         for(int i = 0 ; i < bArr.Length ; i++)
             bArr[i] = (Byte)i;
         iar = fs2.BeginWrite(bArr, 0, bArr.Length, null, null);
         fs2.EndWrite(iar);
         iCountTestcases++;
         if(!iar.IsCompleted) 
         {
             iCountErrors++;
             printerr( " Error_300dd! Operation should be complete");
         }
         iCountTestcases++;
         iCountTestcases++;
         if(fs2.Length != bArr.Length) 
         {
             iCountErrors++;
             printerr( "Error_300bb! Expected=="+bArr.Length+", Return=="+fs2.Length);
         }
         fs2.Close();
         strLoc = "Loc_400aa";
         fs2 = new FileStream(filName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 100, true);
         bArr = new Byte[1000*1024];
         for(int i = 0 ; i < bArr.Length ; i++)
             bArr[i] = (Byte)i;
         iar = fs2.BeginWrite(bArr, 0, bArr.Length, null, null);
         fs2.EndWrite(iar);
         iCountTestcases++;
         if(!iar.IsCompleted) 
         {
             iCountErrors++;
             printerr( "Error_400bb! Operation should be complete");
         } 
         iCountTestcases++;
         iCountTestcases++;
         if(fs2.Length != bArr.Length) 
         {
             iCountErrors++;
             printerr( "Error_400dd! Expected=="+bArr.Length+", Return=="+fs2.Length);
         }
         fs2.Close();
         if(File.Exists(filName))
             File.Delete(filName);
     } 
     catch (Exception exc_general ) 
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5728endwrite.cs

示例10: BeginProcessRequest

    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        try
        {
            _log.Info("Starting process request...");
            _log.Info("fontname: " + m_sFontName);

            context.Response.Clear();
            context.Response.Cache.SetExpires(DateTime.Now);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.ContentType = Utils.GetMimeType(m_sFontName);
            if (context.Request.ServerVariables.Get("HTTP_USER_AGENT").Contains("MSIE"))
                context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + context.Server.UrlEncode(m_sFontName) + "\"");
            else
                context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + m_sFontName + "\"");

            string sConfigFontDir = ConfigurationManager.AppSettings["utils.common.fontdir"];
            string strFilepath;
            if (null != sConfigFontDir && string.Empty != sConfigFontDir)
                strFilepath = Path.Combine(Environment.ExpandEnvironmentVariables(sConfigFontDir), m_sFontName);
            else
                m_mapFontNameToFullPath.TryGetValue(m_sFontName.ToUpper(), out strFilepath);
            if (".js" == Path.GetExtension(m_sFontName))
            {
                string[] aFontExts = {".ttf", ".ttc", ".otf"};
                for(int i = 0; i < aFontExts.Length; i++)
                {
                    strFilepath = Path.ChangeExtension(strFilepath, aFontExts[i]);
                    if (File.Exists(strFilepath))
                        break;
                }
            }
            FileInfo oFileInfo = new FileInfo(strFilepath);
            if (oFileInfo.Exists)
            {
                DateTime oLastModified = oFileInfo.LastWriteTimeUtc;
                string sETag = oLastModified.Ticks.ToString("x");

                DateTime oDateTimeUtcNow = DateTime.UtcNow;

                if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
                {
                    _log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
                    oLastModified = oDateTimeUtcNow;
                }

                string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
                string sRequestETag = context.Request.Headers["If-None-Match"];
                bool bNoModify = false;
                if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                {
                    bool bRequestETag = true;
                    if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
                        bRequestETag = false;
                    bool bRequestIfModifiedSince = true;
                    if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                    {
                        try
                        {
                            DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
                            if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
                                bRequestIfModifiedSince = false;
                        }
                        catch
                        {
                            bRequestIfModifiedSince = false;
                        }
                    }
                    if (bRequestETag && bRequestIfModifiedSince)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                        bNoModify = true;
                    }
                }
                if (false == bNoModify)
                {
                    context.Response.Cache.SetETag(sETag);
                    context.Response.Cache.SetLastModified(oLastModified);

                    FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true);
                    byte[] aBuffer = new byte[oFileStreamInput.Length];
                    TransportClass oTransportClass = new TransportClass(context, cb, oFileStreamInput, aBuffer);
                    oFileStreamInput.BeginRead(aBuffer, 0, aBuffer.Length, ReadFileCallback, oTransportClass);
                    bStartAsync = true;
                }
            }
            else
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
        }
        catch(Exception e)
        {
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

            _log.Error(context.Request.Params.ToString());
            _log.Error("Exeption catched in BeginProcessRequest:", e);
        }
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
//.........这里部分代码省略.........
开发者ID:hernanewdg,项目名称:ONLYOFFICE-OnlineEditors,代码行数:101,代码来源:FontService.ashx.cs


注:本文中的FileStream.BeginRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。