/// <summary> /// COPY所有简单类型的属性的值 /// </summary> /// <typeparam name="TCopyTo"></typeparam> /// <param name="copyFrom"></param> /// <param name="copyTo"></param> /// <param name="excludeProperties"></param> /// <returns></returns> public static void TryCopyTo <TCopyTo>(this object copyFrom, TCopyTo copyTo, params string[] excludeProperties) { if (copyFrom == null) { return; } if (copyTo == null) { throw new ArgumentNullException("copyTo"); } //better relace impl from reflection with expression tree, not find good impl yet. todo MyModelHelper.TryCopyProperties(copyTo, copyFrom, excludeProperties); }
private ClientSpan CreateSaveClientSpans(string tracerId, string traceId, string parentSpanId, string spanId, string opName, bool withLogs = false) { var clientSpan = ClientSpan.Create(tracerId, traceId, parentSpanId, spanId, opName); var saveClientSpan = new ClientSpan(); MyModelHelper.SetProperties(saveClientSpan, clientSpan); if (withLogs) { saveClientSpan.Logs.Add("foo-log-key", LogItem.Create("foo-log-key", "foo-log-value", null)); saveClientSpan.Tags.Add("foo-tag-key", "foo-tag-value"); } return(saveClientSpan); }
public static T WithProperties <T>(this T instance, object copyFrom) { if (copyFrom == null) { return(instance); } var items = MyModelHelper.GetKeyValueDictionary(copyFrom); var propertyNames = MyModelHelper.GetPropertyNames(copyFrom.GetType()); foreach (var propertyName in propertyNames) { MyModelHelper.SetProperty(instance, propertyName, items[propertyName]); } return(instance); }
public AccountDto GetAccount(GetAccountArgs args) { if (args == null) { return(null); } var theOne = _context.Accounts.FirstOrDefault(x => x.Username == args.Username); if (theOne == null) { return(null); } var accountDto = new AccountDto(); MyModelHelper.SetProperties(accountDto, theOne); return(accountDto); }
public Task Add(IList <IClientSpan> spans) { if (spans == null || spans.Count == 0) { return(0.AsTask()); } var entities = new List <ClientSpanEntity>(); foreach (var span in spans) { var spanEntity = new ClientSpanEntity(); MyModelHelper.SetProperties(spanEntity, span); entities.Add(spanEntity); } var jsonLine = entities.ToJson(false); var now = spans.Min(x => x.StartUtc); var archive = DateTimeRangeArchive.Create(now); var filePath = CreateFilePath(archive.ArchiveId); return(_asyncFile.AppendAllText(filePath, jsonLine, true)); }
private IList <SimpleProcessInfo> GetProcessInfos(string iniFileName) { var processInfos = new List <SimpleProcessInfo>(); var simpleIniFile = SimpleIni.ResolveFile(); var fullPath = Path.GetFullPath(AppDomain.CurrentDomain.Combine(iniFileName)); if (!File.Exists(fullPath)) { LogInfo("IniFile Not Exist: " + fullPath); return(processInfos); } var traceIniItems = simpleIniFile.TryLoadIniFileItems(fullPath); if (traceIniItems == null) { LogInfo(fullPath + " has no items value "); return(processInfos); } LogInfo(string.Format("-----{0}----", iniFileName)); foreach (var item in traceIniItems) { LogInfo(string.Format("{0}: {1}", item.Key, item.Value)); } var processesValue = simpleIniFile.GetValue(traceIniItems, "Daemon", "Processes"); if (processesValue == null) { LogInfo("[Daemon]Processes is null!"); return(processInfos); } var processSections = processesValue.ToString().Trim().Split(new[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .ToList(); foreach (var processSection in processSections) { //[TraceApi] //ProcessName="SimpleTrace.Api" //ExePath="TraceApi\SimpleTrace.Api.exe" //ExeArgs= var processNameValue = simpleIniFile.GetValue(traceIniItems, processSection, "ProcessName"); var exePathValue = simpleIniFile.GetValue(traceIniItems, processSection, "ExePath"); var exeArgsValue = simpleIniFile.GetValue(traceIniItems, processSection, "ExeArgs"); var processName = processNameValue == null ? string.Empty : processNameValue.ToString(); var exePath = exePathValue == null ? string.Empty : exePathValue.ToString(); var exeArgs = exeArgsValue == null ? string.Empty : exeArgsValue.ToString(); if (string.IsNullOrWhiteSpace(processName)) { LogInfo(string.Format("SimpleTrace.ini => [{0}]ProcessName is null!", processSection)); continue; } if (string.IsNullOrWhiteSpace(exePath)) { LogInfo(string.Format("SimpleTrace.ini => [{0}]ExePath is null!", processSection)); continue; } var fullExePath = Path.GetFullPath(AppDomain.CurrentDomain.Combine(exePath)); var processInfo = SimpleProcessInfo.Create(processName, fullExePath, exeArgs); LogInfo(string.Format("----{0}----", processSection)); LogInfo(MyModelHelper.MakeIniString(processInfo)); processInfos.Add(processInfo); } return(processInfos); }
private static void AddTraceClients(IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IClientTracerApi, ClientTracerApi>(); services.AddSingleton <CommandQueue>(); services.AddSingleton <CommandQueueTask>(); //SimpleTrace.dll var assemblyToScan = Assembly.GetAssembly(typeof(ICommandLogistic)); //All IClientSpanProcess services.AddSingletonFromAssembly(assemblyToScan, typeof(IClientSpanProcess)); //All ICommandLogistic and KnownCommands services.AddSingletonFromAssembly(assemblyToScan, typeof(ICommandLogistic)); services.AddSingleton(sp => { var knownCommands = KnownCommands.Instance; var commandLogistics = sp.GetServices <ICommandLogistic>().ToList(); foreach (var commandLogistic in commandLogistics) { knownCommands.Register(commandLogistic); } return(knownCommands); }); //TraceConfig var traceConfig = TryLoadTraceConfig(configuration); services.AddSingleton(traceConfig); //CommandQueueTaskLoop services.AddSingleton(sp => { var commandQueueTaskLoop = new CommandQueueTaskLoop(); var queueTask = sp.GetService <CommandQueueTask>(); var knownCommands = sp.GetService <KnownCommands>(); var commandLogistics = sp.GetServices <ICommandLogistic>().ToList(); foreach (var commandLogistic in commandLogistics) { knownCommands.Register(commandLogistic); } commandQueueTaskLoop.Init( TimeSpan.FromSeconds(traceConfig.FlushIntervalSecond), queueTask, sp.GetService <CommandQueue>(), sp.GetServices <ICommandLogistic>(), sp.GetServices <IClientSpanProcess>(), DateHelper.Instance.GetDateNow); return(commandQueueTaskLoop); }); services.AddSingleton(CommandQueueProcessLogs.Instance); //IClientSpanRepository if (traceConfig.TraceSaveProcessEnabled) { services.AddSingleton <IClientSpanRepository, ClientSpanRepository>(); } else { services.AddSingleton <IClientSpanRepository, NullClientSpanRepository>(); } //TracerContext var tracerContext = TracerContext.Resolve(); services.AddSingleton <TracerContext>(tracerContext); if (traceConfig.TraceSendProcessEnabled) { //JaegerTracerConfig var jaegerTracerConfig = new JaegerTracerConfig(); jaegerTracerConfig.DefaultTracerId = traceConfig.DefaultTracerId; jaegerTracerConfig.TraceEndPoint = traceConfig.TraceEndPoint; services.AddSingleton(jaegerTracerConfig); //ITracerFactory and TracerContext var tracerFactory = new JaegerTracerFactory(jaegerTracerConfig); services.AddSingleton <ITracerFactory>(tracerFactory); tracerContext.Factory = tracerFactory; //ITraceSender services.AddSingleton <ITraceSender, JaegerTraceSender>(); //log TraceConfig var tracer = tracerContext.Current(); using (var scope = tracer.BuildSpan("LogObject").StartActive(true)) { scope.Span.SetTag("Name", "TraceConfig"); var dictionary = MyModelHelper.GetKeyValueDictionary(traceConfig); foreach (var kv in dictionary) { scope.Span.Log(kv.Key + " : " + kv.Value); } } } else { services.AddSingleton <ITracerFactory, NullTracerFactory>(); services.AddSingleton <ITraceSender, NullTraceSender>(); } }