예제 #1
0
        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;
            }
        }
예제 #2
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));
        }
예제 #3
0
        /// <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);
        }
예제 #5
0
        /// <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
        }
예제 #6
0
        /// <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));
        }
예제 #7
0
 public HttpSource()
 {
     ViewModel    = new HttpViewModel(this);
     SettingsPage = new HttpSettingsView()
     {
         DataContext = ViewModel
     };
     ControlsPage = new HttpRunView()
     {
         DataContext = ViewModel
     };
 }
예제 #8
0
        /// <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
        }
예제 #9
0
 public HttpView()
 {
     InitializeComponent();
     BindingContext = new HttpViewModel();
 }