private void GenerateSubstGroupMap()
        {
            StringWriter stringWriter = new StringWriter();

            if (_substGroupMapQualified == null)
            {
                _substGroupMapQualified = new Dictionary<XmlQualifiedName, List<SubstitutionGroup>>();
            }

            foreach (MetadataSection mds in _metadataSet.MetadataSections)
            {
                XmlSchema xsd = mds.Metadata as XmlSchema;
                if (xsd != null)
                {
                    foreach (XmlSchemaObject xso in xsd.Items)
                    {
                        if (xso is XmlSchemaElement)
                        {
                            XmlSchemaElement xse = xso as XmlSchemaElement;

                            if (xse.SubstitutionGroup != null && !xse.SubstitutionGroup.IsEmpty)
                            {
                                XmlQualifiedName elemQualName = new XmlQualifiedName(xse.SubstitutionGroup.Name, xse.SubstitutionGroup.Namespace);

                                SubstitutionGroup substGroup = new SubstitutionGroup();
                                substGroup.headElementName = xse.SubstitutionGroup.Name;
                                substGroup.headElementNamespace = xse.SubstitutionGroup.Namespace;
                                substGroup.headElementType = string.Empty;
                                substGroup.substitutableElementName = xse.QualifiedName.Name;
                                substGroup.substitutableElementNamespace = xse.QualifiedName.Namespace;
                                substGroup.isNullable = xse.IsNillable;

                                if (xse.ElementSchemaType.QualifiedName.Name.Length > 0)
                                {
                                    substGroup.substitutableElementType = xse.ElementSchemaType.QualifiedName.Name;
                                }

                                if (!_substGroupMapQualified.ContainsKey(elemQualName))
                                {
                                    _substGroupMapQualified[elemQualName] = new List<SubstitutionGroup>();
                                }

                                _substGroupMapQualified[elemQualName].Add(substGroup);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SetContentFromHandListYaku(ContentControl container, SubstitutionGroup subGroup)
        {
            if (subGroup?.Yakus == null)
            {
                container.Content = new TextBlock
                {
                    Text = "Shanten"
                };
            }
            else
            {
                StackPanel sp = new StackPanel
                {
                    Orientation = Orientation.Vertical,
                    Margin      = new Thickness(5, 0, 0, 0)
                };
                sp.Children.Add(new TextBlock
                {
                    Text       = subGroup.Yakus.FansName,
                    FontSize   = 12,
                    Foreground = System.Windows.Media.Brushes.Red
                });
                if (subGroup.Probability < 1)
                {
                    sp.Children.Add(new TextBlock
                    {
                        Text       = $"Prob. of {Math.Round(subGroup.Probability * 100, 3)} %",
                        FontSize   = 12,
                        Foreground = System.Windows.Media.Brushes.DarkSlateBlue
                    });
                }

                StackPanel spYakus = new StackPanel {
                    Orientation = Orientation.Vertical
                };
                foreach (YakuPivot yaku in subGroup.Yakus.Yakus)
                {
                    spYakus.Children.Add(new TextBlock
                    {
                        Text    = $"{yaku.Name} ({yaku.FansConcealed})",
                        ToolTip = yaku.Description
                    });
                }

                GroupBox gbYakus = new GroupBox {
                    Header = "Yakus", Content = spYakus
                };
                sp.Children.Add(gbYakus);

                if (subGroup.SubstitutionSequences.Any())
                {
                    StackPanel spSubs = new StackPanel {
                        Orientation = Orientation.Vertical
                    };
                    foreach (var sub in subGroup.SubstitutionSequences)
                    {
                        spSubs.Children.Add(new TextBlock
                        {
                            Text = string.Join(", then ", sub.Substitutions.Select(x => $"discard/pick {x.Subbed}/{x.Subber}").ToArray())
                        });
                    }

                    GroupBox gbSubs = new GroupBox {
                        Header = "Potential discards & picks", Content = spSubs
                    };
                    sp.Children.Add(gbSubs);
                }

                container.Content = sp;
            }
        }