예제 #1
0
        public static int HandleUser(UserRegistrationExtended user, UserService service, UserDao dao)
        {
            try
            {
                OrganisationRegistryProperties.SetCurrentMunicipality(user.Cvr);

                if (user.Operation.Equals(OperationType.DELETE))
                {
                    service.Delete(user.Uuid, user.Timestamp);
                }
                else
                {
                    service.Update(user);
                }

                dao.OnSuccess(user.Id);
                dao.Delete(user.Id);

                return(0);
            }
            catch (TemporaryFailureException ex)
            {
                log.Warn("Could not handle user '" + user.Uuid + "' at the moment, will try later", ex);

                return(-1);
            }
            catch (Exception ex)
            {
                log.Error("Could not handle user '" + user.Uuid + "'", ex);
                dao.OnFailure(user.Id, ex.Message);
                dao.Delete(user.Id);

                return(-2);
            }
        }
예제 #2
0
        public static void HandleUsers(out long count)
        {
            UserService service = new UserService();
            UserDao     dao     = new UserDao();

            count = 0;

            UserRegistrationExtended user = null;

            while ((user = dao.GetOldestEntry()) != null)
            {
                try
                {
                    if (user.Operation.Equals(OperationType.DELETE))
                    {
                        service.Delete(user.Uuid, user.Timestamp);
                    }
                    else
                    {
                        service.Update(user);
                    }

                    count++;
                    dao.Delete(user.Id);

                    errorCount = 0;
                }
                catch (TemporaryFailureException ex)
                {
                    log.Error("Could not handle user '" + user.Uuid + "' at the moment, will try later");
                    throw ex;
                }
                catch (Exception ex)
                {
                    log.Error("Could not handle user '" + user.Uuid + "'", ex);
                    dao.Delete(user.Id);
                }
            }
        }
예제 #3
0
        public List <UserRegistrationExtended> Get4OldestEntries()
        {
            var users = new List <UserRegistrationExtended>();

            using (DbConnection connection = DaoUtil.GetConnection())
            {
                connection.Open();

                using (DbCommand command = DaoUtil.GetCommand(UserStatements.Select, connection))
                {
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            UserRegistrationExtended user = new UserRegistrationExtended();
                            long user_id = (long)reader["id"];
                            user.Id = user_id;

                            user.PhoneNumber = GetValue(reader, "phone_number");
                            user.Email       = GetValue(reader, "email");
                            user.RacfID      = GetValue(reader, "racfid");
                            user.Location    = GetValue(reader, "location");

                            user.UserId   = GetValue(reader, "user_id");
                            user.Cvr      = GetValue(reader, "cvr");
                            user.Uuid     = GetValue(reader, "uuid");
                            user.ShortKey = GetValue(reader, "shortkey");

                            user.Person.Name = GetValue(reader, "name");
                            user.Person.Cpr  = GetValue(reader, "cpr");
                            user.Timestamp   = (DateTime)reader["timestamp"];
                            user.Operation   = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));

                            users.Add(user);
                        }
                    }
                }

                foreach (var user in users)
                {
                    // read positions
                    using (DbCommand command = DaoUtil.GetCommand(UserStatements.SelectPositions, connection))
                    {
                        command.Parameters.Add(DaoUtil.GetParameter("@id", user.Id));

                        using (DbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Position position = new Position();
                                position.OrgUnitUuid = GetValue(reader, "orgunit_uuid");
                                position.Name        = GetValue(reader, "name");

                                user.Positions.Add(position);
                            }
                        }
                    }
                }
            }

            return(users);
        }
예제 #4
0
        public UserRegistrationExtended GetOldestEntry()
        {
            UserRegistrationExtended user = null;
            long user_id = 0;

            if (useSqlLite)
            {
                using (SQLiteConnection connection = new SQLiteConnection(connectionString))
                {
                    connection.Open();

                    using (SQLiteCommand command = new SQLiteCommand(UserStatements.SELECT_SQLITE, connection))
                    {
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                user    = new UserRegistrationExtended();
                                user_id = (long)reader["id"];
                                user.Id = user_id;

                                if (GetValue(reader, "user_phone_value") != null)
                                {
                                    user.Phone          = new Address();
                                    user.Phone.Uuid     = GetValue(reader, "user_phone_uuid");
                                    user.Phone.ShortKey = GetValue(reader, "user_phone_shortkey");
                                    user.Phone.Value    = GetValue(reader, "user_phone_value");
                                }

                                if (GetValue(reader, "user_email_value") != null)
                                {
                                    user.Email          = new Address();
                                    user.Email.Uuid     = GetValue(reader, "user_email_uuid");
                                    user.Email.ShortKey = GetValue(reader, "user_email_shortkey");
                                    user.Email.Value    = GetValue(reader, "user_email_value");
                                }

                                if (GetValue(reader, "user_location_value") != null)
                                {
                                    user.Location          = new Address();
                                    user.Location.ShortKey = GetValue(reader, "user_location_shortkey");
                                    user.Location.Value    = GetValue(reader, "user_location_value");
                                    user.Location.Uuid     = GetValue(reader, "user_location_uuid");
                                }

                                user.UserId   = GetValue(reader, "user_id");
                                user.Uuid     = GetValue(reader, "user_uuid");
                                user.ShortKey = GetValue(reader, "user_shortkey");

                                user.Person.ShortKey = GetValue(reader, "person_shortkey");
                                user.Person.Uuid     = GetValue(reader, "person_uuid");
                                user.Person.Name     = GetValue(reader, "person_name");
                                user.Person.Cpr      = GetValue(reader, "person_cpr");

                                // legacy read (TODO: remove this in some future version, when we remove these fields from the schema)
                                Position position = new Position();
                                position.Uuid        = GetValue(reader, "position_uuid");
                                position.ShortKey    = GetValue(reader, "position_shortkey");
                                position.OrgUnitUuid = GetValue(reader, "position_orgunit_uuid");
                                position.Name        = GetValue(reader, "position_name");

                                if (!string.IsNullOrEmpty(position.OrgUnitUuid) && !string.IsNullOrEmpty(position.Name))
                                {
                                    user.Positions.Add(position);
                                }

                                user.Timestamp = (DateTime)reader["timestamp"];
                                user.Operation = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));
                            }
                        }
                    }

                    // read positions
                    if (user != null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand(UserStatements.SELECT_POSITIONS, connection))
                        {
                            command.Parameters.Add(new SQLiteParameter("@id", user_id));

                            using (SQLiteDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    Position position = new Position();
                                    position.Uuid        = GetValue(reader, "uuid");
                                    position.ShortKey    = GetValue(reader, "shortkey");
                                    position.OrgUnitUuid = GetValue(reader, "orgunit_uuid");
                                    position.Name        = GetValue(reader, "name");

                                    user.Positions.Add(position);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand(UserStatements.SELECT_MSSQL, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                user    = new UserRegistrationExtended();
                                user_id = (long)reader["id"];
                                user.Id = user_id;

                                if (GetValue(reader, "user_phone_value") != null)
                                {
                                    user.Phone          = new Address();
                                    user.Phone.Uuid     = GetValue(reader, "user_phone_uuid");
                                    user.Phone.ShortKey = GetValue(reader, "user_phone_shortkey");
                                    user.Phone.Value    = GetValue(reader, "user_phone_value");
                                }

                                if (GetValue(reader, "user_email_value") != null)
                                {
                                    user.Email          = new Address();
                                    user.Email.Uuid     = GetValue(reader, "user_email_uuid");
                                    user.Email.ShortKey = GetValue(reader, "user_email_shortkey");
                                    user.Email.Value    = GetValue(reader, "user_email_value");
                                }

                                if (GetValue(reader, "user_location_value") != null)
                                {
                                    user.Location          = new Address();
                                    user.Location.ShortKey = GetValue(reader, "user_location_shortkey");
                                    user.Location.Value    = GetValue(reader, "user_location_value");
                                    user.Location.Uuid     = GetValue(reader, "user_location_uuid");
                                }

                                user.UserId   = GetValue(reader, "user_id");
                                user.Uuid     = GetValue(reader, "user_uuid");
                                user.ShortKey = GetValue(reader, "user_shortkey");

                                user.Person.ShortKey = GetValue(reader, "person_shortkey");
                                user.Person.Uuid     = GetValue(reader, "person_uuid");
                                user.Person.Name     = GetValue(reader, "person_name");
                                user.Person.Cpr      = GetValue(reader, "person_cpr");

                                // legacy read (TODO: remove this in some future version, when we remove these fields from the schema)
                                Position position = new Position();
                                position.Uuid        = GetValue(reader, "position_uuid");
                                position.ShortKey    = GetValue(reader, "position_shortkey");
                                position.OrgUnitUuid = GetValue(reader, "position_orgunit_uuid");
                                position.Name        = GetValue(reader, "position_name");

                                if (!string.IsNullOrEmpty(position.OrgUnitUuid) && !string.IsNullOrEmpty(position.Name))
                                {
                                    user.Positions.Add(position);
                                }

                                user.Timestamp = (DateTime)reader["timestamp"];
                                user.Operation = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));
                            }
                        }
                    }

                    // read positions
                    if (user != null)
                    {
                        using (SqlCommand command = new SqlCommand(UserStatements.SELECT_POSITIONS, connection))
                        {
                            command.Parameters.Add(new SqlParameter("@id", user_id));

                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    Position position = new Position();
                                    position.Uuid        = GetValue(reader, "uuid");
                                    position.ShortKey    = GetValue(reader, "shortkey");
                                    position.OrgUnitUuid = GetValue(reader, "orgunit_uuid");
                                    position.Name        = GetValue(reader, "name");

                                    user.Positions.Add(position);
                                }
                            }
                        }
                    }
                }
            }

            return(user);
        }