private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
        {
            switch (propertyName)
            {
            case "#text":
                currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
                return;

            case "#cdata-section":
                currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
                return;

            case "#whitespace":
                currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
                return;

            case "#significant-whitespace":
                currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
                return;
            }
            if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
            {
                CreateInstruction(reader, document, currentNode, propertyName);
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                ReadArrayElements(reader, document, propertyName, currentNode, manager);
            }
            else
            {
                ReadElement(reader, document, currentNode, propertyName, manager);
            }
        }
        private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
        {
            if (propertyName == "?xml")
            {
                string version    = null;
                string encoding   = null;
                string standalone = null;
                while (reader.Read() && reader.TokenType != JsonToken.EndObject)
                {
                    string text = reader.Value.ToString();
                    if (text != null)
                    {
                        if (XmlNodeConverter.< > f__switch$map1 == null)
                        {
                            Dictionary <string, int> dictionary = new Dictionary <string, int>(3);
                            dictionary.Add("@version", 0);
                            dictionary.Add("@encoding", 1);
                            dictionary.Add("@standalone", 2);
                            XmlNodeConverter.< > f__switch$map1 = dictionary;
                        }
                        int num;
                        if (XmlNodeConverter.< > f__switch$map1.TryGetValue(text, ref num))
                        {
                            switch (num)
                            {
                            case 0:
                                reader.Read();
                                version = reader.Value.ToString();
                                continue;

                            case 1:
                                reader.Read();
                                encoding = reader.Value.ToString();
                                continue;

                            case 2:
                                reader.Read();
                                standalone = reader.Value.ToString();
                                continue;
                            }
                        }
                    }
                    throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                }
                IXmlNode newChild = document.CreateXmlDeclaration(version, encoding, standalone);
                currentNode.AppendChild(newChild);
            }
            else
            {
                IXmlNode newChild2 = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
                currentNode.AppendChild(newChild2);
            }
        }
示例#3
0
 private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
 {
     if (propertyName == null)
     {
         if (string.IsNullOrEmpty(propertyName) || propertyName[0] != '?')
         {
             if (reader.TokenType == JsonToken.StartArray)
             {
                 this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
                 return;
             }
             this.ReadElement(reader, document, currentNode, propertyName, manager);
         }
         else
         {
             this.CreateInstruction(reader, document, currentNode, propertyName);
         }
         return;
     }
     else if (propertyName == "#text")
     {
         currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
     }
     else if (propertyName == "#cdata-section")
     {
         currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
     }
     else if (propertyName == "#whitespace")
     {
         currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
     }
     else
     {
         if (propertyName != "#significant-whitespace")
         {
             if (string.IsNullOrEmpty(propertyName) || propertyName[0] != '?')
             {
                 if (reader.TokenType == JsonToken.StartArray)
                 {
                     this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
                     return;
                 }
                 this.ReadElement(reader, document, currentNode, propertyName, manager);
             }
             else
             {
                 this.CreateInstruction(reader, document, currentNode, propertyName);
             }
             return;
         }
         currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
     }
 }
示例#4
0
 private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
 {
     if (propertyName != "?xml")
     {
         IXmlNode xmlNode = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
         currentNode.AppendChild(xmlNode);
     }
     else
     {
         string str  = null;
         string str1 = null;
         string str2 = null;
         while (true)
         {
             if (!reader.Read() || reader.TokenType == JsonToken.EndObject)
             {
                 IXmlNode xmlNode1 = document.CreateXmlDeclaration(str, str1, str2);
                 currentNode.AppendChild(xmlNode1);
                 return;
             }
             else
             {
                 string str3 = reader.Value.ToString();
                 if (str3 == null)
                 {
                     break;
                 }
                 if (str3 == "@version")
                 {
                     reader.Read();
                     str = reader.Value.ToString();
                 }
                 else if (str3 == "@encoding")
                 {
                     reader.Read();
                     str1 = reader.Value.ToString();
                 }
                 else if (str3 == "@standalone")
                 {
                     reader.Read();
                     str2 = reader.Value.ToString();
                 }
                 else
                 {
                     break;
                 }
             }
         }
         throw new JsonSerializationException(string.Concat("Unexpected property name encountered while deserializing XmlDeclaration: ", reader.Value));
     }
 }
        private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
        {
            if (propertyName != null)
            {
                if (XmlNodeConverter.< > f__switch$map0 == null)
                {
                    Dictionary <string, int> dictionary = new Dictionary <string, int>(4);
                    dictionary.Add("#text", 0);
                    dictionary.Add("#cdata-section", 1);
                    dictionary.Add("#whitespace", 2);
                    dictionary.Add("#significant-whitespace", 3);
                    XmlNodeConverter.< > f__switch$map0 = dictionary;
                }
                int num;
                if (XmlNodeConverter.< > f__switch$map0.TryGetValue(propertyName, ref num))
                {
                    switch (num)
                    {
                    case 0:
                        currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
                        return;

                    case 1:
                        currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
                        return;

                    case 2:
                        currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
                        return;

                    case 3:
                        currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
                        return;
                    }
                }
            }
            if (!string.IsNullOrEmpty(propertyName) && propertyName.get_Chars(0) == '?')
            {
                this.CreateInstruction(reader, document, currentNode, propertyName);
            }
            else
            {
                if (reader.TokenType == JsonToken.StartArray)
                {
                    this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
                    return;
                }
                this.ReadElement(reader, document, currentNode, propertyName, manager);
            }
        }
示例#6
0
 private void DeserializeValue(
     JsonReader reader,
     IXmlDocument document,
     XmlNamespaceManager manager,
     string propertyName,
     IXmlNode currentNode)
 {
     if (!(propertyName == "#text"))
     {
         if (!(propertyName == "#cdata-section"))
         {
             if (!(propertyName == "#whitespace"))
             {
                 if (propertyName == "#significant-whitespace")
                 {
                     currentNode.AppendChild(document.CreateSignificantWhitespace(this.ConvertTokenToXmlValue(reader)));
                 }
                 else if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
                 {
                     this.CreateInstruction(reader, document, currentNode, propertyName);
                 }
                 else if (string.Equals(propertyName, "!DOCTYPE", StringComparison.OrdinalIgnoreCase))
                 {
                     this.CreateDocumentType(reader, document, currentNode);
                 }
                 else if (reader.TokenType == JsonToken.StartArray)
                 {
                     this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
                 }
                 else
                 {
                     this.ReadElement(reader, document, currentNode, propertyName, manager);
                 }
             }
             else
             {
                 currentNode.AppendChild(document.CreateWhitespace(this.ConvertTokenToXmlValue(reader)));
             }
         }
         else
         {
             currentNode.AppendChild(document.CreateCDataSection(this.ConvertTokenToXmlValue(reader)));
         }
     }
     else
     {
         currentNode.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
     }
 }
示例#7
0
        private void CreateInstruction(
            JsonReader reader,
            IXmlDocument document,
            IXmlNode currentNode,
            string propertyName)
        {
            if (propertyName == "?xml")
            {
                string version    = (string)null;
                string encoding   = (string)null;
                string standalone = (string)null;
                while (reader.Read() && reader.TokenType != JsonToken.EndObject)
                {
                    string str = reader.Value.ToString();
                    if (!(str == "@version"))
                    {
                        if (!(str == "@encoding"))
                        {
                            if (!(str == "@standalone"))
                            {
                                throw JsonSerializationException.Create(reader,
                                                                        "Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                            }
                            reader.Read();
                            standalone = this.ConvertTokenToXmlValue(reader);
                        }
                        else
                        {
                            reader.Read();
                            encoding = this.ConvertTokenToXmlValue(reader);
                        }
                    }
                    else
                    {
                        reader.Read();
                        version = this.ConvertTokenToXmlValue(reader);
                    }
                }

                IXmlNode xmlDeclaration = document.CreateXmlDeclaration(version, encoding, standalone);
                currentNode.AppendChild(xmlDeclaration);
            }
            else
            {
                IXmlNode processingInstruction =
                    document.CreateProcessingInstruction(propertyName.Substring(1), this.ConvertTokenToXmlValue(reader));
                currentNode.AppendChild(processingInstruction);
            }
        }
        private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
        {
            string      prefix     = MiscellaneousUtils.GetPrefix(propertyName);
            IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);

            currentNode.AppendChild(xmlElement);
            int num = 0;

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                this.DeserializeValue(reader, document, manager, propertyName, xmlElement);
                num++;
            }
            if (this.WriteArrayAttribute)
            {
                this.AddJsonArrayAttribute(xmlElement, document);
            }
            if (num == 1 && this.WriteArrayAttribute)
            {
                foreach (IXmlNode childNode in xmlElement.ChildNodes)
                {
                    IXmlElement xmlElement1 = childNode as IXmlElement;
                    if (xmlElement1 == null || !(xmlElement1.LocalName == propertyName))
                    {
                        continue;
                    }
                    this.AddJsonArrayAttribute(xmlElement1, document);
                    return;
                }
            }
        }
        private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary <string, string> attributeNameValues)
        {
            IXmlElement xmlElement = this.CreateElement(elementName, document, elementPrefix, manager);

            currentNode.AppendChild(xmlElement);
            foreach (KeyValuePair <string, string> attributeNameValue in attributeNameValues)
            {
                string str    = XmlConvert.EncodeName(attributeNameValue.Key);
                string prefix = MiscellaneousUtils.GetPrefix(attributeNameValue.Key);
                xmlElement.SetAttributeNode((!string.IsNullOrEmpty(prefix) ? document.CreateAttribute(str, manager.LookupNamespace(prefix) ?? string.Empty, attributeNameValue.Value) : document.CreateAttribute(str, attributeNameValue.Value)));
            }
            if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer || reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Boolean || reader.TokenType == JsonToken.Date)
            {
                string xmlValue = this.ConvertTokenToXmlValue(reader);
                if (xmlValue != null)
                {
                    xmlElement.AppendChild(document.CreateTextNode(xmlValue));
                    return;
                }
            }
            else if (reader.TokenType != JsonToken.Null)
            {
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();
                    this.DeserializeNode(reader, document, manager, xmlElement);
                    manager.PopScope();
                }
                manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
            }
        }
示例#10
0
        public static void ToastImageAndText04(string t1, string t2, string t3, string imgsrc, string imgalt = "")
        {
            ToastTemplateType toastTemplate     = ToastTemplateType.ToastImageAndText04;
            XmlDocument       toastXml          = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList       toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(t1));
            if (t2 != null)
            {
                toastTextElements[1].AppendChild(toastXml.CreateTextNode(t2));
            }
            if (t3 != null)
            {
                toastTextElements[2].AppendChild(toastXml.CreateTextNode(t3));
            }

            if (!string.IsNullOrEmpty(imgsrc))
            {
                XmlNodeList toastImgElement = toastXml.GetElementsByTagName("image");
                ((XmlElement)toastImgElement[0]).SetAttribute("src", imgsrc);
                ((XmlElement)toastImgElement[0]).SetAttribute("alt", imgalt);
            }
            IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio     = toastXml.CreateElement("audio");

            audio.SetAttribute("silent", "true");
            toastNode?.AppendChild(audio);

            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
示例#11
0
        public static void Toast_Notification_For_Devs(string title, string subtitle)
        {
            try
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
                XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
                toastTextElements[1].AppendChild(toastXml.CreateTextNode(subtitle));

                IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                ((XmlElement)toastNode).SetAttribute("launch", "MainPage.xaml");

                XmlElement audio = toastXml.CreateElement("audio");
                audio.SetAttribute("src", Memory.Toast_Sound);
                toastNode.AppendChild(audio);

                ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
                System.Diagnostics.Debug.WriteLine("Toast notification for devs created " + "(" + title + " / " + subtitle + ")");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Greška pri registraciji \"Toast notification for devs\" za " + title + " (" + ex.Message + ")");
            }
        }
示例#12
0
        public async void toastMessage(String message, int delay)
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
            XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(message));

            XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");

            //((XmlElement)toastImageAttributes[0]).SetAttribute("src", "http://microsoft-chat.com/wp-content/uploads/2014/05/Microsoft_0-300x168.jpg");
            //((XmlElement)toastImageAttributes[0]).SetAttribute("src", "https://raw.githubusercontent.com/seksenov/grouppost/master/images/AddNote.png");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "https://raw.githubusercontent.com/seksenov/grouppost/master/images/logo.png");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic");

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ((XmlElement)toastNode).SetAttribute("duration", "short");

            XmlElement audio = toastXml.CreateElement("audio");

            audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
            toastNode.AppendChild(audio);

            ((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

            ToastNotification toast = new ToastNotification(toastXml);

            await Task.Delay(delay);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
示例#13
0
        private void ToastNotificationOptions_Click(object sender, RoutedEventArgs e)
        {
            ToastTemplateType toastType   = ToastTemplateType.ToastImageAndText02;
            XmlDocument       toastXML    = ToastNotificationManager.GetTemplateContent(toastType);
            XmlNodeList       toastText   = toastXML.GetElementsByTagName("text");
            XmlNodeList       toastImages = toastXML.GetElementsByTagName("image");

            toastText[0].InnerText = "Funny cat";
            toastText[1].InnerText = "This cat looks like it's trying to eat your face.";
            ((XmlElement)toastImages[0]).SetAttribute("src", "ms-appx:///Assets/10-XAML-CatImageSmall.png");
            ((XmlElement)toastImages[0]).SetAttribute("alt", "Scary Cat Face");

            //This is the options code, which is all optional based on your needs.
            IXmlNode toastNode = toastXML.SelectSingleNode("/toast");

            ((XmlElement)toastNode).SetAttribute("duration", "long");

            XmlElement audioNode = toastXML.CreateElement("audio");

            audioNode.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Alarm");

            //Must be used when looping audio has been selected.
            audioNode.SetAttribute("loop", "true");
            toastNode.AppendChild(audioNode);

            //You can append any text data you would like to the optional
            //launch property, but clicking a Toast message should drive
            //the user to something contextually relevant.
            ((XmlElement)toastNode).SetAttribute("launch", "<cat state='angry'><facebite state='true' /></cat>");

            ToastNotification toast = new ToastNotification(toastXML);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
        private void ReadArrayElements(
            JsonReader reader,
            IXmlDocument document,
            string propertyName,
            IXmlNode currentNode,
            XmlNamespaceManager manager)
        {
            string      prefix   = MiscellaneousUtils.GetPrefix(propertyName);
            IXmlElement element1 = this.CreateElement(propertyName, document, prefix, manager);

            currentNode.AppendChild((IXmlNode)element1);
            int num = 0;

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                this.DeserializeValue(reader, document, manager, propertyName, (IXmlNode)element1);
                ++num;
            }
            if (this.WriteArrayAttribute)
            {
                this.AddJsonArrayAttribute(element1, document);
            }
            if (num != 1 || !this.WriteArrayAttribute)
            {
                return;
            }
            foreach (IXmlNode childNode in element1.ChildNodes)
            {
                if (childNode is IXmlElement element2 && element2.LocalName == propertyName)
                {
                    this.AddJsonArrayAttribute(element2, document);
                    break;
                }
            }
        }
        public Task PublishAsync(Song song, IPlaylist currentPlaylist, Uri albumArtUri, CancellationToken cancellationToken)
        {
            this.TilesInitialization();

            return(Task.Factory.StartNew(() =>
            {
                XmlDocument wideTileTemplate = this.GenerateWideTile(song, albumArtUri);
                XmlDocument squareTileTemplate = this.GenerateSquareTile(song);

                IXmlNode squareBindingNode = squareTileTemplate.GetElementsByTagName("binding").Item(0);
                IXmlNode visualNode = wideTileTemplate.GetElementsByTagName("visual").Item(0);
                if (visualNode != null && squareBindingNode != null)
                {
                    visualNode.AppendChild(wideTileTemplate.ImportNode(squareBindingNode, true));
                }

                var tileNotification = new TileNotification(wideTileTemplate)
                {
                    ExpirationTime = DateTimeOffset.UtcNow.Add(song.Duration),
                    Tag = CurrentSongTileTag
                };

                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
            }, cancellationToken));
        }
示例#16
0
        void InvokeSimpleToast(string messageReceived)
        {
            // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing
            // the toast XML
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);

            // You can use the methods from the XML document to specify all of the
            // required parameters for the toast
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Push notification message:"));
            stringElements.Item(1).AppendChild(toastXml.CreateTextNode(messageReceived));

            // Audio tags are not included by default, so must be added to the
            // XML document
            string     audioSrc     = "ms-winsoundevent:Notification.IM";
            XmlElement audioElement = toastXml.CreateElement("audio");

            audioElement.SetAttribute("src", audioSrc);

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            toastNode.AppendChild(audioElement);

            // Create a toast from the Xml, then create a ToastNotifier object to show
            // the toast
            ToastNotification toast = new ToastNotification(toastXml);

            OutputDebugString("edetocCCTSample_Tracing:  PushNotifyTask Show Toast");

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
示例#17
0
        public static void Toast(string msg)
        {
            //1. create element
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
            XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);
            //2.设置消息文本
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(msg));
            //3. 图标
            Windows.Data.Xml.Dom.XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///Assets/StoreLogo.png");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo");
            // 4. duration
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ((XmlElement)toastNode).SetAttribute("duration", "short");

            // 5. audio
            XmlElement audio = toastXml.CreateElement("audio");

            audio.SetAttribute("src", $"ms-winsoundevent:Notification.SMS");
            toastNode.AppendChild(audio);

            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
示例#18
0
        static IXmlNode AppendNode(IXmlNode parentNode, IXmlNode childNode)
        {
            IXmlNode appendedChild;

            ComFunctions.CheckHRESULT(parentNode.AppendChild(childNode, out appendedChild));
            return(appendedChild);
        }
示例#19
0
        private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary <string, string> attributeNameValues)
        {
            IXmlElement newChild = this.CreateElement(elementName, document, elementPrefix, manager);

            currentNode.AppendChild(newChild);
            foreach (KeyValuePair <string, string> pair in attributeNameValues)
            {
                string qualifiedName = XmlConvert.EncodeName(pair.Key);
                string prefix        = MiscellaneousUtils.GetPrefix(pair.Key);
                string text1         = manager.LookupNamespace(prefix);
                if (text1 == null)
                {
                }
                IXmlNode attribute = !string.IsNullOrEmpty(prefix) ? document.CreateAttribute(qualifiedName, string.Empty, pair.Value) : document.CreateAttribute(qualifiedName, pair.Value);
                newChild.SetAttributeNode(attribute);
            }
            if (((reader.TokenType == JsonToken.String) || (reader.TokenType == JsonToken.Integer)) || (((reader.TokenType == JsonToken.Float) || (reader.TokenType == JsonToken.Boolean)) || (reader.TokenType == JsonToken.Date)))
            {
                string text = this.ConvertTokenToXmlValue(reader);
                if (text != null)
                {
                    newChild.AppendChild(document.CreateTextNode(text));
                }
            }
            else if (reader.TokenType != JsonToken.Null)
            {
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();
                    this.DeserializeNode(reader, document, manager, newChild);
                    manager.PopScope();
                }
                manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
            }
        }
        /// <summary> Works with Windows 10 because i do not install a startmenu entry,
        ///  which is apparently needed on previous versions for desktop notifcations</summary>
        /// <param name="p_channel"></param>
        public void ShowNotification(IChannel p_channel)
        {
            try
            {
                XmlDocument notificationNode = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

                //Text
                XmlNodeList nodeList = notificationNode.GetElementsByTagName("text");
                nodeList[0].AppendChild(notificationNode.CreateTextNode(p_channel.Username));
                nodeList[1].AppendChild(notificationNode.CreateTextNode(p_channel.Game));
                nodeList[2].AppendChild(notificationNode.CreateTextNode(p_channel.Title));

                //Play Notification true/false
                IXmlNode   audioNode    = notificationNode.SelectSingleNode("/toast");
                XmlElement audioElement = notificationNode.CreateElement("audio");
                audioElement.SetAttribute("silent", !Properties.Settings.Default.PlayNotificationSound ? "true" : "false");
                audioNode.AppendChild(audioElement);

                //Channel Logo
                string      logoPath      = "file:///" + Utility.GetLogoPath(p_channel.Username, p_channel.Logo);
                XmlNodeList imageElements = notificationNode.GetElementsByTagName("image");
                imageElements[0].Attributes.GetNamedItem("src").NodeValue = logoPath;

                //Show
                ToastNotification toast = new ToastNotification(notificationNode);
                ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
            }
            catch (Exception ex)
            {
                Utility.LogTrace(ex.Message);
            }
        }
示例#21
0
        private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
        {
            string      prefix   = MiscellaneousUtils.GetPrefix(propertyName);
            IXmlElement newChild = this.CreateElement(propertyName, document, prefix, manager);

            currentNode.AppendChild(newChild);
            int num = 0;

            while (reader.Read() && (reader.TokenType != JsonToken.EndArray))
            {
                this.DeserializeValue(reader, document, manager, propertyName, newChild);
                num++;
            }
            if (this.WriteArrayAttribute)
            {
                this.AddJsonArrayAttribute(newChild, document);
            }
            if ((num == 1) && this.WriteArrayAttribute)
            {
                foreach (IXmlElement element2 in newChild.ChildNodes)
                {
                    if ((element2 != null) && (element2.LocalName == propertyName))
                    {
                        this.AddJsonArrayAttribute(element2, document);
                        break;
                    }
                }
            }
        }
示例#22
0
        private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
        {
            do
            {
                switch (reader.TokenType)
                {
                case JsonToken.StartConstructor:
                    string propertyName1 = reader.Value.ToString();
                    while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
                    {
                        this.DeserializeValue(reader, document, manager, propertyName1, currentNode);
                    }
                    break;

                case JsonToken.PropertyName:
                    if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
                    {
                        throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.");
                    }
                    string propertyName = reader.Value.ToString();
                    reader.Read();
                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        int num = 0;
                        while (reader.Read() && reader.TokenType != JsonToken.EndArray)
                        {
                            this.DeserializeValue(reader, document, manager, propertyName, currentNode);
                            ++num;
                        }
                        if (num == 1 && this.WriteArrayAttribute)
                        {
                            this.AddJsonArrayAttribute(Enumerable.Single <IXmlElement>(CollectionUtils.CastValid <IXmlElement>((IEnumerable)currentNode.ChildNodes), (Func <IXmlElement, bool>)(n => n.LocalName == propertyName)), document);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        this.DeserializeValue(reader, document, manager, propertyName, currentNode);
                        break;
                    }

                case JsonToken.Comment:
                    currentNode.AppendChild(document.CreateComment((string)reader.Value));
                    break;

                case JsonToken.EndObject:
                    return;

                case JsonToken.EndArray:
                    return;

                default:
                    throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + (object)reader.TokenType);
                }
            }while (reader.TokenType == JsonToken.PropertyName || reader.Read());
        }
示例#23
0
        public static void SendToast(
            string head,
            string text,
            DateTimeOffset dueTime,
            string launch)
        {
            ToastTemplateType toastTemplate     = ToastTemplateType.ToastText02;
            XmlDocument       toastXml          = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList       toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(head));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(text));

            IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio     = toastXml.CreateElement("audio");

            audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");

            toastNode.AppendChild(audio);

            if (launch != null)
            {
                ((XmlElement)toastNode).SetAttribute("launch", launch);
            }

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);

            scheduledToast.Id = "Future_Toast";
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
        }
示例#24
0
        private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
        {
            Dictionary <string, string> attributeNameValues = ReadAttributeElements(reader, manager);

            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);

            currentNode.AppendChild(element);

            // add attributes to newly created element
            foreach (KeyValuePair <string, string> nameValue in attributeNameValues)
            {
                string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

                IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                               ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
                               : document.CreateAttribute(nameValue.Key, nameValue.Value);

                element.SetAttributeNode(attribute);
            }

            if (reader.TokenType == JsonToken.String)
            {
                element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
            }
            else if (reader.TokenType == JsonToken.Integer)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Float)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Boolean)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Date)
            {
                DateTime d = (DateTime)reader.Value;
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
            }
            else if (reader.TokenType == JsonToken.Null)
            {
                // empty element. do nothing
            }
            else
            {
                // finished element will have no children to deserialize
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();

                    DeserializeNode(reader, document, manager, element);

                    manager.PopScope();
                }
            }
        }
        private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
        {
            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            IXmlElement nestedArrayElement = CreateElement(propertyName, document, elementPrefix, manager);

            currentNode.AppendChild(nestedArrayElement);

            int count = 0;

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                DeserializeValue(reader, document, manager, propertyName, nestedArrayElement);
                count++;
            }

            if (WriteArrayAttribute)
            {
                AddJsonArrayAttribute(nestedArrayElement, document);
            }

            if (count == 1 && WriteArrayAttribute)
            {
                IXmlElement arrayElement = nestedArrayElement.ChildNodes.CastValid <IXmlElement>().Single(n => n.LocalName == propertyName);
                AddJsonArrayAttribute(arrayElement, document);
            }
        }
        private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
        {
            do
            {
                switch (reader.TokenType)
                {
                case JsonToken.PropertyName:
                    if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
                    {
                        throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.");
                    }

                    string propertyName = reader.Value.ToString();
                    reader.Read();

                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        int count = 0;
                        while (reader.Read() && reader.TokenType != JsonToken.EndArray)
                        {
                            DeserializeValue(reader, document, manager, propertyName, currentNode);
                            count++;
                        }

                        if (count == 1 && WriteArrayAttribute)
                        {
                            IXmlElement arrayElement = currentNode.ChildNodes.CastValid <IXmlElement>().Single(n => n.LocalName == propertyName);
                            AddJsonArrayAttribute(arrayElement, document);
                        }
                    }
                    else
                    {
                        DeserializeValue(reader, document, manager, propertyName, currentNode);
                    }
                    break;

                case JsonToken.StartConstructor:
                    string constructorName = reader.Value.ToString();

                    while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
                    {
                        DeserializeValue(reader, document, manager, constructorName, currentNode);
                    }
                    break;

                case JsonToken.Comment:
                    currentNode.AppendChild(document.CreateComment((string)reader.Value));
                    break;

                case JsonToken.EndObject:
                case JsonToken.EndArray:
                    return;

                default:
                    throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
                }
            } while (reader.TokenType == JsonToken.PropertyName || reader.Read());
            // don't read if current token is a property. token was already read when parsing element attributes
        }
示例#27
0
    //改变通知的声音
    //the avaliable tones are here:Default,IM,Mail,Reminder,SMS,Looping.Alarm,Looping.Alarm2,Looping.Alarm3,Looping.Alarm4,Looping.Alarm5,Looping.Alarm6,Looping.Alarm7,Looping.Alarm8,Looping.Alarm9,Looping.Alarm10,Looping.Call,Looping.Call2,Looping.Call3,Looping.Call4,Looping.Call5,Looping.Call6,Looping.Call7,Looping.Call8,Looping.Call9,Looping.Call10
    public ToastLib setToastTone(string tone)
    {
        XmlElement audio = toastXml.CreateElement("audio");

        audio.SetAttribute("src", $"ms-winsoundevent:Notification." + tone);
        toastNode.AppendChild(audio);
        return(this);
    }
示例#28
0
        private void SetSilent(XmlDocument toastXml)
        {
            IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio     = toastXml.CreateElement("audio");

            audio.SetAttribute("silent", "true");
            toastNode.AppendChild(audio);
        }
示例#29
0
        /// <summary>
        /// Clears the queue of currently scheduled notifications and schedules all notifications that should happen in the next 30 min.
        /// 30 min is chosen because our background task is guarenteed to run every 30 min (smallest possible interval).
        /// Each time the background task runs, it will call this function and set all notifications that should appear before the next time the task is able to run.
        /// </summary>
        public void ScheduleNotifications()
        {
            if (!HasMultipleModes)
            {
                // Don't try to schedule notitfications if the user has not set any modes
                return;
            }

            List <string> removedNotifications = new List <string>();
            List <string> addedNotifications   = new List <string>();

            // First, clear the scheduled notification queue
            IReadOnlyList <ScheduledToastNotification> scheduledNotifications = _toastNotifier.GetScheduledToastNotifications();

            foreach (ScheduledToastNotification notification in scheduledNotifications)
            {
                removedNotifications.Add(notification.DeliveryTime.ToString());
                _toastNotifier.RemoveFromSchedule(notification);
            }

            // Clear any of our existing notifications from the user's action center
            // TODO: leaving this in for now to test. Want to make sure that past notifications fire properly
            //ToastNotificationManager.History.Clear();

            if (State == TimerState.Running)
            {
                // Schedule all notifications that will appear in the next 30 min
                DateTimeOffset now                  = DateTimeOffset.Now;
                TimeSpan       thirtyMin            = TimeSpan.FromMinutes(30);
                ModeModel      modeToNotifyEnd      = CurrentMode;
                DateTimeOffset nextNotificationTime = now + GetTimeRemainingInCurrentMode();

                while (nextNotificationTime - now < thirtyMin)
                {
                    ModeModel nextMode = getNextMode(modeToNotifyEnd);

                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
                    IXmlNode    textNode = toastXml.GetElementsByTagName("text")[0];
                    textNode.AppendChild(toastXml.CreateTextNode($"Time to {nextMode}! ({nextNotificationTime.ToString("t")})"));

                    ScheduledToastNotification notification = new ScheduledToastNotification(toastXml, nextNotificationTime);
                    _toastNotifier.AddToSchedule(notification);
                    addedNotifications.Add(notification.DeliveryTime.ToString());

                    modeToNotifyEnd = nextMode;

                    TimeSpan timeForMode = modeToNotifyEnd.TimeInMode;
                    nextNotificationTime = nextNotificationTime + timeForMode;
                }
            }

            _lastDebugInfo = new DebugInfo()
            {
                LastRunTime                   = DateTime.Now,
                NotificationsScheduled        = addedNotifications.ToArray(),
                ScheduledNotificationsRemoved = removedNotifications.ToArray()
            };
        }
        static void SetNodeValueString(string str, IXmlDocument xmldoc, IXmlNode node) {
            IXmlText textNode;
            int res = xmldoc.CreateTextNode(str, out textNode);
            ComFunctions.CheckHRESULT(res);

            IXmlNode textNodeAsNode = (IXmlNode)textNode;
            IXmlNode appendedChild;
            res = node.AppendChild(textNodeAsNode, out appendedChild);
            ComFunctions.CheckHRESULT(res);
        }
示例#31
0
        private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
        {
            if (propertyName != "?xml")
            {
                IXmlNode newChild = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
                currentNode.AppendChild(newChild);
            }
            else
            {
                string version    = null;
                string encoding   = null;
                string standalone = null;
                while (reader.Read() && (reader.TokenType != JsonToken.EndObject))
                {
                    string str4 = reader.Value.ToString();
                    if (str4 != "@version")
                    {
                        if (str4 != "@encoding")
                        {
                            if (str4 != "@standalone")
                            {
                                throw JsonSerializationException.Create(reader, "Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                            }
                            goto Label_008D;
                        }
                    }
                    else
                    {
                        reader.Read();
                        version = reader.Value.ToString();
                        continue;
                    }
                    reader.Read();
                    encoding = reader.Value.ToString();
                    continue;
Label_008D:
                    reader.Read();
                    standalone = reader.Value.ToString();
                }
                IXmlNode newChild = document.CreateXmlDeclaration(version, encoding, standalone);
                currentNode.AppendChild(newChild);
            }
        }
示例#32
0
 private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
 {
   string prefix = MiscellaneousUtils.GetPrefix(propertyName);
   IXmlElement element = this.CreateElement(propertyName, document, prefix, manager);
   currentNode.AppendChild((IXmlNode) element);
   int num = 0;
   while (reader.Read() && reader.TokenType != JsonToken.EndArray)
   {
     this.DeserializeValue(reader, document, manager, propertyName, (IXmlNode) element);
     ++num;
   }
   if (this.WriteArrayAttribute)
     this.AddJsonArrayAttribute(element, document);
   if (num != 1 || !this.WriteArrayAttribute)
     return;
   this.AddJsonArrayAttribute(Enumerable.Single<IXmlElement>(CollectionUtils.CastValid<IXmlElement>((IEnumerable) element.ChildNodes), (Func<IXmlElement, bool>) (n => n.LocalName == propertyName)), document);
 }
        private static void AddHyperlink(IXmlNode xamlParentElement, IXmlNode htmlElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Convert href attribute into NavigateUri and TargetName
            string href = GetAttribute(htmlElement, "href");
            if (href == null)
            {
                // When href attribute is missing - ignore the hyperlink
                AddSpanOrRun(xamlParentElement, htmlElement, inheritedProperties, sourceContext);
            }
            else
            {
                // Create currentProperties as a compilation of local and inheritedProperties, set localProperties
                Dictionary<string,string> localProperties;
                Dictionary<string, string> currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, sourceContext);

                // Create a XAML element corresponding to this html element
                XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, HtmlToXamlConverter.Xaml_Hyperlink);

                ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/false);

                string[] hrefParts = href.Split(new char[] { '#' });
                if (hrefParts.Length > 0 && hrefParts[0].Trim().Length > 0)
                {
                    xamlElement.SetAttribute(HtmlToXamlConverter.Xaml_Hyperlink_NavigateUri, hrefParts[0].Trim());
                }
                if (hrefParts.Length == 2 && hrefParts[1].Trim().Length > 0)
                {
                    xamlElement.SetAttribute(HtmlToXamlConverter.Xaml_Hyperlink_TargetName, hrefParts[1].Trim());
                }

                // Recurse into element subtree
                for (var htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
                {
                    AddInline(xamlElement, htmlChildNode, currentProperties, sourceContext);
                }

                // Add the new element to the parent.
                xamlParentElement.AppendChild(xamlElement);
            }
        }
 // Token: 0x060006EA RID: 1770
 // RVA: 0x00038974 File Offset: 0x00036B74
 private void CreateDocumentType(JsonReader reader, IXmlDocument document, IXmlNode currentNode)
 {
     string name = null;
     string publicId = null;
     string systemId = null;
     string internalSubset = null;
     while (reader.Read())
     {
         if (reader.TokenType == JsonToken.EndObject)
         {
             break;
         }
         string a;
         if ((a = reader.Value.ToString()) != null)
         {
             if (a == "@name")
             {
                 reader.Read();
                 name = reader.Value.ToString();
                 continue;
             }
             if (a == "@public")
             {
                 reader.Read();
                 publicId = reader.Value.ToString();
                 continue;
             }
             if (a == "@system")
             {
                 reader.Read();
                 systemId = reader.Value.ToString();
                 continue;
             }
             if (a == "@internalSubset")
             {
                 reader.Read();
                 internalSubset = reader.Value.ToString();
                 continue;
             }
         }
         throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
     }
     IXmlNode newChild = document.CreateXmlDocumentType(name, publicId, systemId, internalSubset);
     currentNode.AppendChild(newChild);
 }
示例#35
0
 private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
 {
   do
   {
     switch (reader.TokenType)
     {
       case JsonToken.StartConstructor:
         string propertyName1 = reader.Value.ToString();
         while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
           this.DeserializeValue(reader, document, manager, propertyName1, currentNode);
         break;
       case JsonToken.PropertyName:
         if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
           throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.");
         string propertyName = reader.Value.ToString();
         reader.Read();
         if (reader.TokenType == JsonToken.StartArray)
         {
           int num = 0;
           while (reader.Read() && reader.TokenType != JsonToken.EndArray)
           {
             this.DeserializeValue(reader, document, manager, propertyName, currentNode);
             ++num;
           }
           if (num == 1 && this.WriteArrayAttribute)
           {
             this.AddJsonArrayAttribute(Enumerable.Single<IXmlElement>(CollectionUtils.CastValid<IXmlElement>((IEnumerable) currentNode.ChildNodes), (Func<IXmlElement, bool>) (n => n.LocalName == propertyName)), document);
             break;
           }
           else
             break;
         }
         else
         {
           this.DeserializeValue(reader, document, manager, propertyName, currentNode);
           break;
         }
       case JsonToken.Comment:
         currentNode.AppendChild(document.CreateComment((string) reader.Value));
         break;
       case JsonToken.EndObject:
         return;
       case JsonToken.EndArray:
         return;
       default:
         throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + (object) reader.TokenType);
     }
   }
   while (reader.TokenType == JsonToken.PropertyName || reader.Read());
 }
        // .............................................................
        //
        // Lists
        //
        // .............................................................
        /// <summary>
        /// Converts Html ul or ol element into Xaml list element. During conversion if the ul/ol element has any children 
        /// that are not li elements, they are ignored and not added to the list element
        /// </summary>
        /// <param name="xamlParentElement">
        /// XmlElement representing Xaml parent to which the converted element should be added
        /// </param>
        /// <param name="htmlListElement">
        /// XmlElement representing Html ul/ol element to be converted
        /// </param>
        /// <param name="inheritedProperties">
        /// properties inherited from parent context
        /// </param>
        /// 
        /// <param name="sourceContext"></param>
        private static void AddList(IXmlNode xamlParentElement, IXmlNode htmlListElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            string htmlListElementName = htmlListElement.LocalName.ToLower();

            Dictionary<string,string> localProperties;
            Dictionary<string, string> currentProperties = GetElementProperties(htmlListElement, inheritedProperties, out localProperties, sourceContext);

            // Create Xaml List element
            XmlElement xamlListElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_List);

            // Set default list markers
            if (htmlListElementName == "ol")
            {
                // Ordered list
                xamlListElement.SetAttribute(Xaml_List_MarkerStyle, Xaml_List_MarkerStyle_Decimal);
            }
            else
            {
                // Unordered list - all elements other than OL treated as unordered lists
                xamlListElement.SetAttribute(Xaml_List_MarkerStyle, Xaml_List_MarkerStyle_Disc);
            }

            // Apply local properties to list to set marker attribute if specified
            // TODO: Should we have separate list attribute processing function?
            ApplyLocalProperties(xamlListElement, localProperties, /*isBlock:*/true);

            // Recurse into list subtree
            for (var htmlChildNode = htmlListElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
            {
                if (htmlChildNode.NodeType == NodeType.ElementNode && htmlChildNode.LocalName.ToLower() == "li")
                {
                    sourceContext.Add(htmlChildNode);

                    AddListItem(xamlListElement, htmlChildNode, currentProperties, sourceContext);

                    Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlChildNode);

                    sourceContext.RemoveAt(sourceContext.Count - 1);
                }
                else
                {
                    // Not an li element. Add it to previous ListBoxItem
                    //  We need to append the content to the end
                    // of a previous list item.
                }
            }

            // Add the List element to xaml tree - if it is not empty
            if (xamlListElement.HasChildNodes())
            {
                xamlParentElement.AppendChild(xamlListElement);
            }
        }
        private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary<string, string> attributeNameValues)
        {
            IXmlElement element = CreateElement(elementName, document, elementPrefix, manager);

            currentNode.AppendChild(element);

            // add attributes to newly created element
            foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
            {
                string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

                IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                    ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value)
                    : document.CreateAttribute(nameValue.Key, nameValue.Value);

                element.SetAttributeNode(attribute);
            }

            if (reader.TokenType == JsonToken.String
                || reader.TokenType == JsonToken.Integer
                || reader.TokenType == JsonToken.Float
                || reader.TokenType == JsonToken.Boolean
                || reader.TokenType == JsonToken.Date)
            {
                element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
            }
            else if (reader.TokenType == JsonToken.Null)
            {
                // empty element. do nothing
            }
            else
            {
                // finished element will have no children to deserialize
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();
                    DeserializeNode(reader, document, manager, element);
                    manager.PopScope();
                }

                manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
            }
        }
示例#38
0
 private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
 {
   switch (propertyName)
   {
     case "#text":
       currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
       break;
     case "#cdata-section":
       currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
       break;
     case "#whitespace":
       currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
       break;
     case "#significant-whitespace":
       currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
       break;
     default:
       if (!string.IsNullOrEmpty(propertyName) && (int) propertyName[0] == 63)
       {
         this.CreateInstruction(reader, document, currentNode, propertyName);
         break;
       }
       else if (reader.TokenType == JsonToken.StartArray)
       {
         this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
         break;
       }
       else
       {
         this.ReadElement(reader, document, currentNode, propertyName, manager);
         break;
       }
   }
 }
 // Token: 0x060006E3 RID: 1763
 // RVA: 0x000381B4 File Offset: 0x000363B4
 private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
 {
     if (propertyName != null)
     {
         if (propertyName == "#text")
         {
             currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
             return;
         }
         if (propertyName == "#cdata-section")
         {
             currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
             return;
         }
         if (propertyName == "#whitespace")
         {
             currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
             return;
         }
         if (propertyName == "#significant-whitespace")
         {
             currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
             return;
         }
     }
     if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
     {
         this.CreateInstruction(reader, document, currentNode, propertyName);
         return;
     }
     if (string.Equals(propertyName, "!DOCTYPE", StringComparison.OrdinalIgnoreCase))
     {
         this.CreateDocumentType(reader, document, currentNode);
         return;
     }
     if (reader.TokenType == JsonToken.StartArray)
     {
         this.ReadArrayElements(reader, document, propertyName, currentNode, manager);
         return;
     }
     this.ReadElement(reader, document, currentNode, propertyName, manager);
 }
        private static void AddSpanOrRun(IXmlNode xamlParentElement, IXmlNode htmlElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Decide what XAML element to use for this inline element.
            // Check whether it contains any nested inlines
            bool elementHasChildren = false;

            for (var htmlNode = htmlElement.FirstChild; htmlNode != null; htmlNode = htmlNode.NextSibling)
            {
                if (htmlNode is XmlElement)
                {
                    string htmlChildName = ((string)htmlNode.LocalName).ToLower();

                    if (HtmlSchema.IsInlineElement(htmlChildName) ||
                        HtmlSchema.IsBlockElement(htmlChildName) ||
                        htmlChildName == "img" ||
                        htmlChildName == "br" ||
                        htmlChildName == "hr")
                    {
                        elementHasChildren = true;

                        break;
                    }
                }
            }

            string xamlElementName = elementHasChildren ? HtmlToXamlConverter.Xaml_Span : HtmlToXamlConverter.Xaml_Run;

            // Create currentProperties as a compilation of local and inheritedProperties, set localProperties
            Dictionary<string,string> localProperties;
            Dictionary<string, string> currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, sourceContext);

            // Create a XAML element corresponding to this html element
            XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, xamlElementName);

            ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/false);

            // Recurse into element subtree
            for (var htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
            {
                AddInline(xamlElement, htmlChildNode, currentProperties, sourceContext);
            }

            // Add the new element to the parent.
            xamlParentElement.AppendChild(xamlElement);
        }
示例#41
0
 private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
 {
   if (string.IsNullOrEmpty(propertyName))
     throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
   Dictionary<string, string> dictionary = this.ReadAttributeElements(reader, manager);
   string prefix1 = MiscellaneousUtils.GetPrefix(propertyName);
   if (propertyName.StartsWith("@"))
   {
     string str1 = propertyName.Substring(1);
     string str2 = reader.Value.ToString();
     string prefix2 = MiscellaneousUtils.GetPrefix(str1);
     IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(str1, manager.LookupNamespace(prefix2), str2) : document.CreateAttribute(str1, str2);
     ((IXmlElement) currentNode).SetAttributeNode(attribute);
   }
   else
   {
     IXmlElement element = this.CreateElement(propertyName, document, prefix1, manager);
     currentNode.AppendChild((IXmlNode) element);
     foreach (KeyValuePair<string, string> keyValuePair in dictionary)
     {
       string prefix2 = MiscellaneousUtils.GetPrefix(keyValuePair.Key);
       IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(keyValuePair.Key, manager.LookupNamespace(prefix2), keyValuePair.Value) : document.CreateAttribute(keyValuePair.Key, keyValuePair.Value);
       element.SetAttributeNode(attribute);
     }
     if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer || (reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Boolean) || reader.TokenType == JsonToken.Date)
     {
       element.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
     }
     else
     {
       if (reader.TokenType == JsonToken.Null || reader.TokenType == JsonToken.EndObject)
         return;
       manager.PushScope();
       this.DeserializeNode(reader, document, manager, (IXmlNode) element);
       manager.PopScope();
     }
   }
 }
示例#42
0
    private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
    {
      if (propertyName == DeclarationName)
      {
        string version = null;
        string encoding = null;
        string standalone = null;
        while (reader.Read() && reader.TokenType != JsonToken.EndObject)
        {
          switch (reader.Value.ToString())
          {
            case "@version":
              reader.Read();
              version = reader.Value.ToString();
              break;
            case "@encoding":
              reader.Read();
              encoding = reader.Value.ToString();
              break;
            case "@standalone":
              reader.Read();
              standalone = reader.Value.ToString();
              break;
            default:
              throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
          }
        }

        IXmlNode declaration = document.CreateXmlDeclaration(version, encoding, standalone);
        currentNode.AppendChild(declaration);
      }
      else
      {
        IXmlNode instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
        currentNode.AppendChild(instruction);
      }
    }
 // Token: 0x060006E9 RID: 1769
 // RVA: 0x00038868 File Offset: 0x00036A68
 private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
 {
     if (propertyName == "?xml")
     {
         string version = null;
         string encoding = null;
         string standalone = null;
         while (reader.Read())
         {
             if (reader.TokenType == JsonToken.EndObject)
             {
                 break;
             }
             string a;
             if ((a = reader.Value.ToString()) != null)
             {
                 if (a == "@version")
                 {
                     reader.Read();
                     version = reader.Value.ToString();
                     continue;
                 }
                 if (a == "@encoding")
                 {
                     reader.Read();
                     encoding = reader.Value.ToString();
                     continue;
                 }
                 if (a == "@standalone")
                 {
                     reader.Read();
                     standalone = reader.Value.ToString();
                     continue;
                 }
             }
             throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
         }
         IXmlNode newChild = document.CreateXmlDeclaration(version, encoding, standalone);
         currentNode.AppendChild(newChild);
         return;
     }
     IXmlNode newChild2 = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
     currentNode.AppendChild(newChild2);
 }
 // Token: 0x060006EC RID: 1772
 // RVA: 0x00038AB8 File Offset: 0x00036CB8
 private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
 {
     JsonToken tokenType;
     while (true)
     {
         tokenType = reader.TokenType;
         switch (tokenType)
         {
         case JsonToken.StartConstructor:
         {
             string propertyName2 = reader.Value.ToString();
             while (reader.Read())
             {
                 if (reader.TokenType == JsonToken.EndConstructor)
                 {
                     break;
                 }
                 this.DeserializeValue(reader, document, manager, propertyName2, currentNode);
             }
             goto IL_44;
         }
         case JsonToken.PropertyName:
         {
             if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
             {
                 goto IL_17B;
             }
             string propertyName = reader.Value.ToString();
             reader.Read();
             if (reader.TokenType != JsonToken.StartArray)
             {
                 this.DeserializeValue(reader, document, manager, propertyName, currentNode);
                 goto IL_44;
             }
             int num = 0;
             while (reader.Read())
             {
                 if (reader.TokenType == JsonToken.EndArray)
                 {
                     break;
                 }
                 this.DeserializeValue(reader, document, manager, propertyName, currentNode);
                 num++;
             }
             if (num == 1 && this.WriteArrayAttribute)
             {
                 IXmlElement element = Enumerable.Single<IXmlElement>(Enumerable.OfType<IXmlElement>(currentNode.ChildNodes), (IXmlElement n) => n.LocalName == propertyName);
                 this.AddJsonArrayAttribute(element, document);
                 goto IL_44;
             }
             goto IL_44;
         }
         case JsonToken.Comment:
             currentNode.AppendChild(document.CreateComment((string)reader.Value));
             goto IL_44;
         }
         break;
         IL_44:
         if (reader.TokenType != JsonToken.PropertyName && !reader.Read())
         {
             return;
         }
     }
     switch (tokenType)
     {
     case JsonToken.EndObject:
     case JsonToken.EndArray:
         return;
     default:
         throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
     }
     return;
     IL_17B:
     throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.");
 }
        private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
        {
            Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager);

              string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

              IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);

              currentNode.AppendChild(element);

              // add attributes to newly created element
              foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
              {
            string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

            IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                               ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
                               : document.CreateAttribute(nameValue.Key, nameValue.Value);

            element.SetAttributeNode(attribute);
              }

              if (reader.TokenType == JsonToken.String)
              {
            element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
              }
              else if (reader.TokenType == JsonToken.Integer)
              {
            element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
              }
              else if (reader.TokenType == JsonToken.Float)
              {
            element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
              }
              else if (reader.TokenType == JsonToken.Boolean)
              {
            element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
              }
              else if (reader.TokenType == JsonToken.Date)
              {
            DateTime d = (DateTime)reader.Value;
            element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
              }
              else if (reader.TokenType == JsonToken.Null)
              {
            // empty element. do nothing
              }
              else
              {
            // finished element will have no children to deserialize
            if (reader.TokenType != JsonToken.EndObject)
            {
              manager.PushScope();

              DeserializeNode(reader, document, manager, element);

              manager.PopScope();
            }
              }
        }
        private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
        {
            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

              IXmlElement nestedArrayElement = CreateElement(propertyName, document, elementPrefix, manager);

              currentNode.AppendChild(nestedArrayElement);

              while (reader.Read() && reader.TokenType != JsonToken.EndArray)
              {
            DeserializeValue(reader, document, manager, propertyName, nestedArrayElement);
              }
        }
示例#47
0
        private void CreateDocumentType(JsonReader reader, IXmlDocument document, IXmlNode currentNode)
        {
            string name = null;
            string publicId = null;
            string systemId = null;
            string internalSubset = null;
            while (reader.Read() && reader.TokenType != JsonToken.EndObject)
            {
                switch (reader.Value.ToString())
                {
                    case "@name":
                        reader.Read();
                        name = reader.Value.ToString();
                        break;
                    case "@public":
                        reader.Read();
                        publicId = reader.Value.ToString();
                        break;
                    case "@system":
                        reader.Read();
                        systemId = reader.Value.ToString();
                        break;
                    case "@internalSubset":
                        reader.Read();
                        internalSubset = reader.Value.ToString();
                        break;
                    default:
                        throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                }
            }

            IXmlNode documentType = document.CreateXmlDocumentType(name, publicId, systemId, internalSubset);
            currentNode.AppendChild(documentType);
        }
 // Token: 0x060006E4 RID: 1764
 // RVA: 0x000382C8 File Offset: 0x000364C8
 private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
 {
     if (string.IsNullOrEmpty(propertyName))
     {
         throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
     }
     Dictionary<string, string> dictionary = this.ReadAttributeElements(reader, manager);
     string prefix = MiscellaneousUtils.GetPrefix(propertyName);
     if (StringUtils.StartsWith(propertyName, '@'))
     {
         string text = propertyName.Substring(1);
         string value = reader.Value.ToString();
         string prefix2 = MiscellaneousUtils.GetPrefix(text);
         IXmlNode attributeNode = (!string.IsNullOrEmpty(prefix2)) ? document.CreateAttribute(text, manager.LookupNamespace(prefix2), value) : document.CreateAttribute(text, value);
         ((IXmlElement)currentNode).SetAttributeNode(attributeNode);
         return;
     }
     IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);
     currentNode.AppendChild(xmlElement);
     foreach (KeyValuePair<string, string> current in dictionary)
     {
         string prefix3 = MiscellaneousUtils.GetPrefix(current.Key);
         IXmlNode attributeNode2 = (!string.IsNullOrEmpty(prefix3)) ? document.CreateAttribute(current.Key, manager.LookupNamespace(prefix3), current.Value) : document.CreateAttribute(current.Key, current.Value);
         xmlElement.SetAttributeNode(attributeNode2);
     }
     if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Integer && reader.TokenType != JsonToken.Float && reader.TokenType != JsonToken.Boolean)
     {
         if (reader.TokenType != JsonToken.Date)
         {
             if (reader.TokenType == JsonToken.Null)
             {
                 return;
             }
             if (reader.TokenType != JsonToken.EndObject)
             {
                 manager.PushScope();
                 this.DeserializeNode(reader, document, manager, xmlElement);
                 manager.PopScope();
             }
             manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
             return;
         }
     }
     xmlElement.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
 }
        /// <summary>
        /// Creates a Paragraph element and adds all nodes starting from htmlNode
        /// converted to appropriate Inlines.
        /// </summary>
        /// <param name="xamlParentElement">
        /// XmlElement representing Xaml parent to which the converted element should be added
        /// </param>
        /// <param name="htmlNode">
        /// XmlElement starting a collection of implicitly wrapped inlines.
        /// </param>
        /// <param name="inheritedProperties">
        /// properties inherited from parent context
        /// </param>
        /// 
        /// <param name="sourceContext"></param>
        /// true indicates that a content added by this call contains at least one block element
        /// </param>
        /// <returns>
        /// The last htmlNode added to the implicit paragraph
        /// </returns>
        private static IXmlNode AddImplicitParagraph(IXmlNode xamlParentElement, IXmlNode htmlNode, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Collect all non-block elements and wrap them into implicit Paragraph
            var xamlParagraph = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, HtmlToXamlConverter.Xaml_Paragraph);

            IXmlNode lastNodeProcessed = null;

            while (htmlNode != null)
            {
                if (htmlNode.NodeType == NodeType.CommentNode)
                {
                    DefineInlineFragmentParent(htmlNode, null);
                }
                else if (htmlNode.NodeType == NodeType.TextNode)
                {
                    if (((string)htmlNode.NodeValue).Trim().Length > 0)
                    {
                        AddTextRun(xamlParagraph, (string)htmlNode.NodeValue);
                    }
                }
                else if (htmlNode is XmlElement)
                {
                    string htmlChildName = ((string)htmlNode.LocalName).ToLower();

                    if (HtmlSchema.IsBlockElement(htmlChildName))
                    {
                        // The sequence of non-blocked inlines ended. Stop implicit loop here.
                        break;
                    }
                    else
                    {
                        AddInline(xamlParagraph, htmlNode, inheritedProperties, sourceContext);
                    }
                }

                // Store last processed node to return it at the end
                lastNodeProcessed = htmlNode;

                htmlNode = htmlNode.NextSibling;
            }

            // Add the Paragraph to the parent
            // If only whitespaces and commens have been encountered,
            // then we have nothing to add in implicit paragraph; forget it.
            if (xamlParagraph.FirstChild != null)
            {
                xamlParentElement.AppendChild(xamlParagraph);
            }

            // Need to return last processed node
            return lastNodeProcessed;
        }
        private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
        {
            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            IXmlElement nestedArrayElement = CreateElement(propertyName, document, elementPrefix, manager);

            currentNode.AppendChild(nestedArrayElement);

            int count = 0;
            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                DeserializeValue(reader, document, manager, propertyName, nestedArrayElement);
                count++;
            }

            if (WriteArrayAttribute)
            {
                AddJsonArrayAttribute(nestedArrayElement, document);
            }

            if (count == 1 && WriteArrayAttribute)
            {
                foreach (IXmlNode childNode in nestedArrayElement.ChildNodes)
                {
                    IXmlElement element = childNode as IXmlElement;
                    if (element != null && element.LocalName == propertyName)
                    {
                        AddJsonArrayAttribute(element, document);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Converts htmlLIElement into Xaml ListItem element, and appends it to the parent xamlListElement
        /// </summary>
        /// <param name="xamlListElement">
        /// XmlElement representing Xaml List element to which the converted td/th should be added
        /// </param>
        /// <param name="htmlLIElement">
        /// XmlElement representing Html li element to be converted
        /// </param>
        /// <param name="inheritedProperties">
        /// Properties inherited from parent context
        /// </param>
        private static void AddListItem(IXmlNode xamlListElement, IXmlNode htmlLIElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Parameter validation
            Debug.Assert(xamlListElement != null);
            Debug.Assert((string)xamlListElement.LocalName == Xaml_List);
            Debug.Assert(htmlLIElement != null);
            Debug.Assert(htmlLIElement.LocalName.ToLower() == "li");
            Debug.Assert(inheritedProperties != null);

            Dictionary<string,string> localProperties;
            Dictionary<string, string> currentProperties = GetElementProperties(htmlLIElement, inheritedProperties, out localProperties, sourceContext);

            XmlElement xamlListItemElement = xamlListElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_ListItem);

            // TODO: process local properties for li element

            // Process children of the ListItem
            for (var htmlChildNode = htmlLIElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
            {
                htmlChildNode = AddBlock(xamlListItemElement, htmlChildNode, currentProperties, sourceContext);
            }

            // Add resulting ListBoxItem to a xaml parent
            xamlListElement.AppendChild(xamlListItemElement);
        }
 // Token: 0x060006E6 RID: 1766
 // RVA: 0x000385A8 File Offset: 0x000367A8
 private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
 {
     string prefix = MiscellaneousUtils.GetPrefix(propertyName);
     IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);
     currentNode.AppendChild(xmlElement);
     int num = 0;
     while (reader.Read())
     {
         if (reader.TokenType == JsonToken.EndArray)
         {
             break;
         }
         this.DeserializeValue(reader, document, manager, propertyName, xmlElement);
         num++;
     }
     if (this.WriteArrayAttribute)
     {
         this.AddJsonArrayAttribute(xmlElement, document);
     }
     if (num == 1 && this.WriteArrayAttribute)
     {
         IXmlElement element = Enumerable.Single<IXmlElement>(Enumerable.OfType<IXmlElement>(xmlElement.ChildNodes), (IXmlElement n) => n.LocalName == propertyName);
         this.AddJsonArrayAttribute(element, document);
     }
 }
示例#53
0
    private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
    {
      if (string.IsNullOrEmpty(propertyName))
        throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");

      Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager);

      string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

      if (propertyName.StartsWith("@"))
      {
        var attributeName = propertyName.Substring(1);
        var attributeValue = reader.Value.ToString();

        var attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);

        var attribute = (!string.IsNullOrEmpty(attributePrefix))
                                 ? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
                                 : document.CreateAttribute(attributeName, attributeValue);

        ((IXmlElement)currentNode).SetAttributeNode(attribute);
      }
      else
      {
        IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);

        currentNode.AppendChild(element);

        // add attributes to newly created element
        foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
        {
          string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

          IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                                 ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
                                 : document.CreateAttribute(nameValue.Key, nameValue.Value);

          element.SetAttributeNode(attribute);
        }

        if (reader.TokenType == JsonToken.String
            || reader.TokenType == JsonToken.Integer
            || reader.TokenType == JsonToken.Float
            || reader.TokenType == JsonToken.Boolean
            || reader.TokenType == JsonToken.Date)
        {
          element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
        }
        else if (reader.TokenType == JsonToken.Null)
        {
          // empty element. do nothing
        }
        else
        {
          // finished element will have no children to deserialize
          if (reader.TokenType != JsonToken.EndObject)
          {
            manager.PushScope();

            DeserializeNode(reader, document, manager, element);

            manager.PopScope();
          }
        }
      }
    }
        // .............................................................
        //
        // Tables
        //
        // .............................................................
        /// <summary>
        /// Converts htmlTableElement to a Xaml Table element. Adds tbody elements if they are missing so
        /// that a resulting Xaml Table element is properly formed.
        /// </summary>
        /// <param name="xamlParentElement">
        /// Parent xaml element to which a converted table must be added.
        /// </param>
        /// <param name="htmlTableElement">
        /// XmlElement reprsenting the Html table element to be converted
        /// </param>
        /// <param name="inheritedProperties">
        /// Dictionary<string,string> representing properties inherited from parent context. 
        /// </param>
        private static void AddTable(IXmlNode xamlParentElement, IXmlNode htmlTableElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Parameter validation
            Debug.Assert(htmlTableElement.LocalName.ToLower() == "table");
            Debug.Assert(xamlParentElement != null);
            Debug.Assert(inheritedProperties != null);

            // Create current properties to be used by children as inherited properties, set local properties
            Dictionary<string,string> localProperties;
            Dictionary<string, string> currentProperties = GetElementProperties(htmlTableElement, inheritedProperties, out localProperties, sourceContext);

            // TODO: process localProperties for tables to override defaults, decide cell spacing defaults

            // Check if the table contains only one cell - we want to take only its content
            var singleCell = GetCellFromSingleCellTable(htmlTableElement);

            if (singleCell != null)
            {
                //  Need to push skipped table elements onto sourceContext
                sourceContext.Add(singleCell);

                // Add the cell's content directly to parent
                for (var htmlChildNode = singleCell.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
                {
                    htmlChildNode = AddBlock(xamlParentElement, htmlChildNode, currentProperties, sourceContext);
                }

                Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == singleCell);
                sourceContext.RemoveAt(sourceContext.Count - 1);
            }
            else
            {
                // Create xamlTableElement
                XmlElement xamlTableElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_Table);

                // Analyze table structure for column widths and rowspan attributes
                List<double> columnStarts = AnalyzeTableStructure(htmlTableElement);

                // Process COLGROUP & COL elements
                AddColumnInformation(htmlTableElement, xamlTableElement, columnStarts, currentProperties, sourceContext);

                // Process table body - TBODY and TR elements
                var htmlChildNode = htmlTableElement.FirstChild;

                while (htmlChildNode != null)
                {
                    string htmlChildName = htmlChildNode.LocalName.ToLower();

                    // Process the element
                    if (htmlChildName == "tbody" || htmlChildName == "thead" || htmlChildName == "tfoot")
                    {
                        //  Add more special processing for TableHeader and TableFooter
                        XmlElement xamlTableBodyElement = xamlTableElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_TableRowGroup);

                        xamlTableElement.AppendChild(xamlTableBodyElement);

                        sourceContext.Add(htmlChildNode);

                        // Get properties of Html tbody element
                        Dictionary<string,string> tbodyElementLocalProperties;
                        Dictionary<string, string> tbodyElementCurrentProperties = GetElementProperties(htmlChildNode, currentProperties, out tbodyElementLocalProperties, sourceContext);
                        // TODO: apply local properties for tbody

                        // Process children of htmlChildNode, which is tbody, for tr elements
                        AddTableRowsToTableBody(xamlTableBodyElement, htmlChildNode.FirstChild, tbodyElementCurrentProperties, columnStarts, sourceContext);

                        if (xamlTableBodyElement.HasChildNodes())
                        {
                            xamlTableElement.AppendChild(xamlTableBodyElement);
                            // else: if there is no TRs in this TBody, we simply ignore it
                        }

                        Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlChildNode);
                        sourceContext.RemoveAt(sourceContext.Count - 1);

                        htmlChildNode = htmlChildNode.NextSibling;
                    }
                    else if (htmlChildName == "tr")
                    {
                        // Tbody is not present, but tr element is present. Tr is wrapped in tbody
                        XmlElement xamlTableBodyElement = xamlTableElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_TableRowGroup);

                        // We use currentProperties of xamlTableElement when adding rows since the tbody element is artificially created and has
                        // no properties of its own

                        htmlChildNode = AddTableRowsToTableBody(xamlTableBodyElement, htmlChildNode, currentProperties, columnStarts, sourceContext);

                        if (xamlTableBodyElement.HasChildNodes())
                        {
                            xamlTableElement.AppendChild(xamlTableBodyElement);
                        }
                    }
                    else
                    {
                        // Element is not tbody or tr. Ignore it.
                        // TODO: add processing for thead, tfoot elements and recovery for td elements
                        htmlChildNode = htmlChildNode.NextSibling;
                    }
                }

                if (xamlTableElement.HasChildNodes())
                {
                    xamlParentElement.AppendChild(xamlTableElement);
                }
            }
        }
示例#55
0
    private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
    {
      switch (propertyName)
      {
        case TextName:
          currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
          break;
        case CDataName:
          currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
          break;
        case WhitespaceName:
          currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
          break;
        case SignificantWhitespaceName:
          currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
          break;
        default:
          // processing instructions and the xml declaration start with ?
          if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
          {
            CreateInstruction(reader, document, currentNode, propertyName);
          }
          else
          {
            if (reader.TokenType == JsonToken.StartArray)
            {
              // handle nested arrays
              ReadArrayElements(reader, document, propertyName, currentNode, manager);
              return;
            }

            // have to wait until attributes have been parsed before creating element
            // attributes may contain namespace info used by the element
            ReadElement(reader, document, currentNode, propertyName, manager);
          }
          break;
      }
    }
        /// <summary>
        /// Generates Paragraph element from P, H1-H7, Center etc.
        /// </summary>
        /// <param name="xamlParentElement">
        /// XmlElement representing Xaml parent to which the converted element should be added
        /// </param>
        /// <param name="htmlElement">
        /// XmlElement representing Html element to be converted
        /// </param>
        /// <param name="inheritedProperties">
        /// properties inherited from parent context
        /// </param>
        /// 
        /// <param name="sourceContext"></param>
        /// true indicates that a content added by this call contains at least one block element
        /// </param>
        private static void AddParagraph(IXmlNode xamlParentElement, IXmlNode htmlElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Create currentProperties as a compilation of local and inheritedProperties, set localProperties
            Dictionary<string,string> localProperties;
            Dictionary<string, string> currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, sourceContext);

            // Create a XAML element corresponding to this html element
            XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, HtmlToXamlConverter.Xaml_Paragraph);

            ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/true);

            // Recurse into element subtree
            for (var htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
            {
                AddInline(xamlElement, htmlChildNode, currentProperties, sourceContext);
            }

            // Add the new element to the parent.
            xamlParentElement.AppendChild(xamlElement);
        }
示例#57
0
    private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
    {
      string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

      IXmlElement nestedArrayElement = CreateElement(propertyName, document, elementPrefix, manager);

      currentNode.AppendChild(nestedArrayElement);

      int count = 0;
      while (reader.Read() && reader.TokenType != JsonToken.EndArray)
      {
        DeserializeValue(reader, document, manager, propertyName, nestedArrayElement);
        count++;
      }

      if (WriteArrayAttribute)
      {
        AddJsonArrayAttribute(nestedArrayElement, document);
      }

      if (count == 1 && WriteArrayAttribute)
      {
        IXmlElement arrayElement = nestedArrayElement.ChildNodes.CastValid<IXmlElement>().Single(n => n.LocalName == propertyName);
        AddJsonArrayAttribute(arrayElement, document);
      }
    }
        /// <summary>
        /// If li items are found without a parent ul/ol element in Html string, creates xamlListElement as their parent and adds
        /// them to it. If the previously added node to the same xamlParentElement was a List, adds the elements to that list.
        /// Otherwise, we create a new xamlListElement and add them to it. Elements are added as long as li elements appear sequentially.
        /// The first non-li or text node stops the addition.
        /// </summary>
        /// <param name="xamlParentElement">
        /// Parent element for the list
        /// </param>
        /// <param name="htmlLIElement">
        /// Start Html li element without parent list
        /// </param>
        /// <param name="inheritedProperties">
        /// Properties inherited from parent context
        /// </param>
        /// <returns>
        /// XmlElement representing the first non-li node in the input after one or more li's have been processed.
        /// </returns>
        private static IXmlNode AddOrphanListItems(IXmlNode xamlParentElement, IXmlNode htmlLIElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            Debug.Assert(htmlLIElement.LocalName.ToLower() == "li");

            IXmlNode lastProcessedListItemElement = null;

            // Find out the last element attached to the xamlParentElement, which is the previous sibling of this node
            var xamlListItemElementPreviousSibling = xamlParentElement.LastChild;

            IXmlNode xamlListElement;

            if (xamlListItemElementPreviousSibling != null && (string)xamlListItemElementPreviousSibling.LocalName == Xaml_List)
            {
                // Previously added Xaml element was a list. We will add the new li to it
                xamlListElement = xamlListItemElementPreviousSibling;
            }
            else
            {
                // No list element near. Create our own.
                xamlListElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, Xaml_List);

                xamlParentElement.AppendChild(xamlListElement);
            }

            var htmlChildNode = htmlLIElement;

            string htmlChildNodeName = htmlChildNode == null ? null : htmlChildNode.LocalName.ToLower();

            //  Current element properties missed here.
            //currentProperties = GetElementProperties(htmlLIElement, inheritedProperties, out localProperties, stylesheet);

            // Add li elements to the parent xamlListElement we created as long as they appear sequentially
            // Use properties inherited from xamlParentElement for context
            while (htmlChildNode != null && htmlChildNodeName == "li")
            {
                AddListItem(xamlListElement, htmlChildNode, inheritedProperties, sourceContext);

                lastProcessedListItemElement = htmlChildNode;

                htmlChildNode = htmlChildNode.NextSibling;
                htmlChildNodeName = htmlChildNode == null ? null : htmlChildNode.LocalName.ToLower();
            }

            return lastProcessedListItemElement;
        }
示例#59
0
    private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
    {
      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
              throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.");

            string propertyName = reader.Value.ToString();
            reader.Read();

            if (reader.TokenType == JsonToken.StartArray)
            {
              int count = 0;
              while (reader.Read() && reader.TokenType != JsonToken.EndArray)
              {
                DeserializeValue(reader, document, manager, propertyName, currentNode);
                count++;
              }

              if (count == 1 && WriteArrayAttribute)
              {
                IXmlElement arrayElement = currentNode.ChildNodes.CastValid<IXmlElement>().Single(n => n.LocalName == propertyName);
                AddJsonArrayAttribute(arrayElement, document);
              }
            }
            else
            {
              DeserializeValue(reader, document, manager, propertyName, currentNode);
            }
            break;
          case JsonToken.StartConstructor:
            string constructorName = reader.Value.ToString();

            while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
            {
              DeserializeValue(reader, document, manager, constructorName, currentNode);
            }
            break;
          case JsonToken.Comment:
            currentNode.AppendChild(document.CreateComment((string)reader.Value));
            break;
          case JsonToken.EndObject:
          case JsonToken.EndArray:
            return;
          default:
            throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
        }
      } while (reader.TokenType == JsonToken.PropertyName || reader.Read());
      // don't read if current token is a property. token was already read when parsing element attributes
    }
        // .............................................................
        //
        // Text Flow Elements
        //
        // .............................................................
        /// <summary>
        /// Generates Section or Paragraph element from DIV depending whether it contains any block elements or not
        /// </summary>
        /// <param name="xamlParentElement">
        /// XmlElement representing Xaml parent to which the converted element should be added
        /// </param>
        /// <param name="htmlElement">
        /// XmlElement representing Html element to be converted
        /// </param>
        /// <param name="inheritedProperties">
        /// properties inherited from parent context
        /// </param>
        /// 
        /// <param name="sourceContext"></param>
        /// true indicates that a content added by this call contains at least one block element
        /// </param>
        private static void AddSection(IXmlNode xamlParentElement, IXmlNode htmlElement, Dictionary<string, string> inheritedProperties, List<IXmlNode> sourceContext)
        {
            // Analyze the content of htmlElement to decide what xaml element to choose - Section or Paragraph.
            // If this Div has at least one block child then we need to use Section, otherwise use Paragraph
            bool htmlElementContainsBlocks = false;

            for (var htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
            {
                if (htmlChildNode is XmlElement)
                {
                    string htmlChildName = ((string)htmlChildNode.LocalName).ToLower();

                    if (HtmlSchema.IsBlockElement(htmlChildName))
                    {
                        htmlElementContainsBlocks = true;

                        break;
                    }
                }
            }

            if (!htmlElementContainsBlocks)
            {
                // The Div does not contain any block elements, so we can treat it as a Paragraph
                AddParagraph(xamlParentElement, htmlElement, inheritedProperties, sourceContext);
            }
            else
            {
                // The Div has some nested blocks, so we treat it as a Section

                // Create currentProperties as a compilation of local and inheritedProperties, set localProperties
                Dictionary<string,string> localProperties;
                Dictionary<string, string> currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, sourceContext);

                // Create a XAML element corresponding to this html element
                XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElementNS(_xamlNamespace, HtmlToXamlConverter.Xaml_Section);

                ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/true);

                // Decide whether we can unwrap this element as not having any formatting significance.
                if (xamlElement.Attributes.Count == 0)
                {
                    // This elements is a group of block elements whitout any additional formatting.
                    // We can add blocks directly to xamlParentElement and avoid
                    // creating unnecessary Sections nesting.
                    xamlElement = xamlParentElement as XmlElement;
                }

                // Recurse into element subtree
                for (var htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
                {
                    htmlChildNode = AddBlock(xamlElement, htmlChildNode, currentProperties, sourceContext);
                }

                // Add the new element to the parent.
                if (xamlElement != xamlParentElement)
                {
                    xamlParentElement.AppendChild(xamlElement);
                }
            }
        }