CampfireHoon.CampfireRoom.Say C# (CSharp) Méthode

Say() public méthode

public Say ( string message ) : void
message string
Résultat void
        public async void Say(string message)
        {
            string url = string.Format("{0}{1}.campfirenow.com/room/{2}/speak.xml", Scheme, _config.AccountName, _roomId);
            
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/xml";
            request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", EncodedAuthToken);
            request.Accept = "application/xml";

            using (var sw = new XmlTextWriter(await request.GetRequestStreamAsync(), Encoding.UTF8))
            {
                sw.WriteStartDocument();
                sw.WriteStartElement("message");
                sw.WriteElementString("type", "TextMessage");
                sw.WriteElementString("body", message);
                sw.WriteEndElement();
                sw.WriteEndDocument();
            }

            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse) await request.GetResponseAsync();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
                SystemMessage(string.Format("Failed to say '{0}': {1}", message, ex.Message));
            }
        }
        

Usage Example

Exemple #1
0
 private void textBox2_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter)
     {
         _room.Say(textBox2.Text);
         textBox2.Text = string.Empty;
     }
 }