public FileResult GetProcessDomain(string processName, string instanceName, DateTime?instanceDate) { using (var activity = new RFEngineActivity(Context, EngineConfig)) { RFGraphProcessorDomain domain = null; var engineConfig = activity.GetEngineConfig(); var graphInstance = new RFGraphInstance { Name = string.IsNullOrWhiteSpace(instanceName) ? null : instanceName, ValueDate = instanceDate.HasValue ? new RFDate(instanceDate.Value.Date) : RFDate.NullDate }; foreach (var graph in engineConfig.Graphs.Values) { var process = graph.Processes.Values.FirstOrDefault(p => RFGraphDefinition.GetFullName(graph.GraphName, p.Name) == processName); if (process != null) { var processor = process.Processor(); domain = processor.CreateDomain(); if (domain != null) { foreach (var propertyInfo in domain.GetType().GetProperties()) { var ioBehaviourAttribute = (propertyInfo.GetCustomAttributes(typeof(RFIOBehaviourAttribute), true).FirstOrDefault() as RFIOBehaviourAttribute); RFCatalogKey ioKey = null; if (ioBehaviourAttribute != null) { var ioBehaviour = ioBehaviourAttribute.IOBehaviour; var ioMapping = process.IOMappings.FirstOrDefault(m => m.PropertyName == propertyInfo.Name); if (ioMapping != null) { ioKey = ioMapping.Key.CreateForInstance(graphInstance); var options = RFGraphInstance.ImplyOptions(ioMapping); var entry = Context.LoadEntry(ioKey, options) as RFDocument; if (entry != null) { propertyInfo.SetValue(domain, entry.Content); } } } } } break; } } if (domain != null) { var xmlString = RFXMLSerializer.PrettySerializeContract(domain); return(File( Encoding.UTF8.GetBytes(xmlString), "text/xml", String.Format("{0}_{1}_{2}.xml", processName, instanceName ?? String.Empty, instanceDate.Value.ToString("yyyy-MM-dd")) )); } } return(null); }
public static RFCatalogKey Create(RFKeyDomain domain, RFEnum reportCode, RFGraphInstance instance) { return(domain.Associate(new RFRawReportKey { Plane = RFPlane.User, ReportCode = reportCode, StoreType = RFStoreType.Document, GraphInstance = instance })); }
public static RFDataSetKey Create(RFKeyDomain domain, RFEnum dataSetCode, RFGraphInstance instance, params string[] path) { return(domain.Associate(new RFDataSetKey { Plane = RFPlane.User, DataSetCode = dataSetCode, StoreType = RFStoreType.Document, Path = path != null ? String.Join("/", path) : null, GraphInstance = instance }) as RFDataSetKey); }
public ActionResult RunProcess(bool isGraph, string processName, string instanceName, RFDate?instanceDate, string returnUrl = null) { try { var graphInstance = /*isGraph ? */ new RFGraphInstance { Name = string.IsNullOrWhiteSpace(instanceName) ? RFGraphInstance.DEFAULT_INSTANCE : instanceName, ValueDate = instanceDate.HasValue ? instanceDate.Value : RFDate.NullDate };// : null; using (var rfService = new RFServiceClient()) { RFProcessingTrackerHandle trackerKey = null; trackerKey = rfService.RFService.RunProcess(isGraph, processName, graphInstance, new RFUserLogEntry { Action = "Run", Description = String.Format("Manually run process {0}", processName), ValueDate = instanceDate ?? RFDate.NullDate, IsUserAction = true, IsWarning = false, Username = Username }); AddModelToCache(trackerKey.TrackerCode, new ProcessingModel { Tracker = trackerKey, ProcessingKey = trackerKey.TrackerCode, FileKey = string.Empty, FileName = String.Format("Process: {0} for value date {1}", processName, instanceDate), FileSize = 0, ReturnUrl = returnUrl }); return(RedirectToAction("ProcessingStatus", new { processKey = trackerKey.TrackerCode })); } } catch (Exception ex) { Log.Exception(this, "RunProcess", ex); return(Error("Index", "Home", null, "Error running process: {0}", ex.Message)); } }
public void GraphDependencyTest() { var instance = new RFGraphInstance { Name = "default", ValueDate = RFDate.Today() }; var s1Key = RFGenericCatalogKey.Create(_fixture.KeyDomain, "S", TestEngine.TestKeys.Key1, instance); var s2Key = RFGenericCatalogKey.Create(_fixture.KeyDomain, "S", TestEngine.TestKeys.Key2, instance); _fixture.Context.SaveDocument(s1Key, "S", true); _fixture.Context.SaveDocument(s2Key, "S", true); Thread.Sleep(2000); // results var e1Key = RFGenericCatalogKey.Create(_fixture.KeyDomain, "E", TestEngine.TestKeys.Key1, instance); var e2Key = RFGenericCatalogKey.Create(_fixture.KeyDomain, "E", TestEngine.TestKeys.Key2, instance); // execution counts var a1Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "A_Counter", TestEngine.TestKeys.Key1, instance); var b1Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "B_Counter", TestEngine.TestKeys.Key1, instance); var c1Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "C_Counter", TestEngine.TestKeys.Key1, instance); var a2Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "A_Counter", TestEngine.TestKeys.Key2, instance); var b2Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "B_Counter", TestEngine.TestKeys.Key2, instance); var c2Count = RFGenericCatalogKey.Create(_fixture.KeyDomain, "C_Counter", TestEngine.TestKeys.Key2, instance); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(a1Count)); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(b1Count)); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(c1Count)); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(a2Count)); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(b2Count)); Assert.Equal(1, _fixture.Context.LoadDocumentContent <object>(c2Count)); Assert.Equal("SASABC", _fixture.Context.LoadDocumentContent <string>(e1Key)); Assert.Equal("SASABC", _fixture.Context.LoadDocumentContent <string>(e2Key)); }
public RFEngineStats GetEngineStats(RFGraphInstance instance) { RFEngineStats stats = null; var graphlessItem = Context.LoadEntry(RFEngineStatsKey.Create(_engineConfig.KeyDomain, null)) as RFDocument; if (graphlessItem != null) { stats = graphlessItem.GetContent <RFEngineStats>(); } else { stats = new RFEngineStats { GraphInstance = instance, Stats = new Dictionary <string, RFEngineStat>() }; } if (instance != null) { stats.GraphInstance = instance; var instanceItem = Context.LoadEntry(RFEngineStatsKey.Create(_engineConfig.KeyDomain, instance)) as RFDocument; if (instanceItem != null) { var instanceStats = instanceItem.GetContent <RFEngineStats>(); foreach (var instanceStat in instanceStats.Stats) { if (stats.Stats.ContainsKey(instanceStat.Key)) { stats.Stats.Remove(instanceStat.Key); } stats.Stats.Add(instanceStat.Key, instanceStat.Value); } } } return(stats); }
public override bool HasInstance(RFGraphInstance instance) { return(true); }
public JsonResult GetTasks(string instanceName, DateTime?instanceDate) { try { using (var activity = new RFEngineActivity(Context, EngineConfig)) { var engineConfig = activity.GetEngineConfig(); var graphInstance = new RFGraphInstance { Name = string.IsNullOrWhiteSpace(instanceName) ? RFGraphInstance.DEFAULT_INSTANCE : instanceName, ValueDate = instanceDate.HasValue ? new RFDate(instanceDate.Value.Date) : RFDate.NullDate }; var engineStats = activity.GetEngineStats(graphInstance); var errors = _systemContext.DispatchStore.GetErrorQueue(0); var tasks = new List <object>(); foreach (var t in EngineConfig.Tasks) { var stat = engineStats?.GetStat(t.ProcessName); var dispatchKey = new RFParamProcessInstruction(t.ProcessName, null).DispatchKey(); var error = dispatchKey.NotBlank() ? errors.Where(e => e.DispatchKey == dispatchKey).FirstOrDefault() : null; var schedule = t.SchedulerConfig(Context); tasks.Add(new { t.TaskName, t.Description, t.GraphName, Schedule = String.Join(", ", new string[] { t.Trigger, schedule?.SchedulerScheduleString, schedule?.SchedulerRangeString }.Where(s => s.NotBlank())), IsEnabled = schedule?.IsEnabled ?? true, t.IsSystem, Status = error?.DispatchState.ToString() ?? "OK", Message = error?.Message, LastRun = stat?.LastRun ?? error?.LastStart, LastDuration = stat?.LastDuration, IsGraph = false, FullName = t.ProcessName }); } foreach (var g in EngineConfig.Graphs.Where(g => g.Value.GraphTasks.Any())) { var graphStats = activity.GetGraphStats(g.Value.GraphName, graphInstance); foreach (var t in g.Value.GraphTasks) { var processName = RFGraphDefinition.GetFullName(t.GraphName, t.ProcessName); var stat = graphStats?.GetStat(t.ProcessName); var dispatchKey = new RFGraphProcessInstruction(graphInstance, processName)?.DispatchKey(); var error = dispatchKey.NotBlank() ? errors.Where(e => e.DispatchKey == dispatchKey).FirstOrDefault() : null; var schedule = t.SchedulerConfig(Context); tasks.Add(new { t.TaskName, t.Description, t.GraphName, Schedule = String.Join(", ", new string[] { t.Trigger, schedule?.SchedulerScheduleString, schedule?.SchedulerRangeString }.Where(s => s.NotBlank())), //t.SchedulerRange, //t.SchedulerSchedule, //t.Trigger, IsEnabled = schedule?.IsEnabled ?? true, t.IsSystem, Status = error?.DispatchState.ToString() ?? ((stat?.CalculationOK ?? false) ? "OK" : String.Empty), Message = error?.Message ?? stat?.Message, LastRun = stat?.LastRun ?? error?.LastStart, IsGraph = true, FullName = processName }); } } return(Json(tasks)); } } catch (Exception ex) { return(Json(JsonError.Throw("GetTasks", ex))); } }
public JsonResult GetProcesses(string instanceName, DateTime?instanceDate) { using (var activity = new RFEngineActivity(Context, EngineConfig)) { var engineConfig = activity.GetEngineConfig(); var graphInstance = new RFGraphInstance { Name = string.IsNullOrWhiteSpace(instanceName) ? RFGraphInstance.DEFAULT_INSTANCE : instanceName, ValueDate = instanceDate.HasValue ? new RFDate(instanceDate.Value.Date) : RFDate.NullDate }; var stats = activity.GetEngineStats(graphInstance); var allProcesses = new List <object>(); foreach (var process in engineConfig.Processes.Values) { var processor = process.Processor(); var stat = stats.GetStat(process.Name); allProcesses.Add(new { Graph = "(none)", Name = process.Name, FullName = process.Name, Description = process.Description, Type = processor.GetType().FullName, RequiresIdle = false, IsGraph = false, LastRun = stat != null ? (DateTimeOffset?)stat.LastRun : null, LastDuration = stat != null ? (long?)stat.LastDuration : null, }); } foreach (var graph in engineConfig.Graphs.Values) { foreach (var process in graph.Processes.Values) { var fullName = RFGraphDefinition.GetFullName(graph.GraphName, process.Name); var stat = stats.GetStat(fullName); var processor = process.Processor(); var domain = processor.CreateDomain(); var io = new List <object>(); if (domain != null) { foreach (var propertyInfo in domain.GetType().GetProperties()) { var ioBehaviourAttribute = (propertyInfo.GetCustomAttributes(typeof(RFIOBehaviourAttribute), true).FirstOrDefault() as RFIOBehaviourAttribute); string direction = "-"; string dateType = "-"; RFCatalogKey ioKey = null; if (ioBehaviourAttribute != null) { var ioBehaviour = ioBehaviourAttribute.IOBehaviour; direction = ioBehaviour.ToString(); var ioMapping = process.IOMappings.FirstOrDefault(m => m.PropertyName == propertyInfo.Name); if (ioMapping != null) { ioKey = ioMapping.Key.CreateForInstance(graphInstance); var options = RFGraphInstance.ImplyOptions(ioMapping); dateType = options.DateBehaviour.ToString(); } } io.Add(new { Field = propertyInfo.Name, Direction = direction, DateType = dateType, DataType = propertyInfo.PropertyType.Name, KeyType = ioKey != null ? ioKey.GetType().Name : null, ShortKey = ioKey != null ? ioKey.FriendlyString() : null, FullKey = ioKey != null ? RFXMLSerializer.SerializeContract(ioKey) : null }); } } allProcesses.Add(new { Graph = graph.GraphName, Name = process.Name, FullName = fullName, IsGraph = true, Description = process.Description, Type = processor.GetType().FullName, IO = io, LastRun = stat != null ? (DateTimeOffset?)stat.LastRun : null, LastDuration = stat != null ? (long?)stat.LastDuration : null }); } } return(Json(allProcesses)); } }
public void ExecuteCommand(string input) { if (!string.IsNullOrWhiteSpace(input)) { var tokens = new RIFF.Interfaces.Formats.CSV.CSVParser(input, ' ').Where(t => !string.IsNullOrWhiteSpace(t)).ToArray(); switch (tokens[0]) { case "importupdates": { if (tokens.Length < 2) { Console.WriteLine("Usage: importupdates,<path>"); break; } var c = RFCatalogMaintainer.ImportCatalogUpdates(_context, tokens[1]); Console.WriteLine("Imported {0} documents", c); break; } case "exportupdates": { if (tokens.Length < 3) { Console.WriteLine("Usage: exportupdates,<startDate>,<path>"); break; } var startDate = RFDate.Parse(tokens[1], "yyyy-MM-dd"); var c = RFCatalogMaintainer.ExportCatalogUpdates(_context, tokens[2], startDate, null, null); Console.WriteLine("Exported {0} documents", c); break; } case "run": case "runsequential": { if (tokens.Length == 1) { Console.WriteLine("Usage: run,<fullProcessName>,<graphInstance>,<startDate>,[endDate]"); break; } var processName = tokens[1]; if (tokens.Length > 2) { var graphInstanceName = tokens[2]; var startDate = RFDate.Parse(tokens[3], "yyyy-MM-dd"); var endDate = startDate; if (tokens.Length > 4) { endDate = RFDate.Parse(tokens[4], "yyyy-MM-dd"); } var instructions = new List <RFInstruction>(); while (startDate <= endDate) { var graphInstance = new RFGraphInstance { Name = graphInstanceName, ValueDate = startDate }; instructions.Add(new RFGraphProcessInstruction(graphInstance, processName)); startDate = startDate.OffsetDays(1); } var ra = new RFRequestActivity(_context, _config); var tracker = ra.Submit(null, instructions, null); while (!tracker.IsComplete) { Thread.Sleep(100); } Console.WriteLine("Finished: #{0} cycles, #{1} keys, last run {2}.", tracker.FinishedCycles, tracker.KeyCount, tracker.CurrentProcess); foreach (var message in tracker.Messages) { Console.WriteLine("Message: {0}: {1}", message.Key, message.Value); } } else { // non-graph var instruction = new RFParamProcessInstruction( processName, new RFEngineProcessorKeyParam(RFGenericCatalogKey.Create(_config.KeyDomain, "dummy", "dummy", null))); var ra = new RFRequestActivity(_context, _config); var tracker = ra.Submit(null, new List <RFInstruction> { instruction }, null); while (!tracker.IsComplete) { Thread.Sleep(100); } Console.WriteLine("Finished: #{0} cycles, #{1} keys, last run {2}.", tracker.FinishedCycles, tracker.KeyCount, tracker.CurrentProcess); foreach (var message in tracker.Messages) { Console.WriteLine("Message: {0}: {1}", message.Key, message.Value); } } break; } case "error": { _context.SystemLog.Error(this, "System Log error message"); //_context.SystemLog.Exception(this, "System Log exception message", new Exception("Test exception")); break; } case "version": { var runLicense = RFPublicRSA.GetHost(_config.LicenseTokens.Key, _config.LicenseTokens.Value); Console.WriteLine("RIFF Framework {0} | (c) rohatsu software studios limited | www.rohatsu.com", RFCore.sVersion); Console.WriteLine("Licensed to '{0}' ({1})", runLicense.Key, runLicense.Value.ToString(RFCore.sDateFormat)); Console.WriteLine("Loaded engine {0} from {1} in environment {2}", _engine?.EngineName, _engine?.Assembly, _engine.Environment); break; } case "email": { if (tokens.Length > 1) { var e = new RFGenericEmail(new RFEmailConfig { Enabled = true, To = tokens[1] }, string.Format("<html><body>Test email from RIFF System.<p/>Sent on {0} from {1}.</body></html>", DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss \"GMT\"zzz"), Environment.MachineName)); e.Send("RIFF Test e-mail"); } else { Console.WriteLine("provide email address as parameter"); } } break; case "list": { Console.WriteLine("== PROCESSES"); foreach (var p in _config.Processes.OrderBy(p => p.Key)) { Console.WriteLine($"\"{p.Key}\" -> {p.Value.Processor().GetType().Name}"); } Console.WriteLine("== GRAPHS"); foreach (var g in _config.Graphs.OrderBy(g => g.Key)) { foreach (var p in g.Value.Processes.OrderBy(p => p.Key)) { Console.WriteLine($"\"{RFGraphDefinition.GetFullName(g.Key, p.Key)}\" -> {p.Value.Processor().GetType().Name}"); } } } break; case "scheduler": { if (tokens.Length == 1) { Console.WriteLine("Controls task scheduler. Commands: list, reload"); break; } _context.RaiseEvent(this, new RFServiceEvent { ServiceName = RFSchedulerService.SERVICE_NAME, ServiceCommand = tokens[1], ServiceParams = tokens.Length > 2 ? tokens[2] : null }); break; } case "rebuildgraph": { if (tokens.Length < 4) { Console.WriteLine("Usage: rebuild,<graphNameOrBlank>,<graphInstance>,<startDate>,[endDate]"); break; } var graphName = tokens[1]; var graphInstanceName = tokens[2]; if (tokens.Length > 3) { var startDate = RFDate.Parse(tokens[3], "yyyy-MM-dd"); var endDate = startDate; if (tokens.Length > 4) { endDate = RFDate.Parse(tokens[4], "yyyy-MM-dd"); } var instructions = new List <RFInstruction>(); // queue all graph processes foreach (var vd in RFDate.Range(startDate, endDate, d => true)) { var instance = new RFGraphInstance { Name = graphInstanceName, ValueDate = vd }; foreach (var g in this._config.Graphs.Values.Where(g => graphName.IsBlank() || g.GraphName.StartsWith(graphName, StringComparison.OrdinalIgnoreCase))) { foreach (var gp in g.Processes.Values) { var processName = RFGraphDefinition.GetFullName(gp.GraphName, gp.Name); instructions.Add(new RFGraphProcessInstruction(instance, processName)); } } } if (instructions.Any()) { var tracker = new RFRequestActivity(_context, _config).Submit(null, instructions, null); while (!tracker.IsComplete) { Thread.Sleep(100); } Console.WriteLine("Finished: #{0} cycles, #{1} keys, last run {2}.", tracker.FinishedCycles, tracker.KeyCount, tracker.CurrentProcess); foreach (var message in tracker.Messages) { Console.WriteLine("Message: {0}: {1}", message.Key, message.Value); } } } } break; case "exit": case "quit": _isExiting = true; break; default: { if (_engineConsole != null) { var queueCommands = new List <string>(); if (!_engineConsole.RunCommand(tokens, queueCommands)) { Console.WriteLine(String.Format("Unrecognized command '{0}'", tokens[0])); } foreach (var c in queueCommands) { ExecuteCommand(c); } } } break; } } }
public RFGraphStats GetGraphStats(string graphName, RFGraphInstance instance) { return(Context.LoadDocumentContent <RFGraphStats>(RFGraphStatsKey.Create(_engineConfig.KeyDomain, graphName, instance))); }
public RFProcessingTrackerHandle RunProcess(bool isGraph, string processName, RFGraphInstance instance, RFUserLogEntry userLogEntry) { try { Log.Info(this, "RunProcess {0} / ({1},{2})", processName, instance != null ? instance.Name : null, instance != null ? instance.ValueDate : null); LogRequest(); var activity = new RFRequestActivity(_context, _engineConfig); // TODO: how should we treat non-graph? return(RegisterTracker(activity.Run(isGraph, processName, new RFEngineProcessorGraphInstanceParam(instance), userLogEntry))); } catch (Exception ex) { Log.Exception(this, "RunProcess", ex); return(new RFProcessingTrackerHandle { TrackerCode = "error" }); } }