public bool SaveEntry(RFCatalogEntry entry, bool raiseEvent = true, bool overwrite = false)
        {
            var materialUpdate = false;

            if (entry is RFDocument && !(entry as RFDocument).Type.Contains("."))
            {
                SystemLog.Warning(this, "Full type name required to save key {0}", entry.Key);
            }
            if (entry.Key.Plane == RFPlane.Ephemeral)
            {
                lock (_memoryStore)
                {
                    if (!_memoryStore.ContainsKey(entry.Key.ToString()))
                    {
                        _memoryStore.Add(entry.Key.ToString(), entry);
                    }
                    else
                    {
                        _memoryStore[entry.Key.ToString()] = entry;
                    }
                }
            }
            else
            {
                // don't raise events if not saved (i.e. same content)
                materialUpdate = _catalog.SaveItem(entry, overwrite);
                raiseEvent    &= materialUpdate;
            }
            if (raiseEvent)
            {
                _events.RaiseEvent(this, new RFCatalogUpdateEvent
                {
                    Key = entry.Key
                }, ProcessingKey);
            }
            return(materialUpdate);
        }
        public RFCatalogEntry LoadEntry(RFCatalogKey key, RFCatalogOptions options = null)
        {
            DefaultOptions(ref options);
            if (key is RFCatalogKey)
            {
                lock (_memoryStore)
                {
                    if (_memoryStore.ContainsKey(key.ToString()))
                    {
                        return(_memoryStore[key.ToString()]);
                    }
                }

                switch (options.DateBehaviour)
                {
                case RFDateBehaviour.NotSet:
                case RFDateBehaviour.Exact:
                {
                    var item = _catalog.LoadItem(key as RFCatalogKey, options.Version, options.IgnoreContent);
                    return((item != null && item.IsValid) ? item : null);
                }

                case RFDateBehaviour.Dateless:
                {
                    var keyToLoad = key.CreateForInstance(new RFGraphInstance
                        {
                            Name      = key.GraphInstance.Name,
                            ValueDate = null
                        });
                    var item = _catalog.LoadItem(keyToLoad, options.Version, options.IgnoreContent);
                    return((item != null && item.IsValid) ? item : null);
                }

                case RFDateBehaviour.Latest:
                case RFDateBehaviour.Previous:
                {
                    if (key.GraphInstance == null || !key.GraphInstance.ValueDate.HasValue)
                    {
                        throw new RFSystemException(this, "Unable to load latest date for key without date {0}", key);
                    }
                    var allKeys        = _catalog.GetKeyInstances(key);
                    var candidateDates = new SortedSet <RFDate>();

                    foreach (var candidateKey in allKeys.Where(k => k.Key.Name == key.GraphInstance.Name))
                    {
                        if (candidateKey.Value.GraphInstance.ValueDate.Value <= key.GraphInstance.ValueDate.Value)
                        {
                            if ((options.DateBehaviour == RFDateBehaviour.Latest) ||
                                (options.DateBehaviour == RFDateBehaviour.Previous && candidateKey.Value.GraphInstance.ValueDate.Value < key.GraphInstance.ValueDate.Value))
                            {
                                candidateDates.Add(candidateKey.Value.GraphInstance.ValueDate.Value);
                            }
                        }
                    }
                    if (candidateDates.Count == 0)
                    {
                        SystemLog.Warning(this, "No latest date instance item found for key {0}", key);
                        return(null);
                    }
                    foreach (var latestDate in candidateDates.OrderByDescending(d => d))
                    {
                        var keyToLoad = key.CreateForInstance(new RFGraphInstance
                            {
                                Name      = key.GraphInstance.Name,
                                ValueDate = latestDate
                            });
                        var item = _catalog.LoadItem(keyToLoad, options.Version, options.IgnoreContent);
                        if (item != null && item.IsValid)
                        {
                            return(item);
                        }
                    }
                    return(null);
                }

                default:
                    throw new RFSystemException(this, "Unsupported date behaviour in LoadEntry: {0}", options.DateBehaviour);
                }
            }
            else
            {
                throw new RFSystemException(this, "Unknown store key type {0}", key.ToString());
            }
        }