internal virtual IChannel startChannelRequest(System.Collections.ICollection profiles, IRequestHandler handler, bool tuning) { string channelNumber = NextFreeChannelNumber; // create the message in a buffer and send it System.Text.StringBuilder startBuffer = new System.Text.StringBuilder(); startBuffer.Append("<start number='"); startBuffer.Append(channelNumber); if ((object) serverName != null && !sentServerName) { startBuffer.Append("' serverName='"); startBuffer.Append(serverName); } startBuffer.Append("'>"); foreach(StartChannelProfile p in profiles) { // @todo maybe we should check these against peerSupportedProfiles startBuffer.Append("<profile uri='"); startBuffer.Append(p.uri); startBuffer.Append("' "); if ((object) p.data == null) { startBuffer.Append(" />"); } else { if (p.base64Encoding) { startBuffer.Append("encoding='base64' "); } startBuffer.Append("><![CDATA["); startBuffer.Append(p.data); startBuffer.Append("]]></profile>"); } } startBuffer.Append("</start>"); // @todo handle the data element // Create a channel ChannelImpl ch = new ChannelImpl(null, channelNumber, handler, false, this); // Make a message OutputDataStream ds = new ByteOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, System.Text.Encoding.ASCII.GetBytes(startBuffer.ToString())); if (tuning) { this.changeState(core.SessionState.SESSION_STATE_TUNING_PENDING); this.changeState(core.SessionState.SESSION_STATE_TUNING); this.zero.setState(core.ChannelState.STATE_TUNING); } // Tell Channel Zero to start us up StartReplyListener reply = new StartReplyListener(this, ch); lock (reply) { this.zero.sendMSG(ds, reply); try { System.Threading.Monitor.Wait(reply); } catch (System.Threading.ThreadInterruptedException e) { log.error("Interrupted waiting for reply", e); throw new BEEPException("Interrupted waiting for reply"); } } // check the channel state and return the appropriate exception if (reply.isError()) { throw reply.getError(); } if (ch.getState() != core.ChannelState.STATE_ACTIVE) { throw new BEEPException("Error channel state (" + ch.getState() + ")"); } if (tuning) { ch.setState(core.ChannelState.STATE_TUNING); } if ((object) serverName != null) { sentServerName = true; } fireChannelStarted(ch); return ch; }
/// <summary>The Initiator Oriented close channel call...but this one is not an /// external call, it's invoked from Channel.close();</summary> /// <param name="channel"></param> /// <param name="code"></param> /// <param name="xmlLang"></param> /// <exception cref="BEEPException" /> internal virtual void closeChannel(ChannelImpl channel, BEEPStatusCode code, string xmlLang) { // Construct Message System.Text.StringBuilder closeBuffer = new System.Text.StringBuilder(); closeBuffer.Append("<close number='"); closeBuffer.Append(channel.NumberAsString); closeBuffer.Append("' code='"); closeBuffer.Append(code); if ((object) xmlLang != null) { closeBuffer.Append("' xml:lang='"); closeBuffer.Append(xmlLang); } closeBuffer.Append("' />"); // Lock necessary because we have to know the msgNo // before we send the message, in order to be able // to associate the reply with this start request CloseReplyListener reply = new CloseReplyListener(this, channel); lock (reply) { OutputDataStream ds = new ByteOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, System.Text.Encoding.ASCII.GetBytes(closeBuffer.ToString())); this.zero.sendMSG(ds, reply); try { System.Threading.Monitor.Wait(reply); } catch (System.Threading.ThreadInterruptedException e) { log.error("Error waiting for reply", e); throw new BEEPException("Interrupted waiting for reply"); } } // check the channel state and return the appropriate exception if (reply.isError()) { throw reply.getError(); } if (channel.getState() != core.ChannelState.STATE_CLOSED) { throw new BEEPException("Error channel state (" + channel.getState() + ")"); } fireChannelClosed(channel); }
/// <summary>Listener oriented Start Channel call, a call here means that /// we've received a start channel request over the wire.</summary> //UPGRADE_ISSUE: Class hierarchy differences between ''java.util.Collection'' and ''SupportClass.CollectionSupport'' may cause compilation errors. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1186"' private void processStartChannel(string channelNumber, System.Collections.ICollection profiles) { IStartChannelListener scl; ChannelImpl ch = null; System.Collections.IEnumerator i = profiles.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilIteratorhasNext"' while (i.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilIteratornext"' StartChannelProfile p = (StartChannelProfile) i.Current; scl = profileRegistry.getStartChannelListener(this.tuningProperties, p.uri); if (scl == null) { continue; } ch = new ChannelImpl(p.uri, channelNumber, this); try { string encoding = p.base64Encoding?"base64":"none"; scl.StartChannel(ch, encoding, p.data); } catch (StartChannelException e) { this.enableIO(); try { ((IMessageMSG) zero.AppData).sendERR(e); } catch (BEEPException) { terminate("Error sending ERR response to start channel"); } return ; } if ((object) p.data != null && (object) ch.StartData == null) { byte[] data; if (p.base64Encoding) { try { data = Convert.FromBase64String(p.data); } catch (System.FormatException) { ch.abort(); this.enableIO(); throw new BEEPError(BEEPStatusCode.REQUESTED_ACTION_ABORTED, "Error parsing piggybacked data."); } } else { data = System.Text.Encoding.UTF8.GetBytes(p.data); } PiggybackedMSG msg = new PiggybackedMSG(ch, data, p.base64Encoding); ch.setState(core.ChannelState.STATE_STARTING); try { ch.addPiggybackedMSG(msg); } catch (BEEPException e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' terminate("Error sending profile. " + e.Message); return ; } } else { try { sendProfile(p.uri, ch.StartData, ch); ch.setState(core.ChannelState.STATE_ACTIVE); } catch (BEEPException e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' terminate("Error sending profile. " + e.Message); return ; } fireChannelStarted(ch); if ((object) p.data == null && ch.getState() != core.ChannelState.STATE_TUNING) { this.enableIO(); } } return ; } this.enableIO(); try { ((IMessageMSG) zero.AppData).sendERR(BEEPStatusCode.REQUESTED_ACTION_NOT_TAKEN2, "all requested profiles are unsupported"); } catch (System.Exception x) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' terminate("Error sending error. " + x.Message); } }