/// <summary>
        /// Add a batch operation
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sourceModel"></param>
        /// <param name="linkRel"></param>
        /// <param name="method"></param>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BatchRequestBuilder AddOperation <T>(string id, Linkable sourceModel, string linkRel, string method, T requestModel)
        {
            string uri = GetUriFromLinkRelation(sourceModel, linkRel);

            this.AddOperation(id, "", uri, method, null, requestModel);
            return(this);
        }
        /// <summary>
        /// Add a batch operation
        /// </summary>
        /// <param name="id"></param>
        /// <param name="description"></param>
        /// <param name="sourceModel"></param>
        /// <param name="linkRel"></param>
        /// <param name="method"></param>
        /// <param name="headers"></param>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BatchRequestBuilder AddOperation <T>(string id, string description, Linkable sourceModel, string linkRel, string method, List <BatchOperationHeader> headers, T requestModel)
        {
            string uri = GetUriFromLinkRelation(sourceModel, linkRel);

            this.AddOperation(id, description, uri, method, headers, requestModel);
            return(this);
        }
Esempio n. 3
0
        public Link makeLink(Linkable origin, Linkable destination, Guid?id = null)
        {
            var link = new Link(id.HasValue ? id.Value : Guid.NewGuid(), origin, destination);

            _identifiables.Add(link);

            // Console.WriteLine(String.Format("Created Link ({0}).", link.ID.ToString()));
            return(link);
        }
        private static string GetUriFromLinkRelation(Linkable sourceModel, string linkRel)
        {
            string uri = LinkRelations.FindLinkAsString(sourceModel.Links, linkRel);

            if (uri != null && uri.Contains("{"))
            {
                uri = uri.Substring(0, uri.IndexOf("{"));
            }
            return(uri);
        }
Esempio n. 5
0
        public Linkable popFront()
        {
            Linkable next = tail.next;

            if (next == tail)
            {
                return(null);
            }

            next.unlink();
            return(next);
        }
Esempio n. 6
0
        public void pushFront(Linkable item)
        {
            if (item.previous != null)
            {
                item.unlink();
            }

            item.previous      = tail;
            item.next          = tail.next;
            item.previous.next = item;
            item.next.previous = item;
        }
Esempio n. 7
0
        public void unlink()
        {
            if (previous == null)
            {
                return;
            }

            previous.next = next;
            next.previous = previous;
            next          = null;
            previous      = null;
        }
Esempio n. 8
0
        public Linkable getPrevious()
        {
            Linkable node = current;

            if (node == tail)
            {
                current = null;
                return(null);
            }

            current = node.previous;
            return(node);
        }
Esempio n. 9
0
        public Linkable peekBack()
        {
            Linkable node = tail.previous;

            if (node == tail)
            {
                current = null;
                return(null);
            }

            current = node.previous;
            return(node);
        }
Esempio n. 10
0
        public Linkable peekFront()
        {
            Linkable node = tail.next;

            if (node == tail)
            {
                current = null;
                return(null);
            }

            current = node.next;
            return(node);
        }
Esempio n. 11
0
        public LinkableHashMap(int size)
        {
            this.size    = size;
            this.entries = new Linkable[size];

            for (int i = 0; i < size; i++)
            {
                Linkable entry = new Linkable();
                entry.next     = entry;
                entry.previous = entry;
                entries[i]     = entry;
            }
        }
Esempio n. 12
0
        public Linkable getNext()
        {
            Linkable node = current;

            if (node == tail)
            {
                current = null;
                return(null);
            }

            current = node.next;
            return(node);
        }
Esempio n. 13
0
        public Chain(Story story, Linkable start)
        {
            this._story     = story;
            this._stalemate = false;
            this._finished  = false;
            this._items     = new List <Linkable>();
            this._activeItemValidOutputs = new List <Link>();
            this._previousHub            = null;

            this._items.Add(start);
            start.addDelegate(this);
            start.tryActivate();
        }
Esempio n. 14
0
        public void setDestination(Linkable dest)
        {
            if (dest != null && dest == _origin)
            {
                Console.WriteLine(String.Format("ERROR: Tried to set Link ({0}) destination to its origin ({1}).", _id.ToString(), dest.ID));
                return;
            }
            var prevID = (null == _destination) ? "null" : _destination.ID.ToString();
            var newID  = (null == dest) ? "null" : dest.ID.ToString();

            // Console.WriteLine(String.Format("Link ({0}) destination changed ({1} -> {2}).", _id.ToString(), prevID, newID));
            _destination = dest;
        }
Esempio n. 15
0
        public Linkable get(long key)
        {
            Linkable start = entries[(int)(key & size - 1)];

            for (Linkable next = start.next; next != start; next = next.next)
            {
                if (next.id == key)
                {
                    return(next);
                }
            }

            return(null);
        }
Esempio n. 16
0
        public Link(Guid id, Linkable origin, Linkable destination)
        {
            this._id     = id;
            this._origin = origin;

            if (null == origin || !origin.canBeOrigin())
            {
                var originID = (null == origin) ? "null" : origin.ID.ToString();
                Console.WriteLine(String.Format("ERROR: Link ({0}) has invalid origin ({1})!", id.ToString(), originID));
                this._origin = null;
            }

            setDestination(destination);
        }
Esempio n. 17
0
        public void put(long key, Linkable item)
        {
            if (item.previous != null)
            {
                item.unlink();
            }

            Linkable current = entries[(int)(key & size - 1)];

            item.previous      = current.previous;
            item.next          = current;
            item.previous.next = item;
            item.next.previous = item;
            item.id            = key;
        }
Esempio n. 18
0
        public List <Link> getValidOutputsFor(Linkable obj)
        {
            var result = new List <Link>();

            foreach (var link in Links)
            {
                if (link.Origin == obj)
                {
                    if (null == link.Condition || link.Condition.evaluate())
                    {
                        result.Add(link);
                    }
                }
            }

            return(result);
        }
Esempio n. 19
0
        public void clear()
        {
            if (tail.next == tail)
            {
                return;
            }

            while (true)
            {
                Linkable next = tail.next;

                if (next == tail)
                {
                    return;
                }

                next.unlink();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Gets the results of a request and converts them to a LIST
        /// </summary>
        /// <typeparam name="T">The type of list to be returned</typeparam>
        /// <param name="feed">The feed to be converted</param>
        /// <param name="fetchFullObject">Whether or not to fetch the full object(s) or just convert the feed to a list</param>
        /// <returns></returns>
        public static List <T> getFeedAsList <T>(Feed <T> feed, bool fetchFullObject)
        {
            List <T>          list    = new List <T>();
            List <Entry <T> > entries = feed.Entries;

            foreach (Entry <T> entry in entries)
            {
                T content     = entry.Content;
                T fullContent = default(T);

                {
                    if (content is Linkable && fetchFullObject)
                    {
                        Linkable linkable = content as Linkable;
                        if (linkable.Links.Count > 0)
                        {
                            Link self = LinkRelations.FindLink((content as Linkable).Links, LinkRelations.SELF.Rel);
                            if (self == null)
                            {
                                self = (content as Linkable).Links[0];
                            }
                            fullContent = feed.Client.Get <T>(self.Href, null);
                        }
                        else
                        {
                            fullContent = content;
                        }
                    }
                    else
                    {
                        fullContent = content;
                    }
                }

                if (content is Executable)
                {
                    (fullContent as Executable).SetClient(feed.Client);
                }
                list.Add(fullContent);
            }
            return(list);
        }
Esempio n. 21
0
 public DoubleEndedQueue()
 {
     tail          = new Linkable();
     tail.next     = tail;
     tail.previous = tail;
 }