当前位置: 首页>>代码示例>>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;未经允许,请勿转载。