public void IfNotOccupiedClientCheck()
        {
            Car    car    = new Car();
            Client client = new Client();

            DatabaseManager.RemoveCar(car);
            DatabaseManager.RemoveClient(client);

            DatabaseManager.AddCar(car);
            DatabaseManager.AddClient(client);

            Order order = new Order(car, client, DateTime.Today, DateTime.Today);

            DatabaseManager.RemoveOrder(order);

            bool checkBefore = DatabaseManager.IfNotOccupied(client);

            DatabaseManager.AddOrder(order);
            bool checkAfter = DatabaseManager.IfNotOccupied(client);

            DatabaseManager.RemoveOrder(order);
            DatabaseManager.RemoveCar(car);
            DatabaseManager.RemoveClient(client);

            Assert.IsFalse(checkBefore);
            Assert.IsTrue(checkAfter);
        }
Exemple #2
0
        public void AddingClientTest()
        {
            var amountBefore = DatabaseManager.CountAllClients();

            DatabaseManager.AddClient("nsli", "name", "surname", "licNo", 25);
            var amountAfter = DatabaseManager.CountAllClients();

            Assert.Greater(amountAfter, amountBefore);
            DatabaseManager.RemoveClient("nsli");
        }
Exemple #3
0
        public void GetClientNameSurnameTest()
        {
            DatabaseManager.AddClient("nsli", "name", "surname", "licNo", 50);

            Client client1 = DatabaseManager.GetClient("name", "surname");
            var    client2 = new Client("name", "surname", "licNo", 50);

            DatabaseManager.RemoveClient("nsli");

            Assert.True(client1.Equals(client2));
        }
        public void AddingClientObjTest()
        {
            var client = new Client();

            var amountBefore = DatabaseManager.CountAllClients();

            DatabaseManager.AddClient(client);
            var amountAfter = DatabaseManager.CountAllClients();

            Assert.IsTrue(amountAfter > amountBefore);
        }
Exemple #5
0
        public void AddingClientObjTest()
        {
            var client = new Client();

            var amountBefore = DatabaseManager.CountAllClients();

            DatabaseManager.AddClient(client);
            var amountAfter = DatabaseManager.CountAllClients();

            DatabaseManager.RemoveClient(client.Id);
            Assert.Greater(amountAfter, amountBefore);
        }
        public void UpdateClientTest()
        {
            DatabaseManager.AddClient("nsli", "name", "surname", "licNo", 50);
            DatabaseManager.UpdateClient("nsli", "name1", "surname1", "licNo1", 55);

            var client1 = DatabaseManager.GetClient("nsli");
            var client2 = new Client("name1", "surname1", "licNo1", 55);

            DatabaseManager.RemoveClient("nsli");

            Assert.IsTrue(client1.Equals(client2));
        }
Exemple #7
0
        public void ClientIfExistsTest()
        {
            bool check1 = DatabaseManager.IfClientExists("name", "surname");

            DatabaseManager.AddClient("nsli", "name", "surname", "licNo", 50);

            bool check = DatabaseManager.IfClientExists("name", "surname");

            DatabaseManager.RemoveClient("nsli");

            Assert.False(check1);
            Assert.True(check);
        }
Exemple #8
0
        public static void AdminAccess()
        {
            Name    = "admin";
            Surname = "admin";

            if (DatabaseManager.IfClientExists("admin", "admin"))
            {
                CurrentUserConfig.CurrentUser = DatabaseManager.GetClient("admin", "admin");
            }
            else
            {
                Client admin = new Client("admin", "admin", "100000", 100);
                DatabaseManager.AddClient(admin);
            }
        }
        public void IfClientExistsTest()
        {
            Client client = new Client();

            DatabaseManager.RemoveClient(client);
            bool checkBefore = DatabaseManager.IfClientExists(client.Name, client.Surname);

            DatabaseManager.AddClient(client);
            bool checkAfter = DatabaseManager.IfClientExists(client.Name, client.Surname);

            DatabaseManager.RemoveClient(client);

            Assert.IsFalse(checkBefore);
            Assert.IsTrue(checkAfter);
        }
Exemple #10
0
        public void GettingOrderTest()
        {
            Car    car    = new Car();
            Client client = new Client();
            Order  order  = new Order(car, client, DateTime.Today, DateTime.Today);

            DatabaseManager.AddCar(car);
            DatabaseManager.AddClient(client);
            DatabaseManager.AddOrder(order);

            Order order1 = DatabaseManager.GetOrder(order.OrderId);

            DatabaseManager.RemoveOrder(order);
            DatabaseManager.RemoveClient(client);
            DatabaseManager.RemoveCar(car);

            Assert.True(order1.Equals(order));
        }
        public void AddOrderObjTest()
        {
            var date = DateTime.Today;

            var car    = new Car();
            var client = new Client();
            var order  = new Order(car, client, date, date);

            var beforeAmountAdd = DatabaseManager.CountAllOrders();

            DatabaseManager.AddClient(client);
            DatabaseManager.AddCar(car);
            DatabaseManager.AddOrder(order);

            var afterAmountAdd = DatabaseManager.CountAllOrders();

            Assert.IsTrue(afterAmountAdd > beforeAmountAdd);
        }
        public void GetOrderTest()
        {
            Order  order  = new Order();
            Car    car    = new Car();
            Client client = new Client();

            DatabaseManager.RemoveOrder(order);
            DatabaseManager.RemoveCar(car);
            DatabaseManager.RemoveClient(client);

            DatabaseManager.AddCar(car);
            DatabaseManager.AddClient(new Client());
            DatabaseManager.AddOrder(order);

            Order order1 = DatabaseManager.GetOrder(order.Client.Name, order.Client.Surname);

            DatabaseManager.RemoveOrder(order);
            DatabaseManager.RemoveCar(car);
            DatabaseManager.RemoveClient(client);

            Assert.IsTrue(order.Equals(order1));
        }
        private void Submit(object o)
        {
            Alert = "";
            bool check = true;

            var values = (object[])o;

            if (CheckData.CheckObjectArray(values))
            {
                var name    = (string)values[0];
                var surname = (string)values[1];
                var licNo   = (string)values[2];
                var age     = (string)values[3];

                check = CheckData.CheckIfWord(name) &&
                        CheckData.CheckIfWord(surname) &&
                        CheckData.CheckIfNumber(age);

                if (check)
                {
                    if (!DatabaseManager.IfClientExists(name, surname))
                    {
                        if (CheckBox1 == true && CheckBox2 == true)
                        {
                            if (!CheckData.CheckName(name) || !CheckData.CheckName(surname))
                            {
                                Alert = "Name or surname is incorrect";
                                check = false;
                            }
                            if (!CheckData.CheckLicenceNo(licNo))
                            {
                                Alert = "Liecence no is incorrect";
                                check = false;
                            }
                            if (!CheckData.CheckAge(Int32.Parse(age)))
                            {
                                Alert = "You must be over 18.";
                                check = false;
                            }

                            if (check)
                            {
                                Client newUser = new Client(name, surname, licNo, Int32.Parse(age));
                                DatabaseManager.AddClient(newUser);
                                CurrentUserConfig.CurrentUser = DatabaseManager.GetClient(newUser.Id);

                                Mediator.NotifyColleagues("toHome", true);
                            }
                        }
                        else
                        {
                            Alert = "Tick all checkboxes";
                        }
                    }
                    else
                    {
                        Alert = "Such client already exists";
                    }
                }
                else
                {
                    Alert = "Check if word is a word and number is a number";
                }
            }
        }
Exemple #14
0
 internal void AddClient(Client cust)
 {
     _data.AddClient(cust);
     RaisePropertyChanged("Client");
 }
        public bool LogIn(SslStream sslStream, BinaryReader binaryReader, BinaryWriter binaryWriter,
                          out ClientData clientData, out CoreClientInformation coreClientInformation, out bool isNewClient)
        {
            clientData            = null;
            coreClientInformation = null;
            isNewClient           = false;

            Logger.Debug("Send key request");

            binaryWriter.Write((byte)AuthentificationFeedback.GetKey);
            var keys  = new KeyDatabase();
            var index = Random.Next(keys.Length);
            var key   = keys.GetKey(index,
                                    "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh");

            binaryWriter.Write(index);
            var result = binaryReader.ReadString();

            if (key != result)
            {
                binaryWriter.Write((byte)AuthentificationFeedback.InvalidKey);
                Logger.Info("Invalid key - denied");
                return(false);
            }

            Logger.Debug("Valid key. Get hardware id");

            binaryWriter.Write((byte)AuthentificationFeedback.GetHardwareId);
            var hardwareId = binaryReader.ReadString();

            if (hardwareId.Length > 256)
            {
                Logger.Info("Client rejected because the hardware id was too long. Length: {0}, MaxLength: 256",
                            hardwareId.Length);
                return(false);
            }

            Logger.Debug("Hardware id received: {0}", hardwareId);
            Logger.Debug("Get client from database...");

            var    knowClient = _databaseManager.GetClient(hardwareId, out clientData);
            string clientTag  = null;

            Logger.Debug(knowClient ? "Client was already registered" : "Seems like a new client");

            if (knowClient)
            {
                Logger.Debug("Client accepted");
                binaryWriter.Write((byte)AuthentificationFeedback.Accepted);
            }
            else
            {
                Logger.Debug("Get client tag");
                binaryWriter.Write((byte)AuthentificationFeedback.GetClientTag);
                clientTag = binaryReader.ReadString();
                if (clientTag.Length > 256)
                {
                    Logger.Info("Client rejected because the client tag was too long. Length: {0}, MaxLength: 256",
                                clientTag.Length);
                    return(false);
                }
                Logger.Debug("Client tag received: {0}. Client accepted", clientTag);
                binaryWriter.Write((byte)AuthentificationFeedback.Accepted);
            }

            var types = new List <Type>(BuilderPropertyHelper.GetAllBuilderPropertyTypes())
            {
                typeof(BasicComputerInformation)
            };
            var serializer = new Serializer(types);

            Logger.Debug("Attempt to deserialize BasicComputerInformation");
            var basicComputerInformation = (BasicComputerInformation)serializer.Deserialize(sslStream);

            Logger.Debug("BasicComputerInformation received, processing...");
            coreClientInformation = new CoreClientInformation
            {
                UserName         = basicComputerInformation.UserName,
                OSName           = basicComputerInformation.OperatingSystemName,
                OSType           = basicComputerInformation.OperatingSystemType,
                Language         = basicComputerInformation.Language,
                IsAdministrator  = basicComputerInformation.IsAdministrator,
                IsServiceRunning = basicComputerInformation.IsServiceRunning,
                Plugins          = basicComputerInformation.Plugins,
                LoadablePlugins  = basicComputerInformation.LoadablePlugins,
                ClientConfig     = basicComputerInformation.ClientConfig,
                ClientVersion    = basicComputerInformation.ClientVersion,
                ClientPath       = basicComputerInformation.ClientPath,
                ApiVersion       = basicComputerInformation.ApiVersion,
                FrameworkVersion = basicComputerInformation.FrameworkVersion,
                ActiveCommands   = basicComputerInformation.ActiveCommands
            };

            if (basicComputerInformation.MacAddress?.Length == 6)
            {
                coreClientInformation.MacAddress = basicComputerInformation.MacAddress;
            }

            Logger.Trace("Client Information:\r\n{0}", coreClientInformation);

            if (coreClientInformation.OSName.Length > 256)
            {
                Logger.Info("Client rejected because the OSName was too long. Length: {0}, MaxLength: 256",
                            coreClientInformation.OSName.Length);
                return(false);
            }

            if (coreClientInformation.UserName.Length > 256)
            {
                Logger.Info("Client rejected because the UserName was too long. Length: {0}, MaxLength: 256",
                            coreClientInformation.UserName.Length);
                return(false);
            }

            if (coreClientInformation.Language.Length > 32)
            {
                Logger.Info("Client rejected because the Language was too long. Length: {0}, MaxLength: 256",
                            coreClientInformation.Language.Length);
                return(false);
            }

            Logger.Debug("Seems like the information is OK");

            if (knowClient)
            {
                Logger.Debug("Because the client was already registered, updating database entry");
                _databaseManager.RefreshClient(clientData.Id, coreClientInformation.UserName,
                                               coreClientInformation.OSName, (int)coreClientInformation.OSType, coreClientInformation.Language,
                                               coreClientInformation.MacAddress);
                clientData.UserName   = coreClientInformation.UserName;
                clientData.OSName     = coreClientInformation.OSName;
                clientData.OSType     = coreClientInformation.OSType;
                clientData.Language   = coreClientInformation.Language;
                clientData.MacAddress = coreClientInformation.MacAddress;
            }
            else
            {
                Logger.Info("Register client...");
                Logger.Debug("Create database entry");
                var id = _databaseManager.AddClient(coreClientInformation.UserName, hardwareId,
                                                    coreClientInformation.OSName, (int)coreClientInformation.OSType, coreClientInformation.Language,
                                                    clientTag, coreClientInformation.MacAddress);
                if (id == -1)
                {
                    Logger.Error("The generated id of the new client is -1");
                    return(false);
                }
                clientData = new ClientData
                {
                    Id         = id,
                    Language   = coreClientInformation.Language,
                    HardwareId = hardwareId,
                    LastSeen   = DateTime.UtcNow,
                    UserName   = coreClientInformation.UserName,
                    OSType     = coreClientInformation.OSType,
                    OSName     = coreClientInformation.OSName,
                    Group      = clientTag,
                    MacAddress = coreClientInformation.MacAddress
                };
            }

            Logger.Debug("Client authentication successful");

            isNewClient = !knowClient;
            return(true);
        }