Example #1
0
        public void SimpleTest()
        {
            var container = new ConfigContainer();
            container.Register((Foo x) => x.Bar1)
                .Named("Bar1")
                .Described("Bar1 description")
                .WithInputType(InputType.Auto)
                .WithVisibilityConfig(all: Visibility.Show)
                .WithObjectListConfig(new ObjectListConfig(() => {
                return new GestUAB.DataAccess.DataFacade().ReadAllCursos();
            }));

            var config = container.GetConfig((Foo x) => x.Bar1);
            Assert.AreEqual(config.Name, "Bar1");
            Assert.AreEqual(config.Description, "Bar1 description");
            Assert.AreEqual(config.InputType, InputType.Auto);
            Assert.AreEqual(config.VisibilityConfig.Create, Visibility.Show);
            Assert.AreEqual(config.VisibilityConfig.Delete, Visibility.Show);
            Assert.AreEqual(config.VisibilityConfig.Read, Visibility.Show);
            Assert.AreEqual(config.VisibilityConfig.Update, Visibility.Show);
            Assert.NotNull(config.ObjectListConfig.Objects);

            container.Register((Foo x) => x.Bar2)
                .Named("Bar2")
                    .Described("Bar2 description")
                    .WithInputType(InputType.Checkbox)
                    .WithVisibilityConfig(create: Visibility.Hidden);

            config = container.GetConfig((Foo x) => x.Bar2);
            Assert.AreNotEqual(config.Name, "Bar1");
            Assert.AreNotEqual(config.Description, "Bar1 description");
            Assert.AreNotEqual(config.InputType, InputType.Auto);
            Assert.AreEqual(config.VisibilityConfig.Create, Visibility.Hidden);
        }
Example #2
0
 public FormSettings()
 {
     InitializeComponent();
     _config               = ConfigContainer.GetConfig <ClientConfig>();
     PortTextBox.Text      = _config.ServerPort.ToString();
     IpAddressTextBox.Text = _config.ServerIp;
 }
Example #3
0
        private static void Listen()
        {
            TcpListener listener = null;

            try
            {
                var config = ConfigContainer.GetConfig <ServerConfig>();

                listener = new TcpListener(IPAddress.Parse(config.ServerIp), config.ServerPort);

                listener.Start();

                while (true)
                {
                    var client = listener.AcceptTcpClient();

                    var connectionHandler = new ConnectionHandler(client);
                    var thread            = new Thread(connectionHandler.Handle)
                    {
                        IsBackground = true
                    };
                    thread.Start();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                listener?.Stop();
            }
        }
Example #4
0
        private void FillSubjectList()
        {
            var subjectFileService = new SubjectFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);
            var subjects           = subjectFileService.Load();

            SelectSubjectComboBox.Items.AddRange(subjects.Select(s => (object)s.Name).ToArray());
        }
Example #5
0
        public PlatoonsForm()
        {
            InitializeComponent();
            _platoonWorker = new PlatoonWorker(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);

            PlatoonsListBox.Items.AddRange(_platoonWorker.GetPlatoonNamesAsObjects());
        }
Example #6
0
        public void Handle(Command command)
        {
            var saveFolder             = ConfigContainer.GetConfig <ServerConfig>().SaveFolder;
            var testDevidedFileService = new TestDevidedFileService(saveFolder);
            var tests = testDevidedFileService.Load();

            _streamWrapperService.SendObject(tests);
        }
Example #7
0
        public void Handle(Command command)
        {
            var saveFolder = ConfigContainer.GetConfig <ServerConfig>().SaveFolder;
            var imageDevidedFileService = new ImageDevidedFileService(saveFolder);
            var images = imageDevidedFileService.Load(command.Args[0]);

            _streamWrapperService.SendObject(images);
        }
        public void Handle(Command command)
        {
            var saveFolder = ConfigContainer.GetConfig <ServerConfig>().SaveFolder;
            var imageDevidedFileService = new ImageDevidedFileService(saveFolder);
            var informationObjects      = imageDevidedFileService.GetInformationObjects();

            _streamWrapperService.SendObject(informationObjects);
        }
Example #9
0
        private void SaveButton_Click(object sender, System.EventArgs e)
        {
            ConfigContainer.GetConfig <EditorConfig>().SaveFolder = SavePathTextBox.Text;
            ConfigContainer.SaveConfiguration();

            Close();

            MessageBox.Show(@"Сохранение настроек прошло успешно", @"Настройки сохранены", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #10
0
        private void StartThread()
        {
            LoadingStatusLabel.Text = @"Ожидание подключения";

            var configuration = ConfigContainer.GetConfig <ClientConfig>();

            var testUpdater = new ClientTestUpdater(configuration.ServerIp, configuration.ServerPort);

            LoadingTestBackgroundWorker.RunWorkerAsync(testUpdater);
        }
Example #11
0
        public ClientTestUpdater(string serverId, int serverPort)
        {
            _serverConnectionService = new ServerConnectionService(serverId, serverPort);

            _subjectFileService = new SubjectFileService(ConfigContainer.GetConfig <ClientConfig>().SaveFolder);
            _platoonFileService = new PlatoonFileService(ConfigContainer.GetConfig <ClientConfig>().SaveFolder);

            var config = ConfigContainer.GetConfig <ClientConfig>();

            _clientTestFileService =
                new ClientTestFileService(config.TestFolder, config.ImageFolder);
        }
Example #12
0
        public SettingForm()
        {
            InitializeComponent();

            var config = ConfigContainer.GetConfig <ServerConfig>();

            ResultFolderTextBox.Text = config.ResultFolder;
            TestFolderTextBox.Text   = config.TestFolder;

            IpTextBox.Text        = config.ServerIp;
            PortLabelTextBox.Text = config.ServerPort.ToString();
        }
Example #13
0
        private void SaveConfig()
        {
            var config = ConfigContainer.GetConfig <ServerConfig>();

            config.ResultFolder = ResultFolderTextBox.Text;
            config.TestFolder   = TestFolderTextBox.Text;

            config.ServerIp   = IpTextBox.Text;
            config.ServerPort = int.Parse(PortLabelTextBox.Text);

            ConfigContainer.SaveConfiguration();
            ListenerContainer.Restart();
        }
Example #14
0
        public StartForm()
        {
            InitializeComponent();

            var savePath = ConfigContainer.GetConfig <ClientConfig>().SaveFolder;

            _subjects = new SubjectFileService(savePath).Load();
            _platoons = new PlatoonFileService(savePath).Load();
            _tests    = new TestDevidedFileService(savePath).Load().Values.ToList();

            ChoiceSubjectComboBox.Items.AddRange(_subjects.Select(subject => (object)subject.Name).OrderBy(o => o).ToArray());
            ChoicePlatoonComboBox.Items.AddRange(_platoons.OrderBy(platoon => platoon.Name).Select(platoon => (object)platoon.Name).ToArray());
        }
Example #15
0
        private void DrawTestPanels()
        {
            TestFlowLayoutPanel.Controls.Clear();

            var testDevidedFileService =
                new TestDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);
            var tests = testDevidedFileService.Load().Values;

            foreach (var test in tests)
            {
                var panel = CreatePanelForTest(test);
                TestFlowLayoutPanel.Controls.Add(panel);
            }
        }
Example #16
0
        private void SaveTestSettingsButton_Click(object sender, System.EventArgs e)
        {
            if (ValidateInputs())
            {
                var testDevidedFileService =
                    new TestDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);

                var fileUpdateActions = new List <FileUpdateAction <Test> >
                {
                    new FileUpdateAction <Test>
                    {
                        FileName        = InputTestNameTextBox.Text + ".test",
                        SaveInformation = new Test
                        {
                            Name  = InputTestNameTextBox.Text,
                            Marks = new Marks
                            {
                                Excellent    = Convert(InputExcellentMarkTextBox.Text),
                                Good         = Convert(InputGoodMarkTextBox.Text),
                                Satisfaction = Convert(InputSatisfactionMarkTextBox.Text)
                            },
                            Subject = new Subject
                            {
                                Name = (string)SelectSubjectComboBox.SelectedItem
                            }
                        },
                        Type = FileUpdateActionType.Save
                    }
                };

                if (_test != null)
                {
                    fileUpdateActions.Add(new FileUpdateAction <Test>
                    {
                        FileName = _test.Name + ".test",
                        Type     = FileUpdateActionType.Remove
                    });
                }

                testDevidedFileService.Update(fileUpdateActions);

                Close();

                MessageBox.Show(@"Сохранение теста прошло успешно", @"Тест сохранен", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(@"Ввод не валидный");
            }
        }
Example #17
0
        private void DeleteTest(object sender, System.EventArgs e)
        {
            var test = (Test)((Button)sender).Parent.Tag;
            var testDevidedFileService =
                new TestDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);

            testDevidedFileService.Update(new List <FileUpdateAction <Test> >
            {
                new FileUpdateAction <Test>
                {
                    FileName = test.Name + ".test",
                    Type     = FileUpdateActionType.Remove
                }
            });
        }
Example #18
0
        private string SaveImage(string fromPath)
        {
            var fileName = Path.GetRandomFileName() + ".bin";

            var bitmap = new Bitmap(fromPath);

            new ImageDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder).Update(
                new List <FileUpdateAction <Bitmap> >
            {
                new FileUpdateAction <Bitmap>
                {
                    FileName        = fileName,
                    SaveInformation = bitmap,
                    Type            = FileUpdateActionType.Save
                }
            });

            return(fileName);
        }
Example #19
0
        private static PictureBox CreatePictureBox(ImageTaskElement element)
        {
            var bitmap = new ImageDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder).LoadAsBitmap(element.ImageName);

            //TODO Сделать адекватное изменение размеров изображения

            var pictureBox = new PictureBox
            {
                Image    = bitmap,
                Height   = element.Height,
                Width    = element.Width,
                Location = element.Point,
                Tag      = element
            };

            //TODO Добавить обработку событий драг эн дроп
            //TODO Добавть контекстное меню с удалением. Можно скопировать из CreateAnswerRichTextBox

            return(pictureBox);
        }
Example #20
0
        private void SaveAndCloseButton_Click(object sender, System.EventArgs e)
        {
            var testDevidedFileService =
                new TestDevidedFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);

            testDevidedFileService.Update(new List <FileUpdateAction <Test> >
            {
                new FileUpdateAction <Test>
                {
                    FileName        = _test.Name + ".test",
                    SaveInformation = _test,
                    Type            = FileUpdateActionType.Save
                }
            });

            Hide();
            var startForm = new StartForm();

            startForm.Closed += (s, args) => Close();
            startForm.Show();
        }
Example #21
0
 public StartForm()
 {
     InitializeComponent();
     SaveDirectoryFileSystemWatcher.Path = ConfigContainer.GetConfig <EditorConfig>().SaveFolder;
     DrawTestPanels();
 }
Example #22
0
 public GetPlatoonsHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
     _platoonFileService   = new PlatoonFileService(ConfigContainer.GetConfig <ServerConfig>().SaveFolder);
 }
Example #23
0
 public SettingForm()
 {
     InitializeComponent();
     SavePathTextBox.Text = ConfigContainer.GetConfig <EditorConfig>().SaveFolder;
 }
Example #24
0
 public GetSubjectsHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
     _subjectFileService   = new SubjectFileService(ConfigContainer.GetConfig <ServerConfig>().SaveFolder);
 }
Example #25
0
 public SubjectForm()
 {
     InitializeComponent();
     _subjectFileService = new SubjectFileService(ConfigContainer.GetConfig <EditorConfig>().SaveFolder);
     LoadSubjects();
 }
Example #26
0
        public void Update(BackgroundWorker worker, DoWorkEventArgs e)
        {
            if (!_serverConnectionService.IsConnected())
            {
                return;
            }

            var platoons = _serverConnectionService.GetPlatoons();

            _platoonFileService.Update(platoons);

            var subjects = _serverConnectionService.GetSubjects();

            _subjectFileService.Update(subjects);

            var state = new ClientTestUpdaterState {
                State = ClientTestUpdaterStates.GetInformationObjectsFromServer
            };

            worker.ReportProgress(0, state);

            var testInformationObjects = _serverConnectionService.GetTestInformationObjects();

            //TODO Добавить получение списка тестов на клиенте. Удалять ненужные тесты и обновлять только те тесты, которые надо

            state.State = ClientTestUpdaterStates.GetTests;
            worker.ReportProgress(0, state);

            var tests = _serverConnectionService.GetTests(testInformationObjects);

            state.State = ClientTestUpdaterStates.GetImageInfromationObjects;
            worker.ReportProgress(0, state);

            var imageInfromationObjects = _serverConnectionService.GetImageInfromationObjects();

            //TODO Добавить получение списка тестов на клиенте. Удалять ненужные изображения и обновлять только те изображения, которые надо

            state.State = ClientTestUpdaterStates.GetImages;
            worker.ReportProgress(0, state);

            var images = _serverConnectionService.GetImages(imageInfromationObjects);

            state.State = ClientTestUpdaterStates.SavingTests;
            worker.ReportProgress(0, state);


            var saveFolder             = ConfigContainer.GetConfig <ClientConfig>().SaveFolder;
            var testDevidedFileService = new TestDevidedFileService(saveFolder);

            testDevidedFileService.Update(tests.Select(pair => new FileUpdateAction <Test>
            {
                FileName        = pair.Key,
                SaveInformation = pair.Value,
                Type            = FileUpdateActionType.Save
            }).ToList());

            state.State = ClientTestUpdaterStates.SavingImages;
            worker.ReportProgress(0, state);

            var imageDevidedFileService = new ImageDevidedFileService(saveFolder);

            imageDevidedFileService.Update(images.Select(pair => new FileUpdateAction <byte[]>
            {
                FileName        = pair.Key,
                SaveInformation = pair.Value,
                Type            = FileUpdateActionType.Save
            }).ToList());
        }