public void ShouldReturnErrorResponseCodeIfIdIsUnknown()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Rooms.Add(new Room {
                    Id = 1, Description = "Room 1"
                });
                context.Rooms.Add(new Room {
                    Id = 2, Description = "Room 2"
                });
                context.Rooms.Add(new Room {
                    Id = 300, Description = "Room 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new GetRoomDescriptionRequestHandler();

            var response = (GetRoomDescriptionDataResponse)requestHandler.Handle(new GetRoomDescriptionDataRequest {
                Identifier = 99
            });

            response.ResponseCode0.Should().Be(0x01);
            response.ResponseCode1.Should().Be(0x00);
            response.Identifier.Should().Be(0);
            response.Description.Should().Be("");
        }
        public void ShouldReturnErrorResponseCodeIfIdIsUnknown()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Devices.Add(new Device {
                    Id = 1, Description = "Device 1"
                });
                context.Devices.Add(new Device {
                    Id = 2, Description = "Device 2"
                });
                context.Devices.Add(new Device {
                    Id = 300, Description = "Device 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new RenameDeviceDescriptionRequestHandler();

            var response = (RenameDeviceDescriptionDataResponse)requestHandler.Handle(new RenameDeviceDescriptionDataRequest {
                Identifier = 99, Description = "New device"
            });

            response.ResponseCode0.Should().Be(0x01);
            response.ResponseCode1.Should().Be(0x00);
            response.Identifier.Should().Be(99);
        }
        public void ShouldUpdateDeviceDescriptionForExistingEntry()
        {
            const string newDeviceDescription = "New device";

            using (var context = new ServerDatabaseContext())
            {
                context.Devices.Add(new Device {
                    Id = 1, Description = "Device 1"
                });
                context.Devices.Add(new Device {
                    Id = 2, Description = "Device 2"
                });
                context.Devices.Add(new Device {
                    Id = 300, Description = "Device 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new RenameDeviceDescriptionRequestHandler();

            requestHandler.Handle(new RenameDeviceDescriptionDataRequest {
                Identifier = 2, Description = newDeviceDescription
            });

            using (var context = new ServerDatabaseContext())
            {
                context.Devices.Find(2).Description.Should().Be(newDeviceDescription);
            }
        }
Exemple #4
0
        public void ShouldDeleteDeviceForExistingEntry()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Devices.Add(new Device {
                    Id = 1, Description = "Device 1"
                });
                context.Devices.Add(new Device {
                    Id = 2, Description = "Device 2"
                });
                context.Devices.Add(new Device {
                    Id = 300, Description = "Device 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new DeleteDeviceRequestHandler();

            var response = (DeleteDeviceDataResponse)requestHandler.Handle(new DeleteDeviceDataRequest {
                Identifier = 2
            });

            response.Identifier.Should().Be(2);
            response.ResponseCode0.Should().Be(0);
            response.ResponseCode1.Should().Be(0);
            using (var context = new ServerDatabaseContext())
            {
                var devices = context.Devices.ToList();
                devices.Should().HaveCount(2);
                devices.Find(x => x.Id == 2).Should().BeNull();
            }
        }
Exemple #5
0
        public bool ExchangeNew(string LoginSender, string LoginCreator, int IsOneWay)
        {
            using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
            {
                UserTable creator = databaseContext.UserTables.Where(u => u.Login == LoginCreator).FirstOrDefault();
                UserTable sender  = databaseContext.UserTables.Where(u => u.Login == LoginSender).FirstOrDefault();
                bool      isOne   = false;
                if (IsOneWay == 1)
                {
                    isOne = true;
                }
                DatabaseExchangeTable exchange = new DatabaseExchangeTable
                {
                    IsCreatorDone  = false,
                    IsOneWay       = isOne,
                    IsSenderAccept = null,
                    IsSenderDone   = false,
                    UserCreatorId  = creator.UserId,
                    UserSenderId   = sender.UserId
                };
                if (IsOneWay == 1)
                {
                    exchange.IsSenderDone = true;
                }

                databaseContext.DatabaseExchangeTables.Add(exchange);
                databaseContext.SaveChanges();
            }
            return(true);
        }
Exemple #6
0
        public void ShouldReturnErrorResponseCodeIfIdIsUnknown()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Devices.Add(new Device {
                    Id = 1, Description = "Device 1"
                });
                context.Devices.Add(new Device {
                    Id = 2, Description = "Device 2"
                });
                context.Devices.Add(new Device {
                    Id = 300, Description = "Device 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new DeleteDeviceRequestHandler();

            var response = (DeleteDeviceDataResponse)requestHandler.Handle(new DeleteDeviceDataRequest {
                Identifier = 99
            });

            response.ResponseCode0.Should().Be(0x01);
            response.ResponseCode1.Should().Be(0x00);
            response.Identifier.Should().Be(0);
            using (var context = new ServerDatabaseContext())
            {
                var devices = context.Devices.ToList();
                devices.Should().HaveCount(3);
            }
        }
Exemple #7
0
 public bool ExchangeDone(int Id, int Doned)
 {
     using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
     {
         DatabaseExchangeTable exchange = databaseContext.DatabaseExchangeTables.Where(u => u.DatabaseExchangeId == Id).FirstOrDefault();
         if (Doned == 0)
         {
             exchange.IsSenderDone = false;
         }
         else
         {
             exchange.IsCreatorDone = true;
         }
         databaseContext.SaveChanges();
     }
     return(true);
 }
Exemple #8
0
 public bool ExchangeAccept(int Id, int Accepting)
 {
     using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
     {
         DatabaseExchangeTable exchange = databaseContext.DatabaseExchangeTables.Where(u => u.DatabaseExchangeId == Id).FirstOrDefault();
         if (Accepting == 0)
         {
             exchange.IsSenderAccept = false;
         }
         else
         {
             exchange.IsSenderAccept = true;
         }
         databaseContext.SaveChanges();
     }
     return(true);
 }
Exemple #9
0
        public IResponse Handle(IRequest request)
        {
            var    dataRequest = (CreateDeviceDataRequest)request;
            Device device;

            using (var context = new ServerDatabaseContext())
            {
                device = new Device {
                    Description = dataRequest.Description
                };
                context.Devices.Add(device);
                context.SaveChanges();
            }

            return(new CreateDeviceDataResponse {
                Identifier = device.Id, ClientObjectIdentifier = dataRequest.ClientObjectIdentifier
            });
        }
        public IResponse Handle(IRequest request)
        {
            var  dataRequest = (CreateRoomDataRequest)request;
            Room room;

            using (var context = new ServerDatabaseContext())
            {
                room = new Room {
                    Description = dataRequest.Description
                };
                context.Rooms.Add(room);
                context.SaveChanges();
            }

            return(new CreateRoomDataResponse {
                Identifier = room.Id, ClientObjectIdentifier = dataRequest.ClientObjectIdentifier
            });
        }
 public bool RegistrationUser(RegistrationData data)
 {
     if (IsLoginFromBase(data.Login))
     {
         return(false);
     }
     using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
     {
         databaseContext.UserTables.Add(new UserTable()
         {
             Login            = data.Login,
             Md5              = data.Md5,
             DateEditDatabase = null,
             DateEditSetting  = null
         });
         databaseContext.SaveChanges();
         GenerateStructDirectoryes(data.Login);
     }
     return(true);
 }
Exemple #12
0
        public IResponse Handle(IRequest request)
        {
            var dataRequest = (RenameDeviceDescriptionDataRequest)request;

            using (var context = new ServerDatabaseContext())
            {
                var device = context.Devices.Find(dataRequest.Identifier);
                if (device == null)
                {
                    return new RenameDeviceDescriptionDataResponse {
                               Identifier = dataRequest.Identifier, ResponseCode0 = 0x01, ResponseCode1 = 0x00
                    }
                }
                ;

                device.Description = dataRequest.Description;
                context.SaveChanges();
                return(new RenameDeviceDescriptionDataResponse {
                    Identifier = device.Id
                });
            }
        }
    }
Exemple #13
0
        public IResponse Handle(IRequest request)
        {
            var dataRequest = (DeleteRoomDataRequest)request;

            using (var context = new ServerDatabaseContext())
            {
                var room = context.Rooms.Find(dataRequest.Identifier);
                if (room == null)
                {
                    return new DeleteRoomDataResponse {
                               RoomIdentifier = 0, ResponseCode0 = 0x01, ResponseCode1 = 0x00
                    }
                }
                ;

                context.Remove(room);
                context.SaveChanges();
                return(new DeleteRoomDataResponse {
                    RoomIdentifier = room.Id
                });
            }
        }
    }
        public IResponse Handle(IRequest request)
        {
            var dataRequest = (DeleteDeviceDataRequest)request;

            using (var context = new ServerDatabaseContext())
            {
                var device = context.Devices.Find(dataRequest.Identifier);
                if (device == null)
                {
                    return new DeleteDeviceDataResponse {
                               Identifier = 0, ResponseCode0 = 0x01, ResponseCode1 = 0x00
                    }
                }
                ;

                context.Remove(device);
                context.SaveChanges();
                return(new DeleteDeviceDataResponse {
                    Identifier = device.Id
                });
            }
        }
    }
        public IResponse Handle(IRequest request)
        {
            var dataRequest = (RenameRoomDescriptionDataRequest)request;

            using (var context = new ServerDatabaseContext())
            {
                var room = context.Rooms.Find(dataRequest.Identifier);
                if (room == null)
                {
                    return new RenameRoomDescriptionDataResponse {
                               RoomIdentifier = dataRequest.Identifier, ResponseCode0 = 0x01, ResponseCode1 = 0x00
                    }
                }
                ;

                room.Description = dataRequest.Description;
                context.SaveChanges();
                return(new RenameRoomDescriptionDataResponse {
                    RoomIdentifier = room.Id
                });
            }
        }
    }
        public void ShouldReturnAllRoomIds()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Rooms.Add(new Room {
                    Id = 1
                });
                context.Rooms.Add(new Room {
                    Id = 2
                });
                context.Rooms.Add(new Room {
                    Id = 300
                });
                context.SaveChanges();
            }
            var requestHandler = new GetAllRoomsRequestHandler();

            var response = (GetAllRoomsDataResponse)requestHandler.Handle(new GetAllRoomsDataRequest());

            response.Identifiers.Should().HaveCount(3);
            response.Identifiers[0].Should().Be(1);
            response.Identifiers[1].Should().Be(2);
            response.Identifiers[2].Should().Be(300);
        }
        public void ShouldReturnRoomDescriptionForExistingEntry()
        {
            using (var context = new ServerDatabaseContext())
            {
                context.Rooms.Add(new Room {
                    Id = 1, Description = "Room 1"
                });
                context.Rooms.Add(new Room {
                    Id = 2, Description = "Room 2"
                });
                context.Rooms.Add(new Room {
                    Id = 300, Description = "Room 300"
                });
                context.SaveChanges();
            }
            var requestHandler = new GetRoomDescriptionRequestHandler();

            var response = (GetRoomDescriptionDataResponse)requestHandler.Handle(new GetRoomDescriptionDataRequest {
                Identifier = 2
            });

            response.Identifier.Should().Be(2);
            response.Description.Should().Be("Room 2");
        }
Exemple #18
0
        public JsonResult GetListFilesInfo([FromBody] ListFileInfoData list)
        {
            //Формирование полного пути
            string mainPath = Request.MapPath("..//data//" + list.Login);

            //Получение массивов путей к файлам
            string[] masb = Directory.GetFiles(mainPath + "\\Backups");
            string[] masp = Directory.GetFiles(mainPath + "\\Photos");
            string[] masd = Directory.GetFiles(mainPath + "\\Documents");
            string[] masm = Directory.GetFiles(mainPath);

            //Получение списков имен файлов
            List <string> backupFileNames   = new List <string>();
            List <string> photoFileNames    = new List <string>();
            List <string> documentFileNames = new List <string>();
            List <string> mainFileNames     = new List <string>();

            foreach (var elem in masb)
            {
                FileInfo infFile = new FileInfo(elem);
                backupFileNames.Add(infFile.Name);
            }
            foreach (var elem in masp)
            {
                FileInfo infFile = new FileInfo(elem);
                photoFileNames.Add(infFile.Name);
            }
            foreach (var elem in masd)
            {
                FileInfo infFile = new FileInfo(elem);
                documentFileNames.Add(infFile.Name);
            }
            foreach (var elem in masm)
            {
                FileInfo infFile = new FileInfo(elem);
                mainFileNames.Add(infFile.Name);
            }

            if (list.FilesInfo != null)
            {
                foreach (var elem in list.FilesInfo)
                {
                    switch (elem.FileType)
                    {
                    case FileToUpload.Settings:
                    {
                        using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
                        {
                            UserTable user = databaseContext.UserTables.FirstOrDefault(u => u.Login == list.Login);
                            if (user.DateEditSetting == null || elem.DateChange - user.DateEditSetting.Value > TimeSpan.FromMinutes(1))
                            {
                                user.DateEditSetting = DateTime.Now;
                                databaseContext.SaveChanges();
                                elem.IsUpload = true;
                            }
                            else if (user.DateEditSetting.Value - elem.DateChange > TimeSpan.FromMinutes(1))
                            {
                                if (System.IO.File.Exists(mainPath + "\\" + elem.NameFile))
                                {
                                    elem.IsDownload = true;
                                }
                            }
                            if (mainFileNames.Contains(elem.NameFile))
                            {
                                mainFileNames.Remove(elem.NameFile);
                            }
                        }
                        break;
                    }

                    case FileToUpload.Database:
                    {
                        using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
                        {
                            UserTable user = databaseContext.UserTables.FirstOrDefault(u => u.Login == list.Login);
                            if (user.DateEditDatabase == null || elem.DateChange - user.DateEditDatabase.Value > TimeSpan.FromMinutes(1))
                            {
                                user.DateEditDatabase = DateTime.Now;
                                databaseContext.SaveChanges();
                                elem.IsUpload = true;
                            }
                            else if (user.DateEditDatabase.Value - elem.DateChange > TimeSpan.FromMinutes(1))
                            {
                                if (System.IO.File.Exists(mainPath + "\\" + elem.NameFile))
                                {
                                    elem.IsDownload = true;
                                }
                            }
                            if (mainFileNames.Contains(elem.NameFile))
                            {
                                mainFileNames.Remove(elem.NameFile);
                            }
                        }
                        break;
                    }

                    case FileToUpload.Backup:
                    {
                        if (!backupFileNames.Contains(elem.NameFile))
                        {
                            using (ServerDatabaseContext databaseContext = new ServerDatabaseContext())
                            {
                                UserTable user = databaseContext.UserTables.FirstOrDefault(u => u.Login == list.Login);
                                databaseContext.BackupTables.Add(new BackupTable {
                                        BackupName = elem.NameFile, DateOfCreate = DateTime.Now,
                                        UserId     = user.UserId
                                    });
                                databaseContext.SaveChanges();
                                elem.IsUpload = true;
                            }
                        }
                        else
                        {
                            backupFileNames.Remove(elem.NameFile);
                        }
                        break;
                    }

                    case FileToUpload.Document:
                    {
                        if (!documentFileNames.Contains(elem.NameFile))
                        {
                            elem.IsUpload = true;
                        }
                        else
                        {
                            documentFileNames.Remove(elem.NameFile);
                        }
                        break;
                    }

                    case FileToUpload.Photo:
                    {
                        if (!photoFileNames.Contains(elem.NameFile))
                        {
                            elem.IsUpload = true;
                        }
                        else
                        {
                            photoFileNames.Remove(elem.NameFile);
                        }
                        break;
                    }
                    }
                }
            }

            List <FileInfoData> newList = list.FilesInfo.ToList();

            if (documentFileNames.Count > 0)
            {
                foreach (var elem in documentFileNames)
                {
                    newList.Add(new FileInfoData
                    {
                        DateChange = DateTime.Now,
                        FileType   = FileToUpload.Document,
                        IsChanged  = false,
                        IsDownload = true,
                        IsUpload   = false,
                        NameFile   = elem,
                        PathFile   = ""
                    });
                }
            }
            if (photoFileNames.Count > 0)
            {
                foreach (var elem in photoFileNames)
                {
                    newList.Add(new FileInfoData
                    {
                        DateChange = DateTime.Now,
                        FileType   = FileToUpload.Photo,
                        IsChanged  = false,
                        IsDownload = true,
                        IsUpload   = false,
                        NameFile   = elem,
                        PathFile   = ""
                    });
                }
            }

            if (mainFileNames.Count > 0)
            {
                foreach (var elem in mainFileNames)
                {
                    FileToUpload fileTo;
                    if (elem == "Settings.bin")
                    {
                        fileTo = FileToUpload.Settings;
                    }
                    else
                    {
                        fileTo = FileToUpload.Database;
                    }
                    newList.Add(new FileInfoData
                    {
                        DateChange = DateTime.Now,
                        FileType   = fileTo,
                        IsChanged  = false,
                        IsDownload = true,
                        IsUpload   = false,
                        NameFile   = elem,
                        PathFile   = ""
                    });
                }
            }

            list = new ListFileInfoData(newList.ToArray());
            return(Json(list));
        }
Exemple #19
0
 public virtual void Commit()
 {
     _context.SaveChanges();
 }