コード例 #1
0
        public void ReadFromXmlPack(Stream xmlPackStream, PathableResourceManager pathableResourceManager)
        {
            string xmlPackContents;

            using (var xmlReader = new StreamReader(xmlPackStream)) {
                xmlPackContents = xmlReader.ReadToEnd();
            }

            NanoXml.NanoXmlDocument packDocument = null;

            bool packLoaded = false;

            try {
                packDocument = NanoXmlDocument.LoadFromXml(xmlPackContents);
                packLoaded   = true;
            } catch (XmlException ex) {
                Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} at line: {xmlExceptionLine} position: {xmlExceptionPosition} due to an XML error.", pathableResourceManager.DataReader.GetPathRepresentation(), ex.LineNumber, ex.LinePosition);
            } catch (Exception ex) {
                Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} due to an unexpected exception.", pathableResourceManager.DataReader.GetPathRepresentation());
            }

            if (packLoaded)
            {
                int currentPathablesCount = this.Pathables.Count;

                TryLoadCategories(packDocument);
                TryLoadPOIs(packDocument, pathableResourceManager, Categories);

                Logger.Info("{pathableDelta} pathables were loaded from {pathableResourceManager}.", this.Pathables.Count - currentPathablesCount, pathableResourceManager.DataReader.GetPathRepresentation());
            }
        }
コード例 #2
0
 private void TryLoadCategories(NanoXmlDocument packDocument)
 {
     foreach (var categoryNode in packDocument.RootNode.SelectNodes(PackConstImpl.XML_ELEMENT_MARKERCATEGORY))
     {
         Builder.PathableCategoryBuilder.UnpackCategory(categoryNode, _packCollection.Categories);
     }
 }
コード例 #3
0
ファイル: NppStylers.cs プロジェクト: zhitian/3P
 public void Reload()
 {
     // read npp's stylers.xml file
     try {
         var widgetStyle = new NanoXmlDocument(Utils.ReadAllText(ConfXml.FileNppStylersXml)).RootNode["GlobalStyles"].SubNodes;
         WhiteSpaceFg             = GetColorInStylers(widgetStyle, "White space symbol", "fgColor");
         IndentGuideLineBg        = GetColorInStylers(widgetStyle, "Indent guideline style", "bgColor");
         IndentGuideLineFg        = GetColorInStylers(widgetStyle, "Indent guideline style", "fgColor");
         SelectionBg              = GetColorInStylers(widgetStyle, "Selected text colour", "bgColor");
         CaretLineBg              = GetColorInStylers(widgetStyle, "Current line background colour", "bgColor");
         CaretFg                  = GetColorInStylers(widgetStyle, "Caret colour", "fgColor");
         FoldMarginBg             = GetColorInStylers(widgetStyle, "Fold margin", "bgColor");
         FoldMarginFg             = GetColorInStylers(widgetStyle, "Fold margin", "fgColor");
         FoldMarginMarkerFg       = GetColorInStylers(widgetStyle, "Fold", "fgColor");
         FoldMarginMarkerBg       = GetColorInStylers(widgetStyle, "Fold", "bgColor");
         FoldMarginMarkerActiveFg = GetColorInStylers(widgetStyle, "Fold active", "fgColor");
     } catch (Exception e) {
         ErrorHandler.LogError(e, "Error parsing " + ConfXml.FileNppStylersXml);
         if (!_warnedAboutFailStylers)
         {
             _warnedAboutFailStylers = true;
             UserCommunication.Notify("Error while reading one of Notepad++ file :<div>" + ConfXml.FileNppStylersXml.ToHtmlLink() + "</div><br>The xml isn't correctly formatted, Npp manages to read anyway but you should correct it.", MessageImg.MsgError, "Error reading stylers.xml", "Xml read error");
         }
     }
 }
コード例 #4
0
        public override IRow Transform(IRow row)
        {
            var xml = row[_input] as string;

            if (string.IsNullOrEmpty(xml))
            {
                Increment();
                return(row);
            }

            var count = 0;
            var doc   = new NanoXmlDocument(xml);

            if (_elements.ContainsKey(doc.RootNode.Name))
            {
                var field = _elements[doc.RootNode.Name];
                row[field] = field.Convert(doc.RootNode.Value ?? (field.ReadInnerXml ? doc.RootNode.InnerText() : doc.RootNode.ToString()));
                count++;
            }

            var subNodes = doc.RootNode.SubNodes.ToArray();

            while (subNodes.Any())
            {
                var nextNodes = new List <NanoXmlNode>();
                foreach (var node in subNodes)
                {
                    if (_elements.ContainsKey(node.Name))
                    {
                        var field = _elements[node.Name];
                        count++;
                        var value = node.Value ?? (field.ReadInnerXml ? node.InnerText() : node.ToString());
                        if (!string.IsNullOrEmpty(value))
                        {
                            row[field] = field.Convert(value);
                        }
                    }
                    if (_searchAttributes)
                    {
                        foreach (var attribute in node.Attributes.Where(attribute => _attributes.ContainsKey(attribute.Name)))
                        {
                            var field = _attributes[attribute.Name];
                            count++;
                            if (!string.IsNullOrEmpty(attribute.Value))
                            {
                                row[field] = field.Convert(attribute.Value);
                            }
                        }
                    }
                    if (count < _total)
                    {
                        nextNodes.AddRange(node.SubNodes);
                    }
                }
                subNodes = nextNodes.ToArray();
            }
            Increment();
            return(row);
        }
コード例 #5
0
        private void TryLoadCategories(NanoXmlDocument packDocument)
        {
            var categoryNodes = packDocument.RootNode.SelectNodes("markercategory");

            for (int i = 0; i < categoryNodes.Length; i++)
            {
                Builders.PathingCategoryBuilder.UnpackCategory(categoryNodes[i], Categories);
            }
        }
コード例 #6
0
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows) {
            foreach (var row in rows) {
                if (ShouldRun(row)) {

                    var xml = row[InKey].ToString();
                    if (xml.Equals(string.Empty)) {
                        yield return row;
                        continue;
                    }

                    var count = 0;
                    var doc = new NanoXmlDocument(xml);
                    if (_elements.ContainsKey(doc.RootNode.Name)) {
                        var field = _elements[doc.RootNode.Name];
                        row[field.Alias] = _converter[field.SimpleType](doc.RootNode.Value ?? (field.ReadInnerXml ? doc.RootNode.InnerText() : doc.RootNode.ToString()));
                        count++;
                    }

                    var subNodes = doc.RootNode.SubNodes.ToArray();
                    while (subNodes.Any()) {
                        var nextNodes = new List<NanoXmlNode>();
                        foreach (var node in subNodes) {
                            if (_elements.ContainsKey(node.Name)) {
                                var field = _elements[node.Name];
                                count++;
                                var value = node.Value ?? (field.ReadInnerXml ? node.InnerText() : node.ToString());
                                if (!string.IsNullOrEmpty(value)) {
                                    row[field.Alias] = _converter[field.SimpleType](value);
                                }
                            }
                            if (_searchAttributes) {
                                foreach (var attribute in node.Attributes.Where(attribute => _attributes.ContainsKey(attribute.Name))) {
                                    var field = _attributes[attribute.Name];
                                    count++;
                                    if (!string.IsNullOrEmpty(attribute.Value)) {
                                        row[field.Alias] = _converter[field.SimpleType](attribute.Value);
                                    }
                                }
                            }
                            if (count < _total) {
                                nextNodes.AddRange(node.SubNodes);
                            }
                        }
                        subNodes = nextNodes.ToArray();
                    }
                    yield return row;
                } else {
                    Interlocked.Increment(ref SkipCount);
                    yield return row;
                }
            }
        }
コード例 #7
0
        private async Task TryLoadPois(NanoXmlDocument packDocument)
        {
            foreach (var poisNode in packDocument.RootNode.SelectNodes(PackConstImpl.XML_ELEMENT_POIS))
            {
                for (int i = 0; i < poisNode.SubNodes.Count; i++)
                {
                    var nPathable = await Builder.PathablePrototypeBuilder.UnpackPathableAsync(poisNode.SubNodes[i], _packResourceManager, _packCollection.Categories);

                    if (nPathable != null)
                    {
                        _packCollection.PointsOfInterest.Add(nPathable);
                    }
                }
            }
        }
コード例 #8
0
            /// <summary>
            /// Allows to reload the npp configuration from the files
            /// </summary>
            public void Reload()
            {
                // get the base folder
                FolderBaseConf = FolderNppDefaultBaseConf;
                if (File.Exists(FileNppCloudChoice))
                {
                    var cloudpath = Utils.ReadAllText(FileNppCloudChoice, Encoding.Default);
                    if (Directory.Exists(cloudpath))
                    {
                        FolderBaseConf = cloudpath;
                    }
                }

                // Get info from the config.xml
                FileNppStylersXml = null;

                if (File.Exists(FileNppConfigXml))
                {
                    try {
                        var configs = new NanoXmlDocument(Utils.ReadAllText(FileNppConfigXml)).RootNode["GUIConfigs"].SubNodes;
                        FileNppStylersXml     = configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("stylerTheme")).GetAttribute("path").Value;
                        AutocompletionMode    = int.Parse(configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("auto-completion")).GetAttribute("autoCAction").Value);
                        CustomBackupDirectory = configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("Backup")).GetAttribute("dir").Value;
                        BackupUseCustomDir    = configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("Backup")).GetAttribute("useCustumDir").Value.EqualsCi("yes");
                        BackupMode            = int.Parse(configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("Backup")).GetAttribute("action").Value);
                        MultiSelectionEnabled = configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("ScintillaGlobalSettings")).GetAttribute("enableMultiSelection").Value.EqualsCi("yes");

                        var wordCharListCfg = configs.FirstOrDefault(x => x.GetAttribute("name").Value.Equals("wordCharList"));
                        if (wordCharListCfg != null && wordCharListCfg.GetAttribute("useDefault").Value.EqualsCi("no"))
                        {
                            WordCharList = wordCharListCfg.GetAttribute("charsAdded").Value;
                        }
                    } catch (Exception e) {
                        ErrorHandler.LogError(e, "Error parsing " + FileNppConfigXml);
                    }
                }
                else
                {
                    UserCommunication.Notify("Couldn't find the config.xml file.<br>If this is not your first use of notepad++, please consider opening an issue on 3P", MessageImg.MsgHighImportance, "Reading config.xml", "File not found");
                }

                if (!string.IsNullOrEmpty(FileNppStylersXml) && !File.Exists(FileNppStylersXml))
                {
                    FileNppStylersXml = null;
                }
            }
コード例 #9
0
        private void TryLoadPOIs(NanoXmlDocument packDocument, PathableResourceManager pathableResourceManager, PathingCategory rootCategory)
        {
            var poisNodes = packDocument.RootNode.SelectNodes("pois");

            for (int pSet = 0; pSet < poisNodes.Length; pSet++)
            {
                //ref var poisNode = ref poisNodes[pSet];
                var poisNode = poisNodes[pSet];

                Logger.Info("Found {poiCount} POIs to load.", poisNode.SubNodes.Count());

                for (int i = 0; i < poisNode.SubNodes.Count; i++)
                {
                    Builders.PoiBuilder.UnpackPathable(poisNode.SubNodes[i], pathableResourceManager, rootCategory);
                }
            }
        }
コード例 #10
0
        public async Task <bool> PopulatePackFromString(string xmlPackContents)
        {
            NanoXmlDocument packDocument = null;

            bool packLoaded = false;

            try {
                packDocument = await NanoXmlDocument.LoadFromXmlAsync(xmlPackContents, this.PackReaderSettings);

                packLoaded = true;
            } catch (NanoXmlParsingException e) {
                //Logger.Warn(e, $"Failed to successfully parse TacO overlay file.");
            } catch (Exception e) {
                //Logger.Warn(e, "Could not load TacO overlay file due to an unexpected exception.");
            }

            if (packLoaded)
            {
                TryLoadCategories(packDocument);
                await TryLoadPois(packDocument);
            }

            return(packLoaded);
        }
コード例 #11
0
ファイル: NppLang.cs プロジェクト: massreuy/3P
            /// <summary>
            /// Returns this after checking if we need to read the Api xml file for this language
            /// </summary>
            public LangDescription ReadApiFileIfNeeded()
            {
                var apiFilePath = Path.Combine(Npp.FolderNppAutocompApis, LangName + ".xml");

                if (_keywords != null &&
                    !Utils.HasFileChanged(apiFilePath) &&
                    (!IsUserLang || !Utils.HasFileChanged(Npp.ConfXml.FileNppUserDefinedLang)))
                {
                    return(this);
                }

                _autoCompletionItems = null;
                _keywords            = new List <NppKeyword>();
                var uniqueKeywords = new HashSet <string>(StringComparer.CurrentCultureIgnoreCase);

                // get keywords from plugins/Apis/
                // FORMAT :
                // <AutoComplete language="C++">
                //    <Environment ignoreCase="no" startFunc="(" stopFunc=")" paramSeparator="," terminal=";" additionalWordChar = "."/>
                //    <KeyWord name="abs" func="yes">
                //        <Overload retVal="int" descr="Returns absolute value of given integer">
                //            <Param name="int number" />
                //        </Overload>
                //    </KeyWord>
                // </AutoComplete>
                try {
                    if (File.Exists(apiFilePath))
                    {
                        var xml = new NanoXmlDocument(Utils.ReadAllText(apiFilePath));
                        foreach (var keywordElmt in xml.RootNode["AutoComplete"].SubNodes.Where(node => node.Name.Equals("KeyWord")))
                        {
                            var attr = keywordElmt.GetAttribute("name");
                            if (attr == null)
                            {
                                continue;
                            }
                            var keyword = attr.Value;

                            if (!uniqueKeywords.Contains(keyword))
                            {
                                uniqueKeywords.Add(keyword);
                                List <NppKeyword.NppOverload> overloads = null;
                                foreach (var overload in keywordElmt.SubNodes.Where(node => node.Name.Equals("Overload")))
                                {
                                    if (overloads == null)
                                    {
                                        overloads = new List <NppKeyword.NppOverload>();
                                    }
                                    var xAttribute = overload.GetAttribute("retVal");
                                    var retVal     = xAttribute != null ? xAttribute.Value : string.Empty;
                                    xAttribute = overload.GetAttribute("descr");
                                    var descr      = xAttribute != null ? xAttribute.Value : string.Empty;
                                    var parameters = new List <string>();
                                    foreach (var para in overload.SubNodes.Where(node => node.Name.Equals("Param")))
                                    {
                                        var attrname = para.GetAttribute("name");
                                        if (attrname == null)
                                        {
                                            continue;
                                        }
                                        parameters.Add(attrname.Value);
                                    }
                                    overloads.Add(new NppKeyword.NppOverload {
                                        ReturnValue = retVal,
                                        Description = descr,
                                        Params      = parameters
                                    });
                                }

                                _keywords.Add(new NppKeywordApis(keyword, this)
                                {
                                    Overloads = overloads,
                                    Origin    = NppKeywordOrigin.Api
                                });
                            }
                        }

                        // get other info on the language
                        var envElement = xml.RootNode["AutoComplete"]["Environment"];
                        if (envElement != null)
                        {
                            LoadFromAttributes(this, envElement);
                            if (!string.IsNullOrEmpty(additionalWordChar))
                            {
                                AdditionalWordChar = additionalWordChar.ToArray();
                            }
                        }
                    }
                } catch (Exception e) {
                    ErrorHandler.LogError(e, "Error parsing " + apiFilePath);
                }

                // get core keywords from langs.xml or userDefinedLang.xml

                if (IsUserLang)
                {
                    try {
                        var langElement = new NanoXmlDocument(Utils.ReadAllText(Npp.ConfXml.FileNppUserDefinedLang)).RootNode.SubNodes.FirstOrDefault(x => x.GetAttribute("name").Value.EqualsCi(LangName));
                        if (langElement != null)
                        {
                            // get the list of keywords from userDefinedLang.xml
                            foreach (var descendant in langElement["KeywordLists"].SubNodes)
                            {
                                var xAttribute = descendant.GetAttribute(@"name");
                                if (xAttribute != null && xAttribute.Value.StartsWith("keywords", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    foreach (var keyword in WebUtility.HtmlDecode(descendant.Value).Replace('\r', ' ').Replace('\n', ' ').Split(' '))
                                    {
                                        if (!string.IsNullOrEmpty(keyword) && !uniqueKeywords.Contains(keyword))
                                        {
                                            uniqueKeywords.Add(keyword);
                                            _keywords.Add(new NppKeywordUserLangs(keyword, this)
                                            {
                                                Origin = NppKeywordOrigin.UserLangs
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        ErrorHandler.LogError(e, "Error parsing " + Npp.ConfXml.FileNppUserDefinedLang);
                    }
                }
                else
                {
                    try {
                        var langElement = new NanoXmlDocument(Utils.ReadAllText(Npp.ConfXml.FileNppLangsXml)).RootNode["Languages"].SubNodes.FirstOrDefault(x => x.GetAttribute("name").Value.EqualsCi(LangName));
                        if (langElement != null)
                        {
                            // get the list of keywords from langs.xml
                            foreach (var descendant in langElement.SubNodes)
                            {
                                foreach (var keyword in WebUtility.HtmlDecode(descendant.Value).Split(' '))
                                {
                                    if (!string.IsNullOrEmpty(keyword) && !uniqueKeywords.Contains(keyword))
                                    {
                                        uniqueKeywords.Add(keyword);
                                        _keywords.Add(new NppKeywordLangs(keyword, this)
                                        {
                                            Origin = NppKeywordOrigin.Langs
                                        });
                                    }
                                }
                            }

                            // get other info on the language (comentLine, commentStart, commentEnd)
                            LoadFromAttributes(this, langElement);
                        }
                    } catch (Exception e) {
                        ErrorHandler.LogError(e, "Error parsing " + Npp.ConfXml.FileNppLangsXml);
                    }
                }

                return(this);
            }
コード例 #12
0
        public void Load()
        {
            NanoXmlDocument doc = NanoXmlDocument.LoadFromFile(filename);

            xml = doc.DocumentElement;
        }
コード例 #13
0
        private void LoadFile()
        {
            loadTime = 0;
            LoadTimer       timer = new LoadTimer("XML Parsing");
            NanoXmlDocument xml   = NanoXmlDocument.LoadFromFile(filename);

            loadTime += timer.Stop();
            timer     = new LoadTimer("Items Processing");

            NanoXmlElement doc   = xml.DocumentElement;
            NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"];

            modules.Clear();
            namespaces.Clear();
            namespacesObfuscated.Clear();
            classes.Clear();
            classesCache.Clear();
            haveSystemEntities = false;
            methodsCount       = classesCount = subclassesCount = skippedCount = 0;
            lastModified       = File.GetLastWriteTime(filename);

            List <RenamedClass> subclasses = new List <RenamedClass>();

            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0)
                    {
                        RenamedClass c = new RenamedClass(element, this);
                        classesCount++;
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                            if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null)
                            {
                                haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System.");
                            }
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        methodsCount += c.MethodsCount;

                        if (c.ModuleNew != null)
                        {
                            modules.Add(c.ModuleNew);
                        }
                        if (c.Name.NameOld != null)
                        {
                            classesCache[c.NameOld]     = c;
                            classesCache[c.NameOldFull] = c;

                            if (!string.IsNullOrEmpty(c.Name.NameOld.Namespace))
                            {
                                namespaces.Add(c.Name.NameOld.Namespace);
                            }
                        }
                        if (c.Name.NameNew != null)
                        {
                            classesCache[c.NameNew]     = c;
                            classesCache[c.NameNewFull] = c;

                            if (!string.IsNullOrEmpty(c.Name.NameNew.Namespace))
                            {
                                namespacesObfuscated.Add(c.Name.NameNew.Namespace);
                            }
                        }
                    }
                }
            }

            types = (NanoXmlElement)doc["skippedTypes"];
            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0)
                    {
                        skippedCount++;
                        classesCount++;
                        RenamedClass c = new RenamedClass(element, this);
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        classesCache[c.NameOld]     = c;
                        classesCache[c.NameOldFull] = c;
                    }
                }
            }

            loadTime += timer.Stop();
            timer     = new LoadTimer("Subclasses Processing");

            foreach (RenamedClass subclass in subclasses)
            {
                RenamedClass c;
                if (classesCache.TryGetValue(subclass.OwnerClassName, out c))
                {
                    c.Items.Add(subclass);
                    subclass.OwnerClass = c;
                    subclassesCount++;
                    continue;
                }

                Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName);
                classes.Add(subclass);
            }

            loadTime += timer.Stop();
            timer     = new LoadTimer("Values Updating");

            foreach (RenamedClass c in classes)
            {
                c.UpdateNewNames(this);
            }

            loadTime += timer.Stop();
            Debug.WriteLine("Total Elapsed: {0} ms", loadTime);
        }
コード例 #14
0
        private void LoadFile()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            NanoXmlDocument xml = NanoXmlDocument.LoadFromFile(filename);

            timingXML = sw.ElapsedMilliseconds;
            Debug.WriteLine("XML Loading: " + timingXML + " ms");
            sw.Reset();
            sw.Start();

            NanoXmlElement doc   = xml.DocumentElement;
            NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"];

            modules.Clear();
            namespaces.Clear();
            namespacesObfuscated.Clear();
            classes.Clear();
            haveSystemEntities = false;
            methodsCount       = classesCount = subclassesCount = skippedCount = 0;
            lastModified       = File.GetLastWriteTime(filename);

            List <RenamedClass> subclasses = new List <RenamedClass>();

            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0)
                    {
                        RenamedClass c = new RenamedClass(element, this);
                        classesCount++;
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                            if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null)
                            {
                                haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System.");
                            }
                        }
                        else
                        {
                            subclasses.Add(c);
                        }

                        methodsCount += c.MethodsCount;
                        if (c.ModuleNew != null && !modules.Contains(c.ModuleNew))
                        {
                            modules.Add(c.ModuleNew);
                        }
                        if (c.Name.NameOld != null && !string.IsNullOrEmpty(c.Name.NameOld.Namespace) && !namespaces.Contains(c.Name.NameOld.Namespace))
                        {
                            namespaces.Add(c.Name.NameOld.Namespace);
                        }
                        if (c.Name.NameNew != null && !string.IsNullOrEmpty(c.Name.NameNew.Namespace) && !namespacesObfuscated.Contains(c.Name.NameNew.Namespace))
                        {
                            namespacesObfuscated.Add(c.Name.NameNew.Namespace);
                        }
                    }
                }
            }

            types = (NanoXmlElement)doc["skippedTypes"];
            if (types != null)
            {
                foreach (NanoXmlElement element in types.ChildElements)
                {
                    if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0)
                    {
                        skippedCount++;
                        classesCount++;
                        RenamedClass c = new RenamedClass(element, this);
                        if (c.OwnerClassName == null)
                        {
                            classes.Add(c);
                        }
                        else
                        {
                            subclasses.Add(c);
                        }
                    }
                }
            }


            timingParsing = sw.ElapsedMilliseconds;
            Debug.WriteLine("Parsing: " + timingParsing + " ms");
            sw.Reset();
            sw.Start();

            foreach (RenamedClass subclass in subclasses)
            {
                RenamedClass c = (RenamedClass)SearchForOldName(subclass.OwnerClassName);
                if (c == null)
                {
                    c = (RenamedClass)SearchForNewName(subclass.OwnerClassName);
                }

                if (c != null)
                {
                    c.Items.Add(subclass);
                    subclass.OwnerClass = c;
                    subclassesCount++;
                    continue;
                }

                Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName);
                classes.Add(subclass);
            }

            timingSubclasses = sw.ElapsedMilliseconds;
            Debug.WriteLine("Subclasses processing: " + timingSubclasses + " ms");
            sw.Reset();
            sw.Start();

            foreach (RenamedClass c in classes)
            {
                c.UpdateNewNames(this);
            }

            timingUpdateNewNames = sw.ElapsedMilliseconds;
            Debug.WriteLine("Values updating: " + timingUpdateNewNames + " ms");
            Debug.WriteLine("Total elapsed: " + TimingTotal + " ms");
            sw.Stop();
        }
コード例 #15
0
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            foreach (var row in rows)
            {
                if (ShouldRun(row))
                {
                    var xml = row[InKey].ToString();
                    if (xml.Equals(string.Empty))
                    {
                        yield return(row);

                        continue;
                    }

                    var count = 0;
                    var doc   = new NanoXmlDocument(xml);
                    if (_elements.ContainsKey(doc.RootNode.Name))
                    {
                        var field = _elements[doc.RootNode.Name];
                        row[field.Alias] = _converter[field.SimpleType](doc.RootNode.Value ?? (field.ReadInnerXml ? doc.RootNode.InnerText() : doc.RootNode.ToString()));
                        count++;
                    }

                    var subNodes = doc.RootNode.SubNodes.ToArray();
                    while (subNodes.Any())
                    {
                        var nextNodes = new List <NanoXmlNode>();
                        foreach (var node in subNodes)
                        {
                            if (_elements.ContainsKey(node.Name))
                            {
                                var field = _elements[node.Name];
                                count++;
                                var value = node.Value ?? (field.ReadInnerXml ? node.InnerText() : node.ToString());
                                if (!string.IsNullOrEmpty(value))
                                {
                                    row[field.Alias] = _converter[field.SimpleType](value);
                                }
                            }
                            if (_searchAttributes)
                            {
                                foreach (var attribute in node.Attributes.Where(attribute => _attributes.ContainsKey(attribute.Name)))
                                {
                                    var field = _attributes[attribute.Name];
                                    count++;
                                    if (!string.IsNullOrEmpty(attribute.Value))
                                    {
                                        row[field.Alias] = _converter[field.SimpleType](attribute.Value);
                                    }
                                }
                            }
                            if (count < _total)
                            {
                                nextNodes.AddRange(node.SubNodes);
                            }
                        }
                        subNodes = nextNodes.ToArray();
                    }
                    yield return(row);
                }
                else
                {
                    Interlocked.Increment(ref SkipCount);
                    yield return(row);
                }
            }
        }