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");
        }
Ejemplo n.º 2
0
        public async Task <List <SvgModel> > ReadFile(ElementReference elementReference)
        {
            var tasks = new List <Task <string> >();

            foreach (var file in await fileReaderService.CreateReference(elementReference).EnumerateFilesAsync())
            {
                tasks.Add(ReadFile(file));
            }

            var allTasks = await Task.WhenAll(tasks);

            var uploadedAreas = new List <SvgModel>();

            foreach (var file in allTasks)
            {
                var documentElement = HtmlDocumentHelpers.ReadHtml(file);

                HtmlDocumentHelpers.LoopAllNodes(documentElement, n => n.Id = Guid.NewGuid().ToString());

                SvgModel item = new SvgModel {
                    Html = documentElement.InnerHtml
                };
                uploadedAreas.Add(item);


                Console.WriteLine(item.Id);
                Console.WriteLine(item.Html);
            }

            return(uploadedAreas);
        }
        public async Task <string> LoadImage(ElementRef image)
        {
            Console.WriteLine("Properties");
            foreach (var item in image.GetType().GetProperties())
            {
                Console.WriteLine($"{item.Name} = {item.GetValue(image)}");
            }

            var images = await fileReadService.CreateReference(image).EnumerateFilesAsync();

            var data = (await images.First().CreateMemoryStreamAsync()).ToArray();

            return(Convert.ToBase64String(data));
        }
Ejemplo n.º 4
0
        public async Task UploadTorrent(TorrentUploadViewModel torrent, ElementReference filesRef)
        {
            if (torrent == null)
            {
                throw new AppException(ExceptionEvent.InvalidParameters, "Torrent can't be null.");
            }

            using var content = new MultipartFormDataContent
                  {
                      { new StringContent(JsonSerializer.Serialize(torrent), Encoding.UTF8, "application/json"), "json" }
                  };

            foreach (var file in await _fileReaderService.CreateReference(filesRef).EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                content.Add(new StreamContent(await file.OpenReadAsync()), "files", fileInfo.Name);
            }

            await _customHttpClient.SendAsync(HttpMethod.Post, "api/torrents/UploadTorrent", content);
        }