0

On my client-server system, a user can change a value of a Variable, say "System Power" in a drop-down box ("ON", "OFF", "STANDBY").

When clicking an index, a message gets passed to the server to change the variable that captures the state of "System Power" in this case.

Currently, my server-side code is implemented to try to convert the value in the client's message as an Int64.

Here are my thoughts as to a solution:

1 - hard code logic in my client-side code to send the right Int64 value. Example: send message(System Power, 1) instead of message(System Power, OFF).

2 - from the client-side, read an XML file that maps Variable's state (ON, OFF) to an Int64 value

3 - fix the server-side to behave correctly.

I think #1 is a poor option due to inflexibility. #3 is the right option, but it will take me too long on my schedule.

To implement #2, would it make sense to create an XML file like this:

<root>
  <Variables>
    <System Power>
      <element name="ON">1</element>
      <element name="OFF">0</element>
...

Then, in my client-side code, I could perform a look-up in the XML file to determine the correct message(System Power, 0).

Please advise. Thank you.

2 Answers 2

2

I'd say #1 implemented via enums would be the way to go.

Sign up to request clarification or add additional context in comments.

4 Comments

Enum.Parse can be used to help convert: msdn.microsoft.com/en-us/library/essfb559.aspx
That sounds like an option. Why are enums preferable to XML?
because then its all handled programmaticly automaticly. To the code you get to use (view) nice string representations of the options, but when you send it over the wire it is transmitted as the int value and automajicly interpretted on the other size correctly, providing you cast the int back to the enum. No need for XML configurations.
Well, the drop-down items values were string's ("ON", "OFF", etc.). As a result, I was unable to use Enum.Parse(myEnum, "ON") since I did not know how to use Enum.Parse(...) to accept a string, and then return a number.
1

This could be handled right in the drop down. The client type is not specified, but for example, in html:

<select>
  <option value="0">OFF</option>
  <option value="1">ON</option>
  <option value="2">STANDBY</option>
</select>

The same could be done for a Windows drop down.

1 Comment

How would I use XML to look up the correct Int64 value of a string?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.