Esempio n. 1
0
 public BaseActivityStreamBox(ActivityStreamFilter filter, IActivityStreamRepository ctx)
 {
     this.filter = filter;
     this.ctx    = ctx;
     //Writers.Add(new ObjectStreamWriter(File.Open(PathOf(null), FileMode.Append, FileAccess.Write, FileShare.Read), _serializer, ctx));
     Writers.Add(new ObjectIdStreamWriter(OpenWrite(filter.ToPath(null)), ctx));
 }
Esempio n. 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));
        }