Example #1
0
        public RFCatalogKey CreateForInstance(RFGraphInstance instance)
        {
            var copy = MemberwiseClone() as RFCatalogKey;

            copy.GraphInstance = instance != null?instance.Clone() : null;

            return(copy);
        }
Example #2
0
 public static RFCatalogKey Create(RFKeyDomain domain, RFGraphInstance instance)
 {
     return(domain.Associate(new RFEngineStatsKey
     {
         Plane = RFPlane.System,
         StoreType = RFStoreType.Document,
         GraphInstance = instance
     }));
 }
Example #3
0
 public static RFStatusKey Create(RFKeyDomain domain, string processName, RFGraphInstance instance)
 {
     return(domain.Associate(new RFStatusKey
     {
         ProcessName = processName,
         GraphInstance = instance,
         Plane = RFPlane.System,
         StoreType = RFStoreType.Document
     }));
 }
Example #4
0
        public override void Initialize(RFEngineProcessorParam p, IRFProcessingContext context, RFKeyDomain keyDomain, string processName)
        {
            base.Initialize(p, context, keyDomain, processName);

            if (InstanceParams is RFEngineProcessorGraphInstanceParam)
            {
                GraphInstance = (InstanceParams as RFEngineProcessorGraphInstanceParam).Instance;
            }
            else
            {
                throw new RFSystemException(this, "Unable to extract GraphInstance from params");
            }
        }
Example #5
0
 protected void LogProcessingStat(RFEngineProcess process, RFProcessInstruction i, Stopwatch sw, DateTimeOffset startTime)
 {
     try
     {
         RFGraphInstance graphInstance = null;
         if (i is RFGraphProcessInstruction)
         {
             return; // these are logged by graph stats
             //graphInstance = (i as RFGraphProcessInstruction).Instance;
         }
         var statsKey      = RFEngineStatsKey.Create(_config.KeyDomain, graphInstance);
         var statsDocument = _context.Catalog.LoadItem(statsKey, 0) as RFDocument;
         if (statsDocument == null)
         {
             statsDocument = RFDocument.Create(statsKey,
                                               new RFEngineStats
             {
                 GraphInstance = graphInstance,
                 Stats         = new Dictionary <string, RFEngineStat>()
             });
         }
         var stat = new RFEngineStat
         {
             ProcessName  = process.Name,
             LastDuration = sw.ElapsedMilliseconds,
             LastRun      = startTime
         };
         var statsItem = statsDocument.GetContent <RFEngineStats>();
         if (!statsItem.Stats.ContainsKey(process.Name))
         {
             statsItem.Stats.Add(process.Name, stat);
         }
         else
         {
             statsItem.Stats[process.Name] = stat;
         }
         statsDocument.UpdateTime = DateTimeOffset.Now;
         _context.Catalog.SaveItem(statsDocument, true); // don't keep versions
     }
     catch (Exception ex)
     {
         Log.Warning(this, "Error saving processing stats for process {0}: {1}", process.Name, ex.Message);
     }
 }
Example #6
0
        protected List <RFCatalogKey> SaveDomain(RFGraphProcessorDomain domain, IRFProcessingContext context)
        {
            var updates    = new List <RFCatalogKey>();
            var domainType = domain.GetType();
            int numUpdates = 0;

            foreach (var propertyInfo in domainType.GetProperties())
            {
                var ioBehaviour = propertyInfo.GetCustomAttributes(typeof(RFIOBehaviourAttribute), true).FirstOrDefault() as RFIOBehaviourAttribute;
                if (ioBehaviour != null && (ioBehaviour.IOBehaviour == RFIOBehaviour.Output || ioBehaviour.IOBehaviour == RFIOBehaviour.State))
                {
                    var value = propertyInfo.GetValue(domain);
                    if (value != null)
                    {
                        foreach (var outputMapping in Config.IOMappings.Where(m => m.Property.Name == propertyInfo.Name))
                        {
                            var outputKey = outputMapping.Key.CreateForInstance(this.GraphInstance);
                            var options   = RFGraphInstance.ImplyOptions(outputMapping);
                            // by default date will be set from the graph instance
                            if (options.DateBehaviour == RFDateBehaviour.Dateless)
                            {
                                outputKey.GraphInstance.ValueDate = null;
                            }
                            bool isState    = (ioBehaviour.IOBehaviour == RFIOBehaviour.State);
                            var  hasUpdated = context.SaveEntry(new RFDocument
                            {
                                Content = value,
                                Key     = outputKey,
                                Type    = value.GetType().FullName
                            }, !isState);
                            if (hasUpdated)
                            {
                                updates.Add(outputKey);
                                numUpdates++;
                            }
                        }
                    }
                }
            }
            return(updates);
        }
 public RFGraphProcessInstruction(RFGraphInstance instance, string processName) : base(processName)
 {
     Instance = instance;
 }
Example #8
0
        protected RFGraphProcessorDomain LoadDomain(IRFGraphProcessorInstance processor, IRFProcessingContext context, ref SortedSet <string> missingInputs)
        {
            var domain = processor.CreateDomain();

            domain.Instance = GraphInstance;
            var domainType = domain.GetType();

            var missingNames = new ConcurrentBag <string>();

            try
            {
                foreach (var propertyInfo in domainType.GetProperties())
                {
                    var ioBehaviour = propertyInfo.GetCustomAttributes(typeof(RFIOBehaviourAttribute), true).FirstOrDefault() as RFIOBehaviourAttribute;
                    if (ioBehaviour != null && (ioBehaviour.IOBehaviour == RFIOBehaviour.Input || ioBehaviour.IOBehaviour == RFIOBehaviour.State))
                    {
                        var inputMapping = Config.IOMappings.SingleOrDefault(m => m.Property.Name == propertyInfo.Name);
                        if (inputMapping != null)
                        {
                            var options = RFGraphInstance.ImplyOptions(inputMapping);
                            if (options.DateBehaviour == RFDateBehaviour.Range)
                            {
                                if (inputMapping.RangeRequestFunc == null)
                                {
                                    if (ioBehaviour.IsMandatory)
                                    {
                                        Context.SystemLog.Warning(this, "No range specified for mandatory ranged input {0} on process {1}", propertyInfo.FullName(), this.ProcessName);
                                    }
                                    continue;
                                }
                                var dateRange = inputMapping.RangeRequestFunc(GraphInstance);
                                options.DateBehaviour = RFDateBehaviour.Exact; // override to load one-by-one

                                var rangeInput = Activator.CreateInstance(propertyInfo.PropertyType) as IRFRangeInput;
                                foreach (var vd in dateRange)
                                {
                                    var inputKey = inputMapping.Key.CreateForInstance(GraphInstance.WithDate(vd));

                                    var item = context.LoadEntry(inputKey, options);
                                    if (item != null && item is RFDocument)
                                    {
                                        var content = (item as RFDocument).Content;
                                        if (content != null)
                                        {
                                            rangeInput.Add(vd, content);
                                        }
                                    }
                                }

                                try
                                {
                                    if (propertyInfo.PropertyType.IsAssignableFrom(rangeInput.GetType()))
                                    {
                                        propertyInfo.SetValue(domain, rangeInput);
                                    }
                                    else
                                    {
                                        Context.SystemLog.Warning(this, "Not assigning value of type {0} to property {1} of type {2} due to type mismatch [{3}]", rangeInput.GetType().FullName,
                                                                  propertyInfo.FullName(), propertyInfo.PropertyType.FullName, domain.Instance?.ValueDate);
                                    }
                                }
                                catch (Exception)
                                {
                                    Context.SystemLog.Info(this, "Domain mismatch on property {0} for vd {1} - stale data?", propertyInfo.FullName(), domain.Instance.ValueDate);
                                }
                            }
                            else
                            {
                                var inputKey = inputMapping.Key.CreateForInstance(GraphInstance);
                                var item     = context.LoadEntry(inputKey, options);
                                if (item != null && item is RFDocument)
                                {
                                    try
                                    {
                                        var content = (item as RFDocument).Content;
                                        if (content != null)
                                        {
                                            if (propertyInfo.PropertyType.IsAssignableFrom(content.GetType()))
                                            {
                                                propertyInfo.SetValue(domain, content);
                                            }
                                            else
                                            {
                                                Context.SystemLog.Warning(this, "Not assigning value of type {0} to property {1} of type {2} due to type mismatch [{3}]", content.GetType().FullName,
                                                                          propertyInfo.FullName(), propertyInfo.PropertyType.FullName, domain.Instance?.ValueDate);
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        Context.SystemLog.Info(this, "Domain mismatch on property {0} for vd {1} - stale data?", propertyInfo.FullName(), domain.Instance.ValueDate);
                                    }
                                }
                                else if (ioBehaviour.IsMandatory)
                                {
                                    missingNames.Add(propertyInfo.Name);
                                    // return null;// performance short circuit - only report one missing
                                }
                            }
                        }
                    }
                }
                missingInputs.UnionWith(missingNames);
                if (missingInputs.Count > 0)
                {
                    return(null);
                }
                return(domain);
            }
            catch (Exception ex)
            {
                Context.SystemLog.Exception(this, "Error loading domain", ex);
                return(null);
            }
        }
Example #9
0
 public static RFStateKey CreateKey(RFKeyDomain keyDomain, string graphName, string processName, RFGraphInstance instance)
 {
     return(keyDomain.Associate <RFStateKey>(new RFStateKey
     {
         StoreType = RFStoreType.Document,
         Plane = RFPlane.User,
         GraphInstance = instance,
         GraphName = graphName,
         ProcessName = processName
     }));
 }
        /// <summary>
        /// Configures graph process to automatically trigger on specific schedule
        /// </summary>
        /// <returns></returns>
        public RFGraphTaskDefinition AddScheduledTask <D>(string taskName, Func <List <RFSchedulerSchedule> > schedulesFunc, Func <RFSchedulerRange> rangeFunc, RFGraphProcessDefinition process, RFGraphInstance instance)
            where D : RFGraphProcessorDomain
        {
            var triggerName = RFEnum.FromString(taskName);
            var triggerKey  = RFManualTriggerKey.CreateKey(EngineConfig.KeyDomain, triggerName, instance);

            // map to process' input
            process.MapInput <D>(d => d.Trigger, triggerKey);

            var task = new RFScheduledGraphTaskDefinition
            {
                RangeFunc     = rangeFunc,
                SchedulesFunc = schedulesFunc,
                TaskName      = taskName,
                GraphProcess  = process,
                TriggerKey    = triggerKey
            };

            GraphTasks.Add(task);

            task.AddToEngine(EngineConfig);

            return(task);
        }
 /// <summary>
 /// Configures graph process to automatically trigger on specific schedule
 /// </summary>
 /// <returns></returns>
 public RFGraphTaskDefinition AddScheduledTask <D>(string taskName, List <RFSchedulerSchedule> schedules, RFSchedulerRange range, RFGraphProcessDefinition process, RFGraphInstance instance)
     where D : RFGraphProcessorDomain
 {
     return(AddScheduledTask <D>(taskName, () => schedules, () => range, process, instance));
 }
 public static RFManualTriggerKey CreateKey(RFKeyDomain keyDomain, RFEnum triggerCode, RFGraphInstance instance)
 {
     return(keyDomain.Associate <RFManualTriggerKey>(new RFManualTriggerKey
     {
         StoreType = RFStoreType.Document,
         Plane = RFPlane.User,
         GraphInstance = instance,
         TriggerCode = triggerCode
     }));
 }
Example #13
0
 protected RFCatalogKey()
 {
     GraphInstance = new RFGraphInstance();
 }
Example #14
0
 public static RFGenericCatalogKey Create(RFKeyDomain keyDomain, string path, RFEnum _enum, RFGraphInstance instance)
 {
     return(keyDomain.Associate(new RFGenericCatalogKey
     {
         GraphInstance = instance,
         Name = _enum.ToString(),
         Path = path,
         Plane = RFPlane.User,
         StoreType = RFStoreType.Document
     }));
 }
 public RFEngineProcessorGraphInstanceParam(RFGraphInstance instance)
 {
     Instance = instance;
 }
 /// <summary>
 /// If returns false the calculation will not be called for this instance - use to limit
 /// instances to once per month etc.
 /// </summary>
 /// <returns></returns>
 public virtual bool HasInstance(RFGraphInstance instance)
 {
     return(instance.ValueDate.Value.IsWeekday());
 }