1  | using System;
  | 
2  | using System.Collections.Generic;
  | 
3  | using System.Linq;
  | 
4  | using System.Windows.Forms;
  | 
5  | using System.Runtime.Serialization.Formatters.Soap;
  | 
6  | using System.IO;
  | 
7  | using Newtonsoft.Json;
  | 
8  | using Newtonsoft.Json.Linq;
  | 
9  | 
  | 
10  | using System.Net.NetworkInformation;
  | 
11  | 
  | 
12  | namespace WindowsFormsApplication1
  | 
13  | {
 | 
14  |     static class Program
  | 
15  |     {
 | 
16  |         static Configuration _configuration = new Configuration();
  | 
17  | 
  | 
18  |         const string fileName = @"c:\json.txt";
  | 
19  | 
  | 
20  |         /// <summary>
  | 
21  |         /// Der Haupteinstiegspunkt für die Anwendung.
  | 
22  |         /// </summary>
  | 
23  |         [STAThread]
  | 
24  |         static void Main()
  | 
25  |         {
 | 
26  | 
  | 
27  |             //Ping Sender = new Ping();
  | 
28  |             //PingReply Result = Sender.Send("173.194.59.94");
 | 
29  |             //if (Result.Status == IPStatus.Success)
  | 
30  |             //{
 | 
31  |             //    MessageBox.Show("Erfolg");
 | 
32  |             //}
  | 
33  |             //else
  | 
34  |             //{
 | 
35  |             //    MessageBox.Show("Fehler");
 | 
36  |             //}
  | 
37  |             //string[] s = System.IO.Ports.SerialPort.GetPortNames();
  | 
38  |             //foreach (string a in s)
  | 
39  |             //{
 | 
40  |             //    System.Diagnostics.Debug.Write(a+"\n");
  | 
41  |             //}
  | 
42  |             Application.EnableVisualStyles();
  | 
43  |             Application.SetCompatibleTextRenderingDefault(false);
  | 
44  |             ConfigurationForm configForm = new ConfigurationForm();
  | 
45  |             Configuration copyConfig = _configuration.Clone();
  | 
46  | 
  | 
47  |             if (File.Exists(fileName))
  | 
48  |             {
 | 
49  |                 string serializedConfiguration = string.Empty;
  | 
50  |                 using (var tf = File.OpenText(fileName))
  | 
51  |                 {
 | 
52  |                     serializedConfiguration = tf.ReadToEnd();
  | 
53  |                 }
  | 
54  |                copyConfig = Configuration.Deserialize(serializedConfiguration);
  | 
55  |             }
  | 
56  | 
  | 
57  |             configForm.Configuration = copyConfig;
  | 
58  |             DialogResult dr = configForm.ShowDialog();
  | 
59  |             if (dr == DialogResult.OK)
  | 
60  |             {
 | 
61  |                 _configuration = copyConfig;
  | 
62  |             }
  | 
63  | 
  | 
64  |             string s = JsonConvert.SerializeObject(copyConfig);
  | 
65  |             MessageBox.Show(s);
  | 
66  | 
  | 
67  |             
  | 
68  |             using (var tf = File.CreateText(fileName))
  | 
69  |             {
 | 
70  |                 tf.
  | 
71  |                 tf.Write(s);
  | 
72  |             }
  | 
73  | 
  | 
74  |             //object o = JsonConvert.DeserializeObject(s);
  | 
75  |             //var jo = (JObject)o;
  | 
76  | 
  | 
77  |             //object o2 = JsonConvert.DeserializeObject(s, typeof(Configuration));
  | 
78  |        
  | 
79  |             //configForm = new ConfigurationForm();
  | 
80  |             //configForm.Configuration = (Configuration)o;
  | 
81  |             //configForm.ShowDialog();
  | 
82  |         }
  | 
83  |     }
  | 
84  | }
  |