Example #1
0
        bool matchXMLcall(string calltext, bool fuzzy = false)
        {
            var found   = false;
            var matches = false;
            var ctx0    = this;
            var ctx     = this;

            //  If there are precursors, run them first so the result
            //  will be used to match formations
            //  Needed for calls like "Explode And ..."
            if (callstack.Count > 0)
            {
                ctx           = new CallContext(this);
                ctx.callstack = callstack;
                ctx.performCall();
            }

            //  If actives != dancers, create another call context with just the actives
            if (ctx.dancers.Count != ctx.actives.Count)
            {
                ctx = new CallContext(ctx.actives);
            }
            //  Try to find a match in the xml animations
            var callquery = "^" + TamUtils.callnameQuery(calltext) + "$";
            var callfiles = TamUtils.calllistdata.Where(x => Regex.Match(x.text, callquery).Success);
            //  Found xml file with call, now look through each animation
            //  First read and extract all the animations to a list
            var tams = callfiles.SelectMany(d => TamUtils.getXMLAsset(d.link).SelectNodes("/tamination/tam")).ToList();

            found = tams.Count > 0;
            //  Now find the animations that match the name and formation
            tams.Where(tam => Regex.Match(tam.attr("title").ToLower().ReplaceAll("\\W", ""), callquery).Success)
            .Any(tam => {
                var f = tam.hasAttr("formation")
                    ? TamUtils.getFormation(tam.attr("formation"))
                    : tam.SelectNodes("formation").First();
                var ctx2 = new CallContext(f);
                var sexy = tam.hasAttr("gender-specific");
                //  Try to match the formation to the current dancer positions
                var mm = matchFormations(ctx, ctx2, sexy, fuzzy);
                if (mm != null)
                {
                    matches = true;
                    // add XMLCall object to the call stack
                    ctx0.callstack.Add(new XMLCall(tam, mm, ctx2));
                    ctx0.callname = callname + tam.attr("title") + " ";
                }
                return(matches);
            });
            if (found && !matches)
            {
                //  Found the call but formations did not match
                throw new FormationNotFoundError(calltext);
            }
            return(matches);
        }
        private void searchCallList(string query)
        {
            calllistdata.Clear();
            var qq = TamUtils.callnameQuery(query);

            foreach (IXmlNode call in calls)
            {
                var title = (string)call.Attributes.GetNamedItem("title").NodeValue;
                if (Regex.Match(title.ToLower().ReplaceAll("\\W", ""), qq).Success)
                {
                    var sublevel = (string)call.Attributes.GetNamedItem("sublevel").NodeValue;
                    calllistdata.Add(new CallListItem()
                    {
                        Title = (string)call.Attributes.GetNamedItem("title").NodeValue,
                        Level = (string)call.Attributes.GetNamedItem("sublevel").NodeValue,
                        Link  = (string)call.Attributes.GetNamedItem("link").NodeValue
                    });
                }
            }
            CallList.ItemsSource = calllistdata;
        }