/// <copydocfrom cref="IFileProcessResultHandler.Handle" />
        public void Handle(FileProcessResult fileEvent, ProcessingFile file)
        {
            if (!File.Exists(file.CurrentFilePath))
            {
                // TODO: Log
                return;
            }
            
            switch (fileEvent)
            {
                case FileProcessResult.Cancelled:
                    this.cancelledStrategy.Handle(file);
                    break;
                
                case FileProcessResult.Error:
                    this.failureStrategy.Handle(file);
                    break;

                case FileProcessResult.Processed:                    
                    this.successStrategy.Handle(file);
                    break;

                default:
                    throw new NotSupportedException("Unknown event: " + fileEvent);
            }
        }
        /// <copydocfrom cref="IFileProcessResultHandler.Handle" />
        public void Handle(FileProcessResult fileEvent, ProcessingFile file)
        {
            if (!File.Exists(file.CurrentFilePath))
            {
                // TODO: Log
                return;
            }

            switch (fileEvent)
            {
            case FileProcessResult.Cancelled:
                this.cancelledStrategy.Handle(file);
                break;

            case FileProcessResult.Error:
                this.failureStrategy.Handle(file);
                break;

            case FileProcessResult.Processed:
                this.successStrategy.Handle(file);
                break;

            default:
                throw new NotSupportedException("Unknown event: " + fileEvent);
            }
        }
Ejemplo n.º 3
0
        public static FileProcessResult Apply(ICollection <CodeSnippet> snippets, string inputFile)
        {
            var result = new FileProcessResult();

            var baselineText = File.ReadAllText(inputFile);

            var missingKeys = CheckMissingKeys(snippets, baselineText);

            if (missingKeys.Any())
            {
                foreach (var missingKey in missingKeys)
                {
                    missingKey.File = inputFile;
                }

                result.RequiredSnippets = missingKeys;
                result.Text             = baselineText;
                return(result);
            }

            foreach (var snippet in snippets)
            {
                // TODO: this won't change the text
                // if a snippet is unchanged
                // so we need more context
                var output = ProcessMatch(snippet.Key, snippet.Value, baselineText);

                if (!string.Equals(output, baselineText))
                {
                    // we may have added in a snippet
                    result.Snippets.Add(snippet);
                }

                baselineText = output;
            }

            result.Text = baselineText;

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Processing of file(temp) that has been uploaded to the server.
        ///     Converts file to input data for further processing
        /// </summary>
        /// <param name="input">FileProcessResult</param>
        /// <returns>FileProcessInput</returns>
        public FileProcessResult<ProductInputRow> FileProcess(FileProcessInput input)
        {
            if (input == null) throw new ArgumentNullException("input");
            var result = new FileProcessResult<ProductInputRow>(input.UserContext);
            _logger.Information(string.Format("Processing temp file. File path:  {0}", input.FilePath));

            //convert 
            InputFile inputFile = LoadInputFile(input.FilePath);

            ValidationResult inputDataValidateResult = _validator.InputFileValidate(inputFile);
            if (inputDataValidateResult.HasViolations)
            {
                result.ValidationResult.ValidationErrors = inputDataValidateResult.ValidationErrors;
                //remove temp file if failed
                File.Delete(input.FilePath);

                return result;
            }
            result.FileData = inputFile.Data;
            result.HeadersCount = inputFile.Header.Last().LastCellNum;
            return result;
        }
Ejemplo n.º 5
0
 protected void InvokeFileProcessed(String szFileName, FileProcessResult objResult)
 {
     if (this.OnFileProcessed != null)
     {
         this.OnFileProcessed.Invoke(szFileName, objResult);
     }
 }