public WebServer(ICollection <string> prefixes, ResponseMethod method) { if (!HttpListener.IsSupported) { throw new NotSupportedException("Needs Windows XP SP2, Server 2003 or later."); } if (prefixes == null || prefixes.Count == 0) { throw new ArgumentException("URI prefixes are required"); } if (method == null) { throw new ArgumentException("responder method required"); } foreach (var s in prefixes) { _listener.Prefixes.Add(s); } _responderMethod = method; _listener.Start(); }
public void playConversation(string question, string[] responses, ResponseMethod callback, string fontName) { justinsMethod = callback; string id = question; Rectangle convoMenuRectangle = new Rectangle(100, 0, 600, 510); Rectangle convoTextAreaRectangle = new Rectangle(convoMenuRectangle.X + 100, convoMenuRectangle.Y + 30, 400, 190); TextArea questTextArea = new TextArea(myContentManager, convoTextAreaRectangle, Color.White, Color.Black, fontName); myConvoMenu = new Menu(myContentManager, @"GUITiles\layout", convoMenuRectangle, questTextArea); questTextArea.addConversation(question); myConvoMenu.Name = id; for (int i = 0; i < responses.Length; i++) { Rectangle itemRect = new Rectangle(convoMenuRectangle.X + 100, 65 * i + 240, 400, 45); myConvoMenu.addCustomItem(i + responses[i], itemRect, Color.White, Color.Black, Color.Brown); } CurrentIndex = id; }
public IQueryable <tblMessage> GetMessageById(int?id) { ResponseMethod responseMethod = new ResponseMethod(); try { IQueryable <tblMessage> messageModels = messagecontext.tblMessages.Where(u => u.Id == id); return(messageModels); } catch (Exception ex) { Exception(responseMethod, ex); } return(null); }
public IQueryable <tblMessage> GetAllMessages() { ResponseMethod responseMethod = new ResponseMethod(); try { return(messagecontext.tblMessages); } catch (Exception ex) { Exception(responseMethod, ex); responseMethod.Message = ex.Message; } return(null); }
public ResponseMethod SaveMessage(tblMessage msg) { ResponseMethod responseMethod = new ResponseMethod(); try { if (msg != null) { messagecontext.tblMessages.Add(msg); messagecontext.SaveChanges(); responseMethod.Success = "success"; responseMethod.Message = "record added successfully."; } } catch (Exception ex) { Exception(responseMethod, ex); responseMethod.Message = ex.Message; } return(responseMethod); }
public WebServer(ResponseMethod method, params string[] prefixes) : this(prefixes, method) { }
private void ServerWork(IAsyncResult result) { HttpListenerContext context; try { context = httpServer.EndGetContext(result); } catch (Exception) { return; } HttpListenerRequest request = context.Request; using (HttpListenerResponse response = context.Response) { var remoteIP = request.RemoteEndPoint.Address; if ((!request.IsLocal && httpServerConfig.LocalOnly) || Array.Exists(httpServerConfig.BlacklistedIPs, (e) => e == remoteIP.ToString())) { return; } if (!fr.AccessPermitted(remoteIP)) { response.StatusCode = 403; WriteToRemote(request, response, new byte[0]); return; } response.Headers["Server"] = httpServerConfig.ServerHeader; if (!rl.IsAllowed(remoteIP)) { response.AddHeader("Retry-After", httpServerConfig.RateLimitWaitTime.ToString()); response.StatusCode = 429; WriteToRemote(request, response, rateLimited); return; } string item = request.RawUrl; if (item == "/") { item = "/index.html"; } byte[] buffer = sFM.GetStaticItem(item); DataReceiveArgs eventArgs = new DataReceiveArgs() { ContentType = request.ContentType, Cookies = request.Cookies, HostName = request.UserHostName, Local = request.IsLocal, Referer = request.UrlReferrer, RemoteIP = request.RemoteEndPoint, URL = request.RawUrl, UserAgent = request.UserAgent, Method = request.HttpMethod, Headers = request.Headers.AllKeys }; ResponseMethod output = Tools.FireEvent(OnDataReceiveEvent, this, eventArgs); if (output.cancelExecution && output.Status != 200) { string errorString = $"<html><head><title>{output.Status} {respStatus[output.Status]}</title></head><body bgcolor=\"white\"><center><h1>{output.Status} {respStatus[output.Status]}</h1></center><hr><center>nginx/1.10.3</center></body></html>"; return; } if (output.cancelExecution) { return; } if (buffer.Length > 1 && Tools.FireEvent(OnDataStaticSentEvent, this, eventArgs)) { WriteToRemote(request, response, buffer); return; } buffer = Encoding.UTF8.GetBytes(output.response); WriteToRemote(request, response, buffer); } }
public void closeConversationMenu() { myConvoMenu = null; justinsMethod = null; }
private static void Exception(ResponseMethod responseMethod, Exception ex) { responseMethod.Success = (!string.IsNullOrEmpty(responseMethod.Success)) ? responseMethod.Success : "failed"; responseMethod.Message = ex.Message; }