/// <summary> /// Creates a new instance. /// </summary> public FlowBatch(FlowId flow, long batchId) { Guard.ArgumentNotNull(flow, nameof(flow)); Flow = flow; BatchId = batchId; }
/// <summary> /// Creates a new unique flow batch record against the flow. /// </summary> public FlowBatch GetNewFlowBatch(string flowCode) { var flow = Get(flowCode); lock (_syncLock) { if (flow == null) { flow = new FlowId(flowCode); // just create new flow code } var newBatchId = flow.CurrentBatchId++; var batch = new FlowBatch() { Flow = flow, BatchId = newBatchId, }; // save/update original file - don't call save as it will through error _repo.Save(flow); // now return to caller return(batch); } }
/// <summary> /// Gets the enrichment log for a given target process type. /// </summary> public EnricherLog Get(FlowId flow, FlowEntity sourceEntityType) { Guard.ArgumentNotNull(flow, nameof(flow)); Guard.ArgumentNotNull(sourceEntityType, nameof(sourceEntityType)); // source id would be the name of a processor var fileName = $@"{DataDir}\{flow}-Enrichment-{sourceEntityType.EntityTypeId}.json"; if (!File.Exists(fileName)) { if (_logger.IsInfoEnabled) { _logger.Info($"File {fileName} could not be found."); } return(null); } var content = File.ReadAllText(fileName); var log = JsonConvert.DeserializeObject <EnricherLog>( content, new JsonSerializerSettings()); return(log); }
/// <summary> /// Creates a new instance using a given flow id. /// </summary> public FlowConfiguration(FlowId flow) { Guard.ArgumentNotNull(flow, nameof(flow)); Flow = flow; BasePath = Environment.CurrentDirectory; Controllers = new List <FlowControllerDefinition>(); }
/// <summary> /// Saves a flow. /// </summary> /// <param name="flow">The flow to save.</param> public void Save(FlowId flow) { if (_repo.Exists(flow.Code)) { throw new InvalidOperationException($"Another flow with the code {flow.Code} already exists."); } _repo.Save(flow); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="flow">The related flow.</param> /// <param name="sourceEntityType">The source entity type id.</param> public EnricherLog(FlowId flow, FlowEntity sourceEntityType) { Guard.ArgumentNotNull(flow, nameof(flow)); Guard.ArgumentNotNull(sourceEntityType, nameof(sourceEntityType)); Flow = flow; EntityType = sourceEntityType; Logs = new List <EnrichmentLogEntry>(); Exceptions = new List <Exception>(); }
/// <summary> /// Creates a new flow flow. /// </summary> /// <param name="flowCode">The unique flow code.</param> /// <returns></returns> public FlowId CreateNew(string flowCode) { var flow = new FlowId() { Code = flowCode, DataDir = Environment.CurrentDirectory, DisplayName = flowCode, Entities = new List <FlowEntity>(), CurrentBatchId = 1 }; Save(flow); return(flow); }
/// <summary> /// Gets the next flow file that has not been processed. /// </summary> public FileInfo GetNextFlowFile(FlowEntity entity, FlowId flow) { // this enumerate working folder var dataFilesDirectory = FlowFileController.Config.InDirectory; var flowFiles = new DirectoryInfo(dataFilesDirectory) .GetFiles("*.*") .OrderBy(m => m.CreationTimeUtc) .ToList(); if (flowFiles.Any()) { if (_logger.IsTraceEnabled) { _logger.Trace($"Found {flowFiles.Count} files under {dataFilesDirectory}."); } // determine if it the data source file has been processed var flowTransactionLog = _dataFileTranRepo.Get(entity, flow.Code); foreach (var flowFile in flowFiles) { // determine if the file was processed by the given processor var processLogEntry = flowTransactionLog.Entries.FirstOrDefault( m => string.Equals( flowFile.FullName, m.AddressId, StringComparison.OrdinalIgnoreCase)); if (processLogEntry == null) { return(flowFile); } } } else { if (_logger.IsWarnEnabled) { _logger.Warn($"No files were discovered under {dataFilesDirectory}."); } } return(null); }
/// <summary> /// Saves/updates a given flow. /// </summary> /// <param name="flow">The flow to save.</param> public void Save(FlowId flow) { Guard.ArgumentNotNull(flow, nameof(flow)); CreateDirIfNotExists(); // source log var fileName = $@"{DataDir}\Flow-{flow.Code}.json"; if (_logger.IsInfoEnabled) { _logger.Info($"Saving flow output to {fileName}."); } // save the data in the data directory var body = JsonConvert.SerializeObject(flow, new JsonSerializerSettings()); if (File.Exists(fileName)) { // back up older file, don't delete string backFile = fileName + ".bak"; if (File.Exists(backFile)) { File.Delete(backFile); } File.Move(fileName, backFile); } // wrap in transaction File.WriteAllText(fileName, body); if (_logger.IsInfoEnabled) { _logger.Info($"Saved flow file to {fileName}."); } }