protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestedMethod = request.Method; var userHostAddress = "";//HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : "0.0.0.0"; var useragent = request.Headers.UserAgent.ToString(); var requestMessage = await request.Content.ReadAsByteArrayAsync(); var uriAccessed = request.RequestUri.AbsoluteUri; var responseHeadersString = new StringBuilder(); foreach (var header in request.Headers) { responseHeadersString.Append($"{header.Key}: {String.Join(", ", header.Value)}{Environment.NewLine}"); } var messageLoggingHandler = new MessageLogging(); var requestLog = new ApiLog() { Headers = responseHeadersString.ToString(), AbsoluteUri = uriAccessed, Host = userHostAddress, RequestBody = Encoding.UTF8.GetString(requestMessage), UserHostAddress = userHostAddress, Useragent = useragent, RequestedMethod = requestedMethod.ToString(), StatusCode = string.Empty }; messageLoggingHandler.IncomingMessageAsync(requestLog); var response = await base.SendAsync(request, cancellationToken); byte[] responseMessage; if (response.IsSuccessStatusCode) { responseMessage = await response.Content.ReadAsByteArrayAsync(); } else { responseMessage = Encoding.UTF8.GetBytes(response.ReasonPhrase); } var responseLog = new ApiLog() { Headers = responseHeadersString.ToString(), AbsoluteUri = uriAccessed, Host = userHostAddress, RequestBody = Encoding.UTF8.GetString(responseMessage), UserHostAddress = userHostAddress, Useragent = useragent, RequestedMethod = requestedMethod.ToString(), StatusCode = string.Empty }; messageLoggingHandler.OutgoingMessageAsync(responseLog); return(response); }
public void TestInit() { MessageLogging.SetLogFileName(MessageLogging.WriteType.OverWrite, true); TestServerName = Environment.GetEnvironmentVariable("COMPUTERNAME"); TestDatabaseName = "DbaAdmin"; SqlProcessor = new SqlProcessor(TestServerName, TestDatabaseName); }
public void TestInit() { MessageLogging.SetLogFileName(MessageLogging.WriteType.OverWrite, true); TestServerName = Environment.GetEnvironmentVariable("COMPUTERNAME"); TestDatabaseName = "DbaAdmin"; SqlProcessor = new SqlProcessor(TestServerName, TestDatabaseName); // NOTE! The stored proceudre uspTestParameters must be installed on DbaAdmin // for the tests. }
/// <summary> /// set of callbacks to perform after timer elapse interval /// </summary> /// <param name="callBackActions">list of callbacks inside this wrapper to execute</param> public void Callback(List <Action> callBackActions) { // only execute callbacks if timer is enabled. if (Enabled) { /* * AutoReset = false, so a callback is only executed once, * because of this overlapping callbacks should not occur, * but to be sure exclusive locking is also used. */ var hasLock = false; // show heartbeat at output window if (ShowHeartBeat) { Debug.WriteLine(string.Format("HeartBeat interval: {0}...{1}/thread: 0x{2:X4}", TimerName, ++HeartbeatCounter, AppDomain.GetCurrentThreadId())); } // execute callback action. try { // only perform set of actions if not executing already on this thread. Monitor.TryEnter(locker, ref hasLock); if (hasLock) { // show heartbeat at output window if (ShowHeartBeat) { Debug.WriteLine(string.Format(" action: {0}...{1}/thread: 0x{2:X4}", TimerName, HeartbeatCounter, AppDomain.GetCurrentThreadId())); } // execute the set of callback actions foreach (Action callBackAction in callBackActions) { // execute callback try { callBackAction(); } // log error, but keep the action loop going. catch (Exception ex) { EventLog.WriteEntry(ex.Message, EventLogEntryType.Warning); MessageLogging.Insert(ex.Message); } } } // show that action is busy else if (ShowHeartBeat) { Debug.WriteLine(string.Format(" busy: {0}...{1}/thread: 0x{2:X4}", TimerName, HeartbeatCounter, AppDomain.GetCurrentThreadId())); } } // adjust interval when needed and release exclusive lock when done. finally { // after the complete action is finished the lock should be released. if (hasLock) { // timer interval can be changed when timer is active, callback function is needed for this. double newInterval = 0; if (UpdatebleInterval != null) { // calculate new interval for timer double updatedInterval = UpdatebleInterval(); if (Interval != updatedInterval) { // based on Dutch var dutchCultureInfo = new CultureInfo("nl-NL", false).TextInfo; // write interval change to loggings string intervalMessage = dutchCultureInfo.ToTitleCase(string.Format(@"{0} interval veranderd van {1} naar {2} seconden", TimerName, Interval / 1000, updatedInterval / 1000)); EventLog.WriteEntry(intervalMessage, EventLogEntryType.Information); MessageLogging.Insert(intervalMessage); // set for new interval newInterval = updatedInterval; } } // make ready for new callback after elapsed time, lock can be released by now. Reset(newInterval); } } } // show heartbeat at output window else if (ShowHeartBeat) { Debug.WriteLine(string.Format("HeartBeat thread: {0}...{1}/thread: 0x{2:X4}", TimerName, ++HeartbeatCounter, AppDomain.GetCurrentThreadId())); } }