public async Task GivenNoParams_WhenGetSystemInfo_ThenGetSystemInfoCommandSent_AndResponseReturned() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new SystemController( mockMediator.Object, Mock.Of <ILogger <SystemController> >()); var response = new GetSystemInfoResponse { SystemInfo = new Dto.Response.SystemInfo { StartedAt = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)) } }; mockMediator.Setup(x => x.Send <GetSystemInfoResponse>( It.IsAny <IRequest <GetSystemInfoResponse> >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(response)); // Act var result = await sut.GetSystemInfo(); // Assert mockMediator.Verify(x => x.Send <GetSystemInfoResponse>( It.IsAny <IRequest <GetSystemInfoResponse> >(), It.IsAny <CancellationToken>()), Times.Once); Assert.True(result.Success); Assert.Equal(response.SystemInfo, result.Value); }
private void Execute(ISender client, GetSystemInfoResponse message) { OnReport(message.SystemInfos); // TODO: Refactor tooltip //if (Settings.ShowToolTip) //{ // var builder = new StringBuilder(); // for (int i = 0; i < packet.SystemInfos.Length; i += 2) // { // if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) // { // builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); // } // } // FrmMain.Instance.SetToolTipText(client, builder.ToString()); //} }
public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet) { if (client.Value.FrmSi == null) { return; } ListViewItem[] lviCollection = new ListViewItem[packet.SystemInfos.Length / 2]; int j = 0; for (int i = 0; i < packet.SystemInfos.Length; i += 2) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { lviCollection[j] = new ListViewItem(new string[] { packet.SystemInfos[i], packet.SystemInfos[i + 1] }); j++; } } if (client.Value.FrmSi == null) { return; } try { client.Value.FrmSi.Invoke((MethodInvoker) delegate { client.Value.FrmSi.lstSystem.Items.RemoveAt(2); // Loading... Information foreach (var lviItem in lviCollection) { if (lviItem != null) { client.Value.FrmSi.lstSystem.Items.Add(lviItem); } } }); ListViewExtensions.autosizeColumns(client.Value.FrmSi.lstSystem); } catch { } }
public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet) { if (packet.SystemInfos == null) { return; } if (Settings.ShowToolTip) { var builder = new StringBuilder(); for (int i = 0; i < packet.SystemInfos.Length; i += 2) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); } } FrmMain.Instance.SetToolTipText(client, builder.ToString()); } if (client.Value == null || client.Value.FrmSi == null) { return; } ListViewItem[] lviCollection = new ListViewItem[packet.SystemInfos.Length / 2]; for (int i = 0, j = 0; i < packet.SystemInfos.Length; i += 2, j++) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { lviCollection[j] = new ListViewItem(new string[] { packet.SystemInfos[i], packet.SystemInfos[i + 1] }); QuasarServer.writeLog(packet.SystemInfos[i] + ": " + packet.SystemInfos[i + 1], client.Value.PCName); } } if (client.Value != null && client.Value.FrmSi != null) { client.Value.FrmSi.AddItems(lviCollection); } }
public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet) { if (packet.SystemInfos == null) { return; } if (Ayarlar.ShowToolTip) { var builder = new StringBuilder(); for (int i = 0; i < packet.SystemInfos.Length; i += 2) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); } } AnaForm.Instance.SetToolTipText(client, builder.ToString()); } if (client.Value == null || client.Value.FrmSi == null) { return; } var lviCollection = new ListViewItem[packet.SystemInfos.Length / 2]; for (int i = 0, j = 0; i < packet.SystemInfos.Length; i += 2, j++) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { lviCollection[j] = new ListViewItem(new[] { packet.SystemInfos[i], packet.SystemInfos[i + 1] }); } } if (client.Value != null && client.Value.FrmSi != null) { client.Value.FrmSi.AddItems(lviCollection); } }
/// <summary> /// Call bwsService.getSystemInfo() and display the returned properties. /// <returns>Returns true if getSystemInfo is successful, and false otherwise.</returns> /// </summary> public static bool GetSystemInfo() { const string methodName = "GetSystemInfo()"; const string bwsApiName = "bwsService.getSystemInfo()"; logMessage("Entering {0}", methodName); bool returnValue = false; GetSystemInfoRequest request = new GetSystemInfoRequest(); /* * Setting the value of loadAuthenticatedUserProperties to true will cause the API to return additional * properties about the current user, like the Authenticated User Uid property. The Authenticated User Uid * property is often used to make calls to APIs like getUsersDetail(), assignSWConfigsToGroup() and * others. */ request.loadAuthenticatedUserProperties = true; request.metadata = Metadata; GetSystemInfoResponse response = null; /* * The try catch block here is used to illustrate how to handle a specific type of exception. * For example, in this case we check to see if the error was caused by invalid credentials. */ try { logRequest(bwsApiName); response = bwsService.getSystemInfo(request); logResponse(bwsApiName, response.returnStatus.code, response.metadata); } catch (WebException e) { HttpWebResponse webResponse = e.Response as HttpWebResponse; // Handle authentication failure. if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized) { logMessage("Failed to authenticate with the BWS web service"); logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue); return(returnValue); } // Log and re-throw exception. logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message); throw e; } if (response.returnStatus.code.Equals("SUCCESS")) { if (response.properties != null && response.properties.Length > 0) { logMessage("{0} returned the following properties:", bwsApiName); foreach (Property property in response.properties) { displayResult("{0}: {1}", property.name, property.value); } returnValue = true; } else { logMessage("No properties in response"); } } else { logMessage("Error Message: \"{0}\"", response.returnStatus.message); } logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue); return(returnValue); }
public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet) { if (XMLSettings.ShowToolTip) { try { FrmMain.Instance.lstClients.Invoke((MethodInvoker) delegate { foreach (ListViewItem item in FrmMain.Instance.lstClients.Items) { if (item.Tag == client) { var builder = new StringBuilder(); for (int i = 0; i < packet.SystemInfos.Length; i += 2) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); } } item.ToolTipText = builder.ToString(); } } }); } catch { } } if (client.Value.FrmSi == null) { return; } ListViewItem[] lviCollection = new ListViewItem[packet.SystemInfos.Length / 2]; for (int i = 0, j = 0; i < packet.SystemInfos.Length; i += 2, j++) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { lviCollection[j] = new ListViewItem(new string[] { packet.SystemInfos[i], packet.SystemInfos[i + 1] }); } } try { client.Value.FrmSi.Invoke((MethodInvoker) delegate { client.Value.FrmSi.lstSystem.Items.RemoveAt(2); // Loading... Information foreach (var lviItem in lviCollection) { if (lviItem != null) { client.Value.FrmSi.lstSystem.Items.Add(lviItem); } } client.Value.FrmSi.lstSystem.AutosizeColumns(); }); } catch { } }
/// <summary> /// Call bwsService.getSystemInfo() and set the serverType member. /// </summary> public static void GetSystemInfo() { const string methodName = "GetSystemInfo()"; const string bwsApiName = "bwsService.getSystemInfo()"; logMessage("Entering {0}", methodName); GetSystemInfoRequest request = new GetSystemInfoRequest(); request.metadata = REQUEST_METADATA; GetSystemInfoResponse response = null; /* * The try catch block here is used to illustrate how to handle a specific type of exception. * For example, in this case we check to see if the error was caused by invalid credentials. */ try { logRequest(bwsApiName); response = bwsService.getSystemInfo(request); logResponse(bwsApiName, response.returnStatus.code, response.metadata); } catch (WebException e) { HttpWebResponse webResponse = e.Response as HttpWebResponse; // Handle authentication failure. if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized) { logMessage("Failed to authenticate with the BWS web service"); } // Log and re-throw exception. logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message); throw e; } if (response.returnStatus.code.Equals("SUCCESS")) { if (response.properties != null && response.properties.Length > 0) { foreach (Property property in response.properties) { if (property.name.ToUpper().Equals("BAS VERSION")) { if (property.value.Split('.')[0].Equals("12")) { serverType = ServerType.BES12; logMessage("ServerType found: BES12"); } else { serverType = ServerType.BDS; logMessage("ServerType found: BDS"); } break; } if (property.name.ToUpper().Equals("BUDS VERSION")) { serverType = ServerType.UDS; logMessage("ServerType found: UDS"); break; } } } else { logMessage("No properties in response"); } } else { logMessage("Error Message: \"{0}\"", response.returnStatus.message); } logMessage("Exiting {0}", methodName); }