public urlRetorno IncluirUrl(urlParams parametros) { //Incluir no log o start de execução (data e hora de início) e o request do processo. urlRetorno retorno = new urlRetorno(); urlBusiness urlBusiness = new urlBusiness(); retorno.Sucesso = false; if (parametros.User == 0) { retorno.Mensagem = "O campo User não pode ficar em branco."; } else if (parametros.Url == "" || parametros.Url == null) { retorno.Mensagem = "O campo Url não pode ficar em branco."; } else if (parametros.Url.Substring(0, 7).ToString().ToUpper() != "HTTP://" && parametros.Url.Substring(0, 8).ToString().ToUpper() != "HTTPS://") { retorno.Mensagem = "O campo Url deve iniciar com 'http://' ou 'https://'."; } else { retorno = urlBusiness.CriarUrl(parametros.User, parametros.Url); } //Incluir no log o response do processo e o tempo de execução (Elapsed time). return(retorno); }
private String RemoteAdminCommands(String Command, urlParams currentParams) { String browserresponse = String.Empty; browserresponse = @"<a href=""/?command=SHOWSERVICELOGS"">Show Service Logs</a><BR><BR>" + Environment.NewLine; browserresponse = browserresponse + @"<a href=""/?command=SHOWERRORLOGS"">Show Error Logs</a><BR><BR>" + Environment.NewLine; browserresponse = browserresponse + @"<a href=""/?command=RESETLOGS"">Reset/Delete Logs</a><BR><BR>" + Environment.NewLine; browserresponse = browserresponse + "<BR><BR>" + Environment.NewLine; browserresponse = browserresponse + @"<a href=""/?command=DOHELLOWWORLD"">Do Hello World Method</a><BR><BR>" + Environment.NewLine; browserresponse = browserresponse + "<BR><BR>" + Environment.NewLine; //Return the service log files inside a textarea if (currentParams.ByKey("Command") == "SHOWSERVICELOGS") { browserresponse = browserresponse + @"Current Service Log contents:<BR><BR><textarea cols=""100"" rows=""20"">" + Environment.NewLine; browserresponse = browserresponse + System.IO.File.ReadAllText(ServiceLogPath) + Environment.NewLine; browserresponse = browserresponse + "</textarea>" + Environment.NewLine; } //Return the error log files inside a textarea if (currentParams.ByKey("Command") == "SHOWERRORLOGS") { browserresponse = browserresponse + @"Current Error Log contents:<BR><BR><textarea cols=""100"" rows=""20"">" + Environment.NewLine; browserresponse = browserresponse + System.IO.File.ReadAllText(ErrorLogPath) + Environment.NewLine; browserresponse = browserresponse + "</textarea>" + Environment.NewLine; } if (currentParams.ByKey("Command") == "RESETLOGS") { System.IO.File.WriteAllText(ServiceLogPath, ""); System.IO.File.WriteAllText(ErrorLogPath, ""); } //Pause the main timer if (currentParams.ByKey("Command") == "PAUSESERVICE") { mainTimer.Stop(); UpdateLog(LogType.Standard, "Pause Service"); } //Restart the main timer if (currentParams.ByKey("Command") == "RESTARTSERVICE") { mainTimer.Enabled = true; mainTimer.Start(); UpdateLog(LogType.Standard, "Restart Service"); } if (currentParams.ByKey("Command") == "DOHELLOWWORLD") { DoHelloWorld(); } return(browserresponse); }
public void FromQuery_SingleSimple_KeyValueFuncAdded_Generated() { AddControllerAction("TestAction", MvcConstants.JsonResult_AspNetCore) .AddParameter("fromQuery", "string", attribute: MvcConstants.FromQueryAttributeFullName_AspNetCore) .Commit() ; AssertScriptTextForFunctionIs(@$ " export function TestAction(fromQuery: string): void {{ const urlParams = new URLSearchParams(); tryAppendKeyValueToUrl(urlParams, " "fromQuery" ", fromQuery); fetchWrapper(" "GET" ", `/{ControllerName}/TestAction${{getQueryString(urlParams)}}`, null);
/// <summary> /// Process remote commands /// </summary> private void RemoteAdminGetCommands() { try { while (ClientConnection.Connected) { IPEndPoint clnt = (IPEndPoint)ClientConnection.Client.RemoteEndPoint; string ClientResponse = ""; string response = ""; string ExtraHeader = ""; int responseType = 200; ClientAuth = false; //Get the stream from the client; This will wait until the client //decides to send something, so its essentially a while statement //on one line. NetworkStream strm = ClientConnection.GetStream(); //Put the data into a byte array byte[] inputBuffer = new byte[ClientConnection.ReceiveBufferSize + 1]; //Get the size of it int Bytes = strm.Read(inputBuffer, 0, Convert.ToInt32(ClientConnection.ReceiveBufferSize)); //Convert it to something useable string responsetext = Encoding.ASCII.GetString(inputBuffer, 0, Bytes); if (clnt.Address.ToString() != "127.0.0.1") { ClientAuth = doAuthentication(responsetext, ref ClientResponse, ref responseType, ref ExtraHeader); } else { ClientAuth = true; } //If this isn't from our office, then ignore it. //We must accept the buffer first, or the connection will hang if (ClientAuth == true) { string getText = ""; string postText = ""; string paramText = ""; responsetext = responsetext.Replace(@"\r", " ").Replace(@"\n", " "); //Grab the get response if there is one if (responsetext.Contains("GET")) { getText = responsetext.Substring(0, responsetext.IndexOf("HTTP") - 1); if (getText.Length != (getText.IndexOf("/") + 1)) { getText = (getText.Substring(getText.IndexOf("/") + 2, getText.Length - (getText.IndexOf("/") + 2))).Trim(); paramText = getText; } else { paramText = ""; } } //Grab the post response if there is one if (responsetext.Contains("POST")) { getText = responsetext.Substring(0, responsetext.IndexOf("HTTP") - 1); if (getText.Length != (getText.IndexOf("/") + 1)) { getText = (getText.Substring(getText.IndexOf("/") + 2, getText.Length - (getText.IndexOf("/") + 2))).Trim(); paramText = getText; } postText = (responsetext.Substring(responsetext.LastIndexOf(" "), responsetext.Length - responsetext.LastIndexOf(" "))).Trim(); postText = WebUtility.UrlDecode(postText); if (paramText.Length > 0) { paramText = paramText + "&" + postText; } else { paramText = postText; } } urlParams liveParams = new urlParams(paramText); //Checks the data sent by the user against the RemoteAdminCommands function //to see if a response more than "OK" is needed ClientResponse = RemoteAdminCommands(liveParams.ByKey("COMMAND"), liveParams); if (mainTimer.Enabled == true) { response = "Imagine Service - Running!<BR><BR>" + Environment.NewLine; response = response + "<a href=\"/?command=PAUSESERVICE\">Pause Service</a><BR><BR>" + Environment.NewLine; } else { response = "Imagine Service - Paused!<BR><BR>" + Environment.NewLine; response = response + "<a href=\"/?command=RESTARTSERVICE\">ReStart Service</a><BR><BR>" + Environment.NewLine; } } //Feed the response code back with standard HTTP headers if (!ClientConnection.Connected) { throw new Exception("Command finished but Http connection closed in the meantime."); } ClientConnection.Client.Send(Encoding.ASCII.GetBytes("HTTP/1.1 " + responseType + " OK" + Environment.NewLine + "Server: FATHTTP" + Environment.NewLine + "Date: 25/08/2006" + Environment.NewLine + ExtraHeader + "Content-Type: text/html" + Environment.NewLine + "Accept-Ranges: bytes" + Environment.NewLine + "Last-Modified 02/06/2006" + Environment.NewLine + "Content-Length: " + (response + ClientResponse).Length + Environment.NewLine + "" + Environment.NewLine + response + ClientResponse)); ClientConnection.Close(); } } catch (Exception ex) { ClientConnected = false; Thread.CurrentThread.Abort(); System.IO.File.AppendAllText(ErrorLogPath, "ERROR WITH CLIENT CONNECTION: " + ex.ToString() + Environment.NewLine); } }