[Iiop-net-commits] IIOPNet/Examples/EJBChatRoom/WebSphere_5/net Client.cs,NONE,1.1 ClientForm.cs,NON
Brought to you by:
dullmann,
patrik_reali
Update of /cvsroot/iiop-net/IIOPNet/Examples/EJBChatRoom/WebSphere_5/net In directory sc8-pr-cvs1:/tmp/cvs-serv20362/EJBChatRoom/WebSphere_5/net Added Files: Client.cs ClientForm.cs ExceptionImpl.cs IbmNaming.cs Makefile MessageImpl.cs MessageListenerImpl.cs runClient.bat Log Message: new demo --- NEW FILE: Client.cs --- /* Client.cs * * Project: IIOP.NET * Examples * * WHEN RESPONSIBLE * 22.07.03 Dominic Ullmann (DUL), dominic.ullmann -at- elca.ch * * Copyright 2003 ELCA Informatique SA * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland * www.elca.ch * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting; using System.Windows.Forms; using Ch.Elca.Iiop; using Ch.Elca.Iiop.Services; using omg.org.CosNaming; namespace ch.elca.iiop.demo.ejbChatroom { public class Client { [STAThread] public static void Main(string[] args) { try { string ejbNameServiceHost = "localhost"; int ejbNameServicePort = 2809; if (args.Length > 0) { ejbNameServiceHost = args[0]; } if (args.Length > 1) { ejbNameServicePort = Int32.Parse(args[1]); } // the port the callback is listening on int callbackPort = 0; // auto assign if (args.Length > 2) { callbackPort = Int32.Parse(args[2]); } IiopChannel channel = new IiopChannel(callbackPort); ChannelServices.RegisterChannel(channel); RmiIiopInit init = new RmiIiopInit(ejbNameServiceHost, ejbNameServicePort); NamingContext nameService = (NamingContext)init.GetService("NameServiceServerRoot"); NameComponent[] name = new NameComponent[] { new NameComponent("demo", ""), new NameComponent("chatroomHome", "") }; // get the chatroom home interface ChatroomHome home = (ChatroomHome) nameService.resolve(name); Chatroom chatroom = home.create(); Application.Run(new Chatform(chatroom)); } catch (Exception e) { Console.WriteLine("exception: " + e); } } } } --- NEW FILE: ClientForm.cs --- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.Remoting; namespace ch.elca.iiop.demo.ejbChatroom { /// <summary> /// The chat client form. /// </summary> public class Chatform : System.Windows.Forms.Form { /// <summary> /// used for update message received list /// <summary> public delegate void UpdateInvoker(Message newMessage); #region Constants private const string CONNECTED_INFO = "connected"; private const string NOT_CONNECTED_INFO = "not connected"; #endregion Constants #region IFields private System.Windows.Forms.TextBox m_usernameTextbox; private System.Windows.Forms.Label m_userNameLabel; private System.Windows.Forms.TextBox m_messageTextbox; private System.Windows.Forms.Label m_messageLabel; private System.Windows.Forms.ListBox m_messages; private System.Windows.Forms.Button m_sendMsgButton; private System.Windows.Forms.Button m_sendMsgAsyncButton; private System.Windows.Forms.Panel m_userNamePanel; private System.Windows.Forms.Panel m_sendMsgPanel; private System.Windows.Forms.Button m_connectButton; private System.Windows.Forms.Button m_disconnectbutton; private System.Windows.Forms.Label m_statusLabel; private System.Windows.Forms.Label m_constatus; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; private Chatroom m_chatroom = null; private MessageListenerImpl m_listener = null; #endregion IFields public Chatform(Chatroom chatroom) { // // Required for Windows Form Designer support // InitializeComponent(); m_chatroom = chatroom; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.m_usernameTextbox = new System.Windows.Forms.TextBox(); this.m_userNameLabel = new System.Windows.Forms.Label(); this.m_messageTextbox = new System.Windows.Forms.TextBox(); this.m_messageLabel = new System.Windows.Forms.Label(); this.m_messages = new System.Windows.Forms.ListBox(); this.m_userNamePanel = new System.Windows.Forms.Panel(); this.m_constatus = new System.Windows.Forms.Label(); this.m_statusLabel = new System.Windows.Forms.Label(); this.m_disconnectbutton = new System.Windows.Forms.Button(); this.m_connectButton = new System.Windows.Forms.Button(); this.m_sendMsgPanel = new System.Windows.Forms.Panel(); this.m_sendMsgButton = new System.Windows.Forms.Button(); this.m_sendMsgAsyncButton = new System.Windows.Forms.Button(); this.m_userNamePanel.SuspendLayout(); this.m_sendMsgPanel.SuspendLayout(); this.SuspendLayout(); // // m_usernameTextbox // this.m_usernameTextbox.Location = new System.Drawing.Point(120, 16); this.m_usernameTextbox.MaxLength = 50; this.m_usernameTextbox.Name = "m_usernameTextbox"; this.m_usernameTextbox.Size = new System.Drawing.Size(408, 20); this.m_usernameTextbox.TabIndex = 0; this.m_usernameTextbox.Text = ""; this.m_usernameTextbox.WordWrap = false; // // m_userNameLabel // this.m_userNameLabel.Location = new System.Drawing.Point(8, 16); this.m_userNameLabel.Name = "m_userNameLabel"; this.m_userNameLabel.Size = new System.Drawing.Size(100, 16); this.m_userNameLabel.TabIndex = 1; this.m_userNameLabel.Text = "User name:"; // // m_messageTextbox // this.m_messageTextbox.Location = new System.Drawing.Point(16, 48); this.m_messageTextbox.Name = "m_messageTextbox"; this.m_messageTextbox.Size = new System.Drawing.Size(520, 20); this.m_messageTextbox.TabIndex = 2; this.m_messageTextbox.Text = ""; // // m_messageLabel // this.m_messageLabel.Location = new System.Drawing.Point(16, 8); this.m_messageLabel.Name = "m_messageLabel"; this.m_messageLabel.TabIndex = 3; this.m_messageLabel.Text = "message to send:"; // // m_messages // this.m_messages.Location = new System.Drawing.Point(8, 248); this.m_messages.Name = "m_messages"; this.m_messages.Size = new System.Drawing.Size(536, 355); this.m_messages.TabIndex = 4; this.m_messages.TabStop = false; // // m_userNamePanel // this.m_userNamePanel.Controls.Add(this.m_constatus); this.m_userNamePanel.Controls.Add(this.m_statusLabel); this.m_userNamePanel.Controls.Add(this.m_disconnectbutton); this.m_userNamePanel.Controls.Add(this.m_connectButton); this.m_userNamePanel.Controls.Add(this.m_userNameLabel); this.m_userNamePanel.Controls.Add(this.m_usernameTextbox); this.m_userNamePanel.Location = new System.Drawing.Point(8, 16); this.m_userNamePanel.Name = "m_userNamePanel"; this.m_userNamePanel.Size = new System.Drawing.Size(544, 88); this.m_userNamePanel.TabIndex = 5; // // m_constatus // this.m_constatus.Location = new System.Drawing.Point(296, 56); this.m_constatus.Name = "m_constatus"; this.m_constatus.TabIndex = 5; this.m_constatus.Text = NOT_CONNECTED_INFO; // // m_statusLabel // this.m_statusLabel.Location = new System.Drawing.Point(232, 56); this.m_statusLabel.Name = "m_statusLabel"; this.m_statusLabel.Size = new System.Drawing.Size(48, 23); this.m_statusLabel.TabIndex = 4; this.m_statusLabel.Text = "Status:"; // // m_disconnectbutton // this.m_disconnectbutton.Location = new System.Drawing.Point(112, 56); this.m_disconnectbutton.Name = "m_disconnectbutton"; this.m_disconnectbutton.TabIndex = 3; this.m_disconnectbutton.Text = "Disconnect"; this.m_disconnectbutton.Click += new System.EventHandler(this.m_disconnectbutton_Click); // // m_connectButton // this.m_connectButton.Location = new System.Drawing.Point(16, 56); this.m_connectButton.Name = "m_connectButton"; this.m_connectButton.TabIndex = 2; this.m_connectButton.Text = "Connect"; this.m_connectButton.Click += new System.EventHandler(this.m_connectButton_Click); // // m_sendMsgPanel // this.m_sendMsgPanel.Controls.Add(this.m_sendMsgButton); this.m_sendMsgPanel.Controls.Add(this.m_sendMsgAsyncButton); this.m_sendMsgPanel.Controls.Add(this.m_messageLabel); this.m_sendMsgPanel.Controls.Add(this.m_messageTextbox); this.m_sendMsgPanel.Location = new System.Drawing.Point(8, 120); this.m_sendMsgPanel.Name = "m_sendMsgPanel"; this.m_sendMsgPanel.Size = new System.Drawing.Size(544, 112); this.m_sendMsgPanel.TabIndex = 6; // // m_sendMsgButton // this.m_sendMsgButton.Location = new System.Drawing.Point(16, 80); this.m_sendMsgButton.Name = "m_sendMsgButton"; this.m_sendMsgButton.Size = new System.Drawing.Size(96, 23); this.m_sendMsgButton.TabIndex = 4; this.m_sendMsgButton.Text = "Send message"; this.m_sendMsgButton.Click += new System.EventHandler(this.m_sendMsgButton_Click); // // m_sendMsgAsyncButton // this.m_sendMsgAsyncButton.Location = new System.Drawing.Point(120, 80); this.m_sendMsgAsyncButton.Name = "m_sendMsgAsyncButton"; this.m_sendMsgAsyncButton.Size = new System.Drawing.Size(96, 23); this.m_sendMsgAsyncButton.TabIndex = 7; this.m_sendMsgAsyncButton.Text = "Send msg async"; this.m_sendMsgAsyncButton.Click += new System.EventHandler(this.m_sendMsgAsyncButton_Click); // // Chatform // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(560, 613); this.Controls.Add(this.m_sendMsgPanel); this.Controls.Add(this.m_userNamePanel); this.Controls.Add(this.m_messages); this.Name = "Chatform"; this.Text = "chatclient"; this.Closing += new System.ComponentModel.CancelEventHandler(this.Chatform_Closing); this.m_userNamePanel.ResumeLayout(false); this.m_sendMsgPanel.ResumeLayout(false); this.ResumeLayout(false); } #endregion private void m_connectButton_Click(object sender, System.EventArgs e) { if (m_listener == null) { try { m_listener = new MessageListenerImpl(m_usernameTextbox.Text, this); m_chatroom.registerMe(m_listener, m_listener.userName); m_constatus.Text = CONNECTED_INFO; } catch (AlreadyRegisteredEx) { m_listener = null; MessageBox.Show("this user name is already in use, try to use another one!"); } catch (Exception ex) { m_listener = null; Console.WriteLine("exception: " + ex); MessageBox.Show("an exception occured, while trying to connect!"); } } else { MessageBox.Show("Already connected, disconnect first"); } } private void m_disconnectbutton_Click(object sender, System.EventArgs e) { if (m_listener != null) { try { DisconnectListener(); } catch (Exception ex) { Console.WriteLine("exception while disconnecting: " + ex); MessageBox.Show("an exception occured, while trying to disconnect!"); } m_constatus.Text = NOT_CONNECTED_INFO; } else { MessageBox.Show("Not connected!"); } } private void m_sendMsgButton_Click(object sender, System.EventArgs e) { if (m_listener != null) { MessageImpl msg = new MessageImpl(m_listener.userName, m_messageTextbox.Text); try { m_chatroom.broadCast(msg); } catch (Exception ex) { Console.WriteLine("exception encountered, while broadcasting: " + ex); MessageBox.Show("an exception occured, while broadcasting!"); } } else { MessageBox.Show("not connected, connect first!"); } } delegate void BroadCastDelegate(Message msg); private void m_sendMsgAsyncButton_Click(object sender, System.EventArgs e) { if (m_listener != null) { MessageImpl msg = new MessageImpl(m_listener.userName, m_messageTextbox.Text); try { BroadCastDelegate bcd = new BroadCastDelegate(m_chatroom.broadCast); // async call to broadcast bcd.BeginInvoke(msg, null, null); // do not wait for response } catch (Exception ex) { Console.WriteLine("exception encountered, while broadcasting: " + ex); MessageBox.Show("an exception occured, while broadcasting!"); } } else { MessageBox.Show("not connected, connect first!"); } } private void Chatform_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { DisconnectListener(); } catch (Exception) { } try { m_chatroom.remove(); } catch (Exception) { } Environment.Exit(0); } /// <summary> /// disconnects the listener, if its connected /// </summary> private void DisconnectListener() { if (m_listener != null) { try { m_chatroom.unregisterMe(m_listener.userName); } finally { RemotingServices.Disconnect(m_listener); } m_listener = null; } } /// <summary>adds a new message to the message list</summary> internal void AddMessage(Message newMessage) { MessageImpl theMsg = (MessageImpl) newMessage; string entry = "[" + theMsg.fromUser + "] " + theMsg.msg; Console.WriteLine("received new: " + entry); m_messages.Items.Add(entry); } } } --- NEW FILE: ExceptionImpl.cs --- /* ExceptionImpl.cs * * Project: IIOP.NET * Examples * * WHEN RESPONSIBLE * 24.06.03 Dominic Ullmann (DUL), dominic.ullmann -at- elca.ch * * Copyright 2003 ELCA Informatique SA * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland * www.elca.ch * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; namespace ch.elca.iiop.demo.ejbChatroom { [Serializable] public class AlreadyRegisteredExceptionImpl : AlreadyRegisteredException { public AlreadyRegisteredExceptionImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } [Serializable] public class NotRegisteredExceptionImpl : NotRegisteredException { public NotRegisteredExceptionImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } } namespace javax.ejb { [Serializable] public class CreateExceptionImpl : CreateException { public CreateExceptionImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } [Serializable] public class RemoveExceptionImpl : RemoveException { public RemoveExceptionImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } } namespace java.lang { [Serializable] public class _ExceptionImpl : _Exception { public _ExceptionImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } [Serializable] public class ThrowableImpl : Throwable { public ThrowableImpl() : base() { } public override string message { get { return m_detailMessage; } } public override string localizedMessage { get { return m_detailMessage; } } public override string toString( ) { return "throwable; msg: " + m_detailMessage; } public override void printStackTrace__( ) { } public override void printStackTrace__java_io_PrintStream(java.io.PrintStream arg0 ) { } public override void printStackTrace__java_io_PrintWriter(java.io.PrintWriter arg0 ) { } public override java.lang.Throwable fillInStackTrace( ) { return this; } } } --- NEW FILE: IbmNaming.cs --- using Ch.Elca.Iiop.Idl; using Ch.Elca.Iiop.Services; namespace com.ibm.WsnOptimizedNaming { [RepositoryIDAttribute("IDL:com.ibm/WsnOptimizedNaming/NamingContext:1.0")] [InterfaceTypeAttribute(IdlTypeInterface.ConcreteInterface)] public interface NamingContext : omg.org.CosNaming.NamingContext, IIdlEntity { } } --- NEW FILE: Makefile --- build: build-cls build-client build-cls: if not exist bin mkdir bin if not exist IDL mkdir IDL xcopy /s /q /y ..\java\IDL IDL\ cd IDL copy ..\..\..\..\..\IDLToCLSCompiler\IDL\orb.idl . ..\..\..\..\..\IDLToCLSCompiler\IDLCompiler\bin\IDLToCLSCompiler.exe -o ..\bin chatroom ch\elca\iiop\demo\ejbChatroom\Chatroom.idl ch\elca\iiop\demo\ejbChatroom\ChatroomHome.idl cd .. build-client: copy ..\..\..\..\IIOPChannel\bin\IIOPChannel.dll bin\ csc $(CSFLAGS) /r:bin\IIOPChannel.dll /r:bin\chatroom.dll /t:exe /out:bin\Client.exe *.cs clean: if exist bin del /s /q bin\ if exist bin rmdir /s /q bin\ if exist IDL del /s /q IDL\ if exist IDL rmdir /s /q IDL\ --- NEW FILE: MessageImpl.cs --- using System; namespace ch.elca.iiop.demo.ejbChatroom { /// <summary> /// Implementation of the CORBA value type Message /// </summary> [Serializable] public class MessageImpl : Message { public MessageImpl() { } public MessageImpl(string originator, string msg) { m_originator = originator; m_msg = msg; } public override string fromUser { get { return m_originator; } } public override string msg { get { return m_msg; } } } } --- NEW FILE: MessageListenerImpl.cs --- using System; using System.Threading; using Ch.Elca.Iiop.Idl; namespace ch.elca.iiop.demo.ejbChatroom { /// <summary> /// the callback impl. /// </summary> [SupportedInterface(typeof(MessageListener))] public class MessageListenerImpl : MarshalByRefObject, MessageListener { private string m_userName; private Chatform m_view; public MessageListenerImpl(string userName, Chatform view) { m_userName = userName; m_view = view; } public string userName { get { return m_userName; } } #region IMethods public void notifyMessage(Message msg) { // m_view.AddMessage(msg); // works only when the message was sent asynchronously // because we are in a different thread from the thread created the form, we need to invoke the update method in // in the following way: Chatform.UpdateInvoker invoker = new Chatform.UpdateInvoker(m_view.AddMessage); // need an async call here, because click on button blocks windows, call to update can only succeed after click handling // has finished m_view.BeginInvoke(invoker, new object[] { msg }); } public override object InitializeLifetimeService() { // live forever return null; } #endregion IMethods } } --- NEW FILE: runClient.bat --- bin\Client.exe localhost 2809 |