public CatalogSearchResultViewModel(DefInfo ruleAppDef, RuleSetDef ruleSetDef, string matchedValue, CatalogSearchSettings settings, RuleElementDef ruleDef = null)
        {
            RuleAppName  = ruleAppDef.Name + " v" + ruleAppDef.PublicRevision;
            RuleSetName  = ruleSetDef.AuthoringElementPath;
            MatchedValue = matchedValue;
            //TODO: The way we're navigating to the item does not work properly - add this back in once that works
            IsInCurrentRuleApp = false;// settings.CurrentRuleApp != null && ruleAppDef.Key.Guid == settings.CurrentRuleApp.Value;

            RuleSetDef = ruleSetDef;

            if (ruleDef != null)
            {
                RuleElementName = ruleDef.AuthoringElementPath;
                RuleDef         = ruleDef;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create SetDict frome def element and def info.
        /// </summary>
        /// <param name="defElement"></param>
        /// <param name="defInfo"></param>
        public SetDict(XElement defElement, DefInfo defInfo)
        {
            if (defElement == null)
            {
                throw new ArgumentNullException("defElement");
            }

            if (defInfo == null)
            {
                throw new ArgumentNullException("defInfo");
            }

            this.defType = defElement.Name.ToString();
            this.defName =
                defElement.Element("defName") == null ?
                "UnnamedDef" :
                defElement.Element("defName").Value;
            this.dict = new Dictionary <string, string>();

            LinkedList <XElement> linkedElements = new LinkedList <XElement>();

            linkedElements.AddLast(defElement);

            foreach (TagInfo curTagInfo in defInfo.Tags)
            {
                string curName      = curTagInfo.Name;
                string curClassName = curTagInfo.ClassName;
                bool   isMatched    = false;
                foreach (XElement curTagElement in defElement.Elements())
                {
                    if (curTagElement.Name.ToString() == curName &&
                        curTagElement.GetClassName() == curClassName)
                    {
                        isMatched = true;
                        linkedElements.AddLast(curTagElement);
                        this.AddMatched(linkedElements, curTagInfo);
                        linkedElements.RemoveLast();
                    }
                }
                if (!isMatched)
                {
                    this.AddNonMatched(curTagInfo);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create wiki data from definition data and template capture.
        /// </summary>
        /// <param name="coreDefinitionData"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        public static WikiData Parse(DefinitionData coreDefinitionData, Capture template, params InjectionData[] injectionDatas)
        {
            if (!coreDefinitionData.IsProcessedFieldNames)
            {
                throw new ArgumentException("Non-processed definition data.", "definitionData");
            }

            if (!template.IsTemplate)
            {
                throw new ArgumentException("Used non-template capture", "template");
            }

            Log.Info();
            Log.Write("Start parsing Core Defs and Template Capture to generating ");
            Log.Write(ConsoleColor.Cyan, "Wiki Data");
            Log.WriteLine(".");

            WikiData wikiData = new WikiData();

            int countSetDicts = 0;

            coreDefinitionData = new DefinitionData(coreDefinitionData);

            Dictionary <string, List <XElement> > unnamedDefsDict = new Dictionary <string, List <XElement> >();

            foreach (XElement curDefElement in from doc in coreDefinitionData.Data.Values
                     from ele in doc.Root.Elements()
                     where ele.Attribute("Abstract") == null
                     select ele)
            {
                string   curDefType = curDefElement.Name.ToString();
                XElement defName    = curDefElement.Element("defName");
                string   curPageName;
                if (defName == null)
                {
                    int             count_curUnnamedDefs;
                    List <XElement> curUnnamedDefsList;
                    if (unnamedDefsDict.TryGetValue(curDefType, out curUnnamedDefsList))
                    {
                        count_curUnnamedDefs = curUnnamedDefsList.Count;
                        curUnnamedDefsList.Add(curDefElement);
                    }
                    else
                    {
                        count_curUnnamedDefs = 0;
                        curUnnamedDefsList   = new List <XElement>();
                        curUnnamedDefsList.Add(curDefElement);
                        unnamedDefsDict.Add(curDefType, curUnnamedDefsList);
                    }
                    curPageName = $"Defs_{curDefType}_UnnamedDef_{count_curUnnamedDefs}";
                }
                else
                {
                    curPageName = $"Defs_{curDefType}_{defName.Value}";
                }

                Inject(curDefElement, injectionDatas);
                DefInfo curDefInfo = template.Def(curDefElement);
                if (curDefInfo == null)
                {
                    Log.Warning();
                    Log.WriteLine($"'{curPageName}' no matched DefInfo.");
                    continue;
                }
                if (!curDefInfo.IsValid)
                {
                    Log.Warning();
                    Log.WriteLine($"'{curPageName}' matched invalid DefInfo.");
                    continue;
                }
                SetDict curSetDict = new SetDict(curDefElement, curDefInfo);

                SortedDictionary <string, SetDict> curSubDict;
                if (wikiData.allSetDict.TryGetValue(curDefType, out curSubDict))
                {
                    if (curSubDict.ContainsKey(curPageName))
                    {
                        Log.Warning();
                        Log.WriteLine($"Duplicated SetDict '{curPageName}'.");
                        curSubDict[curPageName] = curSetDict;
                    }
                    else
                    {
                        curSubDict.Add(curPageName, curSetDict);
                    }
                }
                else
                {
                    curSubDict = new SortedDictionary <string, SetDict>();
                    curSubDict.Add(curPageName, curSetDict);
                    wikiData.allSetDict.Add(curDefType, curSubDict);
                }
                countSetDicts++;
            }

            Log.Info();
            Log.WriteLine($"Complete generating wiki data: {wikiData.allSetDict.Count} DefTypes, {countSetDicts} SetDicts.");

            return(wikiData);
        }
Exemplo n.º 4
0
        static public string Process(FileInfo[] files, string language, string txpath, int searchdepth, bool showrepeats, bool showerrorsonly)             // overall index of items
        {
            string            locals  = "";
            List <Definition> idsdone = new List <Definition>();

            BaseUtils.Translator trans = BaseUtils.Translator.Instance;

            if (language.HasChars() && txpath.HasChars())
            {
                trans.LoadTranslation(language, System.Globalization.CultureInfo.CurrentCulture, new string[] { txpath }, searchdepth, Path.GetTempPath(), loadorgenglish: true);

                if (trans.Translating)
                {
                    Console.WriteLine("Loaded translation " + language + " to compare against");
                }
                else
                {
                    Console.WriteLine("Translation for " + language + " Not found");
                    return("");
                }
            }
            else
            {
                Console.WriteLine("No translation comparision given");
            }

            if (!trans.Translating)
            {
                locals += "********************* TRANSLATION NOT LOADED" + Environment.NewLine;
            }

            foreach (var fi in files)
            {
                var utc8nobom = new UTF8Encoding(false);                           // give it the default UTF8 no BOM encoding, it will detect BOM or UCS-2 automatically

                using (StreamReader sr = new StreamReader(fi.FullName, utc8nobom)) // read directly from file.. presume UTF8 no bom
                {
                    List <string> classes      = new List <string>();
                    List <string> baseclasses  = new List <string>();
                    List <int>    classeslevel = new List <int>();
                    Dictionary <string, DefInfo> winformdefs = new Dictionary <string, DefInfo>();

                    int bracketlevel = 0;

                    bool donelocaltitle = false;

                    string line, previoustext = "";
                    int    lineno = 0;

                    string dropdown = null;

                    while ((line = sr.ReadLine()) != null)
                    {
                        lineno++;

                        int startpos = previoustext.Length;

                        string combined = previoustext + line;

                        while (true)
                        {
                            int txpos     = combined.IndexOf(".T(", startpos);
                            int txposcond = combined.IndexOf(".TCond(", startpos);

                            if (txpos == -1 && txposcond == -1)     // if nothing, stop
                            {
                                break;
                            }

                            Tuple <string, string> ret = null;
                            string localtext           = "";

                            if (txposcond != -1 && (txpos == -1 || txposcond < txpos))                  // if txposcond set, AND txpos is not there, or its less than it
                            {
                                StringParser s0 = new StringParser(combined, txposcond);
                                if (s0.NextWordComma() != null)     // waste text up to comma
                                {
                                    string english = s0.NextQuotedWordComma();
                                    if (english != null)
                                    {
                                        string identifier = s0.NextWord(" )");

                                        if (identifier != null && identifier.StartsWith("EDTx."))
                                        {
                                            identifier = identifier.Substring(5).Replace("_", ".");
                                            ret        = new Tuple <string, string>(identifier, english);
                                        }
                                    }
                                }

                                startpos = txposcond + 7;
                            }
                            else
                            {
                                ret = ProcessTLine(combined, line, txpos, txpos + 3, false);
                                if (ret == null)
                                {
                                    localtext = fi.FullName + ":" + lineno + ":Miss formed line around " + combined.Mid(txpos, 30) + Environment.NewLine;
                                }

                                startpos = txpos + 3;     // skip over it
                            }

                            if (ret != null)
                            {
                                System.Diagnostics.Debug.WriteLine("{0} Check {1} {2}", lineno, ret.Item1, ret.Item2);
                                string id        = ret.Item1;
                                string engquoted = ret.Item2.AlwaysQuoteString();

                                Definition def = idsdone.Find(x => x.token.Equals(ret.Item1, StringComparison.InvariantCultureIgnoreCase));

                                string res = null;

                                if (def != null)        // if previously did the def..
                                {
                                    if (def.text != ret.Item2)
                                    {
                                        res = "Different Text: " + id + " at " + fi.FullName + ":" + lineno + Environment.NewLine + "   >> " + ret.Item2.AlwaysQuoteString() + " orginal " + def.text.AlwaysQuoteString() + " at " + def.firstdeflocation;
                                    }
                                    else if (showrepeats)       // if showrepeats is off, then no output, since we already done it
                                    {
                                        res = "Repeat: " + id + " at " + fi.FullName + ":" + lineno + " " + engquoted;
                                    }
                                }
                                else
                                {
                                    idsdone.Add(new Definition(id, ret.Item2, fi.FullName + ":" + lineno));

                                    if (trans.IsDefined(id))
                                    {
                                        if (!showerrorsonly)
                                        {
                                            res = id + ": " + engquoted + " @";     // list it
                                        }
                                        string foreign = trans.GetTranslation(id);
                                        string english = trans.GetOriginalEnglish(id);
                                        english = english.EscapeControlChars();

                                        if (english != ret.Item2)
                                        {
                                            res = "Translator Difference: " + id + " at " + fi.FullName + ":" + lineno + Environment.NewLine +
                                                  "     >> English differs from \"" + ret.Item2 + "\" vs \"" + english + "\"";
                                        }
                                    }
                                    else if (trans.Translating)       // if we are checking translation, do it..
                                    {
                                        res = ".T( Missing: " + id + " at " + fi.FullName + ":" + lineno + " => " + engquoted + " @";
                                    }
                                }

                                if (res != null)
                                {
                                    res      += Environment.NewLine;
                                    localtext = res;
                                }
                            }


                            if (localtext.HasChars())
                            {
                                if (!donelocaltitle)
                                {
                                    string text = "///////////////////////////////////////////////////// " + (classes.Count > 0 ? classes[0] : "?") + " in " + fi.Name + Environment.NewLine;
                                    locals        += text;
                                    donelocaltitle = true;
                                }
                                locals += localtext;
                            }
                        }

                        previoustext += line;
                        if (previoustext.Length > 20000)
                        {
                            previoustext = previoustext.Substring(10000);
                        }


                        line = line.Trim();

                        int clspos = line.IndexOf("partial class ");
                        if (clspos == -1)
                        {
                            clspos = line.IndexOf("public class ");
                        }
                        if (clspos == -1)
                        {
                            clspos = line.IndexOf("abstract class ");
                        }
                        if (clspos == -1)
                        {
                            clspos = line.IndexOf("static class ");
                        }

                        if (clspos >= 0)
                        {
                            StringParser sp = new StringParser(line, clspos);
                            sp.NextWord(" ");
                            sp.NextWord(" ");
                            classes.Add(sp.NextWord(":").Trim());
                            baseclasses.Add(sp.IsCharMoveOn(':') ? sp.NextWord(",") : null);
                            classeslevel.Add(bracketlevel);
                            // System.Diagnostics.Debug.WriteLine(lineno + " {" + bracketlevel * 4 + " Push " + classes.Last() + " " + baseclasses.Last());
                        }

                        if (line.StartsWith("{"))
                        {
                            if (line.Length == 1 || !line.Substring(1).Trim().StartsWith("}"))
                            {
                                //  System.Diagnostics.Debug.WriteLine(lineno + " {" + bracketlevel * 4);
                                bracketlevel++;
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(lineno + " Rejected {" + bracketlevel * 4);
                            }
                        }

                        if (line.StartsWith("}"))
                        {
                            if (line.Length == 1 || line.Substring(1).Trim()[0] == '/' || line.Substring(1).Trim()[0] == ';')
                            {
                                if (classeslevel.Count > 0 && classeslevel.Last() == bracketlevel - 1)
                                {
                                    //   System.Diagnostics.Debug.WriteLine(lineno + " Pop {" + (bracketlevel-1) * 4 + " " + classes.Last());
                                    classes.RemoveAt(classes.Count - 1);
                                    classeslevel.RemoveAt(classeslevel.Count - 1);
                                    baseclasses.RemoveAt(baseclasses.Count - 1);
                                }
                                bracketlevel--;
                                //System.Diagnostics.Debug.WriteLine(lineno + " }" + bracketlevel * 4);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(lineno + " Rejected }" + bracketlevel * 4);
                            }
                        }

                        if (line.StartsWith("this.") && fi.Name.Contains("Designer", StringComparison.InvariantCultureIgnoreCase))
                        {
                            StringParser sp          = new StringParser(line, 5);
                            string       controlname = sp.NextWord(".=,()} ");
                            string       propname    = sp.IsCharMoveOn('.') ? sp.NextWord(".=,()} ") : null;
                            string       value       = null; // value used to indicate we have a id

                            System.Diagnostics.Debug.WriteLine(lineno + " This. " + controlname + " . " + propname);

                            if (dropdown != null)
                            {
                                System.Diagnostics.Debug.WriteLine(">> Drop down " + dropdown + " " + sp.LineLeft);

                                DefInfo di = winformdefs.ContainsKey(controlname) ? winformdefs[controlname] : null;

                                if (di != null)
                                {
                                    di.parent = dropdown;
                                }

                                if (sp.Find("});"))
                                {
                                    dropdown = null;
                                }
                            }
                            else if (propname == "DropDownItems")
                            {
                                System.Diagnostics.Debug.WriteLine("Found drop down " + sp.LineLeft);
                                dropdown = controlname;
                            }
                            else if (propname == "SetToolTip" && sp.IsCharMoveOn('('))
                            {
                                if (sp.NextWord(".") == "this" && sp.IsCharMoveOn('.'))
                                {
                                    controlname = sp.NextWord(".=,()} ") + ".ToolTip";
                                    if (sp.IsCharMoveOn(','))
                                    {
                                        value = sp.NextQuotedWord();
                                    }
                                }
                            }
                            else if (propname == "HeaderText" && sp.IsCharMoveOn('='))
                            {
                                value = sp.NextQuotedWord();
                            }
                            else if (controlname != "Text" && propname == null && sp.IsCharMoveOn('=')) // this.control =
                            {
                                if (sp.NextWord() == "new")                                             // this.name = new..
                                {
                                    winformdefs[controlname] = new DefInfo()
                                    {
                                        newtype = sp.NextWord(";")
                                    };
                                    System.Diagnostics.Debug.WriteLine("Def " + controlname + " " + winformdefs[controlname]);
                                }
                            }
                            else if ((controlname == "Text" && propname == null && sp.IsCharMoveOn('=')) || (propname != null && propname == "Text" && sp.IsCharMoveOn('=')))
                            {
                                value = sp.NextQuotedWord();

                                bool ok = true;

                                if (controlname != "Text")
                                {
                                    DefInfo di = winformdefs.ContainsKey(controlname) ? winformdefs[controlname] : null;

                                    if (di != null)
                                    {
                                        string[] excluded = new string[]
                                        {
                                            "ComboBoxCustom", "NumberBoxDouble", "NumberBoxLong", "VScrollBarCustom",         // Controls not for translation..
                                            "StatusStripCustom", "RichTextBoxScroll", "TextBoxBorder", "AutoCompleteTextBox", "DateTimePicker", "NumericUpDownCustom",
                                            "Panel", "DataGridView", "GroupBox", "SplitContainer", "LinkLabel"
                                        };

                                        ok = Array.FindIndex(excluded, (xx) => di.newtype.Contains(xx)) == -1;

                                        if (di.parent != null)
                                        {
                                            DefInfo dip = winformdefs.ContainsKey(di.parent) ? winformdefs[di.parent] : null;       // double deep ..
                                            controlname = (dip != null && dip.parent != null ? (dip.parent + ".") : "") + di.parent + "." + controlname;
                                        }
                                    }
                                }
                                else
                                {
                                    controlname = "";
                                }

                                if (!ok)
                                {
                                    value = null;
                                }
                            }

                            if (value != null && value != "<code>" && value != "")
                            {
                                string classname = (classes.Count > 0) ? classes.Last() : "ERROR NO CLASS!";
                                string id        = classname + (controlname.HasChars() ? "." + controlname : "");
                                string res       = id + ": " + value.AlwaysQuoteString() + " @";

                                if (trans.IsDefined(id))
                                {
                                    string foreign = trans.GetTranslation(id);
                                    string english = trans.GetOriginalEnglish(id);
                                    english = english.EscapeControlChars();

                                    if (english != value)
                                    {
                                        res = "Translator difference: " + id + " // English differs from \"" + value + "\" vs \"" + english + "\"";
                                    }
                                    else if (showerrorsonly)
                                    {
                                        res = null;
                                    }
                                }
                                else if (trans.Translating)       // if we are checking translation, do it..
                                {
                                    res = "Designer Missing: " + res;
                                }

                                if (res != null)
                                {
                                    if (!donelocaltitle)
                                    {
                                        string text = "///////////////////////////////////////////////////// " + (classes.Count > 0 ? classes[0] : "?") + " in " + fi.Name + Environment.NewLine;
                                        locals        += text;
                                        donelocaltitle = true;
                                    }

                                    locals += res + Environment.NewLine;
                                }
                            }
                        }
                    }
                }
            }

            return(locals);
        }