Exemplo n.º 1
0
        public async Task <BoardCastRoomModel> GetLiveRoomByStreamName(string streamName)
        {
            try
            {
                BoardCastRoomEntity entity = await BoardcastRoomDao.GetBoardCastRoomBySteamName(streamName.ToLower());

                if (entity == null)
                {
                    return(null);
                }

                return(new BoardCastRoomModel()
                {
                    Id = entity.Id,
                    Domain = entity.Domain,
                    Name = entity.Name,
                    AppName = entity.AppName,
                    ExpireTime = entity.ExpireTime,
                    PlayEndUrl = entity.PlayEndNotifyUrl,
                    PlayNotifyUrl = entity.PlayNotifyUrl,
                    PublishEndUrl = entity.PublishEndNotifyUrl,
                    PublishNotifyUrl = entity.PublishNotifyUrl,
                    StreamName = entity.StreamName,
                    State = entity.State,
                });
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                return(null);
            }
        }
        public async Task <DaoResultMessage> CreateRoom(BoardCastRoomEntity boardCastRoomEntity)
        {
            if (boardCastRoomEntity == null)
            {
                return(DaoResultMessage.ItemNotExist);
            }
            DaoResultMessage message = new DaoResultMessage();

            try
            {
                using (var context = new DjLiveCpContext())
                {
                    if (context.Domain.AsNoTracking().Any(obj => obj.SourceDomain == boardCastRoomEntity.Domain))
                    {
                        if (context.BoardCastRoom.AsNoTracking().Any(obj =>
                                                                     obj.Id == boardCastRoomEntity.Id ||
                                                                     (obj.StreamName == boardCastRoomEntity.StreamName
                                                                      //&&obj.AppName == boardCastRoomEntity.AppName && obj.Domain == boardCastRoomEntity.Domain
                                                                     )))
                        {
                            //todo:更新
                            //context.BoardCastRoom.AddOrUpdate(boardCastRoomEntity);
                            var dbentity = context.BoardCastRoom.FirstOrDefault(obj =>
                                                                                obj.Id == boardCastRoomEntity.Id || (obj.StreamName == boardCastRoomEntity.StreamName));
                            context.BoardCastRoom.Remove(dbentity);
                        }

                        context.BoardCastRoom.Add(boardCastRoomEntity);
                        await context.SaveChangesAsync();
                    }
                    else
                    {
                        return(DaoResultMessage.ItemNotExist);
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                message.Code    = DaoResultCode.UnExpectError;
                message.Message = e.Message;
            }

            return(message);
        }
Exemplo n.º 3
0
        public async Task <ServiceResultMessage> CreateLiveRoom(string userId, BoardCastRoomModel model)
        {
            if (model == null)
            {
                return new ServiceResultMessage()
                       {
                           code = ServiceResultCode.UnDefineError, Message = "传入对象为空,请检查参数.."
                       }
            }
            ;
            try
            {
                // var domain = DomainDao.GetDomainCount(userId);//通过Domain 确定是否存在DomainNode

                var entity = new BoardCastRoomEntity()
                {
                    Id                  = model.Id,
                    Domain              = model.Domain,
                    Name                = model.Name,
                    AppName             = string.IsNullOrEmpty(model.AppName) ? "live" : model.AppName,
                    ExpireTime          = model.ExpireTime.Equals(new DateTime()) ? DateTime.Now.AddDays(2) : model.ExpireTime,
                    PlayEndNotifyUrl    = model.PlayEndUrl,
                    PlayNotifyUrl       = model.PlayNotifyUrl,
                    PublishEndNotifyUrl = model.PublishEndUrl,
                    PublishNotifyUrl    = model.PublishNotifyUrl,
                    StreamName          = model.StreamName.ToLower(),
                    State               = 1,
                };

                DaoResultMessage daoresult = await BoardcastRoomDao.CreateRoom(entity);

                return((ServiceResultMessage)ServiceResultBase.DaoResult2ServiceResult(daoresult));
            }
            catch (Exception e)
            {
                LogHelper.Error(e.Message, e);
                return(null);
            }
        }