Example #1
0
        public void Save(User user) {
            user.Id = Guid.NewGuid();

            string sql =
@"insert into `User` (
    `Id`, `Email`, `Username`, `Password`, `Description`, `Website`,
    `NotifyOnWishPriceDrop`, `NotifyOnWishFree`, `NotifyOnWishUpdate`,
    `NotifyOnOwnedUpdate`, `ReceiveSiteUpdates`, `PreferredLanguagePriority`,
    `Status`, `RegisterTime`
) values (
    ?Id, ?Email, ?Username, ?Password, ?Description, ?Website,
    ?NotifyOnWishPriceDrop, ?NotifyOnWishFree, ?NotifyOnWishUpdate,
    ?NotifyOnOwnedUpdate, ?ReceiveSiteUpdates, ?PreferredLanguagePriority,
    ?Status, ?RegisterTime
);";
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = sql;
            command.Parameters.AddWithValue("?Id", user.Id.ToString("N"));
            command.Parameters.AddWithValue("?Email", user.Email);
            command.Parameters.AddWithValue("?Username", user.Username);
            command.Parameters.AddWithValue("?Password", user.Password);
            command.Parameters.AddWithValue("?Description", user.Description);
            command.Parameters.AddWithValue("?Website", user.Website);
            command.Parameters.AddWithValue("?NotifyOnWishPriceDrop", user.NotifyOnWishPriceDrop);
            command.Parameters.AddWithValue("?NotifyOnWishFree", user.NotifyOnWishFree);
            command.Parameters.AddWithValue("?NotifyOnWishUpdate", user.NotifyOnWishUpdate);
            command.Parameters.AddWithValue("?NotifyOnOwnedUpdate", user.NotifyOnOwnedUpdate);
            command.Parameters.AddWithValue("?ReceiveSiteUpdates", user.ReceiveSiteUpdates);
            command.Parameters.AddWithValue("?PreferredLanguagePriority", user.PreferredLanguagePriority);
            command.Parameters.AddWithValue("?Status", user.Status);
            command.Parameters.AddWithValue("?RegisterTime", user.RegisterTime);
            command.ExecuteNonQuery();
        }
Example #2
0
 public bool RequireNotification(User user, AppUpdateType type) {
     if (Status == AppTrackStatus.Owned) {
         return user.NotifyOnOwnedUpdate && type == AppUpdateType.NewRelease;
     }
     else {
         return (user.NotifyOnWishFree && type == AppUpdateType.PriceFree) ||
             (user.NotifyOnWishPriceDrop && type == AppUpdateType.PriceDecrease) ||
             (user.NotifyOnWishUpdate && type == AppUpdateType.NewRelease);
     }
 }
Example #3
0
 public static User ToUser(this IDataRecord record) {
     User user = new User() {
         Id = record.GetGuid("Id"), 
         Description  = record.GetString("Description"), 
         Email = record.GetString("Email"), 
         NotifyOnOwnedUpdate = record.GetBoolean("NotifyOnOwnedUpdate"), 
         NotifyOnWishFree = record.GetBoolean("NotifyOnWishFree"), 
         NotifyOnWishPriceDrop = record.GetBoolean("NotifyOnWishPriceDrop"), 
         NotifyOnWishUpdate = record.GetBoolean("NotifyOnWishUpdate"), 
         Password = record.GetString("Password"), 
         PreferredLanguagePriority = record.GetInt32("PreferredLanguagePriority"), 
         ReceiveSiteUpdates = record.GetBoolean("ReceiveSiteUpdates"), 
         RegisterTime = record.GetDateTime("RegisterTime"), 
         Status = (UserStatus)record.GetInt32("Status"), 
         Username = record.GetString("Username"), 
         Website = record.GetString("Website")
     };
     return user;
 }
Example #4
0
        private MailMessage CreateMailMessage(User user, App app, AppUpdate update) {
            MailMessage message = new MailMessage(
                new MailAddress(settings.MailAddress, settings.MailUser, Encoding.UTF8),
                new MailAddress(user.Email)
            );
            message.SubjectEncoding = Encoding.UTF8;
            message.Subject = String.Format(subjects[update.Type], app.Brief.Name, update.OldValue, update.NewValue);
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;
            message.Body = String.Format(
                templates[update.Type],
                user.Username,
                app.Brief.Name,
                update.OldValue,
                update.NewValue,
                app.Id,
                app.Brief.ViewUrl,
                DateTime.Now,
                app.ReleaseNotes
            );

            return message;
        }
Example #5
0
 public void Update(User user) {
     throw new NotImplementedException();
 }
Example #6
0
        private static int MigrateUsers(int offset, int batchSize) {
            var command = souce.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "select Email, Username, Password, Description, Website, NotifyOnWishPriceDrop, NotifyOnWishFree, NotifyOnWishUpdate, NotifyOnOwnedUpdate, ReceiveSiteUpdates, PreferredLanguagePriority, Status, RegisterTime from User limit ?offset, ?batchSize;";
            command.Parameters.AddWithValue("?offset", offset);
            command.Parameters.AddWithValue("?batchSize", batchSize);

            List<User> collectedUsers = new List<User>();

            Stopwatch watch = new Stopwatch();
            watch.Start();

            using (var reader = command.ExecuteReader()) {
                while (reader.Read()) {
                    User user = new User() {
                        Email = reader.GetString(0),
                        Username = reader.GetString(1),
                        Password = reader.GetString(2),
                        Description = reader.GetString(3),
                        Website = reader.GetString(4),
                        NotifyOnWishPriceDrop = reader.GetBoolean(5),
                        NotifyOnWishFree = reader.GetBoolean(6),
                        NotifyOnWishUpdate = reader.GetBoolean(7),
                        NotifyOnOwnedUpdate = reader.GetBoolean(8),
                        ReceiveSiteUpdates = reader.GetBoolean(9),
                        PreferredLanguagePriority = reader.GetInt32(10),
                        Status = (UserStatus)reader.GetInt32(11),
                        RegisterTime = reader.GetDateTime(12)
                    };

                    collectedUsers.Add(user);
                }
            }

            watch.Stop();
            Console.WriteLine("Retrieved {0} users using {1}", collectedUsers.Count, watch.Elapsed);

            watch.Reset();
            watch.Start();

            using (MySqlTransaction transaction = destination.BeginTransaction()) {
                foreach (User user in collectedUsers) {
                    repository.User.Save(user);
                }
                transaction.Commit();
            }

            watch.Stop();
            Console.WriteLine("Saved to mongo using {0}", watch.Elapsed);

            return collectedUsers.Count;
        }
Example #7
0
 public void Update(User user) {
     users.Save(user);
 }
Example #8
0
 public void Save(User user) {
     users.Save(user);
 }