Ejemplo n.º 1
0
        public async Task <List <DomainModel> > GetSimpleDomains(string userId, int page, int countPerPage, DomainModel delta)
        {
            try
            {
                DomainEntity entityDelta = null;
                if (delta != null)
                {
                    entityDelta = new DomainEntity()
                    {
                    };
                }
                var entities = await DomainDao.GetDomainEntities(page, countPerPage, userId, entityDelta);

                return(entities?.Select(item => new DomainModel()
                {
                    Id = item.Id,
                    SourceDomain = item.SourceDomain,
                    Description = item.Description,
                    FlvPlayDomain = item.FlvPlayDomain,
                    HlsPlayDomain = item.HlsPlayDomain,
                    RtmpPlayDomain = item.RtmpPlayDomain,
                }).ToList());
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public void RemoveDomain(string domain, bool withStorageClean = true)
        {
            if (withStorageClean)
            {
                ClearDomainStorageSpace(domain);
            }

            using (var db = new DbManager(_csName))
            {
                using (var tx = db.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    var aliasDao = new AliasDao(db);

                    aliasDao.RemoveByDomain(domain);

                    var mailboxDao = new MailboxDao(db);

                    mailboxDao.RemoveByDomain(domain);

                    var domainDao = new DomainDao(db);

                    domainDao.Remove(domain);

                    var dkimDao = new DkimDao(db);

                    dkimDao.Remove(domain);

                    tx.Commit();
                }
            }
        }
Ejemplo n.º 3
0
        public int SaveDomain(Domain domain)
        {
            using (var db = new DbManager(_csName))
            {
                var domainDao = new DomainDao(db);

                return(domainDao.Save(domain));
            }
        }
Ejemplo n.º 4
0
        public int SaveDomain(Domain domain)
        {
            using (var db = DbManager.FromHttpContext(_csName))
            {
                var domainDao = new DomainDao(db);

                return(domainDao.Save(domain));
            }
        }
        protected override void SetUp()
        {
            base.SetUp();

            IConnectionInfoAsync connectionInfo = A.Fake <IConnectionInfoAsync>();

            _domainDao = new DomainDao(connectionInfo);

            A.CallTo(() => connectionInfo.GetConnectionStringAsync()).Returns(ConnectionString);
        }
Ejemplo n.º 6
0
        public async Task <ServiceResultMessage> RemoveAsync(string userId, string id)
        {
            try
            {
                //todo:1.保存设置 2.删除水印图片 3.重新生成配置文件 4.上传配置文件 5.重启SRS服务
                var daoresult = await DomainDao.DeleteDomainById(id);

                return((ServiceResultMessage)ServiceResultBase.DaoResult2ServiceResult(daoresult));
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                return(null);
            }
        }
Ejemplo n.º 7
0
 public async Task <int> GetDomainsCount(string userId, DomainModel delta)
 {
     try
     {
         DomainEntity entityDelta = null;
         if (delta != null)
         {
             entityDelta = new DomainEntity()
             {
             };
         }
         return(await DomainDao.GetDomainCount(userId, entityDelta));
     }
     catch (Exception e)
     {
         throw;
     }
 }
Ejemplo n.º 8
0
        public async Task <DomainModel> FindByIdAsync(string userId, string id)
        {
            try
            {
                var entity = await DomainDao.GetDomainEntityById(id);

                if (entity != null)
                {
                    return(new DomainModel()
                    {
                        Id = entity.Id,
                        ServerPair = new KeyNamePair(entity.Server?.Id, entity.Server?.Name),
                        SourceDomain = entity.SourceDomain,
                        Description = entity.Description,
                        SourceType = (SourceStreamType)entity.SourceType,
                        StateType = (StateType)entity.StateType,

                        RtmpPlayDomain = entity.RtmpPlayDomain,
                        FlvPlayDomain = entity.FlvPlayDomain,
                        HlsPlayDomain = entity.HlsPlayDomain,

                        SecurePolicyPair = new KeyNamePair(entity.SecurePolicy?.Id, entity.SecurePolicy?.Name),
                        RecordTemplatePair = new KeyNamePair(entity.RecordTemplate?.Id, entity.RecordTemplate?.Name),
                        TranscodeIdPair = entity.TranscodeList.Select(item =>
                        {
                            return new KeyNamePair(item.Id, item.Name);
                        }).ToList()
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                return(null);
            }
        }
Ejemplo n.º 9
0
        public async Task <ServiceResultMessage> CreateVhost(string userId, DomainModel model)
        {
            ServiceResultMessage result = new ServiceResultMessage();
            var id = string.IsNullOrEmpty(model.Id) ? Guid.NewGuid().Str() : model.Id;

            try
            {
                var daomainResult = await DomainDao.Add2Account(userId, model.ServerPair.Key, new DomainEntity()
                {
                    Id             = id,
                    SourceDomain   = model.SourceDomain,
                    Description    = model.Description,
                    SourceType     = (int)model.SourceType,
                    StateType      = 1,
                    RtmpPlayDomain = model.RtmpPlayDomain,
                    FlvPlayDomain  = model.FlvPlayDomain,
                    HlsPlayDomain  = model.HlsPlayDomain
                });

                if (daomainResult.Code == DaoResultCode.Success)
                {
                    var secureAppendtask    = DomainDao.AppendSecure(id, model.SecurePolicyPair.Key);
                    var transcodeAppendtask = DomainDao.AppendTranscode(id, model.TranscodeIdPair?.Select(item => item.Key).ToList());
                    var resultsMessages     = await Task.WhenAll(secureAppendtask, transcodeAppendtask);

                    if (resultsMessages.Count(item => item.Code != DaoResultCode.Success) > 0)
                    {
                        var rollbackResult = await DomainDao.DeleteDomainById(id);

                        result.code = ServiceResultCode.AppendItemError;
                    }
                    else
                    {
                        try
                        {
                            var updateConfResult = await ServerNodeService.UpdateSrsConf(userId, model.ServerPair.Key);

                            if (updateConfResult.code != ServiceResultCode.Success)
                            {
                                var rollbackResult = await DomainDao.DeleteDomainById(id);

                                result.code    = ServiceResultCode.UpdateSrsError;
                                result.Message = updateConfResult.Message;
                                result.ErrorId = updateConfResult.ErrorId;
                            }
                        }
                        catch (Exception e)
                        {
                            var rollbackResult = await DomainDao.DeleteDomainById(id);

                            result.code    = ServiceResultCode.UpdateSrsError;
                            result.ErrorId = LogHelper.ErrorWithId(e.Message, e);
                            result.Message = "更新Srs服务器失败,请联系管理员,错误代码:" + result.ErrorId;
                        }
                    }
                }
                else
                {
                    result.code = ServiceResultCode.UnExceptError;
                }
            }
            catch (Exception e)
            {
                var rollbackResult = await DomainDao.DeleteDomainById(id);

                LogHelper.Error(e.Message, e);
                result.code    = ServiceResultCode.UnExceptError;
                result.ErrorId = LogHelper.ErrorWithId(e.Message, e);
                result.Message = "发生未知错误,请联系管理员,错误代码:" + result.ErrorId;
            }
            return(result);
        }
Ejemplo n.º 10
0
        //todo:UnFinish
        public async Task <ServiceResultMessage> UpdateDomain(string userId, string id, DomainModel model)
        {
            ServiceResultMessage result = new ServiceResultMessage();

            try
            {
                //todo:1.保存设置  3.重新生成配置文件 4.上传配置文件 5.重启SRS服务
                var daoresult = await DomainDao.UpdataDomain(id, new DomainEntity()
                {
                    Id           = model.Id,
                    SourceDomain = model.SourceDomain,
                    Description  = model.Description,
                    SourceType   = (int)model.SourceType,
                    StateType    = (int)model.StateType,

                    RtmpPlayDomain = model.RtmpPlayDomain,
                    FlvPlayDomain  = model.FlvPlayDomain,
                    HlsPlayDomain  = model.HlsPlayDomain,
                });

                if (daoresult.Code == DaoResultCode.Success)
                {
                    var secureAppendtask    = DomainDao.AppendSecure(id, model?.SecurePolicyPair.Key);
                    var transcodeAppendtask = DomainDao.AppendTranscode(id, model?.TranscodeIdPair?.Select(item => item.Key).ToList());
                    var resultsMessages     = await Task.WhenAll(secureAppendtask, transcodeAppendtask);

                    if (resultsMessages.Count(item => item.Code != DaoResultCode.Success) > 0)
                    {
                        result.code = ServiceResultCode.AppendItemError;
                    }
                    else
                    {
                        try
                        {
                            var updateConfResult = await ServerNodeService.UpdateSrsConf(userId, model.ServerPair.Key);

                            if (updateConfResult.code != ServiceResultCode.Success)
                            {
                                var rollbackResult = await DomainDao.DeleteDomainById(id);

                                result.code    = ServiceResultCode.UpdateSrsError;
                                result.Message = updateConfResult.Message;
                                result.ErrorId = updateConfResult.ErrorId;
                            }
                        }
                        catch (Exception e)
                        {
                            var rollbackResult = await DomainDao.DeleteDomainById(id);

                            result.code    = ServiceResultCode.UpdateSrsError;
                            result.ErrorId = LogHelper.ErrorWithId(e.Message, e);
                            result.Message = "更新Srs服务器失败,请联系管理员,错误代码:" + result.ErrorId;
                        }
                    }
                }
                else
                {
                    result.code = ServiceResultCode.UnExceptError;
                }
                return(result);
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                result.code    = ServiceResultCode.UnExceptError;
                result.ErrorId = LogHelper.ErrorWithId(e.Message, e);
                result.Message = "发生未知错误,请联系管理员,错误代码:" + result.ErrorId;
                return(result);
            }
        }