• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.IOException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IO.IOException的典型用法代码示例。如果您正苦于以下问题:C# IOException类的具体用法?C# IOException怎么用?C# IOException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IOException类属于System.IO命名空间,在下文中一共展示了IOException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetHResult

        static int GetHResult(IOException exception, int defaultValue)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            var field = exception.GetType().GetField("_HResult", BindingFlags.NonPublic | BindingFlags.Instance);
            if (field != null)
                return Convert.ToInt32(field.GetValue(exception));

            return defaultValue;
        }
开发者ID:pjlammertyn,项目名称:Cozo-Broker,代码行数:11,代码来源:Utils.cs


示例17: IsSharingViolation

        static bool IsSharingViolation(
            IOException ioEx)
        {
            var field = ioEx
                .GetType().GetField("_HResult", BindingFlags.NonPublic | BindingFlags.Instance);
            if (field == null) return false;

            var hres = (int) field.GetValue(ioEx);
            Debug.WriteLine("Error '{0}' {1}", ioEx.Message, hres);

            return hres == HResultSharingViolation;
        }
开发者ID:MrAntix,项目名称:Folder,代码行数:12,代码来源:IOFileSystemWorker.cs


示例18: GetHResult

        /// <summary>
        /// Gets the HRESULT of the specified exception.
        /// </summary>
        /// <param name="exception">The exception to test. May not be null.</param>
        /// <param name="defaultValue">The default value in case of an error.</param>
        /// <returns>The HRESULT value.</returns>
        private static int GetHResult(IOException exception, int defaultValue)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            try
            {
                return (int)exception.GetType().GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exception, null);
            }
            catch
            {
                return defaultValue;
            }
        }
开发者ID:JmAbuDabi,项目名称:auto-extractor-net,代码行数:20,代码来源:IOUtils.cs


示例19: NativeFileReader

        public NativeFileReader(string file)
        {
            // FILE_SHARE_READ = 1
            hFileHandle = FileNativeMethods.CreateFile(file, GENERIC_READ, 1, 0, (uint)FileMode.Open, FILE_FLAG_NO_BUFFERING, 0);

            // Invalid handle value
            if (hFileHandle == (IntPtr)(-1))
            {
                IOException eb = new IOException("File can not open", null);
                throw eb;
            }

            m_FileSize = FileNativeMethods.SetFilePointer(hFileHandle, 0, 0, SeekOrigin.End);
            Position = 0;
        }
开发者ID:HaKDMoDz,项目名称:baro-corelibrary,代码行数:15,代码来源:NativeFileReader.cs


示例20: DataRefreshError_IsRaisedOnUpstreamDataRefreshErrors

        public void DataRefreshError_IsRaisedOnUpstreamDataRefreshErrors()
        {
            Exception upstreamException = null;
            Subject.Upstream = Mocked<IPublicSuffixDataSource>().Object;
            Subject.DataRefreshError += (s, e) =>
            {
                upstreamException = e.Exception;
            };

            var mockError = new IOException();
            Mocked<IPublicSuffixDataSource>()
                .Raise(s => s.DataRefreshError += null, new PublicSuffixErrorEventArgs(mockError));

            upstreamException.Should().Be(mockError);
        }
开发者ID:DullReferenceException,项目名称:dotnet-publicsuffix-data,代码行数:15,代码来源:InMemoryPublicSuffixDataSourceTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.MemoryStream类代码示例发布时间:2022-05-26
下一篇:
C# IO.FileType类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap