Exemplo n.º 1
0
        /// <summary>
        /// The equivalent to Path.GetFullPath which returns absolute but for vectors (including URI's)
        ///
        /// Resolves the
        /// </summary>
        /// <param name="self"></param>
        /// <param name="values"></param>
        /// <returns>return absolution path</returns>
        public static string GetAbsolutlePath(this string self, params string[] values)
        {
            self.Verify(nameof(self)).IsNotEmpty();

            StringVector vectorValue = StringVector.Parse(self.Trim())
                                       .With(values);

            var vectors = vectorValue
                          .Where(x => !x.IsEmpty() && x != ".")
                          .ToList();

            var stack = new Stack <string>();

            foreach (var item in vectors)
            {
                if (item == "..")
                {
                    stack.Count.Verify().Assert <int, FormatException>(x => x > 0, $"Relative path format error: {vectorValue}, cannot process '../'");

                    // Remove the last path vector
                    stack.Pop();
                    continue;
                }

                stack.Push(item);
            }

            return((vectorValue.HasRoot ? "/" : string.Empty) + string.Join("/", stack.Reverse()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set code tag
        /// </summary>
        /// <param name="tag">code tag</param>
        /// <returns>this</returns>
        public WorkContextBuilder Set(StringVector tag)
        {
            tag.Verify().IsNotNull();

            Tag = Tag.With(tag);
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct work context, for values that are not known to be immutable, shallow copies are made
        /// </summary>
        /// <param name="cv">correlation vector</param>
        /// <param name="tag">code location tag</param>
        /// <param name="container">container</param>
        /// <param name="properties">properties (optional)</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <param name="eventLog"></param>
        /// <param name="dimensions"></param>
        public WorkContext(
            CorrelationVector cv,
            StringVector tag,
            IServiceProvider?container,
            CancellationToken?cancellationToken = null,
            ITelemetry?eventLog         = null,
            IEventDimensions?dimensions = null
            )
        {
            cv.Verify().IsNotNull();
            cv.Verify().IsNotNull();

            Cv                = cv;
            Tag               = tag;
            Container         = container;
            CancellationToken = cancellationToken ?? CancellationToken.None;
            Telemetry         = eventLog ?? new TelemetryLogNull();
            Dimensions        = dimensions != null ? new EventDimensions(dimensions) : new EventDimensions();
        }
        public static TelemetryMessage?ConvertJsonToTelemetryMessage(this string jsonMessage)
        {
            if (jsonMessage.IsEmpty())
            {
                return(null);
            }

            //var md = JsonSerializer.Deserialize<TelemetryMessageModel>(jsonMessage);
            var md = JsonConvert.DeserializeObject <TelemetryMessageModel>(jsonMessage);

            md.Verify(nameof(md)).IsNotNull();

            IWorkContext context = new WorkContextBuilder()
            {
                Cv  = md.Cv != null ? new CorrelationVector(md.Cv) : new CorrelationVector(),
                Tag = md.Tag != null?StringVector.Parse(md.Tag) : StringVector.Empty,
            }.Build();

            return(new TelemetryMessage(md, context));
        }