예제 #1
0
 public void Add(RFDate vd, object t)
 {
     if (!Instances.ContainsKey(vd) && t is T && t != null)
     {
         Instances.Add(vd, t as T);
     }
 }
예제 #2
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         return(RFDate.Parse(value as string, "yyyyMMdd"));
     }
     return(base.ConvertFrom(context, culture, value));
 }
예제 #3
0
        protected override bool InternalInRange(RFInterval interval)
        {
            var today = new RFDate(interval.IntervalEnd.Date);

            if (CalendarDay.HasValue && today.OffsetDays(CalendarDay.Value - 1) != today.LastCalendarDayOfTheMonth())
            {
                return(false);
            }
            if (WeekDay.HasValue && today.OffsetWeekdays(WeekDay.Value - 1) != today.LastWorkdayOfTheMonth())
            {
                return(false);
            }
            return(true);
        }
예제 #4
0
        public List <RFUserLogEntry> GetEntries(RFDate eventDate)
        {
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    var entries = new List <RFUserLogEntry>();
                    connection.Open();
                    try
                    {
                        string getEntriesSQL = "SELECT * FROM [RIFF].[UserLog] WHERE [Timestamp] >= @EventDate AND [Timestamp] < DATEADD(d, 1, @EventDate) ORDER BY [Timestamp] DESC";
                        using (var getEntriesCommand = new SqlCommand(getEntriesSQL, connection))
                        {
                            getEntriesCommand.Parameters.AddWithValue("@EventDate", new DateTimeOffset(eventDate.Date));

                            using (var reader = getEntriesCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult))
                            {
                                var dataTable = new DataTable();
                                dataTable.Load(reader);
                                if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0)
                                {
                                    foreach (DataRow dataRow in dataTable.Rows)
                                    {
                                        try
                                        {
                                            entries.Add(ExtractLogEntry(dataRow));
                                        }
                                        catch (Exception ex)
                                        {
                                            _context.Log.Exception(this, "Error reading user log", ex);
                                        }
                                    }
                                }
                            }
                        }
                        return(entries);
                    }
                    catch (Exception ex)
                    {
                        _context.Log.Exception(this, "Error retrieving user log (inner)", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                _context.Log.Exception(this, "Error retrieving user log (outer)", ex);
            }
            return(null);
        }
예제 #5
0
        public override Dictionary <RFGraphInstance, RFCatalogKey> GetKeyInstances(RFCatalogKey key)
        {
            var    t       = key.GetType();
            var    keys    = new Dictionary <RFGraphInstance, RFCatalogKey>();
            string keyType = t.FullName;

            Log.Debug(this, "GetKeyInstances {0}", keyType);
            try
            {
                var dataTable = new DataTable();
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    string getKeysSQL = "RIFF.GetKeyInstances";
                    using (var getCommand = CreateCommand(getKeysSQL, connection))
                    {
                        var rootHash = RFStringHelpers.QuickHash(key.RootKey().ToString());

                        getCommand.CommandType = CommandType.StoredProcedure;
                        getCommand.Parameters.AddWithValue("@KeyType", keyType);
                        getCommand.Parameters.AddWithValue("@SerializedKey", RFXMLSerializer.SerializeContract(key));
                        getCommand.Parameters.AddWithValue("@RootHash", rootHash);
                        using (var reader = getCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult))
                        {
                            dataTable.Load(reader);
                        }
                    }
                }
                if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0)
                {
                    // cache deserializer if key is explicit
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        try
                        {
                            var catalogKeyID      = (long)dataRow["CatalogKeyID"];
                            var retrievedKeyType  = dataRow["KeyType"].ToString();
                            var serializedKey     = dataRow["SerializedKey"].ToString();
                            var graphInstanceName = dataRow["GraphInstanceName"].ToString();
                            var graphInstanceDate = new RFDate((int)dataRow["GraphInstanceDate"]);
                            var deserializedKey   = RFXMLSerializer.DeserializeContract(retrievedKeyType, serializedKey);

                            keys.Add(
                                new RFGraphInstance
                            {
                                Name      = graphInstanceName,
                                ValueDate = graphInstanceDate
                            },
                                deserializedKey as RFCatalogKey);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(this, ex, "Error deserializing key {0}", dataRow["SerializedKey"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(this, "Error retrieving key instances", ex);
            }

            return(keys);
        }
예제 #6
0
 public static RFDate ParseDate(string str, string format = null)
 {
     return(RFDate.Parse(str, format));
 }
예제 #7
0
 public void SetValueDate(RFDate valueDate)
 {
     _valueDate = valueDate;
 }
예제 #8
0
 /// <summary>
 /// Returns the latest instance that should be attempted to run.
 /// </summary>
 /// <returns></returns>
 public virtual RFDate MaxInstance(RFDate today)
 {
     return(today);
 }
예제 #9
0
        public override List <RFInstruction> React(RFEvent e)
        {
            var cu = e as RFCatalogUpdateEvent;

            if (cu != null && cu.Key != null && cu.Key.GraphInstance != null && cu.Key.MatchesRoot(_key))
            {
                var key            = cu.Key;
                var updateDate     = key.GraphInstance.ValueDate.Value;
                var processingDate = _dateFunc(key.GraphInstance); // this can be a forward date in case of a range input, but usually 1:1 with key's date
                var instructions   = new List <RFInstruction>();
                if (_dateBehaviour != RFDateBehaviour.Previous)
                {
                    instructions.Add(new RFGraphProcessInstruction(cu.Key.GraphInstance.WithDate(processingDate), _processName));
                }

                // for exact inputs there's no need to queue any forward instructions
                if (_dateBehaviour != RFDateBehaviour.Exact)
                {
                    var maxDate = RFDate.NullDate;

                    // use key's original updatedate rather than derived processingdate for the instruction
                    var laterInstances = _context.GetKeyInstances(key).Where(k => k.Key.Name == key.GraphInstance.Name && k.Key.ValueDate.HasValue)
                                         .Where(d => d.Key.ValueDate.Value > updateDate);
                    if (laterInstances.Any())
                    {
                        maxDate = laterInstances.Min(i => i.Key.ValueDate.Value); // next instance date
                        if (_dateBehaviour == RFDateBehaviour.Latest || _dateBehaviour == RFDateBehaviour.Range)
                        {
                            maxDate = maxDate.OffsetDays(-1); // exclude next instance date (for Previous - it will run)
                        }
                    }
                    else // there are no future instances... so how far do we go?
                    {
                        maxDate = _maxDateFunc(updateDate);
                    }

                    if (maxDate < updateDate)
                    {
                        maxDate = updateDate; // don't do anything
                    }

                    var maxInstanceDate        = _maxDateFunc(_context.Today);
                    var nextDate               = key.GraphInstance.ValueDate.Value.OffsetDays(1);
                    var forwardProcessingDates = new SortedSet <RFDate>(); // eliminate dupes
                    foreach (var forwardUpdateDate in RFDate.Range(nextDate, maxDate, d => true))
                    {
                        var forwardProcessingDate = _dateFunc(key.GraphInstance.WithDate(forwardUpdateDate));
                        if (forwardProcessingDate != processingDate && forwardProcessingDate <= maxInstanceDate)
                        {
                            forwardProcessingDates.Add(forwardProcessingDate);
                        }
                    }

                    if (forwardProcessingDates.Any())
                    {
                        instructions.AddRange(forwardProcessingDates.Select(d => new RFGraphProcessInstruction(key.GraphInstance.WithDate(d), _processName)));

                        _context.SystemLog.Debug(this, "Queuing {0} forward instructions for key {1} from {2} to {3}", forwardProcessingDates.Count, key.FriendlyString(), nextDate, maxDate);
                    }
                }
                return(instructions);
            }
            else
            {
                return(null);
            }
        }