public async Task <ActionResult> Upload(HttpPostedFileBase file) { var model = new UploadFileViewModel(); if (file == null || file.ContentLength <= 0) { ModelState.AddModelError("File", "Invalid File request received "); return(View(model)); } if (!_allowedExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.')))) { ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", _allowedExtensions)); return(View(model)); } try { var path = Path.Combine(Path.GetTempPath(), Path.GetFileName(file.FileName)); file.SaveAs(path); var results = Task.Run(() => _parserService.ParseFile(path)); model = new UploadFileViewModel() { Result = results.Result }; ViewBag.Message = "File uploaded successfully"; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } return(View(model)); }
private void textChangedTimer_Tick(object sender, EventArgs e) { string text = Text; Task.Factory.StartNew(() => _parserService.ParseFile(text.GetHashCode(), new FilePath(FileName), text)); _backgroundAssemblerService.RequestAssemble(); _textChangedTimer.Enabled = false; }
public async Task Start(string filepath = null) { _logger.Information("Programa inicializando com caminho do arquivo igual: {0}", filepath); if (filepath == null) { _logger.Error("O caminho do arquivo não foi informado!"); return; } IEnumerable <Tuple <string, string> > communications = _parserService.ParseFile(filepath); await _messageService.SendBatch(communications); _logger.Information("Programa finalizado."); }
private void ParseFiles(ProjectFolder folder, int incrementValue) { double folderInc = (double)incrementValue / (folder.Folders.Count + 1); foreach (ProjectFolder subFolder in folder.Folders) { ParseFiles(subFolder, (int)folderInc); } double fileInc = folderInc / folder.Files.Count; foreach (ProjectFile file in folder.Files.ToArray()) { _parserService.ParseFile(0, file.FileFullPath); _statusBarService.IncrementProgressBarProgress((int)fileInc); } }
public async Task ChunkTextAsync(StorageType sourceStorageType, StorageType destinationStorageType) { InitializeStorage(sourceStorageType, destinationStorageType); var charLimit = _configurationService.GetChunkerConfigModel().CharLimit; var convertedFiles = new ConcurrentBag <string>(); var failedFiles = new ConcurrentDictionary <string, string>(); // read files from source storage var fileNames = await _sourceStorageService.ListFilesAsync(); // chunk files var tasks = fileNames.Select(async fileName => { try { // validate types _parserService.ValidateFileType(fileName); // read file _loggerService.LogOperation(OperationType.ReadingFile, fileName); var file = await _sourceStorageService.ReadFileAsync(fileName); // parse file var parsedFile = await _parserService.ParseFile(file); // chunk file _loggerService.LogOperation(OperationType.ChunkingFile, fileName); List <ChunkInfo> chunkedText = _chunkerService.Chunk(parsedFile, ChunkMethod.Char, charLimit, ElementType.Other); // store file _loggerService.LogOperation(OperationType.StoringResult, fileName); foreach (var item in chunkedText.Select((value, i) => (value, i))) { var newFileName = ChunkInfoHelper.GetChunkFileName(fileName, item.i); await _destinationStorageService.StoreDataAsync(item.value.Text, newFileName); } convertedFiles.Add(fileName); } catch (CliException e) { failedFiles[fileName] = e.Message; _loggerService.LogError(e); } }); await Task.WhenAll(tasks); _loggerService.LogParsingResult(convertedFiles, failedFiles); }
void ParseFiles(List <FileName> filesToParse, IProgressMonitor progressMonitor) { IProjectContent cachedPC = TryReadFromCache(cacheFileName); ParseableFileContentFinder finder = new ParseableFileContentFinder(); object progressLock = new object(); double fileCountInverse = 1.0 / filesToParse.Count; int fileCountLoadedFromCache = 0; int fileCountParsed = 0; int fileCountParsedAndSerializable = 0; Parallel.ForEach( filesToParse, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = progressMonitor.CancellationToken }, fileName => { ITextSource content = finder.CreateForOpenFile(fileName); bool wasLoadedFromCache = false; IUnresolvedFile unresolvedFile = null; if (content == null && cachedPC != null) { unresolvedFile = cachedPC.GetFile(fileName); if (unresolvedFile != null && unresolvedFile.LastWriteTime == File.GetLastWriteTimeUtc(fileName)) { parserService.RegisterUnresolvedFile(fileName, project, unresolvedFile); wasLoadedFromCache = true; } } if (!wasLoadedFromCache) { if (content == null) { try { content = SD.FileService.GetFileContentFromDisk(fileName); } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (content != null) { unresolvedFile = parserService.ParseFile(fileName, content, project); } } lock (progressLock) { if (wasLoadedFromCache) { fileCountLoadedFromCache++; } else { fileCountParsed++; if (IsSerializable(unresolvedFile)) { fileCountParsedAndSerializable++; } } // SD.MainThread.InvokeAsyncAndForget(delegate { assemblyModel.Update(null, unresolvedFile); }); progressMonitor.Progress += fileCountInverse; } }); LoggingService.Debug(projectContent.AssemblyName + ": ParseFiles() finished. " + fileCountLoadedFromCache + " files were re-used from CC cache; " + fileCountParsed + " files were parsed (" + fileCountParsedAndSerializable + " of those are serializable)"); lock (lockObj) { serializedProjectContentIsUpToDate = (fileCountLoadedFromCache > 0 && fileCountParsedAndSerializable == 0); } }