Exemplo n.º 1
0
 public static Uri TryParseUrl(TraceContext trace, Uri documentRoot, JToken token)
 {
     Guard.NotNull(trace, "trace");
     using (trace.EnterExit())
     {
         if (token.Type == JTokenType.String)
         {
             string val = token.Value<string>();
             if (!String.IsNullOrEmpty(val))
             {
                 Uri url;
                 if (Uri.TryCreate(val, UriKind.RelativeOrAbsolute, out url))
                 {
                     // Resolve the url if possible
                     if (documentRoot != null && !url.IsAbsoluteUri)
                     {
                         url = new Uri(documentRoot, url);
                     }
                     return url;
                 }
             }
         }
         return null;
     }
 }
Exemplo n.º 2
0
            private void PassThroughTest(Action <TraceContext> tracerAction, Action <string, Mock <ITraceSink> > sinkVerifier)
            {
                // Arrange
                var sink   = new Mock <ITraceSink>();
                var tracer = new TraceContext("foo", sink.Object);

                // Act
                tracerAction(tracer);

                // Assert
                sinkVerifier("foo", sink);
            }
        /// <summary>
        /// Constructs a new <see cref="ServiceInvocationContext"/> using the specified <see cref="HttpClient"/>, <see cref="ITraceSink"/>, base URL and <see cref="CancellationToken"/>.
        /// </summary>
        /// <param name="httpClient">The <see cref="HttpClient"/> object to use to make Http Requests.</param>
        /// <param name="trace">The <see cref="ITraceSink"/> object to write trace events to.</param>
        /// <param name="baseUrl">The base URL of the <see cref="NuGetRepository"/> associated with this invocation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to check for cancellation.</param>
        public ServiceInvocationContext(HttpClient httpClient, ITraceSink trace, Uri baseUrl, CancellationToken cancellationToken)
        {
            Guard.NotNull(httpClient, "httpClient");
            Guard.NotNull(trace, "trace");
            Guard.NotNull(baseUrl, "baseUrl");

            InvocationId = Tracing.GetNextInvocationId().ToString(CultureInfo.InvariantCulture);
            _client = httpClient;
            Trace = new TraceContext(InvocationId, trace);
            BaseUrl = baseUrl;
            CancellationToken = cancellationToken;

            Trace.Start();
        }
Exemplo n.º 4
0
        public static IEnumerable<Uri> ParseUrlArray(IEnumerable<JToken> array, TraceContext trace, Uri documentRoot, string invalidUrlErrorFormat)
        {
            Guard.NotNull(trace, "trace");

            using (trace.EnterExit())
            {
                return array == null ?
                    Enumerable.Empty<Uri>() :
                    array.Select(token => {
                        var url = TryParseUrl(trace, documentRoot, token);
                        if (url == null)
                        {
                            trace.JsonParseWarning(token, String.Format(CultureInfo.CurrentCulture, invalidUrlErrorFormat, token.ToDisplayString()));
                        }
                        return url;
                    })
                    .Where(url => url != null);
            }
        }
Exemplo n.º 5
0
        public static IEnumerable<KeyValuePair<string, Uri>> ParseUrlDictionary(JObject obj, TraceContext trace, Uri documentRoot, string invalidUrlErrorFormat)
        {
            Guard.NotNull(trace, "trace");

            using (trace.EnterExit())
            {
                return obj == null ?
                    Enumerable.Empty<KeyValuePair<string, Uri>>() :
                    obj
                        .Properties()
                        .Select(prop =>
                        {
                            var url = TryParseUrl(trace, documentRoot, prop.Value);
                            if (url == null)
                            {
                                trace.JsonParseWarning(prop.Value, String.Format(CultureInfo.CurrentCulture, invalidUrlErrorFormat, prop.Value.ToDisplayString(), prop.Name));
                            }
                            return new KeyValuePair<string, Uri>(prop.Name, url);
                        })
                        .Where(pair => pair.Value != null);
            }
        }
Exemplo n.º 6
0
 public EnterExitTracer(TraceContext tracer, string methodName) { 
     _tracer = tracer;
     _methodName = methodName;
 }
Exemplo n.º 7
0
 public EnterExitTracer(TraceContext tracer, string methodName)
 {
     _tracer     = tracer;
     _methodName = methodName;
 }
Exemplo n.º 8
0
            private void PassThroughTest(Action<TraceContext> tracerAction, Action<string, Mock<ITraceSink>> sinkVerifier)
            {
                // Arrange
                var sink = new Mock<ITraceSink>();
                var tracer = new TraceContext("foo", sink.Object);

                // Act
                tracerAction(tracer);

                // Assert
                sinkVerifier("foo", sink);
            }