private void acrolinxSidebar_ReplaceRanges(object sender, Sdk.Sidebar.MatchesWithReplacementEventArgs e) { System.Diagnostics.Trace.WriteLine("acrolinxSidebar_ReplaceRanges"); SelectWholeRange(e.CheckId, e.Matches); if (textBox.SelectionLength > 0) { textBox.SelectedText = string.Join("", e.Matches.Select(m => m.Replacement)); } }
/// <summary> /// 调用系统的 getsockopt() /// </summary> /// <param name="sock"></param> /// <param name="level"></param> /// <param name="name"></param> /// <param name="val"></param> /// <param name="len"></param> /// <returns></returns> public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) { return(Sdk.SYS_GetSocketOption(sock, level, name, val, ref len)); }
/////////////////////////////////////////////////////////////////////////// /// <summary> /// 获取系统返回的错误码 /// </summary> public int SYSGetLastError() { return(Sdk.SYS_GetLastError()); }
/// <summary> /// 发送多组数据 /// 向指定连接发送多组数据 /// TCP - 顺序发送所有数据包 /// </summary> /// <param name="buffers">发送缓冲区数组</param> /// <param name="count">发送缓冲区数目</param> /// <returns>TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码</returns> public bool SendPackets(WSABUF[] buffers, int count) { return(Sdk.HP_Client_SendPackets(pClient, buffers, count)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="bytes"></param> /// <param name="offset">针对bytes的偏移</param> /// <param name="size">发多大</param> /// <returns></returns> public bool Send(byte[] bytes, int offset, int size) { return(Sdk.HP_Client_SendPart(pClient, bytes, size, offset)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="bytes"></param> /// <param name="size"></param> /// <returns></returns> public bool Send(byte[] bytes, int size) { return(Sdk.HP_Client_Send(pClient, bytes, size)); }
protected override void SetCallback() { _OnReceive = new Sdk.OnPullReceive(SDK_OnReceive); Sdk.HP_Set_FN_Server_OnPullReceive(pListener, _OnReceive); base.SetCallback(); }
private void acrolinxSidebar_SelectRanges(object sender, Sdk.Sidebar.MatchesEventArgs e) { System.Diagnostics.Trace.WriteLine("acrolinxSidebar_SelectRanges"); SelectWholeRange(e.CheckId, e.Matches); }
/// <summary> /// 发送数据 /// </summary> /// <param name="connId"></param> /// <param name="bytes"></param> /// <param name="offset">针对bytes的偏移</param> /// <param name="size">发多大</param> /// <returns></returns> public bool Send(IntPtr connId, byte[] bytes, int offset, int size) { return(Sdk.HP_Server_SendPart(pServer, connId, bytes, size, offset)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="connId"></param> /// <param name="bufferPtr"></param> /// <param name="size"></param> /// <returns></returns> public bool Send(IntPtr connId, IntPtr bufferPtr, int size) { return(Sdk.HP_Server_Send(pServer, connId, bufferPtr, size)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="connId"></param> /// <param name="bytes"></param> /// <param name="size"></param> /// <returns></returns> public bool Send(IntPtr connId, byte[] bytes, int size) { return(Sdk.HP_Server_Send(pServer, connId, bytes, size)); }
public Step(Sdk.Step step) { this.step = step; }
public void TracerProviderSdkInvokesSamplingWithCorrectParameters() { var testSampler = new TestSampler(); using var activitySource = new ActivitySource(ActivitySourceName); using var sdk = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(testSampler) .Build(); // OpenTelemetry Sdk is expected to set default to W3C. Assert.True(Activity.DefaultIdFormat == ActivityIdFormat.W3C); using (var rootActivity = activitySource.StartActivity("root")) { Assert.NotNull(rootActivity); Assert.True(rootActivity.ParentSpanId == default); // Validate that the TraceId seen by Sampler is same as the // Activity when it got created. Assert.Equal(rootActivity.TraceId, testSampler.LatestSamplingParameters.TraceId); } using (var parent = activitySource.StartActivity("parent", ActivityKind.Client)) { Assert.Equal(parent.TraceId, testSampler.LatestSamplingParameters.TraceId); using (var child = activitySource.StartActivity("child")) { Assert.Equal(child.TraceId, testSampler.LatestSamplingParameters.TraceId); Assert.Equal(parent.TraceId, child.TraceId); Assert.Equal(parent.SpanId, child.ParentSpanId); } } var customContext = new ActivityContext( ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None); using (var fromCustomContext = activitySource.StartActivity("customContext", ActivityKind.Client, customContext)) { Assert.Equal(fromCustomContext.TraceId, testSampler.LatestSamplingParameters.TraceId); Assert.Equal(customContext.TraceId, fromCustomContext.TraceId); Assert.Equal(customContext.SpanId, fromCustomContext.ParentSpanId); Assert.NotEqual(customContext.SpanId, fromCustomContext.SpanId); } // Validate that when StartActivity is called using Parent as string, // Sampling is called correctly. var act = new Activity("anything").Start(); act.Stop(); var customContextAsString = act.Id; var expectedTraceId = act.TraceId; var expectedParentSpanId = act.SpanId; using (var fromCustomContextAsString = activitySource.StartActivity("customContext", ActivityKind.Client, customContextAsString)) { Assert.Equal(fromCustomContextAsString.TraceId, testSampler.LatestSamplingParameters.TraceId); Assert.Equal(expectedTraceId, fromCustomContextAsString.TraceId); Assert.Equal(expectedParentSpanId, fromCustomContextAsString.ParentSpanId); } using (var fromInvalidW3CIdParent = activitySource.StartActivity("customContext", ActivityKind.Client, "InvalidW3CIdParent")) { // OpenTelemetry ActivityContext does not support // non W3C Ids. Starting activity with non W3C Ids // will result in no activity being created. Assert.Null(fromInvalidW3CIdParent); } }
public void TracerProvideSdkCreatesActivitySource() { using TestActivityProcessor testActivityProcessor = new TestActivityProcessor(); bool startCalled = false; bool endCalled = false; testActivityProcessor.StartAction = (a) => { startCalled = true; }; testActivityProcessor.EndAction = (a) => { endCalled = true; }; TestInstrumentation testInstrumentation = null; using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(testActivityProcessor) .AddDiagnosticSourceInstrumentation((adapter) => { testInstrumentation = new TestInstrumentation(adapter); return(testInstrumentation); }) .Build(); var adapter = testInstrumentation.Adapter; Activity activity = new Activity("test"); activity.Start(); adapter.Start(activity, ActivityKind.Internal, new ActivitySource("test", "1.0.0")); adapter.Stop(activity); activity.Stop(); Assert.True(startCalled); Assert.True(endCalled); // As Processors can be added anytime after Provider construction, // the following validates that updated processors are reflected // in ActivitySourceAdapter. TestActivityProcessor testActivityProcessorNew = new TestActivityProcessor(); bool startCalledNew = false; bool endCalledNew = false; testActivityProcessorNew.StartAction = (a) => { startCalledNew = true; }; testActivityProcessorNew.EndAction = (a) => { endCalledNew = true; }; tracerProvider.AddProcessor(testActivityProcessorNew); Activity activityNew = new Activity("test"); activityNew.Start(); adapter.Start(activityNew, ActivityKind.Internal, new ActivitySource("test", "1.0.0")); adapter.Stop(activityNew); activityNew.Stop(); Assert.True(startCalledNew); Assert.True(endCalledNew); }
/// <summary> /// 调用系统的 ::WSAIoctl() /// </summary> /// <param name="sock"></param> /// <param name="dwIoControlCode"></param> /// <param name="lpvInBuffer"></param> /// <param name="cbInBuffer"></param> /// <param name="lpvOutBuffer"></param> /// <param name="cbOutBuffer"></param> /// <param name="lpcbBytesReturned"></param> /// <returns></returns> public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) { return(Sdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned)); }
private void acrolinxSidebar_Checked(object sender, Sdk.Sidebar.CheckedEventArgs e) { System.Diagnostics.Trace.WriteLine("acrolinxSidebar_Checked"); }
/// <summary> /// 发送数据 /// </summary> /// <param name="connId"></param> /// <param name="bufferPtr"></param> /// <param name="offset">针对bufferPtr的偏移</param> /// <param name="size">发多大</param> /// <returns></returns> public bool Send(IntPtr connId, IntPtr bufferPtr, int offset, int size) { return(Sdk.HP_Server_SendPart(pServer, connId, bufferPtr, size, offset)); }
internal static object Run(int port, int totalDurationInMins) { /* * Following is sample prometheus.yml config. Adjust port,interval as needed. * * scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. # - job_name: 'OpenTelemetryTest' # # metrics_path defaults to '/metrics' # scheme defaults to 'http'. # # static_configs: # - targets: ['localhost:9184'] */ using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter("TestMeter") .AddPrometheusExporter(opt => { opt.StartHttpListener = true; opt.HttpListenerPrefixes = new string[] { $"http://localhost:{port}/" }; }) .Build(); ObservableGauge <long> gauge = MyMeter.CreateObservableGauge <long>( "Gauge", () => { var tag1 = new KeyValuePair <string, object>("tag1", "value1"); var tag2 = new KeyValuePair <string, object>("tag2", "value2"); return(new List <Measurement <long> >() { new Measurement <long>(RandomGenerator.Next(1, 1000), tag1, tag2), }); }); using var token = new CancellationTokenSource(); Task writeMetricTask = new Task(() => { while (!token.IsCancellationRequested) { Counter.Add( 10, new KeyValuePair <string, object>("tag1", "value1"), new KeyValuePair <string, object>("tag2", "value2")); Counter.Add( 100, new KeyValuePair <string, object>("tag1", "anothervalue"), new KeyValuePair <string, object>("tag2", "somethingelse")); MyHistogram.Record( RandomGenerator.Next(1, 1500), new KeyValuePair <string, object>("tag1", "value1"), new KeyValuePair <string, object>("tag2", "value2")); Task.Delay(10).Wait(); } }); writeMetricTask.Start(); token.CancelAfter(totalDurationInMins * 60 * 1000); System.Console.WriteLine($"OpenTelemetry Prometheus Exporter is making metrics available at http://localhost:{port}/metrics/"); System.Console.WriteLine($"Press Enter key to exit now or will exit automatically after {totalDurationInMins} minutes."); System.Console.ReadLine(); token.Cancel(); System.Console.WriteLine("Exiting..."); return(null); }
/// <summary> /// 发送多组数据 /// 向指定连接发送多组数据 /// TCP - 顺序发送所有数据包 /// </summary> /// <param name="connId">连接 ID</param> /// <param name="pBuffers">发送缓冲区数组</param> /// <param name="iCount">发送缓冲区数目</param> /// <returns>TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码</returns> public bool SendPackets(IntPtr connId, WSABUF[] pBuffers, int count) { return(Sdk.HP_Server_SendPackets(pServer, connId, pBuffers, count)); }
/// <summary> /// 抓取数据 /// 用户通过该方法从 Socket 组件中抓取数据 /// </summary> /// <param name="connId"></param> /// <param name="pBuffer"></param> /// <param name="size"></param> /// <returns></returns> public FetchResult Fetch(IntPtr connId, IntPtr pBuffer, int size) { return(Sdk.HP_TcpPullServer_Fetch(PServer, connId, pBuffer, size)); }
/// <summary> /// 名称:发送小文件 /// 描述:向指定连接发送 4096 KB 以下的小文件 /// </summary> /// <param name="connId"></param> /// <param name="filePath">文件路径</param> /// <param name="head">头部附加数据</param> /// <param name="tail">尾部附加数据</param> /// <returns>TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码</returns> public bool SendSmallFile(IntPtr connId, string filePath, ref WSABUF head, ref WSABUF tail) { return(Sdk.HP_TcpServer_SendSmallFile(pServer, connId, filePath, ref head, ref tail)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="bufferPtr"></param> /// <param name="size"></param> /// <returns></returns> public bool Send(IntPtr bufferPtr, int size) { return(Sdk.HP_Client_Send(pClient, bufferPtr, size)); }
/// <summary> /// 断开与某个客户的连接 /// </summary> /// <param name="connId"></param> /// <param name="bForce">是否强制断开</param> /// <returns></returns> public bool Disconnect(IntPtr connId, bool force = true) { return(Sdk.HP_Server_Disconnect(pServer, connId, force)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="bufferPtr"></param> /// <param name="offset">针对bufferPtr的偏移</param> /// <param name="size">发多大</param> /// <returns></returns> public bool Send(IntPtr bufferPtr, int offset, int size) { return(Sdk.HP_Client_SendPart(pClient, bufferPtr, size, offset)); }
/// <summary> /// 断开超过指定时长的静默连接 /// </summary> /// <param name="period">毫秒</param> /// <param name="force">强制</param> /// <returns></returns> public bool DisconnectSilenceConnections(uint period, bool force = true) { return(Sdk.HP_Server_DisconnectSilenceConnections(pServer, period, force)); }
/// <summary> /// </summary> /// <param name="length"></param> /// <returns></returns> public bool GetPendingDataLength(ref int length) { return(Sdk.HP_Client_GetPendingDataLength(pClient, ref length)); }
/// <summary> /// 获取连接中未发出数据的长度 /// </summary> /// <param name="connId"></param> /// <param name="length"></param> /// <returns></returns> public bool GetPendingDataLength(IntPtr connId, ref int length) { return(Sdk.HP_Server_GetPendingDataLength(pServer, connId, ref length)); }
/// <summary> /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 /// </summary> public int SYSWSAGetLastError() { return(Sdk.SYS_WSAGetLastError()); }
/// <summary> /// 获取某个连接静默时间(毫秒) /// </summary> /// <param name="connId"></param> /// <param name="period"></param> /// <returns></returns> public bool GetSilencePeriod(IntPtr connId, ref uint period) { return(Sdk.HP_Server_GetSilencePeriod(pServer, connId, ref period)); }
/// <summary> /// 调用系统的 ioctlsocket() /// </summary> /// <param name="sock"></param> /// <param name="cmd"></param> /// <param name="arg"></param> /// <returns></returns> public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) { return(Sdk.SYS_IoctlSocket(sock, cmd, arg)); }
/// <summary> /// 抓取数据 /// 用户通过该方法从 Socket 组件中抓取数据 /// </summary> /// <param name="connId"></param> /// <param name="pBuffer"></param> /// <param name="size"></param> /// <returns></returns> public FetchResult Peek(IntPtr connId, IntPtr pBuffer, int size) { return(Sdk.HP_TcpPullAgent_Peek(PAgent, connId, pBuffer, size)); }
/// <summary> /// Creates an instance of <see cref="AssertException"/>. /// </summary> /// <param name="original"> /// The exception thrown by the xUnit core. /// </param> public AssertException(Sdk.AssertException original) : base(original.Message) { }
public void SqlClientCallsAreCollectedSuccessfully( string beforeCommand, string afterCommand, CommandType commandType, string commandText, bool captureStoredProcedureCommandName, bool captureTextCommandContent, bool shouldEnrich = true) { using var sqlConnection = new SqlConnection(TestConnectionString); using var sqlCommand = sqlConnection.CreateCommand(); var processor = new Mock <BaseProcessor <Activity> >(); using (Sdk.CreateTracerProviderBuilder() .AddSqlClientInstrumentation( (opt) => { opt.SetDbStatementForText = captureTextCommandContent; opt.SetDbStatementForStoredProcedure = captureStoredProcedureCommandName; if (shouldEnrich) { opt.Enrich = ActivityEnrichment; } }) .AddProcessor(processor.Object) .Build()) { var operationId = Guid.NewGuid(); sqlCommand.CommandType = commandType; sqlCommand.CommandText = commandText; var beforeExecuteEventData = new { OperationId = operationId, Command = sqlCommand, Timestamp = (long?)1000000L, }; this.fakeSqlClientDiagnosticSource.Write( beforeCommand, beforeExecuteEventData); var afterExecuteEventData = new { OperationId = operationId, Command = sqlCommand, Timestamp = 2000000L, }; this.fakeSqlClientDiagnosticSource.Write( afterCommand, afterExecuteEventData); } Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. VerifyActivityData( sqlCommand.CommandType, sqlCommand.CommandText, captureStoredProcedureCommandName, captureTextCommandContent, false, false, sqlConnection.DataSource, (Activity)processor.Invocations[2].Arguments[0]); }
public void SuccessfulCommandTest( CommandType commandType, string commandText, bool captureStoredProcedureCommandName, bool captureTextCommandContent = false, bool isFailure = false, bool recordException = false, bool shouldEnrich = true) { var activityProcessor = new Mock <BaseProcessor <Activity> >(); var sampler = new TestSampler(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .SetSampler(sampler) .AddSqlClientInstrumentation(options => { #if !NETFRAMEWORK options.SetDbStatementForStoredProcedure = captureStoredProcedureCommandName; options.SetDbStatementForText = captureTextCommandContent; options.RecordException = recordException; #else options.SetDbStatement = captureStoredProcedureCommandName; #endif if (shouldEnrich) { options.Enrich = ActivityEnrichment; } }) .Build(); #if NETFRAMEWORK // RecordException not available on netfx recordException = false; #endif using SqlConnection sqlConnection = new SqlConnection(SqlConnectionString); sqlConnection.Open(); string dataSource = sqlConnection.DataSource; sqlConnection.ChangeDatabase("master"); using SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection) { CommandType = commandType, }; try { sqlCommand.ExecuteNonQuery(); } catch { } Assert.Equal(3, activityProcessor.Invocations.Count); var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; VerifyActivityData(commandType, commandText, captureStoredProcedureCommandName, captureTextCommandContent, isFailure, recordException, dataSource, activity); VerifySamplingParameters(sampler.LatestSamplingParameters); }
protected override void ProcessRecord() { WriteObject(Sdk.GetNotebook(GetWorkspaceSetting()), true); }
internal static IQuery FreeTextMatches(Sdk.FieldType fieldType, string name, string freeTextExpression) { return new FieldQuery { FieldType = fieldType, Field = name, Operator = Operators.Match, Value = new PrimtiveFieldValue(freeTextExpression) }; }
private void SetDebugFlag( Sdk.ApiLogFlags flag, bool replaceFlagValue = false ) { if( this.ApiLogFlags == ApiLogFlags.None || replaceFlagValue == true || this.ApiLogFlags == ApiLogFlags.Everything ) this.ApiLogFlags = flag; else this.ApiLogFlags = this.ApiLogFlags | flag; }