示例#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()));
        }
        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));
        }