protected override void _AddDkim(DkimRecordBase dkim_to_add)
        {
            var db_manager = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);

            using (var db = db_manager.GetAdminDb())
            {
                var id_dkim = db.ExecuteScalar <int>(
                    new SqlQuery(DkimTable.name)
                    .Select(DkimTable.Columns.id)
                    .Where(DkimTable.Columns.domain_name, Name));

                if (id_dkim == 0)
                {
                    var insert_dkim = new SqlInsert(DkimTable.name)
                                      .InColumnValue(DkimTable.Columns.domain_name, Name)
                                      .InColumnValue(DkimTable.Columns.selector, dkim_to_add.Selector)
                                      .InColumnValue(DkimTable.Columns.private_key, dkim_to_add.PrivateKey)
                                      .InColumnValue(DkimTable.Columns.public_key, dkim_to_add.PublicKey);
                    db.ExecuteNonQuery(insert_dkim);
                }
                else
                {
                    var update_dkim = new SqlUpdate(DkimTable.name)
                                      .Where(DkimTable.Columns.id, id_dkim)
                                      .Set(DkimTable.Columns.selector, dkim_to_add.Selector)
                                      .Set(DkimTable.Columns.private_key, dkim_to_add.PrivateKey)
                                      .Set(DkimTable.Columns.public_key, dkim_to_add.PublicKey);
                    db.ExecuteNonQuery(update_dkim);
                }
            }
        }
        protected override void _RemoveAlias(MailAddressBase aliasToRemove)
        {
            var removeMailboxAlias = new SqlDelete(AliasTable.name)
                                     .Where(AliasTable.Columns.address, aliasToRemove.ToString());

            var dbManager = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);

            using (var db = dbManager.GetAdminDb())
            {
                db.ExecuteNonQuery(removeMailboxAlias);
            }
        }
        protected override void _AddAlias(MailAddressBase aliasToAdd)
        {
            var insertMailboxAlias = new SqlInsert(AliasTable.name)
                                     .InColumnValue(AliasTable.Columns.address, aliasToAdd.ToString())
                                     .InColumnValue(AliasTable.Columns.redirect, Address.ToString())
                                     .InColumnValue(AliasTable.Columns.domain, aliasToAdd.Domain.Name)
                                     .InColumnValue(AliasTable.Columns.created, aliasToAdd.DateCreated)
                                     .InColumnValue(AliasTable.Columns.modified, aliasToAdd.DateCreated)
                                     .InColumnValue(AliasTable.Columns.active, true)
                                     .InColumnValue(AliasTable.Columns.is_group, false);

            var dbManager = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);

            using (var db = dbManager.GetAdminDb())
            {
                db.ExecuteNonQuery(insertMailboxAlias);
            }
        }
        private IDbManager GetDb()
        {
            var dbProvider = new PostfixAdminDbManager(Server.Id, Server.ConnectionString);

            return(dbProvider.GetAdminDb());
        }
Beispiel #5
0
        protected override WebDomainBase _CreateWebDomain(string name)
        {
            var domain = new WebDomainBase(name)
            {
                DateCreated = DateTime.UtcNow
            };

            try
            {
                var domain_description = String.Format("Domain created in UtcTime: {0}, for tenant: {1}",
                                                       domain.DateCreated, Tenant);
                var insert_domain_query = new SqlInsert(DomainTable.name)
                                          .InColumnValue(DomainTable.Columns.domain, domain.Name)
                                          .InColumnValue(DomainTable.Columns.description, domain_description)
                                          .InColumnValue(DomainTable.Columns.transport, "virtual")
                                          .InColumnValue(DomainTable.Columns.created, domain.DateCreated)
                                          .InColumnValue(DomainTable.Columns.modified, domain.DateCreated)
                                          .InColumnValue(DomainTable.Columns.active, true);

                using (var db = _dbManager.GetAdminDb())
                {
                    db.ExecuteNonQuery(insert_domain_query);
                }

                return(domain);
            }
            catch (MySqlException ex)
            {
                if (ex.Message.StartsWith("Duplicate entry"))
                {
                    throw new ArgumentException("Already added");
                }

                throw;
            }
        }