Exemple #1
0
        public void Load()
        {
            file = File.Open(path, FileMode.Open);
            if (new FileInfo(path).Length > 0)
            {
                data = (Data)bf.Deserialize(file);
            }
            file.Close();
            file = File.Open(chatpath, FileMode.Open);
            ChatCache chatcache = (ChatCache)bf.Deserialize(file);

            file.Close();
            messages = chatcache.cache;
            File.WriteAllLines(basepath + @"/messagecache.txt", messages);
        }
Exemple #2
0
 public void Start()
 {
     bf        = new BinaryFormatter();
     basepath  = Directory.GetCurrentDirectory() + @"\Chatroom";
     path      = basepath + @"\data.dat";
     textpath  = basepath + @"\users.txt";
     chatpath  = basepath + @"\chat.dat";
     adminpath = basepath + @"\admintoken.txt";
     Directory.CreateDirectory(basepath);
     if (File.Exists(adminpath))
     {
         admintoken   = File.ReadAllText(adminpath);
         adminenabled = true;
     }
     else
     {
         adminenabled = false;
     }
     if (!File.Exists(path))
     {
         file = File.Create(path);
         data = new Data(new List <User>());
         file.Close();
         Save();
     }
     if (!File.Exists(chatpath))
     {
         file = File.Create(chatpath);
         ChatCache chatcache = new ChatCache(new List <string>());
         bf.Serialize(file, chatcache);
         file.Close();
     }
     Load();
     System.Timers.Timer timer = new System.Timers.Timer(3000);
     timer.AutoReset = true;
     timer.Elapsed  += TimerTick;
     timer.Start();
 }