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); }
//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); } }