public async Task <bool> Upload() { var files = (await FileReaderService.CreateReference(inputElement).EnumerateFilesAsync()).ToList(); foreach (var file in files) { try { var inf = await file.ReadFileInfoAsync(); var filename = inf.Name; var imageBinary = (await file.CreateMemoryStreamAsync()).ToArray(); var boundary = string.Format(BoundaryTemplate, Guid.NewGuid()); var startFormData = BuildFormDataStart(boundary, filename); var endFormData = BuildFormDataEnd(boundary); var contentTypeHdrValue = string.Format(CONTENT_TYPE_HEADER_PARAMS, boundary); json = BingImageSearch(startFormData, endFormData, imageBinary, contentTypeHdrValue); await JSRuntime.InvokeVoidAsync("console.log", json); } catch (Exception ex) { } } return(true); }
protected async Task InsertCarAsync() { IsBusy = true; var file = (await FileReaderService.CreateReference(inputReference).EnumerateFilesAsync()).FirstOrDefault(); _fileInfo = await file.ReadFileInfoAsync(); using (var ms = await file.CreateMemoryStreamAsync()) { var result = await CarsService.AddCarAsync(Model, new AppFile { FileStream = ms, FileName = $"{_fileInfo.Name}", Name = Model.CarModel }); if (result.IsSuccess) { Message = "Car has been inserted successfully!"; AlertClass = "alert-success"; MyCars.Add(result.Value); } else { Message = "There is something wrong try again later"; AlertClass = "alert-error"; } } IsBusy = false; }
protected async Task IzberiSliko() { Notification = "SkrijElement"; var file = (await FileReaderService.CreateReference(InputReference).EnumerateFilesAsync()).FirstOrDefault(); var fileInfo = await file.ReadFileInfoAsync(); string extension = Path.GetExtension(fileInfo.Name); var allowExtensions = new string[] { ".jpg", ".jpeg", ".png" }; if (!allowExtensions.Contains(extension)) { Notification = "PokaziElement"; } else { fileName = fileInfo.Name; using (var memoryStream = await file.CreateMemoryStreamAsync()) { slikaStream = new MemoryStream(memoryStream.ToArray()); ImageContent = $"data:{fileInfo.Type}; base64, {Convert.ToBase64String(memoryStream.ToArray())}"; } NovaSlika = true; } }
private void ReadButton_Click(object sender, EventArgs e) { RTBox.Text = string.Empty; txtBoxPath.Text = string.Empty; try { dialog.FileName = rbRoleOthers.Checked ? OtherRoleFilter : ""; dialog.FileName += rbTxtFileType.Checked ? TxtExtension : rbXmlFileType.Checked ? XmlExtension : JsonExtension; dialog.Filter = rbTxtFileType.Checked? TxtFilter : rbXmlFileType.Checked ? XmlFilter : JsonFilter; if (dialog.ShowDialog() == DialogResult.OK) { txtBoxPath.Text = dialog.FileName; Service.IFileReaderService service = new FileReaderService { Path = dialog.FileName, Encryption = ckBoxEncryotion.Checked, FileType = rbTxtFileType.Checked ? FileType.Txt : rbXmlFileType.Checked ? FileType.Xml : FileType.Json }; RTBox.Text = service.ReadFile(); } } catch (Exception ex) { RTBox.Text = $"The text file could not be read | Error : {ex}"; } }
// GET: InputFileHandler public ActionResult Index() { //return DoTask(_ => //{ var fileReaderService = new FileReaderService(); fileReaderService.PopulateCSVToEntity(); var model = new DetailsModel(); return(View(model)); //}); //Task.Factory.StartNew(context => //{ // try // { // var fileReaderService = new FileReaderService(); // fileReaderService.PopulateCSVToEntity(); // var model = new DetailsModel(); // return View(model); // } // catch (Exception ex) // { // // log and return an error response rather than hitting the application's // // error handler - we've dealt with it here. // //_logger.Error(ex, errorMessage, args); // //return new (500 /*server error*/); // } //}); }
public async Task <bool> Upload(string filename) { var files = (await FileReaderService.CreateReference(inputElement).EnumerateFilesAsync()).ToList(); foreach (var file in files) { try { var fi = await file.ReadFileInfoAsync(); if (fi.Size < 20 * 1024 * 1024) { await _service.SetContainer(Container); await _service.UploadBlobToContainer(file, filename); } } catch (Exception ex) { Telemetry.TrackException(ex); } } await ClearFile(); return(true); }
// GET: InputFileHandler/Create public ActionResult Create() { var fileReaderService = new FileReaderService(); fileReaderService.PopulateCSVToEntity(); return(View()); }
public void GivenAListOfWordsWhenTop50ThenReturnsWordsSortedByFrequency() { var stringToReturn = "10"; for (int i = 1; i < 10; i++) { for (int j = 10 - i; j <= 10; j++) { stringToReturn += " " + (10 - i); } } _fileRepository.ReadFile().Returns(stringToReturn); var sut = new FileReaderService(_fileRepository); var result = sut.Top50().ToList(); result[0].Should().Be("1"); result[1].Should().Be("2"); result[2].Should().Be("3"); result[3].Should().Be("4"); result[4].Should().Be("5"); result[5].Should().Be("6"); result[6].Should().Be("7"); result[7].Should().Be("8"); result[8].Should().Be("9"); result[9].Should().Be("10"); }
public override async Task HandleAsync(CallbackQueryUpdateMessage message) { var mainMetric = _metricRepository.GetMainByExternalId(message.ChatId); if (mainMetric == null) { await _botClient.SendTextMessageAsync(message, MessageCode.NoMainMetric); return; } var values = _valueRepository.GetByMetricId(mainMetric.Id, 1, int.MaxValue); if (values.Count() < 2) { await _botClient.SendTextMessageAsync(message, MessageCode.ToFewValues); return; } var plotData = new PlotDataFactory().ValuesTo(values, mainMetric.ToString()); var filename = FileName.GetPlotFilename(message.UpdateId.ToString()); IFileService fileService = new ScottPlotService(new PngFileName(filename), plotData); using (var plotService = new FileReaderService(fileService)) { var stream = plotService.GetFileStream(); await _botClient.SendFileAsync(message.ChatId, stream, filename); } }
public async Task InsertBrandAsync() { IsBusy = true; var file = (await FileReaderService.CreateReference(inputReference).EnumerateFilesAsync()).FirstOrDefault(); _fileInfo = await file.ReadFileInfoAsync(); using (var ms = await file.CreateMemoryStreamAsync((int)_fileInfo.Size)) { FileStream = ms; var result = await BrandsService.AddNewBrandAsync(Model, new AppFile { FileStream = FileStream, FileName = _fileInfo.Name, Name = $"{Model.Name}{Path.GetExtension(_fileInfo.Name)}" }); if (result.IsSuccess) { AlertClass = "alert-success"; Message = "Brand has been added successfully!"; brands.Add(result.Value); } else { AlertClass = "alert-danger"; Message = "There is something wrong"; Debug.WriteLine(result.Message); } } IsBusy = false; }
public void GivenAllOfMobyDickWhenTop50ThenReturnsTheTop50Words() { var sut = new FileReaderService(new FileRepository("http://www.gutenberg.org/files/2701/2701-0.txt")); var result = sut.Top50().ToList(); result.Count.Should().Be(50); }
protected override async Task OnAfterRenderAsync(bool isFirstRender) { if (isFirstRender) { dropReference = FileReaderService.CreateReference(dropTargetElement); await dropReference.RegisterDropEventsAsync(); } }
public void ResultShould() { fileReaderService = new FileReaderService("EmptyPath.txt"); var result = fileReaderService.Result(); Assert.Equal("", result); }
protected async Task ImportData() { var files = (await FileReaderService.CreateReference(inputElement).EnumerateFilesAsync()).ToList(); foreach (var file in files) { } }
public void Import(string path) { using (var fileReader = FileReaderService.Read(path)) { var line = fileReader.ReadLine(); while (line != null) { line = line.Trim(' ', '\t', '\r', '\n'); if (line.StartsWith("#")) { if (line.Contains(":")) { var indexOfSeperater = line.IndexOf(":"); var key = line.Substring(0, indexOfSeperater).Trim(' ', '\t', '\r', '\n'); var value = line.Substring(indexOfSeperater + 1, line.Length - indexOfSeperater - 1).Trim(' ', '\t', '\r', '\n'); string profile = null; HelperService.ExtractProfile(key, ref key, ref profile); key = key.TrimStart('#').Trim(' ', '\t', '\r', '\n'); var configuration = GetOrCreateConfiguration(profile); var changed = false; if (key == "launcher") { configuration.WebAppLauncher = value; changed = true; } if (key == "argumentsPattern") { configuration.WebAppArgumentPattern = value; changed = true; } if (changed) { WebAppConfigurationRepository.SaveConfiguration(configuration); } } } else { var elements = line.Split(' '); var url = elements[0]; var keywords = string.Join(" ", elements.Skip(1).Where(e => e.Length > 0).ToArray()); keywords = keywords.TrimStart('(', ' ', '\t', '\r', '\n').TrimEnd(')', ' ', '\t', '\r', '\n'); string profile = null; if (HelperService.ExtractProfile(keywords, ref keywords, ref profile)) { keywords = keywords.TrimStart('(', ' ', '\t', '\r', '\n').TrimEnd(')', ' ', '\t', '\r', '\n'); } if (!string.IsNullOrEmpty(url)) { AddWebAppItem(url, keywords, profile); } } line = fileReader.ReadLine(); } } }
public void VideoDirectoryShouldReturnOnlyMovies() { var service = new FileReaderService(); var result = service.GetOnlyVideosInPath( "C:\\Users\\dekstop\\RiderProjects\\TvHelper\\TvHelper.Test\\FileContainingMovies"); Assert.True(result.Count == 3); }
public void VideoDirectoryShouldReturnNothingTest() { var service = new FileReaderService(); var result = service.GetAllFilesAndDirectoriesInPath( "C:\\Users\\dekstop\\RiderProjects\\TvHelper\\TvHelper.Test\\FileNotContainingMovies"); Assert.True(result.Count == 0); }
public void ReadFileShould(string filepath, string expected) { fileReaderService = new FileReaderService(filepath); fileReaderService.ReadFile(); var result = fileReaderService.Result(); Assert.Equal(expected, result); }
/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { if (args.Length == 1) { try { Data data = FileReaderService.ExtractData(args[0]); uint amountConverted = CurrencyConverterService.Convert(data); Console.Write(amountConverted); } catch (IOException e) { Console.WriteLine(e.Message); Console.WriteLine("An error has occured during the file reading !"); } catch (DataFormatException e) { Console.WriteLine(e.Message); List <string> log = new List <string> { "Invalid data format !", "", "Reminder of the correct format :", "", "XXX;M;YYY", "N", "AAA;BBB;T.TTTT", "CCC;DDD;U.UUUU", "EEE;FFF;V.VVVV", "... N times" }; Console.WriteLine(string.Join("\n", log.ToArray())); } catch (AlgorithmException e) { Console.WriteLine(e.Message); Console.WriteLine("An error has occured during the dijkstra algorithm !"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Uncaught error !"); } } else if (args.Length > 1) { Console.WriteLine("Multiple files names !"); } else { Console.WriteLine("File name missed !"); } Console.ReadLine(); }
private byte[] CreatePlotWith(string filename, Collection <Value> values) { var title = "Height (cm)"; var plotData = new PlotDataFactory().ValuesTo(values, title); IFileService fileService = new ScottPlotService(new PngFileName(filename), plotData); var plotService = new FileReaderService(fileService); return(plotService.CreateFile()); }
public async Task <ActionResult <ResultResponse> > Upload(CancellationToken ct) { var context = HttpContext; FileReaderService fileReaderService = new FileReaderService(_importerService, _multiPartStreamReaderService, context.Request.Body); return(new ResultResponse() { ParsedRows = await fileReaderService.ReadFileAsync(ct) }); }
public async Task ReadFileByteCode() { var files = await FileReaderService.CreateReference(ByteCodeFileUpload).EnumerateFilesAsync(); var stream = await files.First().CreateMemoryStreamAsync(); var streamReader = new System.IO.StreamReader(stream); Model.ByteCode = streamReader.ReadToEnd(); }
public static void Main(string[] args) { var dataPath = GetCurrentDataFolderPath(); var jsonFilesInDirectory = Directory.EnumerateFiles(dataPath).Where(file => file.Remove(0, file.Length - 5) == ".json"); var predictions = FileReaderService.LoadPredictions(jsonFilesInDirectory); var slaughterWeights = FileReaderService.LoadSlaughterWeights(jsonFilesInDirectory); var slaughterStatistics = StatisticsService.CreateSlaughterStatistics(predictions, slaughterWeights); JsonWriterService.WriteStatisticsFile(slaughterStatistics, dataPath, _statisticsFileName); }
protected async Task ReadFileAsync() { var file = (await FileReaderService.CreateReference(inputReference).EnumerateFilesAsync()).FirstOrDefault(); _fileInfo = await file.ReadFileInfoAsync(); using (var fs = await file.OpenReadAsync()) { FileStream = fs; } }
public void GivenALotOfWhiteSpaceWhenTop50ThenDoesNotReturnWhiteSpace() { _fileRepository.ReadFile().Returns("\n\t \n \t Hello batman"); var sut = new FileReaderService(_fileRepository); var result = sut.Top50().ToList(); result.Count.Should().Be(2); result.Should().Contain("Hello"); result.Should().Contain("batman"); }
public async Task ReadFile() { //var fileReaderService = new Blazor.FileReader.FileReaderService(JSRuntime); var files = await FileReaderService.CreateReference(FileUpload).EnumerateFilesAsync(); var stream = await files.First().CreateMemoryStreamAsync(); //assuming it's only one file (?) var streamReader = new System.IO.StreamReader(stream); var fileContent = streamReader.ReadToEnd(); await Model.SetFileContentAsync(fileContent); }
public void GivenUrlWhenReadFileThenReturnsFileContents() { var allOfMobyDick = "All of Moby Dick"; _fileRepository.ReadFile().Returns(allOfMobyDick); var sut = new FileReaderService(_fileRepository); var result = sut.ReadFile(); result.Should().Be(allOfMobyDick); }
public override Template Build(string productName) { var template = new Template(); template.NameKey = productName; template.Title = FileReaderService.GetTextFromFile(productName, TemplateSections.Title); template.Part1 = FileReaderService.GetTextFromFile(productName, TemplateSections.Part1); template.DividerText1 = FileReaderService.GetTextFromFile(productName, TemplateSections.Divider); template.Part2 = FileReaderService.GetTextFromFile(productName, TemplateSections.Part2); template.Images = FileReaderService.GetImages(productName).ToList(); return(template); }
private async Task <byte[]> ReadFile() { foreach (var file in await FileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync()) { // Read into memory and act using (var memoryStream = await file.CreateMemoryStreamAsync(4096)) { return(memoryStream.ToArray()); } } return(new byte[0]); }
public async void ImageSelected() { foreach (var file in await FileReaderService.CreateReference(InputElement).EnumerateFilesAsync()) { using (MemoryStream memoryStream = await file.CreateMemoryStreamAsync(4 * 1024)) { ImageBytes = new byte[memoryStream.Length]; memoryStream.Read(ImageBytes, 0, (int)memoryStream.Length); ImageBase64 = Convert.ToBase64String(ImageBytes); StateHasChanged(); } } }