Example #1
0
        private static async Task Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            await using var dictionaryStream = File.OpenRead(@"English (American).dic");
            await using var affixStream      = File.OpenRead(@"English (American).aff");
            _dictionary = await WordList.CreateFromStreamsAsync(dictionaryStream, affixStream);

            _schema = await GetPlotlySchemaAsync();

            _stubble = new StubbleBuilder().Configure(settings =>
            {
                settings.SetIgnoreCaseOnKeyLookup(true);
                settings.SetEncodingFunction(s => s);
            })
                       .Build();

            Parallel.Invoke(CreateAnimation, CreateTransforms, CreateFrames, CreateLayout, CreateConfig, CreateTraces);

            foreach (var(key, value) in Jobs)
            {
                Console.WriteLine($"Generating {key}.cs");
                await value.Execute(_stubble);
            }

            await File.WriteAllLinesAsync("UnknownWords.txt", Helper.UnknownWords.Distinct());

            stopwatch.Stop();
            Console.WriteLine($"[PERFORMANCE] Generation took {stopwatch.ElapsedMilliseconds/1000.0}s");
        }
Example #2
0
        private static object ParseRightValue(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            XmlNode subNode = node.SelectSingleNode("x:*", nsmgr);

            if (subNode == null)
            {
                return(node.InnerText);
            }

            switch (subNode.LocalName)
            {
            case "Property":
                //return schema.PropertyTypes[];
                string       name     = subNode.Attributes["name"].Value;
                PropertyType propType = schema.PropertyTypes[name];
                if (propType != null)
                {
                    return(propType);
                }
                try
                {
                    return(Enum.Parse(typeof(NodeAttribute), name));
                }
                catch (Exception e)     //rethrow
                {
                    throw new ApplicationException(String.Concat("Unknown Property: '", name, "'. Source: ", node.OuterXml), e);
                }

            case "NullValue":
                return(null);

            default:
                return(ParseExpression(subNode, nsmgr, schema));
            }
        }
Example #3
0
        private static object ParseLeftValue(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            XmlAttribute attr     = node.Attributes["property"];
            PropertyType propType = schema.PropertyTypes[attr.Value];

            if (propType != null)
            {
                return(propType);
            }
            try
            {
                return(Enum.Parse(typeof(NodeAttribute), attr.Value));
            }
            catch (Exception e) //rethrow
            {
                throw new ApplicationException(String.Concat("Unknown Property: '", attr.Value, "'. Source: ", node.OuterXml), e);
            }
        }
Example #4
0
        private static SearchOrder ParseOrder(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            OrderDirection direction = OrderDirection.Asc;
            XmlAttribute   attr      = node.Attributes["direction"];

            if (attr != null)
            {
                if (attr.Value == "desc")
                {
                    direction = OrderDirection.Desc;
                }
            }
            object       leftValue = ParseLeftValue(node, nsmgr, schema);
            PropertyType leftProp  = leftValue as PropertyType;

            if (leftProp != null)
            {
                return(new SearchOrder(leftProp, direction));
            }
            return(new SearchOrder((NodeAttribute)leftValue, direction));
        }
Example #5
0
        private static Expression ParseFullTextExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            string nodeTypeName = node.InnerXml;

            return(new SearchExpression(nodeTypeName));
        }
Example #6
0
        private static Expression ParseTypeExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            string   nodeTypeName = node.Attributes["nodeType"].Value;
            NodeType nodeType     = schema.NodeTypes[nodeTypeName];

            if (nodeType == null)
            {
                throw new ApplicationException(String.Concat("Unknown NodeType: '", nodeTypeName, "'. Source: ", node.OuterXml));
            }
            bool         exactMatch = false;
            XmlAttribute attr       = node.Attributes["exactMatch"];

            if (attr != null)
            {
                exactMatch = attr.Value == "yes";
            }
            return(new TypeExpression(nodeType, exactMatch));
        }
Example #7
0
        private static Expression ParseReferenceExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            XmlAttribute attr;

            bool existenceOnly = false;

            attr = node.Attributes["existenceOnly"];
            if (attr != null)
            {
                existenceOnly = attr.Value == "yes";
            }

            object       leftValue      = ParseLeftValue(node, nsmgr, schema);
            PropertyType leftProp       = leftValue as PropertyType;
            Node         referencedNode = null;

            attr = node.Attributes["referencedNodeId"];
            if (attr != null)
            {
                int referencedNodeId = XmlConvert.ToInt32(attr.Value);
                referencedNode = Node.LoadNode(referencedNodeId);
                if (referencedNode == null)
                {
                    throw new ApplicationException(String.Concat("Referred node is not found: ", referencedNodeId));
                }
                if (leftProp != null)
                {
                    return(new ReferenceExpression(leftProp, referencedNode));
                }
                ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue;
                return(new ReferenceExpression(leftAttr, referencedNode));
            }
            if (node.SelectSingleNode("x:*[1]", nsmgr) == null)
            {
                if (leftProp != null)
                {
                    if (existenceOnly)
                    {
                        return(new ReferenceExpression(leftProp));
                    }
                    return(new ReferenceExpression(leftProp, (Node)null));
                }
                ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue;
                if (existenceOnly)
                {
                    return(new ReferenceExpression(leftAttr));
                }
                return(new ReferenceExpression(leftAttr, (Node)null));
            }

            object rightValue = ParseRightValue(node, nsmgr, schema);

            Expression rightExpr = rightValue as Expression;

            if (leftProp != null)
            {
                if (rightExpr != null)
                {
                    return(new ReferenceExpression(leftProp, rightExpr));
                }
            }
            else
            {
                ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue;
                if (rightExpr != null)
                {
                    return(new ReferenceExpression(leftAttr, rightExpr));
                }
            }
            throw new ApplicationException(String.Concat("Unrecognized Reference expression: ", node.OuterXml));
        }
Example #8
0
        private static Expression ParseCurrencyExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            ValueOperator op         = ParseValueOperator(node);
            object        leftValue  = ParseLeftValue(node, nsmgr, schema);
            object        rightValue = ParseRightValue(node, nsmgr, schema);

            PropertyType leftProp = leftValue as PropertyType;

            if (leftProp != null)
            {
                if (rightValue == null)
                {
                    return(new CurrencyExpression(leftProp, op, (decimal?)null));
                }

                PropertyType rightProp = rightValue as PropertyType;
                if (rightProp != null)
                {
                    return(new CurrencyExpression(leftProp, op, rightProp));
                }

                string rightString = rightValue as String;
                if (rightString != null)
                {
                    return(new CurrencyExpression(leftProp, op, XmlConvert.ToDecimal(rightString)));
                }
            }
            throw new NotSupportedException(String.Concat("Unknown property in a Currency expression: ", node.OuterXml));
        }
Example #9
0
        private static Expression ParseDateTimeExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            ValueOperator op         = ParseValueOperator(node);
            object        leftValue  = ParseLeftValue(node, nsmgr, schema);
            object        rightValue = ParseRightValue(node, nsmgr, schema);

            PropertyType leftProp = leftValue as PropertyType;

            if (leftProp != null)
            {
                if (rightValue == null)
                {
                    return(new DateTimeExpression(leftProp, op, (DateTime?)null));
                }

                PropertyType rightProp = rightValue as PropertyType;
                if (rightProp != null)
                {
                    return(new DateTimeExpression(leftProp, op, rightProp));
                }

                string rightString = rightValue as String;
                if (rightString != null)
                {
                    return(new DateTimeExpression(leftProp, op, XmlConvert.ToDateTime(rightString, XmlDateTimeSerializationMode.Unspecified)));
                }

                try
                {
                    DateTimeAttribute rightAttr = (DateTimeAttribute)rightValue;
                    return(new DateTimeExpression(leftProp, op, rightAttr));
                }
                catch (Exception e) //rethrow
                {
                    throw new ApplicationException(String.Concat("Unrecognized DateTimeAttribute: '", rightValue, "'. Source: ", node.OuterXml), e);
                }
            }
            else
            {
                DateTimeAttribute leftAttr = (DateTimeAttribute)leftValue;
                if (rightValue == null)
                {
                    return(new DateTimeExpression(leftAttr, op, (DateTime?)null));
                }

                PropertyType rightProp = rightValue as PropertyType;
                if (rightProp != null)
                {
                    return(new DateTimeExpression(leftAttr, op, rightProp));
                }

                string rightString = rightValue as String;
                if (rightString != null)
                {
                    return(new DateTimeExpression(leftAttr, op, XmlConvert.ToDateTime(rightString, XmlDateTimeSerializationMode.Unspecified)));
                }

                try
                {
                    DateTimeAttribute rightAttr = (DateTimeAttribute)rightValue;
                    return(new DateTimeExpression(leftAttr, op, rightAttr));
                }
                catch (Exception e) //rethrow
                {
                    throw new ApplicationException(String.Concat("Unrecognized DateTimeAttribute: '", rightValue, "'. Source: ", node.OuterXml), e);
                }
            }
        }
Example #10
0
        private static Expression ParseStringExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            StringOperator op         = ParseStringOperator(node);
            object         leftValue  = ParseLeftValue(node, nsmgr, schema);
            object         rightValue = ParseRightValue(node, nsmgr, schema);

            PropertyType leftProp = leftValue as PropertyType;

            if (leftProp != null)
            {
                if (rightValue == null)
                {
                    return(new StringExpression(leftProp, op, (string)null));
                }

                PropertyType rightProp = rightValue as PropertyType;
                if (rightProp != null)
                {
                    return(new StringExpression(leftProp, op, rightProp));
                }

                string rightString = rightValue as String;
                if (rightString != null)
                {
                    return(new StringExpression(leftProp, op, rightString));
                }

                try
                {
                    StringAttribute rightAttr = (StringAttribute)rightValue;
                    return(new StringExpression(leftProp, op, rightAttr));
                }
                catch (Exception e)                 //rethrow
                {
                    throw new ApplicationException(String.Concat("Unrecognized StringAttribute: '", rightValue, "'. Source: ", node.OuterXml), e);
                }
            }
            else
            {
                StringAttribute leftAttr = (StringAttribute)leftValue;
                if (rightValue == null)
                {
                    return(new StringExpression(leftAttr, op, (string)null));
                }

                PropertyType rightProp = rightValue as PropertyType;
                if (rightProp != null)
                {
                    return(new StringExpression(leftAttr, op, rightProp));
                }

                string rightString = rightValue as String;
                if (rightString != null)
                {
                    return(new StringExpression(leftAttr, op, rightString));
                }

                try
                {
                    StringAttribute rightAttr = (StringAttribute)rightValue;
                    return(new StringExpression(leftAttr, op, rightAttr));
                }
                catch (Exception e)                 //rethrow
                {
                    throw new ApplicationException(String.Concat("Unrecognized StringAttribute: '", rightValue, "'. Source: ", node.OuterXml), e);
                }
            }
        }
Example #11
0
        private static Expression ParseNotExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            XmlNode subNode = node.SelectSingleNode("x:*[1]", nsmgr);

            if (subNode == null)
            {
                throw new InvalidOperationException("NotExpression cannot be empty.");
            }
            return(new NotExpression(ParseExpression(subNode, nsmgr, schema)));
        }
Example #12
0
        private static Expression ParseExpressionList(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            ChainOperator  op       = (ChainOperator)Enum.Parse(typeof(ChainOperator), node.LocalName);
            ExpressionList exprList = new ExpressionList(op);

            foreach (XmlNode subNode in node.SelectNodes("x:*", nsmgr))
            {
                exprList.Add(ParseExpression(subNode, nsmgr, schema));
            }
            return(exprList);
        }
Example #13
0
        private static Expression ParseExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            switch (node.LocalName)
            {
            case "And":
            case "Or":
                return(ParseExpressionList(node, nsmgr, schema));

            case "Not":
                return(ParseNotExpression(node, nsmgr, schema));

            case "String":
                return(ParseStringExpression(node, nsmgr, schema));

            case "Int":
                return(ParseIntExpression(node, nsmgr, schema));

            case "DateTime":
                return(ParseDateTimeExpression(node, nsmgr, schema));

            case "Currency":
                return(ParseCurrencyExpression(node, nsmgr, schema));

            case "Reference":
                return(ParseReferenceExpression(node, nsmgr, schema));

            case "Type":
                return(ParseTypeExpression(node, nsmgr, schema));

            case "FullText":
                return(ParseFullTextExpression(node, nsmgr, schema));

            default:
                throw new NotSupportedException(String.Concat("Unrecognized expression type: ", node.LocalName));
            }
        }
Example #14
0
        private static NodeQuery Parse(string query, SchemaRoot schema)
        {
            if (RepositoryConfiguration.BackwardCompatibilityXmlNamespaces)
            {
                query = query.Replace(NodeQuery.XmlNamespaceOld, NodeQuery.XmlNamespace);
            }

            query = DateTimeParser.GetDateTimeModifiedQuery(query);
            query = ReplaceJScriptTags(query);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(query);

            NodeQueryTemplateReplacer.ReplaceTemplates(doc, TemplateResolvers);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("x", NodeQuery.XmlNamespace);

            CheckValidation(doc);

            //-- Parse root chain
            var rootChain     = doc.DocumentElement.SelectSingleNode("x:*[1]", nsmgr);
            var rootChainType = rootChain.LocalName == "And" ? ChainOperator.And : ChainOperator.Or;

            NodeQuery nodeQuery = new NodeQuery(rootChainType);

            //-- Parse expression tree
            foreach (XmlNode node in rootChain.SelectNodes("x:*", nsmgr))
            {
                nodeQuery.Add(ParseExpression(node, nsmgr, schema));
            }

            //-- Parse orders
            foreach (XmlNode node in doc.DocumentElement.SelectNodes("x:Orders/x:Order", nsmgr))
            {
                nodeQuery.Orders.Add(ParseOrder(node, nsmgr, schema));
            }

            //-- Parse page
            XmlNode pageNode = doc.DocumentElement.SelectSingleNode("x:Page", nsmgr);

            if (pageNode != null)
            {
                //<Page startIndex="987" pageSize="123" />
                XmlAttribute attr = pageNode.Attributes["startIndex"];
                if (attr != null)
                {
                    nodeQuery.StartIndex = Convert.ToInt32(attr.Value, CultureInfo.InvariantCulture);
                }
                attr = pageNode.Attributes["pageSize"];
                if (attr != null)
                {
                    nodeQuery.PageSize = Convert.ToInt32(attr.Value, CultureInfo.InvariantCulture);
                }
            }
            //-- Parse top
            XmlNode topNode = doc.DocumentElement.SelectSingleNode("x:Top", nsmgr);

            if (topNode != null)
            {
                //<Top>5</Top>
                nodeQuery.Top = Convert.ToInt32(topNode.InnerText, CultureInfo.InvariantCulture);
            }

            return(nodeQuery);
        }
 int GetNextMapping(SchemaRoot schema, bool contentList)
 {
     return(Interlocked.Increment(ref _lastMapping));
 }
Example #16
0
 public NodeQuery Parse(string query, SchemaRoot schema)
 {
     return((NodeQuery)CallPrivateStaticMethod("Parse", new Type[] { typeof(string), typeof(SchemaRoot) }, new object[] { query, schema }));
 }