Exemple #1
0
 public void setUser(BotContact user)
 {
     lock (contacts)
     {
         contacts.AddOrReplace(new Address(user.publicKey).address, user);
         writeContactsToFile();
     }
 }
Exemple #2
0
        public void loadContactsFromFile()
        {
            if (File.Exists(contactsPath) == false)
            {
                return;
            }

            lock (contacts)
            {
                BinaryReader reader;
                try
                {
                    reader = new BinaryReader(new FileStream(contactsPath, FileMode.Open));
                }
                catch (Exception e)
                {
                    Logging.error("Cannot open {0} file: {1}", contactsPath, e.Message);
                    return;
                }

                try
                {
                    int version = reader.ReadInt32();

                    int num_contacts = reader.ReadInt32();
                    for (int i = 0; i < num_contacts; i++)
                    {
                        int    contact_len   = reader.ReadInt32();
                        byte[] contact_bytes = reader.ReadBytes(contact_len);

                        BotContact bc      = new BotContact(contact_bytes, saveNickAsString);
                        byte[]     address = new Address(bc.publicKey).address;
                        contacts.AddOrReplace(address, bc);
                    }
                }
                catch (Exception e)
                {
                    Logging.error("Cannot read from {0} file: {1}", contactsPath, e.Message);
                    // TODO TODO notify the user or something like that
                }

                reader.Close();
            }
        }