Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("+-+-+-+-+-+-+-+-+");
            Console.WriteLine("|O|P|E|R|A|T|E|R|");
            Console.WriteLine("+-+-+-+-+-+-+-+-+");
            Console.WriteLine();
            Client <IGatewayConnection> cli          = new Client <IGatewayConnection>("mbgateway", Konstante.GATEWAY_IP, Konstante.GATEWAY_PORT.ToString(), "GatewayConnection");
            IGatewayConnection          gatewayProxy = cli.GetProxy();
            bool uspesnoUlogovan = false;
            User ulogovanUser    = new User();

            while (!uspesnoUlogovan)
            {
                Console.WriteLine("Username:"******"Password:"******"";
                ConsoleKeyInfo key;

                do
                {
                    key = Console.ReadKey(true);

                    // Backspace Should Not Work
                    if (key.Key != ConsoleKey.Backspace)
                    {
                        pass += key.KeyChar;
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write("\b");
                    }
                }
                // Stops Receving Keys Once Enter is Pressed
                while (key.Key != ConsoleKey.Enter);
                pass = pass.Replace("\r", "");
                string passSifrovano = BitConverter.ToString(Sifrovanje.sifrujCBC(pass, Konstante.ENCRYPTION_KEY));

                ulogovanUser = gatewayProxy.ClientToBankCheckLogin(userSifrovano, passSifrovano, "operater");
                if (ulogovanUser != null)
                {
                    Console.WriteLine();
                    Console.WriteLine("Uspesno logovanje " + ulogovanUser.Username);
                    uspesnoUlogovan = true;
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Neuspesno logovanje");
                    uspesnoUlogovan = false;
                }
            }
            Console.WriteLine("Korisnici koji su na ovom operateru:");
            OperatorDB.operatorName = ulogovanUser.Username;
            ucitajRacune(OperatorDB.operatorName);
            ucitajKorisnike(OperatorDB.operatorName);
            foreach (var item in OperatorDB.BazaKorisnika.Values)
            {
                Console.WriteLine(item.Username);
            }

            //OperatorServer server = new OperatorServer();
            //server.Start();

            Server2 <IOperatorConnection> server = new Server2 <IOperatorConnection>("localhost", Konstante.INITIAL_OPERATER_PORT.ToString(), "OperaterConnection", typeof(OperaterConnection));


            // Javi banci na kom ip-u i portu slusas
            string sifrovanUsername = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));

            if (!gatewayProxy.ClientAndOperatorToBankSetIpAndPort(sifrovanUsername, server.ipAddress, server.connectedPort.ToString()))
            {
                // Ukoliko vec postoji instanca tipa telenora, ugasi aplikaciju ili ponovo loguj itd...
                Environment.Exit(0);
            }

            gatewayProxy.CheckIntoGateway(server.ipAddress, server.connectedPort.ToString(), CertManager.Formatter.ParseName(WindowsIdentity.GetCurrent().Name));

            // Iscitaj iz xml-a



            // Ako je sve proslo ok, uzmi bazu svih racuna i klijenata ciji je operater npr telenor
            //string serializedList = gatewayProxy.OperatorToBankGetOperatorsClients(sifrovanUsername);
            //List<UserIRacun> aktivniKorisnici = ListSerializer.DeserializeString(serializedList);

            //foreach (var item in aktivniKorisnici)
            //{
            //    OperatorDB.BazaRacuna.Add(item.Racun.BrojRacuna,item.Racun);
            //}

            // U novom threadu prodji kroz sve aktivne korisnike i pozovi im sendBill
            Thread sendBillThread = new Thread(() => SendBill(gatewayProxy, sifrovanUsername));

            sendBillThread.Start();

            Console.ReadKey();
            gatewayProxy.OperatorToBankShutdownOperator(ulogovanUser.Username);
        }
Exemple #2
0
        /*
         *
         */
        static void Main(string[] args)
        {
            Console.WriteLine("+-+-+-+-+-+-+");
            Console.WriteLine("|C|L|I|E|N|T|");
            Console.WriteLine("+-+-+-+-+-+-+");
            Console.WriteLine();
            // Prvo konekcija na server radi pristupanja bazi podataka ( gde admin postoji?)
            // Prvo autentifikacija, u zavisnosti od toga gleda se da li je admin ili ne (iz nekog txt-a)
            // ???
            string kljuc = Konstante.ENCRYPTION_KEY;
            Client <IGatewayConnection> cli          = new Client <IGatewayConnection>("mbgateway", Konstante.GATEWAY_IP, Konstante.GATEWAY_PORT.ToString(), "GatewayConnection");
            IGatewayConnection          gatewayProxy = cli.GetProxy();

            Console.WriteLine(">Login");
            User ulogovanUser     = new User();
            bool uspesnoLogovanje = false;

            while (!uspesnoLogovanje)
            {
                Console.WriteLine("Username:"******"Password:"******"";
                ConsoleKeyInfo key;

                do
                {
                    key = Console.ReadKey(true);

                    // Backspace Should Not Work
                    if (key.Key != ConsoleKey.Backspace)
                    {
                        pass += key.KeyChar;
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write("\b");
                    }
                }
                // Stops Receving Keys Once Enter is Pressed
                while (key.Key != ConsoleKey.Enter);
                pass = pass.Replace("\r", "");
                string passSifrovano = BitConverter.ToString(Sifrovanje.sifrujCBC(pass, kljuc));

                ulogovanUser = gatewayProxy.ClientToBankCheckLogin(userSifrovano, passSifrovano, "client");
                if (ulogovanUser != null)
                {
                    uspesnoLogovanje = true;
                }
                else
                {
                    Console.WriteLine("\nNeuspesno logovanje");
                }
            }

            if (ulogovanUser != null)
            {
                string userSifrovanoZaRacun = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, kljuc));

                Console.WriteLine("Uspesno logovanje " + ulogovanUser.Username);
                KlientskiRacun.racun = gatewayProxy.ClientToBankUzmiKlijentskiRacun(userSifrovanoZaRacun);
                if (KlientskiRacun.racun == null)
                {
                    Console.WriteLine("Ne postoji klijentski racun ");
                }
                else
                {
                    Console.WriteLine("Klijentski racun:" + KlientskiRacun.racun.BrojRacuna);
                }

                // podici server za klijenta i javiti banci sa metodomSetIpAndPort na kom portu i ip adresi slusa
                //ClientServer server = new ClientServer();
                //server.Start();
                //string sifrovanUsername = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));
                //gatewayProxy.ClientToBankSetIpAndPortClient(sifrovanUsername, server.ipAddress, server.port.ToString());

                Server2 <IClientConnection> server = new Server2 <IClientConnection>("localhost", Konstante.INITIAL_CLIENT_PORT.ToString(), "ClientConnection", typeof(ClientConnection));
                string sifrovanUsername            = BitConverter.ToString(Sifrovanje.sifrujCBC(ulogovanUser.Username, Konstante.ENCRYPTION_KEY));
                gatewayProxy.ClientToBankSetIpAndPortClient(sifrovanUsername, server.ipAddress, server.connectedPort.ToString());

                // Javi gatewayu da te doda u listu instanci
                gatewayProxy.CheckIntoGateway(server.ipAddress, server.connectedPort.ToString(), CertManager.Formatter.ParseName(WindowsIdentity.GetCurrent().Name));

                if (ulogovanUser.Uloga == "admin")
                {
                    MeniAdmin(gatewayProxy);
                }
                else if (ulogovanUser.Uloga == "korisnik")
                {
                    MeniKorisnik(gatewayProxy);
                }
            }

            Console.ReadKey();
            gatewayProxy.ClientToBankShutdownClient(ulogovanUser.Username);
        }