Beispiel #1
0
        private static void Sync(MailCollection mails, MailCollection newMails)
        {
            MailCollection remove = new MailCollection();

            foreach (Mail mail in mails)
            {
                if (!newMails.Contains(mail))
                {
                    remove.Add(mail);
                }
            }

            foreach (Mail mail in remove)
            {
                mails.Remove(mail);
            }

            foreach (Mail mail in newMails)
            {
                if (!mails.Contains(mail))
                {
                    mails.Add(mail);
                }
            }
        }
Beispiel #2
0
        private void MapMailToObject(SqlDataReader reader, object userData)
        {
            MailCollection mails = (MailCollection)userData;
            Mail           mail  = new Mail();

            mail.Id    = Utils.GetSafeInt32(reader, "MailId");
            mail.Title = Utils.GetSafeString(reader, "MailTitle");
            mail.Text  = Utils.GetSafeString(reader, "MailText");

            //mail.IsDirty = false;

            mails.Add(mail);
        }
Beispiel #3
0
        public override MailCollection GetEmails(int emailsCount)
        {
            MailCollection emails = new MailCollection();

            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                SqlCommand command = new SqlCommand("gopi_GetEmails", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("Count", emailsCount);

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SerializableMailMessage));
                    while (reader.Read())
                    {
                        SerializableMailMessage email = new SerializableMailMessage();

                        string stringData = (string)reader["EmailData"];
                        MemoryStream memoryStream = new MemoryStream();
                        byte[] data = Encoding.Unicode.GetBytes(stringData);
                        Encoding.Convert(Encoding.Default, Encoding.UTF8, data);
                        memoryStream.Write(data, 0, data.Length);

                        memoryStream.Position = 0;

                        email = (SerializableMailMessage)serializer.Deserialize(memoryStream);

                        email.ID = new Guid(reader["ID"].ToString());
                        email.DateAdded = (DateTime)reader["DateAdded"];

                        emails.Add(email);
                    }
                }

                connection.Close();
                command.Dispose();
            }

            return emails;
        }