C
Cralis
Hi guys,
I am using a WorkerThread to do a background service call to check for
a new version availability.
But I need help with regards parameters.
So, I have a shared method that looks like this:
private void CheckFirmwareVersionOnServer(bool silentCheck)
{
Common.WriteLog("Firmware Check being started");
CommRequest cr = BuildServerCommsObject();
cr.CommandRequest = "CHECK_IS_LATEST_FIRMWARE";
PerformWebServiceAction(cr, silentCheck);
}
What's happening is, if silent check comes as TRUE, then I don't want
to show a result if there is no new version available. That's because
it was triggered automatically on startup. However, if the user select
a menu option that does a firmware check, then I pass FALSE, and it
shows the result whether or not there's a new version.
I then call PerformWebServiceAction, passing it an object I want to
send to the server, as well as the SilentCheck value:
private void PerformWebServiceAction(CommRequest commRequest, bool
silentCheck)
{
Common.WriteLog("Sending Web Service Request - " +
commRequest.CommandRequest);
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += PerformWebServiceActionDoWork;
worker.RunWorkerCompleted +=
PerformWebServiceActionComplete;
worker.RunWorkerAsync(commRequest);
}
My DoWork method is then called... but I can only pass it one
parameter. I pass the request object. But here's my problem. I'll
continue...
private static void PerformWebServiceActionDoWork(object sender,
DoWorkEventArgs e)
{
CommRequest commRequest = (CommRequest) e.Argument;
CommsService cs = new CommsService();
try
{
CommRequest reply = cs.Request(commRequest);
reply.CommunicationResult = true;
e.Result = reply;
}
catch (Exception ex)
{
commRequest.CommunicationResult = false;
commRequest.CommunicationError = ex.Message;
e.Result = commRequest;
}
}
On completion of the call, I do this:
private static void PerformWebServiceActionComplete(object sender,
RunWorkerCompletedEventArgs e)
{
CommRequest commRequest = (CommRequest)e.Result;
switch (commRequest.CommandRequest)
{
case "CHECK_IS_LATEST_FIRMWARE":
{
ProcessFirmwareReply(commRequest);
break;
}
default:
{
Common.WriteLog("\tError: Recieved a Service
Request reply, with a CommandRequest [" + commRequest.CommandRequest +
"] that is unhandled.");
break;
}
}
}
Problem is, at this point, I don't know if it was a silent check or
not. So, as you see, I call a method that handles the reply... very
basic, as I am in testing:
private static void ProcessFirmwareReply(CommRequest
commRequest)
{
MessageBox.Show(commRequest.ReplyDescription);
}
What I need to do here is check if it's a SilentCheck. If it is, I
must supress the messagebox, unless the commRequest has a flag that
says there IS a new firmware.
How can I get the SilentCheck flag to this stage?
I am using a WorkerThread to do a background service call to check for
a new version availability.
But I need help with regards parameters.
So, I have a shared method that looks like this:
private void CheckFirmwareVersionOnServer(bool silentCheck)
{
Common.WriteLog("Firmware Check being started");
CommRequest cr = BuildServerCommsObject();
cr.CommandRequest = "CHECK_IS_LATEST_FIRMWARE";
PerformWebServiceAction(cr, silentCheck);
}
What's happening is, if silent check comes as TRUE, then I don't want
to show a result if there is no new version available. That's because
it was triggered automatically on startup. However, if the user select
a menu option that does a firmware check, then I pass FALSE, and it
shows the result whether or not there's a new version.
I then call PerformWebServiceAction, passing it an object I want to
send to the server, as well as the SilentCheck value:
private void PerformWebServiceAction(CommRequest commRequest, bool
silentCheck)
{
Common.WriteLog("Sending Web Service Request - " +
commRequest.CommandRequest);
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += PerformWebServiceActionDoWork;
worker.RunWorkerCompleted +=
PerformWebServiceActionComplete;
worker.RunWorkerAsync(commRequest);
}
My DoWork method is then called... but I can only pass it one
parameter. I pass the request object. But here's my problem. I'll
continue...
private static void PerformWebServiceActionDoWork(object sender,
DoWorkEventArgs e)
{
CommRequest commRequest = (CommRequest) e.Argument;
CommsService cs = new CommsService();
try
{
CommRequest reply = cs.Request(commRequest);
reply.CommunicationResult = true;
e.Result = reply;
}
catch (Exception ex)
{
commRequest.CommunicationResult = false;
commRequest.CommunicationError = ex.Message;
e.Result = commRequest;
}
}
On completion of the call, I do this:
private static void PerformWebServiceActionComplete(object sender,
RunWorkerCompletedEventArgs e)
{
CommRequest commRequest = (CommRequest)e.Result;
switch (commRequest.CommandRequest)
{
case "CHECK_IS_LATEST_FIRMWARE":
{
ProcessFirmwareReply(commRequest);
break;
}
default:
{
Common.WriteLog("\tError: Recieved a Service
Request reply, with a CommandRequest [" + commRequest.CommandRequest +
"] that is unhandled.");
break;
}
}
}
Problem is, at this point, I don't know if it was a silent check or
not. So, as you see, I call a method that handles the reply... very
basic, as I am in testing:
private static void ProcessFirmwareReply(CommRequest
commRequest)
{
MessageBox.Show(commRequest.ReplyDescription);
}
What I need to do here is check if it's a SilentCheck. If it is, I
must supress the messagebox, unless the commRequest has a flag that
says there IS a new firmware.
How can I get the SilentCheck flag to this stage?