Cgw.Channel.MonitorChannelRelationManager.AssignChannel C# (CSharp) Method

AssignChannel() public method

分配通道 调度会议时,输入smc分配的通道标识和会议号 结束会议时,需要再次输入分配的通道标识,会议号设置为空
public AssignChannel ( List channelInfoList ) : SmcErr
channelInfoList List 通道信息列表
return Cgw.SmcError.SmcErr
        public SmcErr AssignChannel(List<ChannelInfo> channelInfoList)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("AssignChannel start.");

            if (null == channelInfoList || 0 == channelInfoList.Count)
            {
                // 错误码 日志
                logEx.Error("AssignChannel param error");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR);
                return err;
            }

            try
            {
                bool successed = this.monitorChannelRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        foreach (ChannelInfo item in channelInfoList)
                        {
                            // 存在任一在通道字典中找不到的通道号码,返回错误
                            if (!this.monitorChannelRelationDic.ContainsKey(item.ChannelLabel))
                            {
                                // 错误码 日志
                                logEx.Error("AssignChannel can't find channelLabel:{0}", item.ChannelLabel);
                                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_FIND_CHANNELNO);
                                return err;
                            }

                            // 存在任一license无效的通道号码,返回错误
                            if (false == this.monitorChannelRelationDic[item.ChannelLabel].IsValid)
                            {
                                // 错误码 日志
                                logEx.Error("AssignChannel channelLabel:{0} is inValid.", item.ChannelLabel);
                                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_CHANNEL_INVALID);
                                return err;
                            }
                        }

                        foreach (ChannelInfo item in channelInfoList)
                        {
                            // 设置通道会议号
                            err = this.SyncChannelConfAccessCode(item.ChannelLabel, item.AccessCode, ChannelControlType.None);
                            if (!err.IsSuccess())
                            {
                                logEx.Error("AssignChannel syncChannelConfAccessCode ChannelLabel:{0}, ConfAccessCode:{1} failed.", item.ChannelLabel, item.AccessCode);
                                return err;
                            }
                        }

                        // 日志
                        string channellLog = "Log AssignChannel result:";
                        foreach (KeyValuePair<string, MonitorChannelRelation> pair in this.monitorChannelRelationDic)
                        {
                            string name = string.Format("  channelLabel:{0},confAccessCode:{1}, cameraNo:{2}, isValid:{3};", pair.Value.Label, pair.Value.ConfAccessCode, pair.Value.CameraNo, pair.Value.IsValid);
                            channellLog += name;
                        }
                        logEx.Trace(channellLog);
                    }
                    finally
                    {
                        // 释放互斥量
                        this.monitorChannelRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("AssignChannel: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "AssignChannel: Enert Write Lock Exception.");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
            }

            // 成功日志
            logEx.Info("AssignChannel successfully");

            return err;
        }