//----< set up channel after entering ports and addresses >---------- //method used to send request to persist data private void start_Click_Persist(object sender, RoutedEventArgs e) { Random random = new Random(); XElement messageNode = new XElement("message"); XAttribute att = new XAttribute("commandType", "persistWPF"); messageNode.Add(att); Message msg = new Message(); msg.fromUrl = "http://localhost:" + localPort + "/CommService"; msg.toUrl = "http://localhost:" + remotePort + "/CommService"; msg.content = messageNode.ToString(); if (!sndr.sendMessage(msg)) { return; } }
//----< send a demonstraton message >-------------------------------- private void send_Click(object sender, RoutedEventArgs e) { try { #region ///////////////////////////////////////////////////// // This commented code was put here to allow // user to change local port and address after // the channel was started. // // It does what is intended, but would throw // if the new port is assigned a slot that // is in use or has been used since the // TCP tables were last updated. // // if (!localPort.Equals(lPort.Text)) // { // localAddress = rcvr.address = lAddr.Text; // localPort = rcvr.port = lPort.Text; // rcvr.shutDown(); // setupChannel(); // } #endregion if (!remoteAddress.Equals(rAddr.Text) || !remotePort.Equals(rPort.Text)) { remoteAddress = rAddr.Text; remotePort = rPort.Text; } // - Make a demo message to send // - You will need to change MessageMaker.makeMessage // to make messages appropriate for your application design // - You might include a message maker tab on the UI // to do this. MessageMaker maker = new MessageMaker(); Message msg = maker.makeMessage( Utilities.makeUrl(lAddr.Text, lPort.Text), Utilities.makeUrl(rAddr.Text, rPort.Text) ); lStat.Text = "sending to" + msg.toUrl; sndr.localUrl = msg.fromUrl; sndr.remoteUrl = msg.toUrl; lStat.Text = "attempting to connect"; if (sndr.sendMessage(msg)) { lStat.Text = "connected"; } else { lStat.Text = "connect failed"; } postSndMsg(msg.content); } catch (Exception ex) { lStat.Text = ex.Message; } }
private void sendTyprReq() { MessageMaker maker = new MessageMaker(); Message msg = maker.makeTypeRequest( Utilities.makeUrl(lAddr.Text, lPort.Text), Utilities.makeUrl(rAddr.Text, rPort.Text) ); if (sndr.sendMessage(msg)) { string content = msg.content; TextBlock item = new TextBlock(); item.Text = trim(content); item.FontSize = 16; sndmsgs.Items.Insert(0, item); } }
//----< send a demonstraton message >-------------------------------- private void send_Click(object sender, RoutedEventArgs e) { try { #region #endregion if (!remoteAddress.Equals(rAddr.Text) || !remotePort.Equals(rPort.Text)) { remoteAddress = rAddr.Text; remotePort = rPort.Text; } MessageMaker maker = new MessageMaker(); Message msg = maker.makeMessage( Utilities.makeUrl(lAddr.Text, lPort.Text), Utilities.makeUrl(rAddr.Text, rPort.Text) ); lStat.Text = "sending to" + msg.toUrl; sndr.localUrl = msg.fromUrl; sndr.remoteUrl = msg.toUrl; lStat.Text = "attempting to connect"; if (sndr.sendMessage(msg)) { lStat.Text = "connected"; } else { lStat.Text = "connect failed"; } postSndMsg(msg.content); } catch (Exception ex) { lStat.Text = ex.Message; } }
public void doOperations(string request) { TextBlock item = new TextBlock(); item.FontSize = 16; Message msg = new Message(); msg.fromUrl = Utilities.makeUrl(lAddr.Text, lPort.Text); msg.toUrl = Utilities.makeUrl(rAddr.Text, rPort.Text); //----------< design messages according to message structure and send to server >----------- try { switch (request) { case "add": msg.content = "write,add,keyWpf,nameWpf,descrWpf,2,childWpf1,childWpf2,2,itemWpf1,itemWpf2"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); msg = new Message(); msg.fromUrl = Utilities.makeUrl(lAddr.Text, lPort.Text); msg.toUrl = Utilities.makeUrl(rAddr.Text, rPort.Text); msg.content = "write,add,keyWpf1,nameWpf,descrWpf,2,childWpf1,childWpf2,2,itemWpf1,itemWpf2"; sndr.sendMessage(msg); break; case "edit": msg.content = "write,edit,keyWpf,NameWpf,DescrWpf,2,childWpf1,childWpf2,2,itemWpf1,itemWpf2"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "delete": msg.content = "write,delete,keyWpf1,0,0,0,,0,"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "persist": msg.content = "write,persist,0,0,0,0,,0,"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "restore": msg.content = "write,restore,0,xmlDocLOS.xml,0,0,,0,"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "value": msg.content = "read,value,keyWpf"; item.Text = "Searching for value of specified key"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "children": msg.content = "read,children,keyWpf"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "pattern": msg.content = "read,pattern,k"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "string": msg.content = "read,string,Name"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; case "interval": msg.content = "read,interval,10/7/1999 12:00:00 AM"; if (sndr.sendMessage(msg)) { item.Text = "Sending " + msg.content; } else { item.Text = "Sending failed"; } OpBox.Items.Insert(1, item); break; default: break; } } catch { item = new TextBlock(); item.Text = "Some problem with sending a message, see main window"; item.FontSize = 16; OpBox.Items.Insert(0, item); } }