public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context) { ChatDatabase db = ChatDatabase.getInstance(); GetChatHistoryResponse response = db.retrieveChatHistory(message.getCommand); return(context.Reply(response)); }
public Task Handle(SendMessageRequest message, IMessageHandlerContext context) { ChatDatabase db = ChatDatabase.getInstance(); ServiceBusResponse response = db.insertNewChatMessage(message.message); return(context.Reply(response)); }
public ActionResult Logout() { string name = Session["name"].ToString(); ChatDatabase.getInstance().removeUser(name); Session.Remove("name"); return(View("Index")); }
static async Task AsyncMain() { Console.Title = "Chat"; EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Chat"); var scanner = endpointConfiguration.AssemblyScanner(); scanner.ExcludeAssemblies("MySql.Data.dll"); endpointConfiguration.EnableInstallers(); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.SendFailedMessagesTo("error"); var transport = endpointConfiguration.UseTransport <MsmqTransport>(); var routing = transport.Routing(); var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); Debug.consoleMsg("Press Enter to exit."); string entry; do { entry = Console.ReadLine(); switch (entry) { case ("DELETEDB"): ChatDatabase.getInstance().deleteDatabase(); Debug.consoleMsg("Delete database attempt complete"); break; case ("CREATEDB"): ChatDatabase.getInstance().createDB(); Debug.consoleMsg("Completed Database Creation Attempt."); break; default: Debug.consoleMsg("Command not understood"); break; } } while (!entry.Equals("")); await endpointInstance.Stop().ConfigureAwait(false); }
public ActionResult Login(string name) { bool success = ChatDatabase.getInstance().addNewUser(name); if (success) { Session["name"] = name; System.Web.Security.FormsAuthentication.SetAuthCookie(name, true); TempData["Login"] = true; return(RedirectToAction("Index")); } else { ViewBag.ErrorMsg = "Ime je zauzeto"; return(RedirectToAction("Index", "Login")); } }
public Task Handle(SendMessageRequest message, IMessageHandlerContext context) { try { string response = ChatDatabase.getInstance().sendMessage(message.message); if (String.Equals(response, "Successful")) { return(context.Reply(new ServiceBusResponse(true, response))); } else { return(context.Reply(new ServiceBusResponse(false, response))); } } catch (Exception err) { return(context.Reply(new ServiceBusResponse(false, err.Message))); } }
public Task Handle(GetChatContactsRequest message, IMessageHandlerContext context) { try { GetChatContacts contacts = ChatDatabase.getInstance().getContacts(message.getCommand); if (contacts != null) { return(context.Reply(new GetChatContactsResponse(true, "Successful", contacts))); } else { return(context.Reply(new GetChatContactsResponse(false, "Unable to connect to database", message.getCommand))); } } catch (Exception err) { return(context.Reply(new GetChatContactsResponse(false, err.Message, message.getCommand))); } }
/// <summary> /// Searches for company information /// </summary> /// <param name="message">Information about the company</param> /// <param name="context">Used to access information regarding the endpoints used for this handle</param> /// <returns>The response to be sent back to the calling process</returns> public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context) { // TODO: May need to fix ChatHistory h = new ChatHistory(); h.user1 = message.getCommand.history.user1; h.user2 = message.getCommand.history.user2; h.messages = ChatDatabase.getInstance().getChats(message.getCommand.history); GetChatHistory hist = new GetChatHistory(); hist.history = h; if (h.messages.Count > 0) { return(context.Reply(new GetChatHistoryResponse(true, "Successfully retrieved chats from database.", hist))); } else { return(context.Reply(new GetChatHistoryResponse(false, "Could not retrieve chats from database.", hist))); } }
/// <summary> /// Searches for company information /// </summary> /// <param name="message">Information about the company</param> /// <param name="context">Used to access information regarding the endpoints used for this handle</param> /// <returns>The response to be sent back to the calling process</returns> public Task Handle(GetChatContactsRequest message, IMessageHandlerContext context) { GetChatContactsResponse response; // TODO: May need to fix. Currently hardcoded to always retrieve client contacts. GetChatContacts conts = new GetChatContacts(message.getCommand.usersname, ChatDatabase.getInstance().getContacts(message.getCommand.usersname)); if (conts.contactNames.Count == 0) { response = new GetChatContactsResponse(false, "Could not find any contacts.", conts); } else { response = new GetChatContactsResponse(true, "Successfully retrieved contacts.", conts); } return(context.Reply(response)); }
public ActionResult Index() { List <string> allUsers = ChatDatabase.getInstance().getAllUsers(); return(View(allUsers)); }
/// <summary> /// This method is responsible for initializing the echo endpoint used to receive events and commands /// </summary> /// <returns>Nothing.</returns> static async Task AsyncMain() { Console.Title = "Chat"; //Create a new Endpoint configuration with the name "Chat" EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Chat"); //These two lines prevemt the endpoint configuration from scanning the MySql dll. //This is done because it speeds up the startup time, and it prevents a rare but //very confusing error sometimes caused by NServiceBus scanning the file. If you //wish to know morw about this, google it, then ask your TA(since they will probably //just google it anyway) var scanner = endpointConfiguration.AssemblyScanner(); scanner.ExcludeAssemblies("MySql.Data.dll"); //Allows the endpoint to run installers upon startup. This includes things such as the creation of message queues. endpointConfiguration.EnableInstallers(); //Instructs the queue to serialize messages with Json, should it need to serialize them endpointConfiguration.UseSerialization <JsonSerializer>(); //Instructs the endpoint to use local RAM to store queues.Good during development, not during deployment (According to the NServiceBus tutorial) endpointConfiguration.UsePersistence <InMemoryPersistence>(); //Instructs the endpoint to send messages it cannot process to a queue named "error" endpointConfiguration.SendFailedMessagesTo("error"); //Instructs the endpoint to use Microsoft Message Queuing var transport = endpointConfiguration.UseTransport <MsmqTransport>(); //This variable is used to configure how messages are routed. Using this, you may set the default reciever of a particular command, and/or subscribe to any number of events var routing = transport.Routing(); // TODO: Might Need to add something here //Register to the CompanyListingsEvent event published by the Authentication endpoint //routing.RegisterPublisher(typeof(ChatEvent), "Authentication"); //Start the endpoint with the configuration defined above. It should be noted that any changes made to the endpointConfiguration after an endpoint is instantiated will not apply to any endpoints that have already been instantiated var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); Debug.consoleMsg("Press Enter to exit."); string entry; do { entry = Console.ReadLine(); switch (entry) { case ("DELETEDB"): ChatDatabase.getInstance().deleteDatabase(); Debug.consoleMsg("Delete database attempt complete"); break; case ("CREATEDB"): ChatDatabase.getInstance().createDB(); Debug.consoleMsg("Completed Database Creation Attempt."); break; default: Debug.consoleMsg("Command not understood"); break; } } while (!entry.Equals("")); await endpointInstance.Stop().ConfigureAwait(false); }