示例#1
0
        /// <inheritdoc />
        public string GetItemContent(SourceInformation sourceInformation)
        {
            sourceInformation.AssertIsValid();
            sourceInformation.AssertIsSourceType(SourceType.TfsVc);

            Logger.Trace("Entering");

            //var stream = _tfVcClient.GetItemContentAsync(searchInformation.SourcePath).Result;

            var stream =
                IgnoreExceptionsHelper.DoMethodIgnoringExceptions <Stream>(
                    new Func <string, Stream>(GetItemContentAsyncWrapper),
                    new[] { typeof(VssServiceException) },
                    sourceInformation.SourcePath
                    );

            string output = null;

            if (stream != null)
            {
                using (var reader = new StreamReader(stream))
                {
                    output = reader.ReadToEnd();
                }
            }

            return(output);
        }
示例#2
0
        /// <inheritdoc />
        public GitItem GetItem(SourceInformation searchInformation)
        {
            searchInformation.AssertIsValid();
            Validators.AssertIsNotNull(_client, "GitHttpClient");

            Logger.Trace("Entering");

            var info = $"{nameof(searchInformation)}: {searchInformation}";

            var result =
                WaitAndRetryPolicy.ExecuteAndCapture(
                    _ => IgnoreExceptionsHelper.DoMethodIgnoringExceptions <GitItem>(
                        new Func <SourceInformation, GitItem>(GetItemWrapper),
                        new[] { typeof(VssServiceException) },
                        searchInformation
                        ),
                    MakeContext(info));

            HandlePolicyResult(result, info);

            var output = result.Result;

            Logger.Trace("Exiting");

            return(output);
        }
示例#3
0
        /// <inheritdoc />
        public string GetItemContent(SourceInformation sourceInformation)
        {
            sourceInformation.AssertIsValid();
            Validators.AssertIsNotNull(_client, "GitHttpClient");

            Logger.Trace("Entering");

            string output = null;

            var info = $"{nameof(sourceInformation)}: {sourceInformation}";

            var result =
                WaitAndRetryPolicy.ExecuteAndCapture(
                    _ => IgnoreExceptionsHelper.DoMethodIgnoringExceptions <Stream>(
                        new Func <SourceInformation, Stream>(GetItemContentWrapper),
                        new[] { typeof(VssServiceException) },
                        sourceInformation
                        ),
                    MakeContext(info));

            HandlePolicyResult(result, info);

            var contentStream = result.Result;

            if (contentStream != null)
            {
                var reader = new StreamReader(contentStream);
                output = reader.ReadToEnd();
            }

            Logger.Trace("Exiting");

            return(output);
        }
示例#4
0
        public static void DoNewIgnoringExceptions_Returns_Null_WithIgnoredException2()
        {
            var result = IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <Uri>(
                new[] { typeof(UriFormatException) },
                "junk uri");

            Assert.That(result, Is.Null);
        }
示例#5
0
        public static void DoNewIgnoringExceptions_Returns_Null_WithIgnoredException1()
        {
            var result = IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <ExampleClass>(
                new[] { typeof(ArgumentException) },
                typeof(ArgumentException));

            Assert.That(result, Is.Null);
        }
示例#6
0
        public static void DoMethodIgnoringExceptions_Returns_Null_WithIgnoredException2()
        {
            var result = IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
                new Func <string, string>(File.ReadAllText),
                new[] { typeof(FileNotFoundException) },
                "junk filename");

            Assert.That(result, Is.Null);
        }
示例#7
0
        public static void DoMethodIgnoringExceptions_Returns_Null_WithIgnoredException1()
        {
            var result = IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
                new Func <Type, string>(ExampleMethod),
                new[] { typeof(ArgumentException) },
                typeof(ArgumentException));

            Assert.That(result, Is.Null);
        }
示例#8
0
 public static void DoNewIgnoringExceptions_Throws_WithNonIgnoredException2()
 {
     Assert.That(
         () => IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <Uri>(
             new[] { typeof(ArgumentException) },
             "Junk Uri"),
         Throws.TypeOf <UriFormatException>()
         );
 }
示例#9
0
 public static void DoNewIgnoringExceptions_Throws_WithNonIgnoredException1()
 {
     Assert.That(
         () => IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <ExampleClass>(
             new[] { typeof(ArgumentException) },
             typeof(InvalidOperationException)),
         Throws.InvalidOperationException
         );
 }
示例#10
0
 public static void DoMethodIgnoringExceptions_Throws_WithNonIgnoredException2()
 {
     Assert.That(
         () => IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
             new Func <string, string>(File.ReadAllText),
             new[] { typeof(ArgumentNullException) },
             "junk filename"),
         Throws.TypeOf <FileNotFoundException>());
 }
示例#11
0
 public static void DoMethodIgnoringExceptions_Throw_WithBadException()
 {
     Assert.That(
         () => IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
             new Func <Type, string>(ExampleMethod),
             new[] { typeof(string) },
             typeof(InvalidOperationException)),
         Throws.ArgumentException
         );
 }
示例#12
0
        public static void DoMethodIgnoringExceptions_Returns_Value_WithNoException1()
        {
            var result = IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
                new Func <Type, string>(ExampleMethod),
                new[] { typeof(ArgumentException) },
                typeof(string));

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Length, Is.GreaterThan(0));
        }
示例#13
0
        public static void DoNewIgnoringExceptions_Returns_Value_WithNoException2()
        {
            var result = IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <Uri>(
                new[] { typeof(ArgumentException) },
                "http://www.google.com");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.AbsoluteUri, Is.Not.Null);
            Assert.That(result.AbsoluteUri.Length, Is.GreaterThan(0));
        }
示例#14
0
        public static void DoNewIgnoringExceptions_Returns_Value_WithNoException1()
        {
            var result = IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <ExampleClass>(
                new[] { typeof(ArgumentException) },
                typeof(string));

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Value, Is.Not.Null);
            Assert.That(result.Value.Length, Is.GreaterThan(0));
        }
示例#15
0
        public static void CheckException_HandlesAggregateExceptions()
        {
            var innerException = new InvalidOperationException("Testing Inner");
            var input          = new AggregateException("Aggregate", innerException);

            Assert.That(() => IgnoreExceptionsHelper.CheckException(
                            input,
                            new[] { typeof(ArgumentException) }),
                        Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("Testing Inner"));
        }
        /// <inheritdoc />
        public string GetItemContent(SourceInformation sourceInformation)
        {
            Validators.AssertIsNotNull(sourceInformation, nameof(sourceInformation));
            sourceInformation.AssertIsValid();
            sourceInformation.AssertIsSourceType(SourceType.Filesystem);

            Logger.Trace("Entering");

            //var output = File.ReadAllText(searchInformation.SourcePath);

            var output = IgnoreExceptionsHelper.DoMethodIgnoringExceptions <string>(
                new Func <string, string>(File.ReadAllText),
                new[] { typeof(FileNotFoundException), typeof(DirectoryNotFoundException), typeof(IOException) },
                sourceInformation.SourcePath
                );

            return(output);
        }
示例#17
0
        /// <inheritdoc />
        public TfvcItem GetItem(SourceInformation searchInformation)
        {
            Validators.AssertIsNotNull(searchInformation, nameof(searchInformation));
            searchInformation.AssertIsValid();
            searchInformation.AssertIsSourceType(SourceType.TfsVc);

            Logger.Trace("Entering");

            //var output = _tfVcClient.GetItemAsync(searchInformation.SourcePath).Result;

            var output = IgnoreExceptionsHelper.DoMethodIgnoringExceptions <TfvcItem>(
                new Func <string, TfvcItem>(GetItemWrapper),
                new[] { typeof(VssServiceException) },
                searchInformation.SourcePath
                );

            return(output);
        }
        /// <inheritdoc />
        public FileInfo GetItem(SourceInformation searchInformation)
        {
            Validators.AssertIsNotNull(searchInformation, nameof(searchInformation));
            searchInformation.AssertIsValid();
            searchInformation.AssertIsSourceType(SourceType.Filesystem);

            Logger.Trace("Entering");

            var output = IgnoreExceptionsHelper.DoConstructorIgnoringExceptions <FileInfo>(
                new[] { typeof(FileNotFoundException), typeof(DirectoryNotFoundException) },
                searchInformation.SourcePath
                );

            if (!output.Exists)
            {
                output = null;
            }

            return(output);
        }