예제 #1
0
    public IQuery FromAst(QueryAbstractSyntaxTree queryAst)
    {
        if (queryAst.SelectExpression is NodeClassReference nodeClassReference == false)
        {
            throw new InvalidQueryException(
                      $"Unsupported select expression: {queryAst.SelectExpression.GetType().FullName}.");
        }

        var path = new QueryPath(new NodeReference(nodeClassReference.NodeIdentifier.Name,
                                                   nodeClassReference.Alias.Name));

        var query = new QueryImplementation(path);

        if (queryAst.ReturnSpecification.Selector is SelectAllProperties selectAllProperties)
        {
            var alias         = selectAllProperties.NodeTypeIdentifier.Name;
            var nodeReference = query.FindNodeByAlias(alias);

            if (nodeReference is null)
            {
                throw new InvalidQueryException(
                          $"Expected node with alias: {alias} to be in the selection path but it was not found. Return specification is invalid.");
            }

            query.AddPropertySelection(new NodeAllPropertiesSelected(nodeReference));
        }
        else
        {
            throw new InvalidQueryException($"Unsupported return specification.");
        }

        return(query);
    }
        public static WorkItemCollection GetWorkItems(this WorkItemStore store, QueryPath queryPath)
        {
            QueryDefinition definition = GetQueryDefinition(store, queryPath);

            return GetWorkItems(store,
                new Query(store, definition.QueryText, new Hashtable {{"project", queryPath.ProjectName}}),
                null);
        }
        /// <summary>
        /// Raises the QueryPath event.
        /// </summary>
        private void RaiseQueryPath()
        {
            QueryPathEventArgs e = new QueryPathEventArgs()
            {
                Context = this.Context
            };

            QueryPath?.Invoke(this, e);

            if (!e.Cancel)
            {
                Videos.AddRange(e.TMDbDetails);
            }
        }
        public static QueryDefinition GetQueryDefinition(this WorkItemStore store, QueryPath queryPath)
        {
            var queryHierarchy = store.Projects[queryPath.ProjectName].QueryHierarchy;

            var foundQueryItem = queryPath.PathNames
                .Aggregate<string, QueryItem>(queryHierarchy,
                    (queryItem, name) =>
                    {
                        var queryFolder = queryItem as QueryFolder;

                        if (queryFolder != null && queryFolder.Contains(name))
                        {
                            return queryFolder[name];
                        }

                        return null;
                    }
                );

            return foundQueryItem as QueryDefinition;
        }