Ejemplo n.º 1
0
        public void ExposingXmlFragment()
        {
            string xml = @"
<library>
  <book genre='novel' ISBN='1-861001-57-5'>
     <title>Pride And Prejudice</title>
  </book>
  <book genre='novel' ISBN='1-81920-21-2'>
     <title>Hook</title>
  </book>
</library>";

            XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

            // <library>
            nav.MoveToFirstChild();
            // <book>
            nav.MoveToFirstChild();

            // Enable fragment reading.
            XPathNavigatorReader reader = new XPathNavigatorReader(nav, true);

            reader.MoveToContent();
            string books = reader.ReadFragmentXml();

            Assert.AreEqual(
                "<book genre=\"novel\" ISBN=\"1-861001-57-5\"><title>Pride And Prejudice</title></book><book genre=\"novel\" ISBN=\"1-81920-21-2\"><title>Hook</title></book>",
                books);
        }
Ejemplo n.º 2
0
        public void ValueAs()
        {
            string         xml = "<root>1</root>";
            XPathNavigator nav = new XPathDocument(XmlReader.Create(new StringReader(xml))).CreateNavigator();

            nav.MoveToFirstChild();
            nav.MoveToFirstChild();
            Assert.AreEqual("1", nav.ValueAs(typeof(string), null), "#1");
            Assert.AreEqual(1, nav.ValueAs(typeof(int), null), "#2");
        }
Ejemplo n.º 3
0
        private bool TryGetXmlFragment(string fragment, out XPathNavigator doc)
        {
            var settings = new XmlReaderSettings
            {
                ConformanceLevel = ConformanceLevel.Fragment,
                Async            = true
            };

            // Fixes open elements
            fragment = fragment
                       .Replace("/>", ">")
                       .Replace(">", "/>");

            try
            {
                var reader = XmlReader.Create(new StringReader(fragment), settings);
                doc = new XPathDocument(reader).CreateNavigator();
                doc.MoveToFirstChild();

                return(true);
            }
            catch (Exception)
            {
                doc = null;
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary />
        public static void SelectChildrenSpeed(int it)
        {
            int            iterations = (int)it;
            long           start;
            long           end;
            XPathNavigator context = new XPathDocument(@"..\data.xml").CreateNavigator();

            context.MoveToFirstChild();
            XPathExpression     expr = context.Compile("child::sch:assert");
            XmlNamespaceManager mgr  = new XmlNamespaceManager(context.NameTable);

            mgr.AddNamespace("dv", "deverest:schemas");
            mgr.AddNamespace("sch", Schema.Namespace);
            expr.SetContext(mgr);

            start = DateTime.Now.Ticks;
            for (int i = 0; i < iterations; i++)
            {
                context.Select(expr);
            }
            end = DateTime.Now.Ticks;
            //Console.WriteLine("Elapsed time for compiled expression select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds);

            string ns = Schema.Namespace;

            start = DateTime.Now.Ticks;
            for (int i = 0; i < iterations; i++)
            {
                context.SelectChildren("assert", ns);
            }
            end = DateTime.Now.Ticks;
            //Console.WriteLine("Elapsed time for children select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds);
        }
Ejemplo n.º 5
0
        public LinkXmlReader()
        {
            IEnumerator <string> enumerator = AssemblyStripper.GetUserBlacklistFiles().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string         current   = enumerator.Current;
                    XPathNavigator navigator = new XPathDocument(current).CreateNavigator();
                    navigator.MoveToFirstChild();
                    XPathNodeIterator iterator = navigator.SelectChildren("assembly", string.Empty);
                    while (iterator.MoveNext())
                    {
                        this._assembliesInALinkXmlFile.Add(iterator.Current.GetAttribute("fullname", string.Empty));
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
        }
Ejemplo n.º 6
0
        public void PushInputDocument(string url)
        {
            Uri    baseUri = (!(this.Input.BaseURI == string.Empty)) ? new Uri(this.Input.BaseURI) : null;
            Uri    uri     = this.res.ResolveUri(baseUri, url);
            string url2    = (!(uri != null)) ? string.Empty : uri.ToString();

            using (Stream stream = (Stream)this.res.GetEntity(uri, null, typeof(Stream)))
            {
                if (stream == null)
                {
                    throw new XsltCompileException("Can not access URI " + uri.ToString(), null, this.Input);
                }
                XmlValidatingReader xmlValidatingReader = new XmlValidatingReader(new XmlTextReader(url2, stream, this.nsMgr.NameTable));
                xmlValidatingReader.ValidationType = ValidationType.None;
                XPathNavigator xpathNavigator = new XPathDocument(xmlValidatingReader, XmlSpace.Preserve).CreateNavigator();
                xmlValidatingReader.Close();
                xpathNavigator.MoveToFirstChild();
                while (xpathNavigator.NodeType != XPathNodeType.Element)
                {
                    if (!xpathNavigator.MoveToNext())
                    {
IL_F9:
                        this.PushInputDocument(xpathNavigator);
                        return;
                    }
                }
                goto IL_F9;
            }
        }
Ejemplo n.º 7
0
        public void PushInputDocument(string url)
        {
            // todo: detect recursion
            Uri    baseUriObj   = (Input.BaseURI == String.Empty) ? null : new Uri(Input.BaseURI);
            Uri    absUri       = res.ResolveUri(baseUriObj, url);
            string absUriString = absUri != null?absUri.ToString() : String.Empty;

            using (Stream s = (Stream)res.GetEntity(absUri, null, typeof(Stream)))
            {
                if (s == null)
                {
                    throw new XsltCompileException("Can not access URI " + absUri.ToString(), null, Input);
                }
                XmlValidatingReader vr = new XmlValidatingReader(new XmlTextReader(absUriString, s, nsMgr.NameTable));
                vr.ValidationType = ValidationType.None;
                XPathNavigator n = new XPathDocument(vr, XmlSpace.Preserve).CreateNavigator();
                vr.Close();
                n.MoveToFirstChild();
                do
                {
                    if (n.NodeType == XPathNodeType.Element)
                    {
                        break;
                    }
                }while (n.MoveToNext());
                PushInputDocument(n);
            }
        }
Ejemplo n.º 8
0
        public static void LoadFileIntoList(TextAsset ass, List <DiaNodeMold> NodeListToFill, List <DiaNodeList> ListListToFill, DiaNodeType NodesType)
        {
            XPathNavigator xPathNavigator = new XPathDocument(new StringReader(ass.text)).CreateNavigator();

            xPathNavigator.MoveToFirst();
            xPathNavigator.MoveToFirstChild();
            foreach (XPathNavigator item2 in xPathNavigator.Select("Node"))
            {
                try
                {
                    TextReader  textReader  = new StringReader(item2.OuterXml);
                    DiaNodeMold diaNodeMold = (DiaNodeMold) new XmlSerializer(typeof(DiaNodeMold)).Deserialize(textReader);
                    diaNodeMold.nodeType = NodesType;
                    NodeListToFill.Add(diaNodeMold);
                    textReader.Dispose();
                }
                catch (Exception ex)
                {
                    Log.Message("Exception deserializing " + item2.OuterXml + ":\n" + ex.InnerException);
                }
            }
            foreach (XPathNavigator item3 in xPathNavigator.Select("NodeList"))
            {
                try
                {
                    TextReader  textReader2 = new StringReader(item3.OuterXml);
                    DiaNodeList item        = (DiaNodeList) new XmlSerializer(typeof(DiaNodeList)).Deserialize(textReader2);
                    ListListToFill.Add(item);
                }
                catch (Exception ex2)
                {
                    Log.Message("Exception deserializing " + item3.OuterXml + ":\n" + ex2.InnerException);
                }
            }
        }
        internal static CngKey FromXml(string xml)
        {
            CngKey key;

            using (TextReader reader = new StringReader(xml))
            {
                using (XmlTextReader reader2 = new XmlTextReader(reader))
                {
                    BigInteger     integer;
                    BigInteger     integer2;
                    XPathNavigator navigator = new XPathDocument(reader2).CreateNavigator();
                    if (!navigator.MoveToFirstChild())
                    {
                        throw new ArgumentException(System.SR.GetString("Cryptography_MissingDomainParameters"));
                    }
                    CngAlgorithm algorithm = ReadAlgorithm(navigator);
                    if (!navigator.MoveToNext(XPathNodeType.Element))
                    {
                        throw new ArgumentException(System.SR.GetString("Cryptography_MissingPublicKey"));
                    }
                    ReadPublicKey(navigator, out integer, out integer2);
                    key = CngKey.Import(NCryptNative.BuildEccPublicBlob(algorithm.Algorithm, integer, integer2), CngKeyBlobFormat.EccPublicBlob);
                }
            }
            return(key);
        }
Ejemplo n.º 10
0
    public void dlLinks_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string mode = e.CommandName;
        string id   = e.CommandArgument.ToString();

        if (mode == "Delete")
        {
            EditXml(mode, id);
        }
        else           //Editing
        {
            ViewState["EditMode"] = mode;
            XPathNavigator nav = new XPathDocument(_XmlPath).CreateNavigator();
            nav.MoveToFirstChild();
            XPathNavigator node = nav.SelectSingleNode("link[@id='" + id + "']");
            if (node != null)
            {
                this.lblID.Text   = id;
                this.txtName.Text = node.GetAttribute("name", String.Empty);
                this.txtURL.Text  = node.GetAttribute("href", String.Empty);
            }
            else
            {
                this.lblOutput.Text = "Unable to find node.";
            }
        }
    }
Ejemplo n.º 11
0
        protected BuildVerifier()
        {
            string         uri       = Path.Combine(Path.Combine(EditorApplication.applicationContentsPath, "Resources"), "BuildVerification.xml");
            XPathNavigator navigator = new XPathDocument(uri).CreateNavigator();

            navigator.MoveToFirstChild();
            XPathNodeIterator iterator = navigator.SelectChildren("assembly", string.Empty);

            while (iterator.MoveNext())
            {
                string attribute = iterator.Current.GetAttribute("name", string.Empty);
                if ((attribute == null) || (attribute.Length < 1))
                {
                    throw new ApplicationException(string.Format("Failed to load {0}, <assembly> name attribute is empty", uri));
                }
                string key = iterator.Current.GetAttribute("platform", string.Empty);
                if ((key == null) || (key.Length < 1))
                {
                    key = "*";
                }
                if (!this.m_UnsupportedAssemblies.ContainsKey(key))
                {
                    this.m_UnsupportedAssemblies.Add(key, new HashSet <string>());
                }
                this.m_UnsupportedAssemblies[key].Add(attribute);
            }
        }
Ejemplo n.º 12
0
        /// <summary />
        public static void SelectDescendentsSpeed(object it)
        {
            int iterations = (int)it;

            long            start;
            long            end;
            XPathNavigator  context = new XPathDocument(@"..\data.xml").CreateNavigator();
            XPathExpression expr    = context.Compile("descendant-or-self::publishers");

            context.MoveToFirstChild();

            start = DateTime.Now.Ticks;
            for (int i = 0; i < iterations; i++)
            {
                context.Select(expr);
            }
            end = DateTime.Now.Ticks;
            //Console.WriteLine("Elapsed time for compiled expression select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds);

            string ns = Schema.Namespace;

            start = DateTime.Now.Ticks;
            for (int i = 0; i < iterations; i++)
            {
                context.SelectDescendants("publisher", ns, true);
            }
            end = DateTime.Now.Ticks;
            //Console.WriteLine("Elapsed time for descendents select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds);
        }
        /// <summary>
        /// Fills in the data table with data from a list of ThingBase.
        /// </summary>
        /// <param name="record"/>
        /// <param name="items"/>
        /// <param name="startIndex"/>
        /// <param name="count"/>
        public async Task GetDataAsync(HealthRecordAccessor record, IList <ThingBase> items, int startIndex, int count)
        {
            ThingDataTableView effectiveView =
                await this.ApplyEffectiveViewAsync(record.Connection).ConfigureAwait(false);

            IDictionary <Guid, ThingTypeDefinition> typeDefDict =
                await ItemTypeManager.GetHealthRecordItemTypeDefinitionAsync(query.TypeIds,
                                                                             record.Connection).ConfigureAwait(false);

            ThingTypeDefinition sttTypeDef =
                typeDefDict.Count == 1 ? typeDefDict[query.TypeIds[0]] : null;

            bool   firstRow      = true;
            string transformName =
                (effectiveView == ThingDataTableView.SingleTypeTable) ? "stt" : "mtt";

            for (int i = startIndex; i < items.Count && i < count; ++i)
            {
                ThingBase item = items[i];

                XPathNavigator itemTransformNav;
                IDictionary <string, XDocument> transformedXmlData = item.TransformedXmlData;
                if (transformedXmlData.ContainsKey(transformName))
                {
                    itemTransformNav =
                        transformedXmlData[transformName].CreateNavigator().SelectSingleNode(
                            "//data-xml/row");
                }
                else
                {
                    string transform = (sttTypeDef == null) ?
                                       ThingTypeDefinitionHelper.Create(typeDefDict[item.TypeId]).TransformItem(transformName, item) :
                                       ThingTypeDefinitionHelper.Create(sttTypeDef).TransformItem(transformName, item);

                    XmlReaderSettings settings = new XmlReaderSettings()
                    {
                        XmlResolver   = null,
                        DtdProcessing = DtdProcessing.Prohibit
                    };

                    using (StringReader stringReader = new StringReader(transform))
                    {
                        itemTransformNav = new XPathDocument(XmlReader.Create(stringReader, settings)).CreateNavigator();
                    }

                    if (!itemTransformNav.MoveToFirstChild())
                    {
                        continue;
                    }
                }

                if (firstRow)
                {
                    SetupColumns(itemTransformNav.Clone());
                    firstRow = false;
                }
                AddRow(itemTransformNav);
            }
        }
Ejemplo n.º 14
0
        public async Task <Message[]> TransformAsync(params Message[] inputMessages)
        {
            var inputXpathDoc = await InputMessageHelper.CreateXPathDocumentAsync(inputMessages);

            var outputMessages = new List <Message>();

            // Execute the transform:
            using (var outputStream = new MemoryStream())
            {
                _xslTransform.Transform(inputXpathDoc, null, outputStream);

                // Rewind the stream
                outputStream.Position = 0;

                using (var outputReader = XmlReader.Create(outputStream))
                {
                    // Load the message:
                    var outputMessageNavigator = new XPathDocument(outputReader).CreateNavigator();

                    outputMessageNavigator.MoveToFirstChild();

                    // If this is a multi-part output message, create a new message for each part:
                    if (string.Equals(outputMessageNavigator.LocalName, Constants.MultipartRootElement) &&
                        string.Equals(outputMessageNavigator.NamespaceURI, Constants.MultipartNamespace))
                    {
                        var messageParts = outputMessageNavigator.Select(string.Format("/*[local-name()='{0}' and namespace-uri()='{2}']/*[starts-with(local-name(), '{1}') and namespace-uri()='{2}']",
                                                                                       Constants.MultipartRootElement,
                                                                                       Constants.MultipartPartElement,
                                                                                       Constants.MultipartNamespace));

                        foreach (XPathNavigator part in messageParts)
                        {
                            var msg = new Message {
                                ContentStream = new MemoryStream(Encoding.UTF8.GetBytes(part.InnerXml))
                            };
                            outputMessages.Add(msg);
                        }
                    }
                    else
                    {
                        // Rewind the stream
                        outputStream.Position = 0;

                        // Copy the result to an output message:
                        var msg = new Message {
                            ContentStream = new MemoryStream()
                        };
                        await outputStream.CopyToAsync(msg.ContentStream);

                        // Rewind the stream
                        msg.ContentStream.Position = 0;

                        outputMessages.Add(msg);
                    }
                }
            }

            return(outputMessages.ToArray());
        }
Ejemplo n.º 15
0
        public override void PopulateTree(Tree tree)
        {
            XPathNavigator n = new XPathDocument(Path.Combine(basedir, "toc.xml")).CreateNavigator();

            n.MoveToRoot();
            n.MoveToFirstChild();
            PopulateNode(n.SelectChildren("node", ""), tree);
        }
Ejemplo n.º 16
0
        public void SignificantWhitespaceConstruction()
        {
            string         xml = @"<root>
        <child xml:space='preserve'>    <!-- -->   </child>
        <child xml:space='preserve'>    </child>
</root>";
            XPathNavigator nav = new XPathDocument(
                new XmlTextReader(xml, XmlNodeType.Document, null),
                XmlSpace.Preserve).CreateNavigator();

            nav.MoveToFirstChild();
            nav.MoveToFirstChild();
            Assert.AreEqual(XPathNodeType.Whitespace, nav.NodeType, "#1");
            nav.MoveToNext();
            nav.MoveToFirstChild();
            Assert.AreEqual(XPathNodeType.SignificantWhitespace,
                            nav.NodeType, "#2");
        }
Ejemplo n.º 17
0
        public void XPathDocumentFragmentLoading()
        {
            string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

            XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

            // <customer>
            nav.MoveToFirstChild();
            // <pp:order>
            nav.MoveToFirstChild();
            // <order>
            nav.MoveToNext();

            XmlReader      reader = new XPathNavigatorReader(nav);
            XPathNavigator clone  = new XPathDocument(reader).CreateNavigator();

            clone.MoveToFirstChild();

            Assert.AreEqual("order", clone.LocalName);
            Assert.AreEqual("urn-kzu", clone.NamespaceURI);
        }
Ejemplo n.º 18
0
        public void XPathDocumentLoading()
        {
            string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

            XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

            XmlReader      reader = new XPathNavigatorReader(nav);
            XPathNavigator clone  = new XPathDocument(reader).CreateNavigator();

            clone.MoveToFirstChild();
            Assert.AreEqual("customer", clone.LocalName);
            Assert.AreEqual("urn-kzu", clone.NamespaceURI);

            clone.MoveToAttribute("id", "urn-pepenamespace");
            Assert.AreEqual("aba", clone.Value);

            clone.MoveToParent();
            clone.MoveToFirstChild();
            Assert.AreEqual("pp:order", clone.Name);
            Assert.IsTrue(clone.IsEmptyElement);
        }
Ejemplo n.º 19
0
        private XPathNavigator SerializeAndReadOutput(ContentItem item)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            CreateExporter().Export(item, ExportOptions.Default, sw);

            StringReader   sr        = new StringReader(sb.ToString());
            XPathNavigator navigator = new XPathDocument(sr).CreateNavigator();

            navigator.MoveToFirstChild();
            return(navigator);
        }
Ejemplo n.º 20
0
 public LinkXmlReader()
 {
     foreach (string userBlacklistFile in AssemblyStripper.GetUserBlacklistFiles())
     {
         XPathNavigator navigator = new XPathDocument(userBlacklistFile).CreateNavigator();
         navigator.MoveToFirstChild();
         XPathNodeIterator xpathNodeIterator = navigator.SelectChildren("assembly", string.Empty);
         while (xpathNodeIterator.MoveNext())
         {
             this._assembliesInALinkXmlFile.Add(xpathNodeIterator.Current.GetAttribute("fullname", string.Empty));
         }
     }
 }
Ejemplo n.º 21
0
        public void XmlDocumentFragmentLoading()
        {
            string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

            XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

            // <customer>
            nav.MoveToFirstChild();
            // <pp:order>
            nav.MoveToFirstChild();
            // <order>
            nav.MoveToNext();

            XmlReader   reader = new XPathNavigatorReader(nav);
            XmlDocument doc    = new XmlDocument(nav.NameTable);

            doc.Load(reader);

            Assert.AreEqual("order", doc.DocumentElement.LocalName);
            Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI);
            Assert.AreEqual(1, doc.DocumentElement.Attributes.Count);
        }
Ejemplo n.º 22
0
        internal IEnumerable <T> Deserialize <T> (string filter, string xml) where T : Object
        {
            if (!object_cache.ContainsKey(filter))
            {
                object_cache[filter] = new Dictionary <string, WeakReference> ();
            }

            using (var reader = new StringReader(xml)) {
                var navigator = new XPathDocument(reader).CreateNavigator();
                if (navigator.MoveToChild("DIDL-Lite", Schemas.DidlLiteSchema) && navigator.MoveToFirstChild())
                {
                    do
                    {
                        yield return(DerserializeObject <T> (filter, navigator));
                    } while (navigator.MoveToNext());
                }
            }
        }
Ejemplo n.º 23
0
        public void WriteNodeXPathNavigatorAttribute()
        {
            string            xml = "<!DOCTYPE root [<!ELEMENT root EMPTY> <!ATTLIST root implicit NMTOKEN 'nam'>]><root attr='val' />";
            XPathNavigator    nav = new XPathDocument(new StringReader(xml)).CreateNavigator();
            XmlWriterSettings s   = new XmlWriterSettings();

            s.OmitXmlDeclaration = true;
            StringWriter sw = new StringWriter();
            XmlWriter    w  = XmlWriter.Create(sw, s);

            w.WriteStartElement("hoge");
            nav.MoveToFirstChild();
            nav.MoveToFirstAttribute();
            w.WriteNode(nav, false);
            nav.MoveToNextAttribute();
            w.WriteNode(nav, false);
            w.Close();
            AssertType.AreEqual("<hoge />", sw.ToString());
        }
Ejemplo n.º 24
0
        public bool LoadProfile(string profileName, bool absolutepath = false)
        {
            string str = !absolutepath ? HotKeyManager._profileRootDirectory + "\\" + profileName + ".keys" : profileName;

            if (profileName == "~Default")
            {
                str = this._assetdir + "\\" + profileName + ".keys";
            }
            if (!File.Exists(str))
            {
                return(false);
            }
            this.HotKeys.Clear();
            if (profileName == "~Default")
            {
                this.DefaultHotKeys.Clear();
            }
            this._profileName = profileName;
            XPathNavigator navigator = new XPathDocument(App.GetStreamForFile(str) != null ? App.GetStreamForFile(str) : (Stream) new FileStream(str, FileMode.Open)).CreateNavigator();

            navigator.MoveToFirstChild();
            do
            {
                if (navigator.HasChildren)
                {
                    navigator.MoveToFirstChild();
                    do
                    {
                        if (navigator.HasChildren)
                        {
                            HotKeyManager.KeyCombo      keyCombo = new HotKeyManager.KeyCombo();
                            HotKeyManager.HotKeyActions key      = HotKeyManager.HotKeyActions.NoAction;
                            navigator.MoveToFirstChild();
                            do
                            {
                                switch (navigator.Name)
                                {
                                case "event":
                                    if (Enum.IsDefined(typeof(HotKeyManager.HotKeyActions), (object)navigator.Value))
                                    {
                                        key = (HotKeyManager.HotKeyActions)Enum.Parse(typeof(HotKeyManager.HotKeyActions), navigator.Value, true);
                                        break;
                                    }
                                    break;

                                case "states":
                                    keyCombo.states = navigator.Value;
                                    break;

                                case "shift":
                                    keyCombo.shift = bool.Parse(navigator.Value);
                                    break;

                                case "ctrl":
                                    keyCombo.control = bool.Parse(navigator.Value);
                                    break;

                                case "alt":
                                    keyCombo.alt = bool.Parse(navigator.Value);
                                    break;

                                case "key":
                                    keyCombo.key = !Enum.IsDefined(typeof(Keys), (object)navigator.Value) ? Keys.None : (Keys)Enum.Parse(typeof(Keys), navigator.Value, true);
                                    break;
                                }
                            }while (navigator.MoveToNext());
                            if (key != HotKeyManager.HotKeyActions.NoAction && !this.HotKeys.ContainsKey(key))
                            {
                                this.HotKeys.Add(key, keyCombo);
                                if (profileName == "~Default")
                                {
                                    this.DefaultHotKeys.Add(key, keyCombo);
                                }
                            }
                            navigator.MoveToParent();
                        }
                    }while (navigator.MoveToNext());
                }
            }while (navigator.MoveToNext());
            this._loaded = true;
            foreach (HotKeyManager.HotKeyActions action in Enum.GetValues(typeof(HotKeyManager.HotKeyActions)))
            {
                if (!this.HotKeys.Keys.Contains <HotKeyManager.HotKeyActions>(action) && this.DefaultHotKeys.Keys.Contains <HotKeyManager.HotKeyActions>(action))
                {
                    this.SetHotKeyCombo(action, this.DefaultHotKeys[action]);
                }
            }
            this.SyncKeyProfile("");
            this.SaveProfile();
            return(true);
        }
Ejemplo n.º 25
0
        public bool LoadProfile(string profileName, bool absolutepath = false)
        {
            string str1 = !absolutepath ? Profile._profileRootDirectory + "\\" + profileName + ".xml" : profileName;

            if (!File.Exists(str1))
            {
                return(false);
            }
            XPathNavigator navigator = new XPathDocument(App.GetStreamForFile(str1) ?? (Stream) new FileStream(str1, FileMode.Open)).CreateNavigator();

            navigator.MoveToFirstChild();
            do
            {
                if (navigator.HasChildren)
                {
                    navigator.MoveToFirstChild();
                    do
                    {
                        switch (navigator.Name)
                        {
                        case "name":
                            this._profileName = navigator.Value;
                            break;

                        case "techs":
                            string str2 = navigator.Value;
                            this._researchedTechs.Clear();
                            string[] strArray = str2.Split('!');
                            for (int index = 0; index < strArray.Length; ++index)
                            {
                                if (strArray[index].Length > 0)
                                {
                                    this._researchedTechs.Add(strArray[index]);
                                }
                            }
                            break;

                        case "username":
                            this.Username = navigator.Value ?? string.Empty;
                            break;

                        case "password":
                            this.Password = navigator.Value ?? string.Empty;
                            break;

                        case "last_game_played":
                            this.LastGamePlayed = navigator.Value ?? string.Empty;
                            break;

                        case "auto_place_defenses":
                            this.AutoPlaceDefenseAssets = bool.Parse(navigator.Value);
                            break;

                        case "auto_repair_fleets":
                            this.AutoRepairFleets = bool.Parse(navigator.Value);
                            break;

                        case "auto_goop":
                            this.AutoUseGoop = bool.Parse(navigator.Value);
                            break;

                        case "auto_joker":
                            this.AutoUseJoker = bool.Parse(navigator.Value);
                            break;

                        case "auto_aoe":
                            this.AutoAOE = bool.Parse(navigator.Value);
                            break;

                        case "auto_patrol":
                            this.AutoPatrol = bool.Parse(navigator.Value);
                            break;
                        }
                    }while (navigator.MoveToNext());
                }
            }while (navigator.MoveToNext());
            this._loaded = true;
            return(true);
        }