Exemplo n.º 1
0
        /// <summary>
        /// 创建本地
        /// </summary>
        /// <param name="operationName"></param>
        /// <returns></returns>
        public PartialContext CreateLocalPartialContext(string operationName)
        {
            if (operationName == null)
            {
                throw new ArgumentNullException(nameof(operationName));
            }
            PartialContext Context = GetParentPartialContext(ChannelType.Local);

            if (Context == null)
            {
                throw new NullReferenceException(nameof(PartialContext));
            }
            PartialContext Partial = new PartialContext(GetTraceId(Context), Context.HeaderValue, ChannelType.Local, operationName);

            if (Context != null)
            {
                ReferencePartialSpanContext Reference = new ReferencePartialSpanContext
                {
                    Component      = Context.Context.Component,
                    EntryServiceId = Context.RequirId,
                    LayerType      = Context.Context.LayerType,
                    OperationName  = Context.OperationName,
                    Tags           = Context.Context.Tags,
                    RequirId       = Guid.NewGuid()
                };
                Partial.References.Add(Reference);
            }
            LocalAccessor.Context = Partial;
            return(Partial);
        }
Exemplo n.º 2
0
 private void CreateCategory(PartialContext context)
 {
     if (context.Categorys.Count() == 0)
     {
         var category = new List <Category>()
         {
             new Category()
             {
                 Name        = "Banh",
                 Description = "Ngon re"
             },
             new Category()
             {
                 Name        = "Keo",
                 Description = "Ngon"
             },
             new Category()
             {
                 Name        = "Mi",
                 Description = "Bo dinh duong"
             }
         };
         context.Categorys.AddRange(category);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 创建退出
        /// </summary>
        /// <param name="operationName"></param>
        /// <returns></returns>
        public PartialContext CreateExitPartialContext(string operationName)
        {
            PartialContext Context = GetParentPartialContext(ChannelType.Exit);

            if (Context == null)
            {
                throw  new NullReferenceException(nameof(PartialContext));
            }
            PartialContext Partial = new PartialContext(GetTraceId(Context), Context.HeaderValue, ChannelType.Exit, operationName);

            if (Context != null)
            {
                var ParentReference = Context.References.FirstOrDefault();
                ReferencePartialSpanContext Reference = new ReferencePartialSpanContext
                {
                    Component      = Context.Context.Component,
                    EntryServiceId = Context.RequirId,
                    LayerType      = Context.Context.LayerType,
                    OperationName  = Context.OperationName,
                    Tags           = Context.Context.Tags,
                    RequirId       = Guid.NewGuid()
                };
                Partial.References.Add(Reference);
                if (ParentReference != null)
                {
                    Partial.References.Add(ParentReference);
                }
            }
            ExitAccessor.Context = Partial;
            return(Partial);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 释放
        /// </summary>
        /// <param name="partialContext"></param>
        public void Release(PartialContext partialContext)
        {
            if (partialContext == null)
            {
                return;
            }
            partialContext.OpenUI();
            switch (partialContext.Channel)
            {
            case ChannelType.Entry:
                EntryAccessor.Context = null;
                break;

            case ChannelType.Local:
                LocalAccessor.Context = null;
                break;

            case ChannelType.Exit:
                ExitAccessor.Context = null;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(ChannelType), partialContext.Channel, "Invalid Chanel");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 创建请求
        /// </summary>
        /// <param name="operationName"></param>
        /// <param name="carrierHeader"></param>
        /// <returns></returns>
        public PartialContext CreateEntryPartialContext(string operationName, ICarrierHeaderCollection carrierHeader)
        {
            if (operationName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(operationName));
            }
            PartialContext Partial = new PartialContext(GetTraceId(), carrierHeader.CurrentSpan, ChannelType.Entry, operationName);

            EntryAccessor.Context = Partial;
            return(Partial);
        }
        public void CommandExecuting([Object] CommandEventData EventData)
        {
            var            CommandType   = EventData.Command.CommandText?.Split(' ');
            var            operationName = $"DB {CommandType.FirstOrDefault() ?? EventData.ExecuteMethod.ToString()}";
            PartialContext Context       = CreateContext(EventData.Command, operationName);

            Context.Context.LayerType = ChannelLayerType.DB;
            Context.Context.Add("DataSource", EventData.Command.Connection.DataSource);
            Context.Context.Add("Type", (CommandType.FirstOrDefault() ?? EventData.ExecuteMethod.ToString()).GetSqlHandlerType());
            Context.Context.Add("DbInstance", EventData.Command.Connection.Database);
            Context.Context.Add("BindData", EventData.Command.Parameters?.FormatParameters(false));
            Context.Context.Add("TSQL", EventData.Command.CommandText);
        }
Exemplo n.º 7
0
        public static void AssertContext(PartialContext expected, PartialContext actual)
        {
            Assert.AreEqual(expected.Name, actual.Name, "Context names didn't match.");
            Assert.AreEqual(expected.Containers.Count, actual.Containers.Count, "Containers are not the same count.");

            using var expectedEnumerator = expected.Containers.GetEnumerator();
            using var actualEnumerator   = actual.Containers.GetEnumerator();

            while (expectedEnumerator.MoveNext() && actualEnumerator.MoveNext())
            {
                AssertContainer(expectedEnumerator.Current, actualEnumerator.Current);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 将数据绘制到UI界面
        /// </summary>
        /// <param name="Context"></param>
        internal static void OpenUI(this PartialContext Context)
        {
            string[]  IP = UIHost.Split(":");
            TcpClient Client;

            if (Clients.ContainsKey(UIHost))
            {
                Client = Clients[UIHost];
            }
            else
            {
                Client = SocketFactory.CreateClient <TcpClient>(IP[0], int.Parse(IP[1]));
                Clients.Add(UIHost, Client);
            }
            Client.LocalEndPoint = new IPEndPoint(IPAddress.Any, 9373);
            Client.Stream.ToPipeStream().WriteLine(Context.ToJson());
            Client.Stream.Flush();
        }
        private static void VerifyPartiallyInitializedOrMigrated <TContext, TMigrationsConfig>(string expectedSeed)
            where TContext : UpDownUpContext, new()
        {
            using (var context = new TContext())
            {
                Assert.Throws <AutomaticMigrationsDisabledException>(() => context.Database.Initialize(force: false));

                Assert.True(context.Database.Exists());
            }

            using (var context = new PartialContext(SimpleConnectionString <TContext>()))
            {
                Assert.False(context.Entities.Any());

                var migrations = context.Database.SqlQuery <MigrationRow>("select * from __MigrationHistory").ToList();

                Assert.Equal(1, migrations.Count);
                Assert.True(migrations.All(m => m.ContextKey == typeof(TMigrationsConfig).ToString()));
                Assert.Equal("201303090309299_Test", migrations[0].MigrationId);
            }
        }
 public void EndRequest(PartialContext partialContext, HttpContext httpContext)
 {
     partialContext.Context.StatusCode          = httpContext.Response.StatusCode;
     partialContext.Context.PenddingEnd         = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
     partialContext.Context.RequestMilliseconds = partialContext.Context.PenddingEnd - partialContext.Context.PenddingStar;
 }
Exemplo n.º 11
0
 protected override void Seed(PartialContext context)
 {
     CreateCategory(context);
 }
Exemplo n.º 12
0
 private UniqueId GetTraceId(PartialContext context = null) => context?.TraceId ?? new UniqueId(0, Thread.CurrentThread.ManagedThreadId, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1000 + GetSequence());