예제 #1
0
        private static int HandleOU(OrgUnitRegistrationExtended ou, OrgUnitService service, OrgUnitDao dao)
        {
            try
            {
                OrganisationRegistryProperties.SetCurrentMunicipality(ou.Cvr);

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

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

                return(0);
            }
            catch (TemporaryFailureException ex)
            {
                log.Warn("Could not handle ou '" + ou.Uuid + "' at the moment, will try later", ex);
                return(-1);
            }
            catch (Exception ex)
            {
                log.Error("Could not handle ou '" + ou.Uuid + "'", ex);
                dao.OnFailure(ou.Id, ex.Message);
                dao.Delete(ou.Id);

                return(-2);
            }
        }
예제 #2
0
        /*
         * public static long HandleItSystems()
         * {
         *  ItSystemService service = new ItSystemService();
         *  ItSystemDao dao = new ItSystemDao();
         *  long count = 0;
         *
         *  ItSystemRegistrationExtended itSystem = null;
         *  while ((itSystem = dao.GetOldestEntry()) != null)
         *  {
         *      try
         *      {
         *          if (itSystem.Operation.Equals(OperationType.DELETE))
         *          {
         *              service.Delete(itSystem.Uuid, itSystem.Timestamp);
         *          }
         *          else
         *          {
         *              service.Update(itSystem);
         *          }
         *
         *          count++;
         *
         *          dao.Delete(itSystem.Uuid);
         *      }
         *      catch (TemporaryFailureException ex)
         *      {
         *          log.Error("Could not handle ItSystem '" + itSystem.Uuid + "' at the moment, will try later", ex);
         *          break;
         *      }
         *      catch (Exception ex)
         *      {
         *          log.Error("Could not handle ItSystem '" + itSystem.Uuid + "'", ex);
         *          dao.Delete(itSystem.Uuid);
         *      }
         *  }
         *
         *  return count;
         * }
         */

        public static void HandleOUs(out long count)
        {
            OrgUnitService service = new OrgUnitService();
            OrgUnitDao     dao     = new OrgUnitDao();

            count = 0;

            OrgUnitRegistrationExtended ou = null;

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

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

                    errorCount = 0;
                }
                catch (TemporaryFailureException ex)
                {
                    log.Error("Could not handle ou '" + ou.Uuid + "' at the moment, will try later");
                    throw ex;
                }
                catch (Exception ex)
                {
                    log.Error("Could not handle ou '" + ou.Uuid + "'", ex);
                    dao.Delete(ou.Id);
                }
            }
        }
예제 #3
0
        public OrgUnitRegistrationExtended GetOldestEntry()
        {
            OrgUnitRegistrationExtended orgUnit = null;
            long orgUnitId = 0;

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

                    using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.SELECT_SQLITE, connection))
                    {
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                orgUnitId = (long)reader["id"];

                                orgUnit                   = new OrgUnitRegistrationExtended();
                                orgUnit.Id                = orgUnitId;
                                orgUnit.Uuid              = GetValue(reader, "uuid");
                                orgUnit.ShortKey          = GetValue(reader, "shortkey");
                                orgUnit.Name              = GetValue(reader, "name");
                                orgUnit.ParentOrgUnitUuid = GetValue(reader, "parent_ou_uuid");
                                orgUnit.PayoutUnitUuid    = GetValue(reader, "payout_ou_uuid");

                                orgUnit.LOSShortName          = new Address();
                                orgUnit.LOSShortName.Uuid     = GetValue(reader, "los_shortname_uuid");
                                orgUnit.LOSShortName.ShortKey = GetValue(reader, "los_shortname_shortkey");
                                orgUnit.LOSShortName.Value    = GetValue(reader, "los_shortname_value");

                                orgUnit.Phone          = new Address();
                                orgUnit.Phone.Uuid     = GetValue(reader, "phone_uuid");
                                orgUnit.Phone.ShortKey = GetValue(reader, "phone_shortkey");
                                orgUnit.Phone.Value    = GetValue(reader, "phone_value");

                                orgUnit.Email          = new Address();
                                orgUnit.Email.Uuid     = GetValue(reader, "email_uuid");
                                orgUnit.Email.ShortKey = GetValue(reader, "email_shortkey");
                                orgUnit.Email.Value    = GetValue(reader, "email_value");

                                orgUnit.Location          = new Address();
                                orgUnit.Location.Uuid     = GetValue(reader, "location_uuid");
                                orgUnit.Location.ShortKey = GetValue(reader, "location_shortkey");
                                orgUnit.Location.Value    = GetValue(reader, "location_value");

                                orgUnit.Ean          = new Address();
                                orgUnit.Ean.Uuid     = GetValue(reader, "ean_uuid");
                                orgUnit.Ean.ShortKey = GetValue(reader, "ean_shortkey");
                                orgUnit.Ean.Value    = GetValue(reader, "ean_value");

                                orgUnit.Post          = new Address();
                                orgUnit.Post.Uuid     = GetValue(reader, "post_uuid");
                                orgUnit.Post.ShortKey = GetValue(reader, "post_shortkey");
                                orgUnit.Post.Value    = GetValue(reader, "post_value");

                                orgUnit.ContactOpenHours          = new Address();
                                orgUnit.ContactOpenHours.Uuid     = GetValue(reader, "contact_open_hours_uuid");
                                orgUnit.ContactOpenHours.ShortKey = GetValue(reader, "contact_open_hours_shortkey");
                                orgUnit.ContactOpenHours.Value    = GetValue(reader, "contact_open_hours_value");

                                orgUnit.EmailRemarks          = new Address();
                                orgUnit.EmailRemarks.Uuid     = GetValue(reader, "email_remarks_uuid");
                                orgUnit.EmailRemarks.ShortKey = GetValue(reader, "email_remarks_shortkey");
                                orgUnit.EmailRemarks.Value    = GetValue(reader, "email_remarks_value");

                                orgUnit.Contact          = new Address();
                                orgUnit.Contact.Uuid     = GetValue(reader, "contact_uuid");
                                orgUnit.Contact.ShortKey = GetValue(reader, "contact_shortkey");
                                orgUnit.Contact.Value    = GetValue(reader, "contact_value");

                                orgUnit.PostReturn          = new Address();
                                orgUnit.PostReturn.Uuid     = GetValue(reader, "post_return_uuid");
                                orgUnit.PostReturn.ShortKey = GetValue(reader, "post_return_shortkey");
                                orgUnit.PostReturn.Value    = GetValue(reader, "post_return_value");

                                orgUnit.PhoneOpenHours          = new Address();
                                orgUnit.PhoneOpenHours.Uuid     = GetValue(reader, "phone_open_hours_uuid");
                                orgUnit.PhoneOpenHours.ShortKey = GetValue(reader, "phone_open_hours_shortkey");
                                orgUnit.PhoneOpenHours.Value    = GetValue(reader, "phone_open_hours_value");

                                orgUnit.Operation = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));
                            }
                        }
                    }

                    // read itsystems
                    if (orgUnit != null)
                    {
                        orgUnit.ItSystemUuids = new List <string>();

                        using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.SELECT_ITSYSTEMS, connection))
                        {
                            command.Parameters.Add(new SQLiteParameter("@id", orgUnitId));

                            using (SQLiteDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    orgUnit.ItSystemUuids.Add(GetValue(reader, "itsystem_uuid"));
                                }
                            }
                        }
                    }

                    // read contact places
                    if (orgUnit != null)
                    {
                        using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.SELECT_CONTACT_PLACES, connection))
                        {
                            command.Parameters.Add(new SQLiteParameter("@id", orgUnitId));

                            using (SQLiteDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    string contactPlaceUuid = GetValue(reader, "contact_place_uuid");
                                    string task             = GetValue(reader, "task");

                                    ContactPlace contactPlace = null;
                                    foreach (ContactPlace cp in orgUnit.ContactPlaces)
                                    {
                                        if (cp.OrgUnitUuid.Equals(contactPlaceUuid))
                                        {
                                            contactPlace = cp;
                                            break;
                                        }
                                    }

                                    if (contactPlace == null)
                                    {
                                        contactPlace             = new ContactPlace();
                                        contactPlace.OrgUnitUuid = contactPlaceUuid;
                                        contactPlace.Tasks       = new List <string>();

                                        orgUnit.ContactPlaces.Add(contactPlace);
                                    }

                                    contactPlace.Tasks.Add(task);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand(OrgUnitStatements.SELECT_MSSQL, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                orgUnitId = (long)reader["id"];

                                orgUnit                   = new OrgUnitRegistrationExtended();
                                orgUnit.Id                = orgUnitId;
                                orgUnit.Uuid              = GetValue(reader, "uuid");
                                orgUnit.ShortKey          = GetValue(reader, "shortkey");
                                orgUnit.Name              = GetValue(reader, "name");
                                orgUnit.ParentOrgUnitUuid = GetValue(reader, "parent_ou_uuid");
                                orgUnit.PayoutUnitUuid    = GetValue(reader, "payout_ou_uuid");

                                orgUnit.LOSShortName          = new Address();
                                orgUnit.LOSShortName.Uuid     = GetValue(reader, "los_shortname_uuid");
                                orgUnit.LOSShortName.ShortKey = GetValue(reader, "los_shortname_shortkey");
                                orgUnit.LOSShortName.Value    = GetValue(reader, "los_shortname_value");

                                orgUnit.Phone          = new Address();
                                orgUnit.Phone.Uuid     = GetValue(reader, "phone_uuid");
                                orgUnit.Phone.ShortKey = GetValue(reader, "phone_shortkey");
                                orgUnit.Phone.Value    = GetValue(reader, "phone_value");

                                orgUnit.Email          = new Address();
                                orgUnit.Email.Uuid     = GetValue(reader, "email_uuid");
                                orgUnit.Email.ShortKey = GetValue(reader, "email_shortkey");
                                orgUnit.Email.Value    = GetValue(reader, "email_value");

                                orgUnit.Location          = new Address();
                                orgUnit.Location.Uuid     = GetValue(reader, "location_uuid");
                                orgUnit.Location.ShortKey = GetValue(reader, "location_shortkey");
                                orgUnit.Location.Value    = GetValue(reader, "location_value");

                                orgUnit.Ean          = new Address();
                                orgUnit.Ean.Uuid     = GetValue(reader, "ean_uuid");
                                orgUnit.Ean.ShortKey = GetValue(reader, "ean_shortkey");
                                orgUnit.Ean.Value    = GetValue(reader, "ean_value");

                                orgUnit.Post          = new Address();
                                orgUnit.Post.Uuid     = GetValue(reader, "post_uuid");
                                orgUnit.Post.ShortKey = GetValue(reader, "post_shortkey");
                                orgUnit.Post.Value    = GetValue(reader, "post_value");

                                orgUnit.ContactOpenHours          = new Address();
                                orgUnit.ContactOpenHours.Uuid     = GetValue(reader, "contact_open_hours_uuid");
                                orgUnit.ContactOpenHours.ShortKey = GetValue(reader, "contact_open_hours_shortkey");
                                orgUnit.ContactOpenHours.Value    = GetValue(reader, "contact_open_hours_value");

                                orgUnit.EmailRemarks          = new Address();
                                orgUnit.EmailRemarks.Uuid     = GetValue(reader, "email_remarks_uuid");
                                orgUnit.EmailRemarks.ShortKey = GetValue(reader, "email_remarks_shortkey");
                                orgUnit.EmailRemarks.Value    = GetValue(reader, "email_remarks_value");

                                orgUnit.Contact          = new Address();
                                orgUnit.Contact.Uuid     = GetValue(reader, "contact_uuid");
                                orgUnit.Contact.ShortKey = GetValue(reader, "contact_shortkey");
                                orgUnit.Contact.Value    = GetValue(reader, "contact_value");

                                orgUnit.PostReturn          = new Address();
                                orgUnit.PostReturn.Uuid     = GetValue(reader, "post_return_uuid");
                                orgUnit.PostReturn.ShortKey = GetValue(reader, "post_return_shortkey");
                                orgUnit.PostReturn.Value    = GetValue(reader, "post_return_value");

                                orgUnit.PhoneOpenHours          = new Address();
                                orgUnit.PhoneOpenHours.Uuid     = GetValue(reader, "phone_open_hours_uuid");
                                orgUnit.PhoneOpenHours.ShortKey = GetValue(reader, "phone_open_hours_shortkey");
                                orgUnit.PhoneOpenHours.Value    = GetValue(reader, "phone_open_hours_value");

                                orgUnit.Operation = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));
                            }
                        }
                    }

                    // read itsystems
                    if (orgUnit != null)
                    {
                        orgUnit.ItSystemUuids = new List <string>();
                        using (SqlCommand command = new SqlCommand(OrgUnitStatements.SELECT_ITSYSTEMS, connection))
                        {
                            command.Parameters.Add(new SqlParameter("@id", orgUnitId));

                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    orgUnit.ItSystemUuids.Add(GetValue(reader, "itsystem_uuid"));
                                }
                            }
                        }
                    }

                    // read contact places
                    if (orgUnit != null)
                    {
                        using (SqlCommand command = new SqlCommand(OrgUnitStatements.SELECT_CONTACT_PLACES, connection))
                        {
                            command.Parameters.Add(new SqlParameter("@id", orgUnitId));

                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    string contactPlaceUuid = GetValue(reader, "contact_place_uuid");
                                    string task             = GetValue(reader, "task");

                                    ContactPlace contactPlace = null;
                                    foreach (ContactPlace cp in orgUnit.ContactPlaces)
                                    {
                                        if (cp.OrgUnitUuid.Equals(contactPlaceUuid))
                                        {
                                            contactPlace = cp;
                                            break;
                                        }
                                    }

                                    if (contactPlace == null)
                                    {
                                        contactPlace             = new ContactPlace();
                                        contactPlace.Tasks       = new List <string>();
                                        contactPlace.OrgUnitUuid = contactPlaceUuid;
                                        orgUnit.ContactPlaces.Add(contactPlace);
                                    }

                                    contactPlace.Tasks.Add(task);
                                }
                            }
                        }
                    }
                }
            }

            return(orgUnit);
        }
예제 #4
0
        public List <OrgUnitRegistrationExtended> Get4OldestEntries()
        {
            List <OrgUnitRegistrationExtended> result = new List <OrgUnitRegistrationExtended>();

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

                using (DbCommand command = DaoUtil.GetCommand(OrgUnitStatements.Select, connection))
                {
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            long orgUnitId = (long)reader["id"];

                            var orgUnit = new OrgUnitRegistrationExtended();
                            orgUnit.Id                = orgUnitId;
                            orgUnit.Uuid              = GetValue(reader, "uuid");
                            orgUnit.ShortKey          = GetValue(reader, "shortkey");
                            orgUnit.Name              = GetValue(reader, "name");
                            orgUnit.ParentOrgUnitUuid = GetValue(reader, "parent_ou_uuid");
                            orgUnit.PayoutUnitUuid    = GetValue(reader, "payout_ou_uuid");
                            orgUnit.ManagerUuid       = GetValue(reader, "manager_uuid");
                            orgUnit.LOSShortName      = GetValue(reader, "los_shortname");
                            orgUnit.LOSId             = GetValue(reader, "losid");
                            orgUnit.PhoneNumber       = GetValue(reader, "phone_number");
                            orgUnit.Email             = GetValue(reader, "email");
                            orgUnit.Landline          = GetValue(reader, "landline");
                            orgUnit.Url               = GetValue(reader, "url");
                            orgUnit.Location          = GetValue(reader, "location");
                            orgUnit.Ean               = GetValue(reader, "ean");
                            orgUnit.Post              = GetValue(reader, "post_address");
                            orgUnit.ContactOpenHours  = GetValue(reader, "contact_open_hours");
                            orgUnit.DtrId             = GetValue(reader, "dtr_id");
                            orgUnit.EmailRemarks      = GetValue(reader, "email_remarks");
                            orgUnit.Contact           = GetValue(reader, "contact");
                            orgUnit.PostReturn        = GetValue(reader, "post_return");
                            orgUnit.PhoneOpenHours    = GetValue(reader, "phone_open_hours");
                            orgUnit.Operation         = (OperationType)Enum.Parse(typeof(OperationType), GetValue(reader, "operation"));
                            orgUnit.Cvr               = GetValue(reader, "cvr");

                            // type can be null on DELETEs
                            string tmpType = GetValue(reader, "orgunit_type");
                            if (!string.IsNullOrEmpty(tmpType))
                            {
                                orgUnit.Type = (OrgUnitType)Enum.Parse(typeof(OrgUnitType), tmpType);
                            }
                            else
                            {
                                orgUnit.Type = OrgUnitType.DEPARTMENT;
                            }

                            result.Add(orgUnit);
                        }
                    }
                }

                foreach (var orgUnit in result)
                {
                    orgUnit.Tasks           = new List <string>();
                    orgUnit.ContactForTasks = new List <string>();

                    using (DbCommand command = DaoUtil.GetCommand(OrgUnitStatements.SelectTasks, connection))
                    {
                        command.Parameters.Add(DaoUtil.GetParameter("@id", orgUnit.Id));

                        using (DbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                string task = GetValue(reader, "task");

                                orgUnit.Tasks.Add(task);
                            }
                        }
                    }

                    using (DbCommand command = DaoUtil.GetCommand(OrgUnitStatements.SelectContactForTasks, connection))
                    {
                        command.Parameters.Add(DaoUtil.GetParameter("@id", orgUnit.Id));

                        using (DbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                string task = GetValue(reader, "task");

                                orgUnit.ContactForTasks.Add(task);
                            }
                        }
                    }
                }
            }

            return(result);
        }