當前位置: 首頁>>代碼示例>>C#>>正文


C# IO.IOException類代碼示例

本文整理匯總了C#中System.IO.IOException的典型用法代碼示例。如果您正苦於以下問題:C# IOException類的具體用法?C# IOException怎麽用?C# IOException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IOException類屬於System.IO命名空間,在下文中一共展示了IOException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PostEditorStorageException

 private PostEditorStorageException(IOException ex)
     : base(StringId.PostEditorStorageExceptionTitle2,
     StringId.PostEditorStorageExceptionMessage2,
     ex.GetType().Name,
     ex.Message)
 {
 }
開發者ID:gmilazzoitag,項目名稱:OpenLiveWriter,代碼行數:7,代碼來源:PostEditorException.cs

示例2: CustomMediaRetryPolicyTestExceededMaxRetryAttempts

        public void CustomMediaRetryPolicyTestExceededMaxRetryAttempts()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetBlobStorageClientRetryPolicy();

            int exceptionCount = 4;
            int expected = 10;
            //This is the new exception included for retrypolicy in the customretrypolicy
            var fakeException = new IOException("CustomRetryPolicyException");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (AggregateException ax)
            {
                IOException x = (IOException)ax.Flatten().InnerException;
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                //Exception is retried only for max retrial attempts,
                //In this case there are max of 2 attempts for blob retry policy.
                Assert.AreEqual(exceptionCount, 1);
                throw;
            }
        }
開發者ID:shushengli,項目名稱:azure-sdk-for-media-services,代碼行數:30,代碼來源:CustomMediaRetryPolicyTests.cs

示例3: AsyncRead

		private void AsyncRead (Handle handle, Result result, byte[] buf,
					ulong bytesRequested, ulong bytesRead)
		{
			if (result == Result.Ok) {
				Array.Copy (buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
				bytesRemaining -= (int)bytesRead;
				if (bytesRemaining > 0) {
					buf = new byte[bytesRemaining];
					Async.Read (handle, out buf[0], (uint)bytesRemaining,
						    new AsyncReadCallback (AsyncRead));
				} else if (cback != null) {
					asyncResult.SetComplete (null, count);
					cback (asyncResult);
				}
			} else if (result == Result.ErrorEof) {
				Array.Copy (buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
				bytesRemaining -= (int)bytesRead;
				asyncResult.SetComplete (null, count - bytesRemaining);
				
				if (cback != null)
					cback (asyncResult);
			} else if (cback != null) {
				Exception e = new IOException (Vfs.ResultToString (result));
				asyncResult.SetComplete (e, -1);
				cback (asyncResult);
			}
		}
開發者ID:directhex,項目名稱:xamarin-gnome-sharp2,代碼行數:27,代碼來源:VfsStream.cs

示例4: AddFileInUseTests

        public void AddFileInUseTests()
        {
            // Arrange
            var fileName = @"x:\test\temp.txt";
            var exception = new IOException("file in use");
            var stream = new MemoryStream();
            var zip = new ZipArchive(stream, ZipArchiveMode.Create);
            var tracer = new Mock<ITracer>();
            var file = new Mock<FileInfoBase>();

            // setup
            file.Setup(f => f.OpenRead())
                .Throws(exception);
            file.SetupGet(f => f.FullName)
                .Returns(fileName);
            tracer.Setup(t => t.Trace(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>()))
                  .Callback((string message, IDictionary<string, string> attributes) =>
                  {
                      Assert.Contains("error", attributes["type"]);
                      Assert.Contains(fileName, attributes["text"]);
                      Assert.Contains("file in use", attributes["text"]);
                  });

            // Act
            zip.AddFile(file.Object, tracer.Object, String.Empty);
            zip.Dispose();

            // Assert
            tracer.Verify(t => t.Trace(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>()), Times.Once());
            zip = new ZipArchive(ReOpen(stream));
            Assert.Equal(0, zip.Entries.Count);
        }
開發者ID:NorimaConsulting,項目名稱:kudu,代碼行數:32,代碼來源:ZipArchiveExtensionFacts.cs

示例5: ShowScanningError

        public static void ShowScanningError(IOException exception)
        {
            var message = exception.Message;
            var options = MessageBoxButton.OK;
            var icon = MessageBoxImage.Error;

            ShowMessageBox(message, options, icon);
        }
開發者ID:Mavtak,項目名稱:Arcadia,代碼行數:8,代碼來源:MainWindowMessageBoxGenerator.cs

示例6: IsSharingViolation

 static bool IsSharingViolation(IOException ex)
 {
     // http://stackoverflow.com/questions/425956/how-do-i-determine-if-an-ioexception-is-thrown-because-of-a-sharing-violation
     // don't ask...
     var hResult = System.Runtime.InteropServices.Marshal.GetHRForException(ex);
     const int sharingViolation = 32;
     return (hResult & 0xFFFF) == sharingViolation;
 }
開發者ID:mojamcpds,項目名稱:lokad-cqrs-1,代碼行數:8,代碼來源:StatelessFileQueueReader.cs

示例7: SetLength

 public override void SetLength(long value)
 {
     if (BreakHow == BreakHowType.ThrowOnSetLength)
     {
         ThrownException = new IOException();
         throw ThrownException;
     }
 }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:8,代碼來源:BrokenStream.cs

示例8: CannotFetchDataException

 /// <summary>The default constructor for CannotFetchDataException.</summary>
 /// <remarks>The default constructor for CannotFetchDataException.</remarks>
 /// <param name="ex"></param>
 public CannotFetchDataException(IOException ex, string serviceName)
     : this(ex is
         UnknownHostException ? CannotFetchDataException.MSG.UNKNOWN_HOST_EXCEPTION : CannotFetchDataException.MSG
         .IO_EXCEPTION, serviceName)
 {
     cause = ex;
     this.serviceName = serviceName;
 }
開發者ID:Gianluigi,項目名稱:dssnet,代碼行數:11,代碼來源:CannotFetchDataException.cs

示例9: T202_FileFormatException

 public void T202_FileFormatException()
 {
     var e2 = new IOException("Test");
     var e = new FileFormatException("Test", e2);
     Assert.Equal("Test", e.Message);
     Assert.Null(e.SourceUri);
     Assert.Same(e2, e.InnerException);
 }
開發者ID:ChuangYang,項目名稱:corefx,代碼行數:8,代碼來源:Tests.cs

示例10: error

        public IOException error(Exception why)
        {
            if (why == null)
                throw new ArgumentNullException ("why");

            IOException e;
            e = new IOException("Encryption error: " + why.Message, why);
            return e;
        }
開發者ID:cocytus,項目名稱:Git-Source-Control-Provider,代碼行數:9,代碼來源:WalkEncryption.cs

示例11: TestLogExceptionPrepends

        public void TestLogExceptionPrepends()
        {
            var exception = new IOException("io");

            _logger.LogException(exception, "Foo {0}", "Bar");
            var result = _writer.ToString();

            Assert.That(result, Is.StringStarting("Exception: IOException, io\r\n"));
        }
開發者ID:trentdm,項目名稱:TripCalculator,代碼行數:9,代碼來源:LoggerTests.cs

示例12: TestLogExceptionAppendsArgs

        public void TestLogExceptionAppendsArgs()
        {
            var exception = new IOException("io");

            _logger.LogException(exception, "Foo {0}", "Bar");
            var result = _writer.ToString();

            Assert.That(result, Is.StringEnding("Foo Bar\r\n"));
        }
開發者ID:trentdm,項目名稱:TripCalculator,代碼行數:9,代碼來源:LoggerTests.cs

示例13: ClusterBase

		static ClusterBase()
		{
			var allDead = new IOException("All nodes are dead.");

			// cached tasks for error reporting
			failSingle = new TaskCompletionSource<IOperation>();
			failBroadcast = new TaskCompletionSource<IOperation[]>();
			failSingle.SetException(allDead);
			failBroadcast.SetException(allDead);
		}
開發者ID:adamhathcock,項目名稱:EnyimMemcached2,代碼行數:10,代碼來源:ClusterBase.cs

示例14: GetErrorCode

        internal static int GetErrorCode(IOException ioe)
        {
#if !WindowsCE && !SILVERLIGHT && !NETFX_CORE
            var permission = new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode);
            permission.Demand();

            return Marshal.GetHRForException(ioe) & 0xFFFF;
#else
            return 0;
#endif
        }
開發者ID:JamieKitson,項目名稱:flickrnet-experimental,代碼行數:11,代碼來源:SafeNativeMethods.cs

示例15: TryWrapException

        // Convert HttpListenerExceptions to IOExceptions
        protected override bool TryWrapException(Exception ex, out Exception wrapped)
        {
            if (ex is HttpListenerException)
            {
                wrapped = new IOException(string.Empty, ex);
                return true;
            }

            wrapped = null;
            return false;
        }
開發者ID:Kstal,項目名稱:Microsoft.Owin,代碼行數:12,代碼來源:HttpListenerStreamWrapper.cs


注:本文中的System.IO.IOException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。