0

All,

I have a program that reads a serial port data and performs some action.

Here is little piece of code that does that .

private void SerialDataReceivedEventHandler(object sender, SerialDataReceivedEventArgs e)
{
    try
    {


        SerialPort sp = (SerialPort)sender;
        Thread.Sleep(100);
        sCommdata = sp.ReadExisting();
        string[] splitter = new string[2];
        splitter = sCommdata.Split('\r');
        string switchMaker = splitter[0].Trim();
        switchMaker = switchMaker.Substring(0, 3);


        Dispatcher.Invoke(new UpdateKiosk(Reintialise), DispatcherPriority.Send, sCommdata);

    }
    catch (Exception ex)
    {
        //log data goes here
    }
}

Application will automatically reset every time it is used unless some double click the company logo and provide application password. Once a correct password is entered, Application will exit completely. Now, I have included the following code that stores application password in WPF app.config. Here is the XML code.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
     <add key ="ApplicationPassword" value ="xxxxxxx"/> 
  </appSettings>
</Configuration>

Once I added the above code , below code is executed but method that needs to be notified (Reinitialise) doesnt receive any notification.

  Dispatcher.Invoke (new UpdateKiosk(Reintialise),DispatcherPriority.Send, sCommdata);

Reinitialise Method does all initial setting for the application by calling web service methods.

Any suggestion?

Thanks

MAXE
  • 4,978
  • 2
  • 45
  • 61
user14750
  • 21
  • 5

1 Answers1

0

I suggest you to use this code and configuration

<applicationSettings>
    <WpfApplication1.Properties.Settings>
        <setting name="ApplicationPassword" serializeAs="String">
            <value>xxxxxxx</value>
        </setting>
    </WpfApplication1.Properties.Settings>
</applicationSettings>

and get the value

var result  = WpfApplication1.Properties.Settings.Default.ApplicationPassword.ToString()
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • Candie,I did see the above code in another thread and tried but it didnt work in the morning. I tried again now , it worked. Thanks for your help. – user14750 Sep 03 '12 at 14:33
  • I'am happy to help you user14750 – Aghilas Yakoub Sep 03 '12 at 14:35
  • Candie, Im sure app.config will allow multiple settings defined in tag – user14750 Sep 03 '12 at 14:39
  • Sorry for incomplete posting as above. For some reason im not able to access"ApplicationPassword" in code behind. – user14750 Sep 03 '12 at 14:40
  • have you copmpiled your project ? – Aghilas Yakoub Sep 03 '12 at 14:42
  • I tried but it will not compile on var result WpfApplication1.Properties.Settings.Default.ApplicationPassword.ToString() – user14750 Sep 03 '12 at 14:48
  • I tried this code var result = System.Configuration.ConfigurationManager.AppSettings.Get("ApplicationPassword"); but it returns null value. – user14750 Sep 03 '12 at 14:54
  • Check your name of application , he must be WpfApplication1 – Aghilas Yakoub Sep 03 '12 at 14:56
  • I published the application and created the setup files.I looked at the config.exe generated. i dont see the entry for application password. There seems to be something wrong. Either Im not looking at correct place or the file is not getting saved properly. I can see appsetting section contains service reference information for webservice. Oh dear... Got to do more investigation – user14750 Sep 03 '12 at 15:00
  • Figured out. I need to create key by going in to settings (project properties). I was adding key in app.config directly. – user14750 Sep 03 '12 at 15:19