Esempio n. 1
0
        public void KeyInstancesTest()
        {
            var key1 = RFGenericCatalogKey.Create(_fixture.KeyDomain, "KeyInstancesTest", TestEngine.TestKeys.Key1, new RFGraphInstance {
                Name = "dummy", ValueDate = RFDate.Today()
            });
            var key2 = RFGenericCatalogKey.Create(_fixture.KeyDomain, "KeyInstancesTest", TestEngine.TestKeys.Key2, new RFGraphInstance {
                Name = "dummy", ValueDate = RFDate.Today()
            });

            foreach (var date in RFDate.Range(new RFDate(2016, 7, 1), new RFDate(2016, 7, 12), d => true))
            {
                // 12 of these
                var key11 = key1.CreateForInstance(new RFGraphInstance
                {
                    Name      = "default1",
                    ValueDate = date
                });
                _fixture.Context.SaveDocument(key11, "Test", false);

                // 6 of these
                if (date.Day % 2 == 0)
                {
                    var key12 = key1.CreateForInstance(new RFGraphInstance
                    {
                        Name      = "default2",
                        ValueDate = date
                    });
                    _fixture.Context.SaveDocument(key12, "Test", false);
                }

                // 4 of these
                if (date.Day % 3 == 0)
                {
                    var key21 = key2.CreateForInstance(new RFGraphInstance
                    {
                        Name      = "default1",
                        ValueDate = date
                    });
                    _fixture.Context.SaveDocument(key21, "Test", false);
                }

                // 3 of these
                if (date.Day % 4 == 0)
                {
                    var key22 = key2.CreateForInstance(new RFGraphInstance
                    {
                        Name      = "default2",
                        ValueDate = date
                    });
                    _fixture.Context.SaveDocument(key22, "Test", false);
                }
            }

            _fixture.Context.SaveDocument(key2.CreateForInstance(null), "Test", false); // this should be ignored

            var keys1 = _fixture.Context.GetKeyInstances(key1);

            Assert.Equal(18, keys1.Count);
            Assert.Equal(12, keys1.Where(k => k.Value.GraphInstance.Name == "default1").Count());
            Assert.Equal(6, keys1.Where(k => k.Value.GraphInstance.Name == "default2").Count());

            var keys2 = _fixture.Context.GetKeyInstances(key2);

            Assert.Equal(7, keys2.Count);
            Assert.Equal(4, keys2.Where(k => k.Value.GraphInstance != null && k.Value.GraphInstance.Name == "default1").Count());
            Assert.Equal(3, keys2.Where(k => k.Value.GraphInstance != null && k.Value.GraphInstance.Name == "default2").Count());

            // invalidate
            _fixture.Context.Invalidate(key1.CreateForInstance(new RFGraphInstance
            {
                Name      = "default1",
                ValueDate = new RFDate(2016, 7, 12)
            }));

            // get latest
            var latest1 = _fixture.Context.LoadEntry(key1.CreateForInstance(new RFGraphInstance
            {
                Name      = "default1",
                ValueDate = RFDate.Today()
            }), new RFCatalogOptions
            {
                DateBehaviour = RFDateBehaviour.Latest
            });

            Assert.Equal(11, latest1.Key.GraphInstance.ValueDate.Value.Day);

            var latest2 = _fixture.Context.LoadEntry(key1.CreateForInstance(new RFGraphInstance
            {
                Name      = "default2",
                ValueDate = RFDate.Today()
            }), new RFCatalogOptions
            {
                DateBehaviour = RFDateBehaviour.Latest
            });

            Assert.Equal(12, latest2.Key.GraphInstance.ValueDate.Value.Day);
        }
Esempio n. 2
0
        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;
                }
            }
        }