Exemple #1
0
        static public void Save()
        {
            NetworkPackage pack = new NetworkPackage();

            pack.Add("name", name);
            pack.Add("IPprefix", IPprefix);
            pack.Add("LINUX", LINUX);
            pack.Add("debug", debug);
            string str = pack.SerializeJson();

            string path = System.Environment.CurrentDirectory + @"/Confige.dat";

            File.WriteAllText(path, str, Encoding.Default);
        }
Exemple #2
0
 public virtual void DeserializeJson(string data)
 {
     try
     {
         var endpos = data.IndexOf("<EOF>");
         if (endpos > -1)
         {
             data = data.Remove(endpos, 5);//remove <EOF>
         }
         NetworkPackage old = JsonConvert.DeserializeObject <NetworkPackage>(data);
         DataList = old.DataList;
     }
     catch
     {
         Console.WriteLine("Deserialize Data Error");
     }
 }
Exemple #3
0
        static public void Read()
        {
            string path = System.Environment.CurrentDirectory + @"/Confige.dat";

            if (!File.Exists(path))
            {
                Save();
            }
            string readText = File.ReadAllText(path, Encoding.Default);

            try
            {
                NetworkPackage dp = new NetworkPackage();
                dp.DeserializeJson(readText);
                name     = (string)dp.GetFromJson("name");
                IPprefix = (string)dp.GetFromJson("IPprefix");
                LINUX    = (bool)dp.GetFromJson("LINUX");
                debug    = (bool)dp.GetFromJson("debug");
            }
            catch (Exception e)
            {
                Read();
            }
        }