Ejemplo n.º 1
0
        public override async Task Invoke(IOwinContext context)
        {
            var isPushEnabled = context.Get <bool>(CommonOwinKeys.EnableServerPush);

            //If push is not allowed then pass to then next layer
            if (!isPushEnabled)
            {
                await Next.Invoke(context);

                return;
            }

            bool gotError = false;
            var  refTree  = context.Get <Dictionary <string, string[]> >(CommonOwinKeys.AdditionalInfo);

            //original request from client
            if (refTree == null)
            {
                string root = context.Request.Path.Value;
                if (!_references.ContainsKey(root))
                {
                    gotError = true; // Cant build tree because no such name in the ref table. Should invoke next
                }
                else
                {
                    var refCpy = new ReferenceTable(_references);
                    var tree   = new GraphHelper().BuildTree(refCpy, root);
                    refTree = tree;
                    context.Set(CommonOwinKeys.AdditionalInfo, tree);
                }
            }
            if (!gotError)
            {
                PushFunc pushPromise;
                string[] pushReferences;

                if (refTree.TryGetValue(context.Request.Path.Value, out pushReferences) &&
                    TryGetPushPromise(context, out pushPromise))
                {
                    foreach (var pushReference in pushReferences)
                    {
                        Push(context.Request, pushPromise, pushReference);
                    }
                }
            }

            context.Set(CommonOwinKeys.AddVertex, new AddVertFunc(AddVertex));
            context.Set(CommonOwinKeys.RemoveVertex, new RemoveVertFunc(RemoveVertex));

            await Next.Invoke(context);
        }
Ejemplo n.º 2
0
            public Dictionary<string, string[]> BuildTree(ReferenceTable table, string root)
            {
                if (!table.ContainsKey(root))
                    throw new Exception("No such key. Should invoke next.");

                _used.Clear();
                _tree.Clear();

                foreach (var key in table.Keys)
                {
                    _used.Add(key, false);
                }

                Dfs(table, root);

                return _tree;
            }
Ejemplo n.º 3
0
            public Dictionary <string, string[]> BuildTree(ReferenceTable table, string root)
            {
                if (!table.ContainsKey(root))
                {
                    throw new Exception("No such key. Should invoke next.");
                }

                _used.Clear();
                _tree.Clear();

                foreach (var key in table.Keys)
                {
                    _used.Add(key, false);
                }

                Dfs(table, root);

                return(_tree);
            }