/// <summary>
        /// Enumerates from top of classroom '{index}' in T's selectors
        /// </summary>
        /// <param name="Index">Index from top of classroom.</param>
        /// <param name="Found">
        /// Predicate used in searching for valid item.
        /// <br/>
        /// Default is item != null
        /// </param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T Get <T>(int Index, Predicate <T> Found = null) where T : new()
        {
            if (Found == null)
            {
                Found = item => item != null;
            }
            var          type      = typeof(T);
            FromSelector baseClass = type.GetCustomAttribute <FromSelector>();
            T            item      = default(T);

            for (int i = 1; Index >= 0;)
            {
                do
                {
                    string selector = baseClass.Selector.Replace("{index}", i.ToString());
                    try
                    {
                        item = Fill <T>(selector);
                    }
                    catch (NoSuchElementException)
                    {
                        // Do nothing...
                        logger.Trace("Timedout `{0}`", selector);
                        item = default(T);
                    }

                    i++;
                } while (!Found(item) && i < POST_DEPTH);
                Index--;
            }

            return(item);
        }
Beispiel #2
0
        public static AddEdgeCommand ConnectVerticies <TFromEntity, TToEntity>(this IGraphClient client,
                                                                               QueryResult <TFromEntity> fromEntity, TToEntity toEntity, string relation)
        {
            var fromSelector  = new FromSelector <TFromEntity>(client);
            var whereSelector = new WhereAnySelector(client, "id", fromEntity.Id)
            {
                ParentSelector = fromSelector
            };
            var addCommand = new AddEdgeCommand(client, toEntity, relation)
            {
                ParentSelector = whereSelector,
                InsertCommand  = new InsertCommand(client, toEntity)
            };

            return(addCommand);
        }
        public T FindAfter <T>(T Item, int Times) where T : new()
        {
            T            el        = default(T);
            FromSelector baseClass = typeof(T).GetCustomAttribute <FromSelector>();
            bool         isXpath   = baseClass is FromXPath;
            int          i         = 1;
            bool         found     = false;

            // logger.Trace("Received {0}", Item);
            while (Times >= 0)
            {
                do
                {
                    string selector = baseClass.Selector.Replace("{index}", i.ToString());
                    // logger.Trace("Filling selector [ {0} ]", selector);
                    try
                    {
                        el = Fill <T>(selector);
                    }
                    catch //(Exception ex)
                    {
                        el = default(T);
                    }
                    i++;
                } while (el == null && i < POST_DEPTH);
                if (el.Equals(Item))
                {
                    found = true;
                }
                if (found)
                {
                    Times--;
                }
            }
            return(el);
        }
Beispiel #4
0
        public static FromSelector <TEntity> From <TEntity>(this IGraphClient client)
        {
            var selector = new FromSelector <TEntity>(client);

            return(selector);
        }