Exemple #1
0
        public void CreateIndexOn(ActivityStreamFilter filter)
        {
            filter = this.filter.Extend(filter);
            var path = filter.ToUri(null);

            Writers.Add(new FilteredObjectIdStreamWriter(filter, OpenWrite(path), ctx));
            Indexes.Add(filter);
        }
Exemple #2
0
        protected virtual Task <BaseObjectStreamReader> OpenReader(ActivityStreamFilter filter)
        {
            BaseObjectStreamReader ret = null;
            string path = null;

            foreach (var index in Indexes)
            {
                if (index.Contains(filter))
                {
                    path = Localize(index.ToUri(null));
                    if (System.IO.File.Exists(path))
                    {
                        break;
                    }
                    else
                    {
                        path = null;
                    }
                }
            }

            if (path == null)
            {
                path = Localize(filter.ToUri(null));
                if (!System.IO.File.Exists(path))
                {
                    path = Localize(filter.ToPath(null));
                }
            }

            if (System.IO.File.Exists(path))
            {
                switch (System.IO.Path.GetExtension(path))
                {
                case ".index":
                {
                    var s = System.IO.File.OpenRead(path);
                    if (filter.reverse)
                    {
                        ret = new ReverseObjectIdStreamReader(s, id =>
                            {
                                var p = Localize(filter.ToPath(id));
                                if (System.IO.File.Exists(p))
                                {
                                    return(System.IO.File.OpenRead(p));
                                }
                                else
                                {
                                    return(null);
                                }
                            }, _serializer);
                    }
                    else
                    {
                        ret = new ObjectIdStreamReader(s, id => System.IO.File.OpenRead(Localize(filter.ToPath(id))), _serializer);
                    }
                }
                break;

                case ".json":
                    ret = new ObjectStreamReader(System.IO.File.OpenRead(path), _serializer);
                    break;

                default:
                    throw new Exception($"Invalid activity stream type: {path}");
                }
            }
            else
            {
                ret = new EmptyObjectStreamReader();
            }
            return(Task.FromResult(ret));
        }