public static void WriteData(HttpViewModel httpViewModel) { if (File.BaseStream == null) { OpenFileStream(); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(httpViewModel.ActivityNote); stringBuilder.Append(","); stringBuilder.Append(httpViewModel.HttpResponse); stringBuilder.Append(","); stringBuilder.AppendLine(DateTime.Now.ToString("hh:mm:ss.ffff")); try { File.WriteLine(stringBuilder.ToString()); File.Flush(); } catch (Exception ex) { int x = 0; } }
/// <summary> /// Send a tcp message /// </summary> /// <param name="httpViewModel"></param> /// <returns></returns> /// <remarks> /// Test URLs /// http://httpbin.org/robots.txt /// http://httpbin.org/get /// http://httpbin.org/post /// </remarks> public ActionResult SendTcpMessage(HttpViewModel httpViewModel) { if (httpViewModel == null) { throw new ArgumentNullException(nameof(HttpViewModel)); } Uri uriResult; bool result = Uri.TryCreate(httpViewModel.HttpRequest, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!result) { httpViewModel.HttpResponse = "Not a valid URL"; return(PartialView("_HttpResponse", httpViewModel)); } string response = ""; if (httpViewModel.HttpRequestType == HttpRequestType.Get) { response = HTTPManager.SendGetRequest(httpViewModel.HttpRequest); } if (httpViewModel.HttpRequestType == HttpRequestType.Post) { response = HTTPManager.SendPostRequest(httpViewModel.HttpRequest); } httpViewModel.HttpResponse = response; return(PartialView("_HttpResponse", httpViewModel)); }
/// <summary> /// Record a Udp message /// </summary> /// <returns></returns> /// <remarks>50002</remarks> public ActionResult RecordUDPMessage(HttpViewModel httpViewModel) { httpViewModel.HttpResponse = HTTPManager.ReceiveUdpBroadcast(httpViewModel.HttpPortNumber); SensorProcessing.RecordData(httpViewModel); return(PartialView("_HttpResponse", httpViewModel)); }
public static void RecordData(HttpViewModel httpViewModel) { if (FileWriterManager.File == null) { FileWriterManager.OpenFileStream(); } FileWriterManager.WriteData(httpViewModel); }
/// <summary> /// Cancel UDP Receive /// </summary> /// <returns></returns> public ActionResult CancelReceiveUDPMessage(HttpViewModel httpViewModel) { string response = ""; HTTPManager.CancelUdpBroadcast(); httpViewModel.HttpResponse = response; return(PartialView("_HttpResponse", httpViewModel)); //Note This is not used in the view we just need it because ActionResults demand a Return }
/// <summary> /// Return the main Http development view /// </summary> /// <returns></returns> public ActionResult HttpDevelopment() { HttpViewModel httpViewModel = new HttpViewModel { HttpRequestType = HttpRequestType.Get, HttpPortNumber = "50002" }; //set defaults return(View(httpViewModel)); }
public HttpSource() { ViewModel = new HttpViewModel(this); SettingsPage = new HttpSettingsView() { DataContext = ViewModel }; ControlsPage = new HttpRunView() { DataContext = ViewModel }; }
/// <summary> /// Send a Udp message /// </summary> /// <param name="httpViewModel"></param> /// <returns></returns> public ActionResult SendUdpBroadcast(HttpViewModel httpViewModel) { if (httpViewModel == null) { throw new ArgumentNullException(nameof(HttpViewModel)); } var response = HTTPManager.SendUdpBroadcast(httpViewModel.HttpRequest, httpViewModel.HttpPortNumber); httpViewModel.HttpResponse = response; return(PartialView("_HttpResponse", httpViewModel)); //Note This is not used in the view we just need it because ActionResults demand a Return }
public HttpView() { InitializeComponent(); BindingContext = new HttpViewModel(); }