Пример #1
0
        /// <summary>
        /// Creates a message fragment from an XML string.
        /// </summary>
        /// <param name="xml">The XML string to parse.</param>
        /// <returns>The message fragment.</returns>
        public static SkypeMessageFragment FromXML(string xml)
        {
            var result = new SkypeMessageFragment();
            var doc = XDocument.Parse(xml, LoadOptions.PreserveWhitespace);
            var quote = doc.Element("quote");

            if (quote.Attribute("authorname") != null)
                result.Author = quote.Attribute("authorname").Value;

            if (quote.Attribute("timestamp") != null)
                result.Time = UnixTime.ToDateTime(long.Parse(quote.Attribute("timestamp").Value));

            // Concatenate all of the text nodes in the quote element, ignoring nodes such as <legacyquote>
            result.Message = quote.Nodes()
                .Where(n => n.NodeType == XmlNodeType.Text || n.NodeType == XmlNodeType.Whitespace || n.NodeType == XmlNodeType.SignificantWhitespace)
                .Aggregate("", (r, n) => r += WebUtility.HtmlDecode(n.ToString()));

            return result;
        }
Пример #2
0
 /// <summary>
 /// Clears the clipboard and copies a message fragment onto it.
 /// </summary>
 /// <param name="message">The message fragment to copy.</param>
 public static void SetMessage(SkypeMessageFragment message)
 {
     var xml = message.ToXML();
     var xmlBytes = Encoding.UTF8.GetBytes(xml);
     using (var xmlData = new MemoryStream(xmlBytes))
     {
         var localeBytes = BitConverter.GetBytes(CultureInfo.CurrentCulture.LCID);
         using (var localeData = new MemoryStream(localeBytes))
         {
             var data = new DataObject();
             var plainText = message.ToPlainText();
             data.SetData(DataFormats.StringFormat, plainText);
             data.SetData(DataFormats.UnicodeText, plainText);
             data.SetData(DataFormats.OemText, plainText);
             data.SetData(DataFormats.Text, plainText);
             data.SetData(MessageFragmentFormat, xmlData);
             data.SetData(DataFormats.Locale, localeData);
             Clipboard.SetDataObject(data, true);
         }
     }
 }
Пример #3
0
        private void setClipboard_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(author.Text))
            {
                MessageBox.Show("Please enter an author.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(message.Text))
            {
                MessageBox.Show("Please enter a message.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var fragment = new SkypeMessageFragment()
            {
                Author = author.Text,
                Time = date.Value,
                Message = message.Text
            };
            SkypeClipboard.SetMessage(fragment);

            MessageBox.Show("Quote copied to the clipboard.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }