public Task Handle(SendMessageRequest message, IMessageHandlerContext context)
        {
            ChatDatabase       db       = ChatDatabase.getInstance();
            ServiceBusResponse response = db.insertNewChatMessage(message.message);

            return(context.Reply(response));
        }
Пример #2
0
        public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context)
        {
            ChatDatabase           db       = ChatDatabase.getInstance();
            GetChatHistoryResponse response = db.retrieveChatHistory(message.getCommand);

            return(context.Reply(response));
        }
Пример #3
0
        public ActionResult Logout()
        {
            string name = Session["name"].ToString();

            ChatDatabase.getInstance().removeUser(name);
            Session.Remove("name");
            return(View("Index"));
        }
Пример #4
0
 public Form1()
 {
     InitializeComponent();
     if (File.Exists(db_file))
     {
         ChatDatabase.ReadXml(db_file);
     }
     txtServerAdres.Text      = getIPaddress();
     DataOntvangenDel        += new DataOntvangenDelegate(DataOntvangenVanClient);
     dataGridView1.DataSource = ChatDatabase.Tables[0];
     dataGridView2.DataSource = ChatDatabase.Tables[1];
 }
Пример #5
0
        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);
        }
Пример #6
0
        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"));
            }
        }
Пример #7
0
        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)));
            }
        }
Пример #8
0
        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)));
            }
        }
Пример #9
0
        /// <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)));
            }
        }
Пример #10
0
 public UserAddReply(ChatDatabase database)
 {
     _database = database;
 }
Пример #11
0
 public ReportManager(ChatDatabase chatDatabase)
 {
     _chatCollection = chatDatabase.LoadChats();
 }
Пример #12
0
        /// <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));
        }
Пример #13
0
 public AdminCheckCommand(ChatDatabase database, TomeChat chat)
 {
     _database = database;
     _chat = chat;
 }
Пример #14
0
 public UserAddReply(ChatDatabase database)
 {
     _database = database;
 }
Пример #15
0
        private void DataOntvangenVanClient(ConnectedClient client, string data)
        {
            txtOntvangen.Text += data + Environment.NewLine;
            string[] data2 = data.Split(';');
            switch (data2[0])
            {
            case "Login":
                DataRow[] rijen = ChatDatabase.Tables[0].Select("gebruikersnaam='" + data2[1] + "'", "id ASC");
                if (rijen.Length == 0)
                {
                    client.Write("Gebruiker bestaat niet");
                }
                else if (rijen.First().Field <string>(2) == data2[2])
                {
                    lstGebruikers.Items.Add(data2[1]);

                    client.User_ID = rijen.First().Field <int>(0);
                    client.Write("Ingelogd;" + client.User_ID.ToString() + "," + data2[1]);
                    foreach (ConnectedClient cl in Clients)
                    {
                        if (cl.CanWrite & (cl.User_ID != -1))
                        {
                            cl.Write(string.Join(";", (new string[] { "Online users" }).Union(Clients
                                                                                              .Except(new ConnectedClient[] { cl })
                                                                                              .Where(T => T.User_ID != -1)
                                                                                              .Select(T => T.User_ID + "," + ChatDatabase.Tables[0].Select("id=" + T.User_ID.ToString(), "id ASC").First().Field <string>(1))
                                                                                              ).ToArray()));
                        }
                    }
                }
                else
                {
                    client.Write("Foutief wachtwoord");
                }
                break;

            case "Logout":
                client.Write("Uitgelogd");
                lstGebruikers.Items.Remove(ChatDatabase.Tables[0].Select("id=" + client.User_ID.ToString()).First().Field <string>(1));
                client.User_ID = -1;
                foreach (ConnectedClient cl in Clients.Except(new ConnectedClient[] { client }))
                {
                    if (cl.CanWrite & (cl.User_ID != -1))
                    {
                        cl.Write(string.Join(";", (new string[] { "Online users" }).Union(Clients
                                                                                          .Except(new ConnectedClient[] { cl })
                                                                                          .Where(T => T.User_ID != -1)
                                                                                          .Select(T => T.User_ID + "," + ChatDatabase.Tables[0].Select("id=" + T.User_ID.ToString(), "id ASC").First().Field <string>(1))
                                                                                          ).ToArray()));
                    }
                }
                client.DataOntvangen -= Client_DataOntvangen;
                client.StopListening();
                break;

            case "Registreer":
                DataRow[] rijen2 = ChatDatabase.Tables[0].Select("gebruikersnaam='" + data2[1] + "'", "id ASC");
                if (data2[1].Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\t", "") == "")
                {
                    client.Write("Geef een gebruikersnaam op");
                }
                else if (data2[2].Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\t", "") == "")
                {
                    client.Write("Geef een wachtwoord op");
                }
                else if (rijen2.Length == 0)
                {
                    DataRow nieuw = ChatDatabase.Tables[0].NewRow();
                    nieuw.SetField <string>(1, data2[1]);
                    nieuw.SetField <string>(2, data2[2]);
                    ChatDatabase.Tables[0].Rows.Add(nieuw);
                    client.Write("Gebruiker aangemaakt");
                    ChatDatabase.WriteXml(db_file);
                }
                else
                {
                    client.Write("Gebruikersnaam niet meer beschikbaar");
                }
                break;

            case "Bericht":
                // Bericht;ik.id;ik.user;dest.id;bericht
                ConnectedClient[] dest = Clients.Where(T => T.User_ID == Convert.ToInt32(data2[3])).ToArray();
                if (dest.Length == 1)
                {
                    dest[0].Write(data);
                }
                DataRow nieuw2 = ChatDatabase.Tables[1].NewRow();
                nieuw2.SetField <int>(1, Convert.ToInt32(data2[1]));
                nieuw2.SetField <int>(2, Convert.ToInt32(data2[3]));
                nieuw2.SetField <string>(3, data2[4]);
                //nieuw2.SetField<bool>(4, dest.Length == 1);
                //nieuw2.SetField<bool>(5, false);
                ChatDatabase.Tables[1].Rows.Add(nieuw2);
                ChatDatabase.WriteXml(db_file);
                break;
            }
        }
Пример #16
0
        /// <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);
        }
Пример #17
0
        public ActionResult Index()
        {
            List <string> allUsers = ChatDatabase.getInstance().getAllUsers();

            return(View(allUsers));
        }
Пример #18
0
 public AdminCheckCommand(ChatDatabase database, TomeChat chat)
 {
     _database = database;
     _chat     = chat;
 }