.


:




:

































 

 

 

 


. csSqw_Dll (SqwComp), .csSqw_RemObject_Dll (RemObj),(SqwModels),(SqwMain)




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 System;

using System.Drawing;

using System.ComponentModel;

 

namespace csSqw_Dll

{

// SqwComp

public class SqwComp: Component //

{

private int numComp; //

private Point point; //

 

//

public SqwComp (int NumComp, Point Pnt)

{

numComp= NumComp;

point= Pnt;

}

// Number -

public int Number

{

get

{

return numComp;

}

}

 

// Point -

public Point Point

{

get

{

return point;

}

}

}

}

/////////////////////////

// C# File csSqw_RemObj_Dll

// (Project/Add Reference) System.Runtime.Remoting.dll

using System;

using System.Collections;

 

namespace csSqw_RemObject_Dll

{

// evToCont

public class RemObjEventArgs: EventArgs

{

public string command; //

public int number; //

public RemObjEventArgs (string S, int N)

{command= S; number= N;}

}

 

// RemObj

public interface IRemObj

{

void CreateAdd (); //

void Remove (int num); // num

ArrayList GetList (); //

void GetRef (ref ArrayList aL); //

}

 

// 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);

}

}

//

public ArrayList GetList ()

{

ArrayList aL= null;

if (evToCont!= null)

{

RemObjEventArgs a= new RemObjEventArgs

("GetList", 0);

evToCont (a, ref aL);

}

return aL;

}

//

public void GetRef (ref ArrayList AL)

{

ArrayList aL= null;

if (evToCont!= null)

{

RemObjEventArgs a= new RemObjEventArgs

("GetList", 0);

evToCont (a, ref aL);

}

AL= aL;

}

}

}

/////////////////////////

// C# File csSqw_Server

// (Project/AddReference) csSqw_RemObject_Dll.dll

// (Project/AddReference) System.Runtime.Remoting.dll

// (Project/AddReference) csSqw_Dll.dll

using System;

using System.Drawing;

using System.Windows.Forms;

using System.Collections;

using System.ComponentModel;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Http;

using csSqw_RemObject_Dll;

using csSqw_Dll;

using System.Threading;

 

// , .

//

public class SqwModels: Form

{

private static int numCompnts= 0; //

public SqwComp cs; //

private Random rand; //

public Container components = null;

 

//

public SqwModels()

{

components= new Container ();

Text= " ";

rand= new Random ();

}

 

// RemObj

public void RemObjHandler (RemObjEventArgs args, ref ArrayList aL)

{

switch (args.command)

{

case "CreateAdd": CreateAdd ();

break;

case "Remove": Remove (args.number);

break;

case "GetList": aL=GetList ();

break;

}

}

 

//

public virtual void CreateAdd ()

{

numCompnts++;

Point point= new Point ();

point.X= rand.Next (this.ClientSize.Width);

point.Y= rand.Next (this.ClientSize.Height);

SqwComp cmpnt= new SqwComp

(numCompnts, point);

components.Add (cmpnt);

Invalidate ();

}

 

//

public virtual void Remove (int Num)

{

IEnumerator inum= components.Components.GetEnumerator ();

while (inum.MoveNext()) //

{

SqwComp cm= (SqwComp) inum.Current;

if (cm.Number == Num)

{

components.Remove (cm); //

Invalidate ();

break;

}

}

}

public virtual ArrayList GetList ()

{

ArrayList aL= new ArrayList (); //

IEnumerator inum= components.Components.GetEnumerator ();

while (inum.MoveNext ()) //

{ //

SqwComp cm= (SqwComp) inum.Current;

aL.Add (cm.Number); //

}

return aL; //

}

 

//

protected override void OnPaint (PaintEventArgs e)

{

base.OnPaint (e);

//

IEnumerator inum=components.Components.GetEnumerator();

while (inum.MoveNext ()) //

{

SqwComp cm= (SqwComp) inum.Current;

e.Graphics.DrawRectangle(new Pen(Color.Blue, 5),

cm.Point.X-20, cm.Point.Y-20, 40, 40);

e.Graphics.DrawString (cm.Number.ToString (),

new Font("Arial", 9),

new SolidBrush (Color.Red), cm.Point.X, cm.Point.Y);

}

}

//

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 System;

using System.Collections;

using System.Drawing;

using System.Windows.Forms;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Http;

using csSqw_RemObject_Dll;

 

namespace csSqw_Client

{

//

public class SqwMain: Form

{

private IRemObj iRemObj; //

private Button butAdd; //

private Button butDel; //

private ListBox listBox; //

int numComp= 0; //

 

//

public SqwMain ()

{

Text= " ";

butAdd= new Button ();

butAdd.Text= " ";

butAdd.Location= new Point (10,10);

butAdd.Size= new Size(130,20);

butAdd.Click+= new EventHandler (ClickButAdd);

this.Controls.Add (butAdd);

//-----

butDel=new Button ();

butDel.Text= :";

butDel.Location= new Point (10,30);

butDel.Size= new Size (180, 20);

butDel.Click += new EventHandler (ClickButDel);

this.Controls.Add (butDel);

listBox= new ListBox ();

listBox.Location= new Point (200, 30);

listBox.Size= new Size (60, 20);

this.Controls.Add (listBox);

/////////////////////////////////////////////

HttpChannel httpChannel= new HttpChannel (0);

ChannelServices.RegisterChannel (httpChannel);

iRemObj= (IRemObj) Activator.GetObject(

typeof (IRemObj),

"http://localhost:8080/RemoteObject");

}

// " "

void ClickButAdd (object o, EventArgs e)

{

numComp++;

iRemObj.CreateAdd (); //

//

ArrayList aL=null;

listBox.Items.Clear ();

aL= iRemObj.GetList (); //

IEnumerator inum=aL.GetEnumerator();

while(inum.MoveNext ())

{

int num= (int)(Object) inum.Current;

listBox.Items.Add (num); //

}

Console.WriteLine ();

}

 

// :"

void ClickButDel (object o, EventArgs e)

{

if (listBox.SelectedIndex==-1)

{

MessageBox.Show ("

");

}

else

{

int numSel= (int) listBox.SelectedItem;

listBox.Items.Remove (numSel);

 

iRemObj.Remove (numSel); //

//

ArrayList aL=null;

listBox.Items.Clear ();

iRemObj.GetRef (ref aL);//

for (int i= 0; i < aL.Count; i++)

{

int num= (int) aL[i];

listBox.Items.Add (num); // -

}

}

}

 

//

static void Main ()

{

SqwMain sqwMain= new SqwMain ();

Application.Run(sqwMain);

}

}

}

 





:


: 2017-02-11; !; : 265 |


:

:

, .
==> ...

1475 - | 1386 -


© 2015-2024 lektsii.org - -

: 0.059 .