csSqw_Dll (SqwComp), . csSqw_RemObject_Dll (RemObj), (SqwModels), (SqwMain)
:
1) csSqw_Dll SqwComp. (Project/Add Reference) System.Drawing.dll, Point.
Build/Build Solution.
2) csSqw_RemObj_Dll RemOb j, IRemObj RemObjEventArgs . (Project/Add Reference) System.Runtime.Remoting.dll, MarshalByRefObject
Build/Build Solution.
3) csSqw_Server, System.Runtime.Remoting.dll, System.Windows.Forms, System.Drawing, csSqw_Dll.dll, csSqw_RemObject_Dll.dll.
Build/Build Solution Debug/ Start Without Debugging.
. ( ).
4) csSqw_Client, System.Runtime.Remoting.dll, System.Windows.Forms, System.Drawing, csSqw_RemObject_Dll.dll.
Build/Build Solution Debug/ Start Without Debugging.
. . ( ).
5) - . , , .
/////////////////////////
// C# File csSqw_Dll
// (Project/AddReference) System.Drawing.dll
using...
namespace csSqw_Dll
{
// SqwComp
public class SqwComp: Component //
{...
//
public SqwComp (int NumComp, Point Pnt)
{... }
// Number -
public int Number
{.. }
}
}
/////////////////////////
// C# File csSqw_RemObj_Dll
// (Project/Add Reference) System.Runtime.Remoting.dll
using...
namespace csSqw_RemObject_Dll
{
// evToCont
public class RemObjEventArgs: EventArgs
{... }
// RemObj
public interface IRemObj
{
void CreateAdd (); //
void Remove (int num); // num...
}
|
|
// evToCont
public delegate void FromRemObjToCont (RemObjEventArgs args,
ref ArrayList aL);
//
public class RemObj: MarshalByRefObject, IRemObj
{
public event FromRemObjToCont evToCont; //
//
public RemObj ()
{
}
//
public void CreateAdd ()
{
if (evToCont!= null)
{
RemObjEventArgs a= new RemObjEventArgs
("CreateAdd", 0);
ArrayList aL= null;
evToCont (a, ref aL);
}
}
//
public void Remove (int num)
{
if (evToCont!= null)
{
RemObjEventArgs a= new RemObjEventArgs
("Remove", num);
ArrayList aL= null;
evToCont (a,ref aL);
}
}
...
}
}
/////////////////////////
// C# File csSqw_Server
// (Project/AddReference) csSqw_RemObject_Dll.dll
// (Project/AddReference) System.Runtime.Remoting.dll
// (Project/AddReference) csSqw_Dll.dll
using...
// , .
//
public class SqwModels: Form
{
public SqwComp cs; //
public Container components = null;
...
//
public SqwModels()
{
components= new Container ();
...
}
// RemObj
public void RemObjHandler (RemObjEventArgs args, ref ArrayList aL)
{
switch (args.command)
{
case "CreateAdd": CreateAdd ();
break;
case "Remove": Remove (args.number);
break;
...
}
}
//
public virtual void CreateAdd ()
{
...
SqwComp cmpnt= new SqwComp
(numCompnts, point);
components.Add (cmpnt);
Invalidate ();
}
...
//
protected override void OnPaint (PaintEventArgs e)
{
...
}
//
static void Main ()
{
SqwModels sqwModels= new SqwModels ();
sqwModels.Show ();
RemObj remObj= new RemObj ();
remObj.evToCont += new
FromRemObjToCont (sqwModels.RemObjHandler);
HttpChannel httpChannel;
try
{
httpChannel= new HttpChannel (8080);
ChannelServices.RegisterChannel (httpChannel);
}
catch(Exception e)
{
Console.WriteLine (e.Message);
return;
}
RemotingServices.Marshal(remObj, "RemoteObject");
Application.Run (sqwModels);
GC.Collect ();
GC.WaitForPendingFinalizers ();
}
}
/////////////////////////
// C# File csSqw_Clien t
// (Project/AddReference) csSqw_RemObj_Dll.dll
// (Project/AddReference) System.Runtime.Remoting.dll
using...
using csSqw_RemObject_Dll;
//
public class SqwMain: Form
{
private IRemObj iRemObj; //
private Button butAdd; //
...
//
public SqwMain ()
{
butAdd= new Button ();
butAdd.Click+= new EventHandler (ClickButAdd);
...
/////////////////////////////////////////////
HttpChannel httpChannel= new HttpChannel (0);
ChannelServices.RegisterChannel (httpChannel);
|
|
iRemObj= (IRemObj) Activator.GetObject(
typeof (IRemObj),
"http://localhost:8080/RemoteObject");
}
// " "
void ClickButAdd (object o, EventArgs e)
{
...
iRemObj.CreateAdd (); //
//
...
}
...
//
static void Main ()
{
SqwMain sqwMain= new SqwMain ();
Application.Run(sqwMain);
}
}
}