public void RunSchedule_ScheduleValidFile_GeneratesSchedule()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_validCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert file is loaded
            Assert.That(component.Instance.Output, Contains.Substring("Loaded 9 activity definitions from DefaultActivities"),
                        "Messages after scheduling");
            Assert.That(component.Instance.Output, Contains.Substring("Loaded 98 camper requests"),
                        "Messages after scheduling");
            Assert.That(component.Instance.Output, Contains.Substring("98 campers scheduled"),
                        "Messages after scheduling");
        }
Beispiel #2
0
 protected override async Task OnAfterRenderAsync(bool isFirstRender)
 {
     if (isFirstRender)
     {
         dropReference = FileReaderService.CreateReference(dropTargetElement);
         await dropReference.RegisterDropEventsAsync();
     }
 }
Beispiel #3
0
        private async Task RefreshFileList(IFileReaderRef reader, List <IFileInfo> list)
        {
            list.Clear();
            foreach (var file in await reader.EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                list.Add(fileInfo);
            }
            this.StateHasChanged();
        }
Beispiel #4
0
        public async Task ReadFile(IFileReaderRef list)
        {
            imageName.Clear();
            DeleteFiles(AppDataService.Instance.pathImageDirectory);

            Output = string.Empty;
            this.StateHasChanged();
            var nl = Environment.NewLine;

            foreach (var file in await list.EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Name)}: {fileInfo.Name}{nl}";
                Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Size)}: {fileInfo.Size}{nl}";
                Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Type)}: {fileInfo.Type}{nl}";
                Output += $"{nameof(IFileInfo)}.{nameof(fileInfo.LastModifiedDate)}: {fileInfo.LastModifiedDate?.ToString() ?? "(N/A)"}{nl}";
                Output += $"Reading file...";
                this.StateHasChanged();

                using (var fs = await file.OpenReadAsync())
                {
                    var bufferSize = 20480;
                    var buffer     = new byte[bufferSize];
                    int count;
                    while ((count = await fs.ReadAsync(buffer, 0, buffer.Length)) != 0)
                    {
                        Output += $"Read {count} bytes. {fs.Position} / {fs.Length}{nl}";
                        this.StateHasChanged();
                    }
                    Output += $"Done reading file {fileInfo.Name}{nl}.";
                }

                using (var ms = await file.CreateMemoryStreamAsync(2048))
                {
                    imageName.Add("file_" + DateTime.Now.ToFileTime().ToString() + "." + fileInfo.Type.Split('/')[1]);
                    string     path       = Path.Combine(AppDataService.Instance.pathImageDirectory, imageName.Last());
                    FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 2048, true);

                    ms.WriteTo(fileStream);

                    fileStream.Close();
                    ms.Close();
                }
            }

            this.StateHasChanged();

            Tesseract.DoAfterRecognise += ShowResults;
            Tesseract.DoAfterRecognise += AddBookAfterResult;

            Tesseract.Recognise();
        }
Beispiel #5
0
        public static Task RegisterDropEventsAsync(this IFileReaderRef source, Action <DropEventsOptions> dropEventsModifier)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (dropEventsModifier is null)
            {
                throw new ArgumentNullException(nameof(dropEventsModifier));
            }

            var options = new DropEventsOptions();

            dropEventsModifier(options);
            return(source.RegisterDropEventsAsync(options));
        }
Beispiel #6
0
        public static Task RegisterPasteEventAsync(this IFileReaderRef source, Action <PasteEventOptions> pasteEventModifier)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (pasteEventModifier is null)
            {
                throw new ArgumentNullException(nameof(pasteEventModifier));
            }

            var options = new PasteEventOptions();

            pasteEventModifier(options);
            return(source.RegisterPasteEventAsync(options));
        }
        public void RunSchedule_ScheduleOversubscribed_OutputsUnhappyCampers()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_overSubscribedCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert file is loaded
            Assert.That(component.Instance.Output, Contains.Substring("3 campers could not be scheduled"),
                        "Messages after scheduling");
        }
        public void RunSchedule_ScheduleMissingActivityFile_IndicatesUnknownActivity()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_missingActivityCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert error message
            Assert.That(component.Instance.Output,
                        Contains.Substring("requested unknown activity: 'Horseplay'"),
                        "Messages after scheduling");
        }
Beispiel #9
0
        public static async Task <IReadOnlyDictionary <IFileInfo, byte[]> > ReadFilesAsync(IFileReaderRef list)
        {
            var files = new Dictionary <IFileInfo, byte[]>();

            foreach (var file in await list.EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                using (var fileStream = await file.OpenReadAsync())
                {
                    if (fileStream.Length != 0)
                    {
                        var buffer = new byte[fileStream.Length];

                        await fileStream.ReadAsync(buffer, 0, buffer.Length);

                        files.Add(fileInfo, buffer);
                    }
                }
            }

            return(files);
        }
Beispiel #10
0
 protected override void OnAfterRender(bool isFirstRender)
 {
     fileReaderReference = fileReaderService.CreateReference(inputElement);
 }