// copy over template to final
        public RFProcessingTrackerHandle ApplyTemplate(RFDate valueDate)
        {
            var entry     = LoadTemplateEntry(valueDate);
            var latestKey = LatestKey(valueDate).CreateForInstance(entry.Key.GetInstance());

            return(Context.SaveDocumentAsync(latestKey, entry.Content, CreateUserLogEntry("Apply", "Applied attribution changes.", valueDate)));
        }
        public ActionResult Index(RFDate?valueDate)
        {
            valueDate = valueDate ?? RFDate.Today();

            using (var activity = _activityFunc(Context, Username))
            {
                valueDate = activity.GetLatestDate(valueDate.Value);

                if (!valueDate.HasValue)
                {
                    return(Error(_errorRedirect.Action, _errorRedirect.Controller, new { area = _errorRedirect.Area }, "No Attributions found."));
                }
                else
                {
                    return(View(new AttributionModel
                    {
                        ValueDate = valueDate.Value,
                        RequiresApply = activity.RequiresApply(valueDate.Value),
                        AreaName = Request.RequestContext.RouteData.DataTokens["area"].ToString(),
                        ControllerName = ControllerContext.RouteData.Values["controller"].ToString(),
                        PresentationMode = IsPresentationMode()
                    }));
                }
            }
        }
Beispiel #3
0
        public List <RFInputReportProperties> GetInputReportsList(RFDate valueDate)
        {
            var reports = new List <RFInputReportProperties>();

            foreach (var reportKey in Context.GetKeysByType <RFRawReportKey>().Where(k => k.Value.GraphInstance != null && k.Value.GraphInstance.ValueDate.Value == valueDate))
            {
                try
                {
                    var fileEntry = Context.LoadEntry(reportKey.Value) as RFDocument;
                    if (fileEntry != null && fileEntry.Content is RFRawReport)
                    {
                        var fileContent = (fileEntry as RFDocument).GetContent <RFRawReport>();
                        reports.Add(new RFInputReportProperties
                        {
                            ReportCode        = fileContent.ReportCode,
                            NumRows           = fileContent.Sections != null ? fileContent.Sections.Sum(s => s.Rows.Count()) : 0,
                            ReportDescription = String.Empty,//"description?",
                            ValueDate         = fileContent.ValueDate,
                            SourceUniqueKey   = fileContent.SourceUniqueKey,
                            UpdateTime        = fileEntry.UpdateTime,
                            Key          = reportKey.Value,
                            KeyReference = reportKey.Key
                        });
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(this, ex, "Exception loading RawReport {0}", reportKey);
                }
            }
            return(reports);
        }
 public JsonResult Attributions(RFDate valueDate)
 {
     using (var activity = _activityFunc(Context, Username))
     {
         return(Json(GetGrid(activity.GetTemplate(valueDate))));
     }
 }
 public ActionResult Apply(RFDate valueDate)
 {
     using (var activity = _activityFunc(Context, Username))
     {
         return(TrackProcess(activity.ApplyTemplate(valueDate), _applyRedirect.Action, _applyRedirect.Controller, new { area = _applyRedirect.Area, valueDate = valueDate }));
     }
 }
 protected RFDocument LoadTemplateEntry(RFDate valueDate)
 {
     return(Context.LoadEntry(TemplateKey(valueDate), new RFCatalogOptions
     {
         DateBehaviour = RFDateBehaviour.Latest
     }) as RFDocument);
 }
        public JsonResult GetPreview(int mirroredFileID, int sectionNo = 0, int maxRows = 100)
        {
            using (var activity = new RFMirrorActivity(Context, Username))
            {
                var file = activity.GetFile(mirroredFileID);
                if (file.content != null)
                {
                    var report = RFReportParserProcessor.LoadFromStream(new System.IO.MemoryStream(file.content), new RFFileTrackedAttributes
                    {
                        FileName     = file.mirroredFile.FileName,
                        FileSize     = file.mirroredFile.FileSize,
                        FullPath     = file.mirroredFile.MirrorPath,
                        ModifiedDate = file.mirroredFile.ModifiedTime
                    }, RFDate.Today(), new RFReportParserConfig
                    {
                        Format     = RFReportParserFormat.AutoDetect,
                        HasHeaders = false
                    }, new RFSimpleReportBuilder());
                    if (report != null && report.Sections.Count > sectionNo)
                    {
                        var dataTable = report.Sections.Skip(sectionNo).First().AsDataTable();
                        if (dataTable != null)
                        {
                            dataTable.Columns["RFRowNo"].SetOrdinal(0);
                            dataTable.Columns["RFRowNo"].ColumnName = "#";
                            foreach (DataColumn c in dataTable.Columns)
                            {
                                if (Int32.TryParse(c.ColumnName, out var n))
                                {
                                    c.ColumnName = Interfaces.Formats.XLS.XLSGenerator.GetExcelColumnName(n + 1);
                                }
                            }
                            for (var i = dataTable.Rows.Count - 1; i >= maxRows; i--)
                            {
                                dataTable.Rows[i].Delete();
                            }
                        }

                        var sections = new List <object>();
                        int sn       = 0;
                        foreach (var s in report.Sections)
                        {
                            sections.Add(new { id = sn, name = $"[{sn + 1}] {s.Name}" });
                            sn++;
                        }

                        return(Json(new
                        {
                            sections = sections,
                            selectedSection = sectionNo,
                            preview = dataTable
                        }));
                    }
                }
                return(null);
            }
        }
        public D GetLatestEntry(RFDate valueDate)
        {
            var entry = LoadLatestEntry(valueDate);

            if (entry != null)
            {
                return(entry.GetContent <D>());
            }
            return(null);
        }
 protected static RFDate?GetCollectionDate(string field, FormCollection collection, RFDate?defaultValue = null)
 {
     try
     {
         var strVal = GetCollectionString(field, collection);
         if (!string.IsNullOrWhiteSpace(strVal))
         {
             return(RFDate.Parse(strVal));
         }
     }
     catch (Exception)
     {
     }
     return(defaultValue);
 }
        public JsonResult GetInputFiles(RFDate receivedDate)
        {
            var activity = new RFInputFilesActivity(Context);

            return(Json(activity.GetInputFilesList(null, receivedDate).Select(c => new
            {
                Key = c.Key.ToString(),
                UpdateDate = c.UpdateTime,
                UpdateTime = c.UpdateTime,
                FileKey = c.FileKey,
                FileName = c.Attributes.FileName,
                FileSize = c.Attributes.FileSize,
                ModifiedTime = new DateTimeOffset(c.Attributes.ModifiedDate),
                UniqueKey = c.UniqueKey
            })));
        }
 private static TestDocument CreateTestDocument()
 {
     return(new TestDocument
     {
         Decimal = 5.55M,
         Dict = new Dictionary <string, string> {
             { "Key1", "Value1" }, { "Key2", "Value2" }
         },
         IgnoreMe = 10,
         Int = 505,
         RFDate = RFDate.Today(),
         StringList = new List <string> {
             "S1", "S2", "S3 "
         }
     });
 }
        public JsonResult GetInputReports(RFDate valueDate)
        {
            var activity = new RFInputReportsActivity(Context);

            return(Json(activity.GetInputReportsList(valueDate).Select(c => new
            {
                Key = c.Key.ToString(),
                KeyReference = c.KeyReference,
                UpdateDate = c.UpdateTime,
                UpdateTime = c.UpdateTime,
                ReportCode = c.ReportCode,
                ReportDescription = c.ReportDescription,
                NumRows = c.NumRows,
                ValueDate = c.ValueDate.ToJavascript(),
                SourceUniqueKey = c.SourceUniqueKey
            })));
        }
 public JsonResult GetUserLog(RFDate logDate)
 {
     return(Json(Context.UserLog.GetEntries(logDate).Select(c => new
     {
         Area = c.Area,
         Action = c.Action,
         Description = c.Description,
         Username = c.Username,
         Processor = c.Processor,
         Timestamp = c.Timestamp,
         ValueDate = c.ValueDate != RFDate.NullDate ? c.ValueDate.ToJavascript() : null,
         KeyType = c.KeyType,
         KeyReference = c.KeyReference,
         IsUserAction = c.IsUserAction,
         IsWarning = c.IsWarning
     })));
 }
 public bool RequiresApply(RFDate valueDate)
 {
     try
     {
         var template = LoadTemplateEntry(valueDate);
         var latest   = LoadLatestEntry(valueDate);
         if (template != null && latest != null)
         {
             return(RFXMLSerializer.SerializeContract(template.Content) != RFXMLSerializer.SerializeContract(latest.Content));
         }
     }
     catch (Exception ex)
     {
         Log.Warning(this, ex.Message);
     }
     return(false);
 }
        protected bool Amend(RFDate valueDate, R row)
        {
            var entry = LoadTemplateEntry(valueDate);

            if (entry != null)
            {
                var dataSet = entry.GetContent <D>();
                if (dataSet != null)
                {
                    dataSet.Replace(row);
                    Context.SaveDocument(TemplateKey(valueDate), dataSet, true, null);
                    return(true);
                }
            }
            else
            {
                throw new RFSystemException(this, "Unable to load attribution for date {0}", valueDate);
            }
            return(false);
        }
        protected static RFDate?GetJsonDate(string field, JToken obj, bool mandatory = false)
        {
            var v = obj[field] as JValue;

            if (v?.Value != null)
            {
                if (v.Value is DateTime)
                {
                    return((DateTime)v.Value);
                }
                else
                {
                    return(RFDate.Parse(v.Value.ToString()));
                }
            }
            if (mandatory)
            {
                throw new RFLogicException(typeof(RIFFController), "Mandatory field {0} not found.", field);
            }
            return(null);
        }
 public JsonResult Update(RFDate valueDate, FormCollection collection)
 {
     try
     {
         using (var activity = _activityFunc(Context, Username))
         {
             var row = ExtractRow(collection);
             if (row != null && row.IsValid())
             {
                 return(Json(activity.Replace(valueDate, row)));
             }
             else
             {
                 return(Json(JsonError.Throw("Update", "Internal system error: invalid update.")));
             }
         }
     }
     catch (Exception ex)
     {
         return(Json(JsonError.Throw("Update", ex)));
     }
 }
Beispiel #18
0
 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     try
     {
         RFDate value       = RFDate.NullDate;
         var    stringValue = controllerContext.HttpContext.Request.Form[bindingContext.ModelName];
         if (string.IsNullOrWhiteSpace(stringValue))
         {
             stringValue = controllerContext.HttpContext.Request.QueryString[bindingContext.ModelName];
         }
         if (string.IsNullOrWhiteSpace(stringValue))
         {
             return(null);
         }
         int ymd = 0;
         if (Int32.TryParse(stringValue, out ymd))
         {
             return(new RFDate(ymd));
         }
         if (stringValue == "null")
         {
             return(RFDate.NullDate);
         }
         DateTime dateTime = DateTime.MinValue;
         if (DateTime.TryParseExact(stringValue.Substring(0, 10), "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out dateTime))
         {
             return(new RFDate(dateTime));
         }
         if (DateTime.TryParseExact(stringValue.Substring(0, 10), "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out dateTime))
         {
             return(new RFDate(dateTime));
         }
     }
     catch (Exception)
     {
     }
     return(null);
 }
        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));
        }
 protected RFCatalogKey AttributionKey(RFDate valueDate, RFEnum key)
 {
     return(mKeyCreatorFunc(key).CreateForInstance(mGetInstanceFunc(valueDate)));
 }
        protected D GetDataSet(RFDate valueDate)
        {
            var entry = LoadTemplateEntry(valueDate);

            return(entry != null?entry.GetContent <D>() : null);
        }
        public ActionResult BackupMasterKey(string p)
        {
            try
            {
                var keys = new List <object>();
                RFLoginCache.Login(LoginUsername, p);
                // find all vaults
                var vaults = Context.GetKeysByType <RFKeyVaultKey>();
                var sb     = new StringBuilder();
                sb.AppendLine("VaultName,KeyID,Base64");
                if (vaults.Any())
                {
                    foreach (var vaultKey in vaults.Values)
                    {
                        using (var secure = new RFSecureActivity(Context, LoginUsername, new RFSimpleKeyDomain(vaultKey.Root), vaultKey.Enum))
                        {
                            var vault     = secure.OpenKeyVault(RFLoginCache.GetPasswordHash(LoginUsername));
                            var masterKey = vault.GetKey(RFKeyVault.MASTER_KEY_ID);
                            if (masterKey != null)
                            {
                                sb.AppendFormat("{0},{1},{2}{3}", vaultKey.Enum.ToString(), RFKeyVault.MASTER_KEY_ID, Convert.ToBase64String(masterKey), Environment.NewLine);
                            }
                        }
                    }
                }

                Context.UserLog.LogEntry(new RFUserLogEntry
                {
                    Action       = "BackupMasterKey",
                    Area         = "Encryption",
                    Description  = "Backed up Master Key.",
                    IsUserAction = true,
                    IsWarning    = false,
                    Username     = Username,
                    Timestamp    = DateTimeOffset.Now
                });

                return(File(System.Text.Encoding.ASCII.GetBytes(sb.ToString()), "text/csv", string.Format("Master Key Backup {0}.csv", RFDate.Today().ToString("yyyy-MM-dd"))));
            }
            catch (Exception ex)
            {
                return(Content("<html><body><h3>Error</h3><p>" + ex.Message + "</p></body></html>"));
            }
        }
        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);
        }
        public static long ExportCatalogUpdates(IRFProcessingContext context, string path, RFDate startDate, RFDate?endDate = null, string password = null)
        {
            long c = 0;

            var keysInScope = context.SearchKeys(typeof(RFCatalogKey), startDate, endDate, 99999, null, false).Where(k => k.IsValid && k.Key.Plane == RFPlane.User).ToList();

            foreach (var keyDate in keysInScope.GroupBy(k => k.UpdateTime.Date))
            {
                var fileName = Path.Combine(path, String.Format("RIFF_{0}_Updates_{1}.zip", context.Environment, keyDate.Key.ToString("yyyyMMdd")));

                context.SystemLog.Info(typeof(RFCatalogMaintainer), "Exporting {0} documents into {1}", keyDate.Count(), fileName);

                var  exportableDocuments = new Dictionary <string, byte[]>();
                long cnt = 1;
                foreach (var key in keyDate)
                {
                    var doc = context.LoadEntry(key.Key) as RFDocument;
                    if (doc != null)
                    {
                        var docName = RFFileHelpers.SanitizeFileName(string.Format("{0}_{1}_{2}_{3}_{4}.xml",
                                                                                   doc.Key.GraphInstance?.ValueDate?.ToString() ?? "none",
                                                                                   doc.Key.GraphInstance?.Name ?? "none",
                                                                                   doc.Key.GetType().Name,
                                                                                   doc.Key.FriendlyString(),
                                                                                   cnt++));
                        exportableDocuments.Add(docName, Encoding.UTF8.GetBytes(RFXMLSerializer.PrettySerializeContract(doc)));
                        c++;
                    }
                }
                ZIPUtils.ZipFiles(fileName, exportableDocuments, password);
            }
            return(c);
        }
 protected RFCatalogKey TemplateKey(RFDate valueDate)
 {
     return(AttributionKey(valueDate, mTemplateEnum));
 }
        public RFDate?GetLatestDate(RFDate valueDate)
        {
            var entry = LoadTemplateEntry(valueDate);

            return(entry != null ? entry.Key.GraphInstance.ValueDate : null);
        }
 public IRFDataSet GetTemplate(RFDate valueDate)
 {
     return(GetDataSet(valueDate));
 }
Beispiel #28
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;
                }
            }
        }
 public bool Replace(RFDate valueDate, IRFMappingDataRow row)
 {
     return(Amend(valueDate, row as R));
 }
 protected RFCatalogKey LatestKey(RFDate valueDate)
 {
     return(AttributionKey(valueDate, mLatestEnum));
 }