|
I was reading a simple article on the Command Pattern and had a quick question.
The article is short and its here:
http://www.c-sharpcorner.com/Code/2002/Mar/CommandPatternsInCSCKU.asp[^]
For example if I had a base Class DVDPlayer and I wanted a status on the player would this be implemented this way ??
<br />
public class DVDPlayer : ICommand <br />
{<br />
protected string mCDStatus="";<br />
<br />
public CDPlayer()<br />
{<br />
<br />
}<br />
public string CDStatus<br />
{<br />
get{return this.mCDStatus;}<br />
}<br />
<br />
public void Execute()<br />
{<br />
<br />
}<br />
public class DVDPlay: DVDPlayer, ICommand <br />
{<br />
public CDPlay()<br />
{<br />
<br />
}<br />
public new void Execute()<br />
{<br />
base.mCDStatus = "Playing";<br />
}<br />
<br />
}<br />
<br />
With my main method like this ??:
<br />
Remote rm = new Remote();<br />
CDPlayer player = new CDPlayer();<br />
player = new CDPlay();<br />
rm.Invoke(player);<br />
MessageBox.Show(player.CDStatus.ToString());<br />
Is this the best implementation ?? Good Design ? Any ideas ?
thks in advance ..
Note : Remote class below:
<br />
public class Remote<br />
{<br />
public Remote()<br />
{<br />
<br />
}<br />
public void Invoke(ICommand cmd)<br />
{<br />
cmd.Execute();<br />
}<br />
<br />
}<br />
|
|
|
|
|
Dato wrote:
Is this the best implementation ??
hmm
Dato wrote:
public string CDStatus
{
get{return this.mCDStatus;}
}
Dato wrote:
MessageBox.Show(player.CDStatus.ToString());
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Why not just modify the original source code?
I take it that ICommand specifies the Execute method? It's really bad practice to use "new", and it shows that the original implementer didn't design the class correctly--the base class that implements Execute should be declarated as virtual, so derived classes can override it.
Why are you doing CDStatus.ToString() when CDStatus returns a string?
I also don't like the "this.mCDStatus", in particular, the "this.". It's redundant and unnecessary. "return mCDStatus" is quite sufficient.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Hi guyz, I'm developing a small experimental application for myself...and I want to implement some motion detection algorithms.
However, I want to take the input from a webcam. Therefore my question is:
How do you use a webcam through C#??
Any help is highly appreciated (even a web tutorial would be a nice suggestion!)
ThankS
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
|
10Q for your help!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
|
10q for your help!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
I have readed this article:
http://www.codeproject.com/cs/miscctrl/AlphaBlendTextBox.asp
it allow to download a dll to implement the custom textbox.
How can i use that dll in my project?
Thanks
|
|
|
|
|
add arefernce to it in your soulution explorer //if you are using VS.NET.
|
|
|
|
|
can you tell me how? i'm newbie
|
|
|
|
|
In the solution explorer ,you will find icon called reference ,right click it ,and then click add reference and then browse to your dll .
|
|
|
|
|
ok i've done thanks, but now to use that object inside my form ho can i do?
|
|
|
|
|
i mean to see it in the toolbar, so i can drag in my form when i want how can i do?
|
|
|
|
|
If you were pointing at this from the beginning you wouldn't have the dll added to your project.
Just right click the toolbar and then choose Add/Remove items Link and click on it ,and then browse to your dll and every control contained in it will be added to the toolbox and then by only dragging it to your form the reference to this dll will be added automatically .
|
|
|
|
|
Yet again I am stuck. I've followed many code examples, most of which are wholly different and do not explain the small details I am lacking in my implementation. Basically what has happened is that, using the Async message sending I have implemented, the messages run together and mix data, which is obviously no good. I assumed that the Async BeginSend took care of this, but I guess I was wrong, either that or I did it wrong. The code below is my basic implementation:
<br />
public void SendMessage(String msg) <br />
{<br />
try<br />
{<br />
if(m_sndCallBack == null) <br />
{<br />
m_sndCallBack = new AsyncCallback(OnDataSent);<br />
}<br />
SocketPacket packet = new SocketPacket();<br />
packet.thisSocket = m_clientSocket;<br />
<br />
packet.dataBuffer = Encoding.UTF8.GetBytes(msg);<br />
<br />
m_clientSocket.BeginSend(packet.dataBuffer,<br />
0, packet.dataBuffer.Length,<br />
SocketFlags.None, <br />
m_sndCallBack, <br />
packet);<br />
}<br />
catch(SocketException se)<br />
{<br />
Debug.WriteLine(se.Message);<br />
} <br />
}<br />
public void OnDataSent(IAsyncResult asyn)<br />
{<br />
SocketPacket theSockId = (SocketPacket)asyn.AsyncState;<br />
try<br />
{<br />
int iRx = theSockId.thisSocket.EndSend (asyn);<br />
theSockId.thisSocket = null;<br />
}<br />
catch (ObjectDisposedException )<br />
{<br />
Debug.WriteLine("Web.OnDataReceived: Socket has been closed");<br />
}<br />
catch(SocketException se)<br />
{<br />
Debug.WriteLine("Web.OnDataReceived: "+se.Message);<br />
}<br />
}<br />
Now my typical calling, which may be the problem? would be:
ClientServer.SendMessage("CONNECT:username:password");
...
ClientServer.SendMessage("REQUEST:STATUS");
ClientServer.SendMessage("REQUEST:LIST");
and the server receives:
CONNECT:username:passwordREQUEST:STATUS...
Am I supposed to be waiting on the data to be sent? And if so, should I not even implement the sending using Async code? Any help would be greatly appreciated.
|
|
|
|
|
If your protocol demands that messages must be sent in a particular order, then you shouldn't use BeginSend. Each BeginSend will use a threadpool thread to run, so there is no guarantee as to the order in which the messages will actually be sent.
Waiting till the callback completes before sending the next message will solve your problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Where would the best place to implement the wait be?
If only I could find GOOD async code to model my implementation hah...
I am contemplating just writing synchronously and reading asynchronously because it doesnt really matter what order the messsages are received just that they are a single message.
Thanks
|
|
|
|
|
Is it OK if the server receives message like
REQUEST:STATUSCONNECT:username:password... ??
That's what I meant by the ordering problem, your messages themselves could get mixed up.
I'd typically implement this by creating my own thread and running a queue system there. All messages to be sent are posted to the queue and the queue synchronously processes them.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks, works beautifully, I figured the problem was the Async sending but I wasn't sure.
|
|
|
|
|
who's use powerbuilder tool or have ebook ! please help me.
thank you very much.
|
|
|
|
|
Hi folks,
I want to write a piece of code to check if a domain user is member of a local group in my machine. I've read some articles but I don't think I can use LDAP here.
Could you guys give me a hint?
Thanks a bunch.
|
|
|
|
|
Hi,
I'm trying to write an Out of proc DCOM server in C#. I have the Server written, its now a COM object so thats done.
Where i'm stuck is this. As far as I kmow, DCOM works by having a stub object on the machine that the server is running on, and then a proxy on each of the client machines that communicates with the stub object.
How are the stub and proxy objects created? I'm told that in C++, they are created automatically but I am developing this in C# so I need to know if it works the same. The client is written in C++ and the DCOM server is written in C#.
Any help or comments will be appreciated
Thanks
Millzy
|
|
|
|
|
hi to all of you, i'm developing a voice over IP application
i need it for a web page also
i studied the directX to include directX sound i suppose
i need it but that didn't work on asp.net
all i found over the internet is applications made in c++
i needed for .net languages so i have 2 questions :
1- is directX Applicable in web pages
2- the way to develop a library of my own what do need to code in this library so i can used it as a component
i really do need help about this cause i found such components on the internet but are not for free
and if i buy it i don't suppose they send me the source code
so for all the experienced out there DO YOU HAVE THE SOLUTION i need HELP
send me mail to charbel_zibara@hotmail.com
|
|
|
|
|
ASP.NET is a server-side only technology that generated HTML pages for a client. You cannot use DirectX in an ASP.NET app. Since a web page cannot access hardware on the client computer, you'll have to develop a control that the client will have to install to do VoIP. No, I don't have ANY code to do this, nor do I have any source of information on it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|