Example #1
0
        public async void ConnectSQLServer(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!UIGlobal.sharedTCPObject.socket.Connected)
                {
                    MessageBox.Show("Server is not available.");
                    throw new SocketException();
                }
                int sentBytes = await TCP.SendTask(UIGlobal.sharedTCPObject, Encoding.UTF8.GetBytes("Login:"******"| Password:"******"|"));

                await TCP.ReceiveAllPacketsSync(UIGlobal.sharedTCPObject);

                Console.WriteLine("Received message: {0} ", UIGlobal.sharedTCPObject.packet);

                if (isAuthorizationSuccessful(UIGlobal.sharedTCPObject.packet))
                {
                    sharedData = new SharedData(UIGlobal.LoginWindowUI.Username, accessLevel, UIGlobal.sharedTCPObject);
                    DataWindowNS.DataWindow dataWindow = new DataWindowNS.DataWindow(sharedData);
                    dataWindow.Show();
                    UIGlobal.LoginWindowUI.rect_window_close();
                    Console.WriteLine("Logged onto server with username: {0} and password: {1}", UIGlobal.LoginWindowUI.Username, UIGlobal.LoginWindowUI.Password);
                }
                else
                {
                    MessageBox.Show("Incorrect username or password, please try again.");
                }
            }
            catch (SocketException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #2
0
        private async void receiveAsync()
        {
            bool reset = false;

            while (!reset)
            {
                try
                {
                    await TCP.ReceiveAllPacketsSync(client);

                    Console.WriteLine("Received complete packet: {0}", client.packet);

                    if (currentPacket == RECEIVED_PACKET_TYPE.EMPLOYEE_LIST)
                    {
                        createNewDataGridFromPacket(client.packet);
                        hideMenuGUI();
                        showEmployeeListGUI();
                        currentPacket = RECEIVED_PACKET_TYPE.DEFAULT;
                    }
                    else
                    {
                        //do nothing
                    }
                }
                catch (SocketException ex) // connection disconnected
                {
                    Console.WriteLine(ex.ToString());

                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        connectedStatusImage.Fill = (Brush)Resources["XMarkImage"];
                        networkStatus.Content = "Attempting to reconnect...";
                    }));
                    reconnectTimer           = new System.Timers.Timer();
                    reconnectTimer.Elapsed  += reconnectTimerFunc;
                    reconnectTimer.Enabled   = true;
                    reconnectTimer.AutoReset = true;

                    reset = true;
                }
            }
        }