Exemple #1
0
        /// <summary>
        ///  以设备Id返回所有通道
        /// </summary>
        /// <param name="device">DeviceId</param>
        /// <param name="customerToken">token</param>
        /// <param name="deviceFlag">返回结果 设备</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByDeviceId(Device device, string customerToken, ref IList <Channel> channeFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.TokenTimeOut;
                    dto.Message = "用户token已失效,请重新登录后继续";
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    channeFlag  = channelServer.SelectChannelByDeviceId(device);
                    dto.Code    = 0;
                    dto.Message = "通道数据获取已完成";
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetChannelByDeviceId方法异常,设备Id:{0}", ex, device.DeviceId);
            }
            return(dto);
        }
Exemple #2
0
        /// <summary>
        /// 查询用户设备下的通道
        /// </summary>
        /// <param name="customer">customerId</param>
        /// <param name="customerToken">token</param>
        /// <param name="deviceChannel">返回数据:通道</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByCustomerId(string customerToken, ref IList <Channel> deviceChannel)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        return(dto);
                    }
                    else
                    {
                        //获取当前用户所有的Device
                        //区分主用户与子用户
                        Customer customer = new Customer();
                        customer.CustomerId = tcp.CustomerId;
                        customerId          = tcp.CustomerId;
                        IList <Customer> customerFlag = customerServer.SelectCustomerByCustomerId(customer);
                        if (customerFlag[0].ParentId != 0 && customerFlag[0].SignInType != 2)
                        {
                            //子账户将查询主用户的分组信息
                            customerFlag[0].CustomerId = customerFlag[0].ParentId;
                        }
                        //获取用户下的设备
                        IList <Device> customerDevice = deviceServer.SelectDeviceCustomerId(customer);
                        //获取设备下的通道
                        if (customerDevice != null && customerDevice.Count != 0)
                        {
                            List <int> deviceIdFlag = new List <int>();
                            for (int i = 0; i < customerDevice.Count; i++)
                            {
                                deviceIdFlag.Add(customerDevice[0].DeviceId);
                            }
                            deviceChannel = channelServer.SelectChannelByDeviceIdList(deviceIdFlag);
                        }
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "设备数据获取完成";
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetChannelByCustomerId方法异常,用户Id:{0},", ex, customerId);
                }
            }
            return(dto);
        }
        /// <summary>
        ///  修改通道是否启用 EnableChannel
        /// </summary>
        /// <param name="channel">Channel.ChannelId</param>
        /// <param name="customerToken">token</param>
        /// <returns></returns>
        public ResponseBaseDto EnableChannel(Channel channel, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "启用或禁用通道";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Channel;
                    oLog.Remarks    = dto.Message;
                    oLog.Result     = dto.Code;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(channel);
                    oLog.TargetId = channel.ChannelId;
                    if (channelFlag == null)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "需要修改的通道不存在";
                    }
                    else
                    {
                        string originalChannelName = channelFlag[0].ChannelName;
                        channelFlag[0].IsEnable = channel.IsEnable;
                        channelServer.UpdateChannel(channelFlag[0]);
                        dto.Code     = 0;
                        dto.Message  = originalChannelName;
                        dto.Message += channel.IsEnable == 1 ? "通道已启用" : "通道已禁用";
                    }
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("EnableChannel方法异常,用户Id:{0},通道Id:{1}", ex, tcp.CustomerId, channel.ChannelId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Channel;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #4
0
        /// <summary>
        ///  添加通道分组 AddResourceGroupByName
        /// </summary>
        /// <param name="resourceGroup">分组中的 分组名与 分组的父节点</param>
        /// <param name="customerToken">用户的唯一Token</param>
        /// <returns>0 表示成功   3 代表服务器异常  5 代表失效</returns>
        public ResponseBaseDto AddResourceGroupByName(ResourceGroup resourceGroup, string customerToken)
        {
            ResponseBaseDto dto  = new ResponseBaseDto();
            OperaterLog     oLog = new OperaterLog();

            oLog.Action = "添加分组";
            //校验token
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        oLog.Remarks = dto.Message;
                        oLog.Result  = dto.Code;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    //添加组
                    customerId = tcp.CustomerId;
                    resourceGroup.CustomerId = tcp.CustomerId;
                    int resourceGroupId = (int)resourceGroupServer.InsertResourceGorup(resourceGroup);
                    oLog.TargetId = resourceGroupId;
                    if (resourceGroupId > 0)
                    {
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "添加通道分组已完成";
                    }
                    else
                    {
                        dto.Code    = (int)CodeEnum.ApplicationErr;
                        dto.Message = "分组添加异常";
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,添加分组失败!";
                    myLog.ErrorFormat("AddResourceGroupByName方法异常,用户Id:{0},添加的分组名:{2}", ex, customerId, resourceGroup.ResourceGroupName);
                }
            }
            oLog.TargetType = (int)OperaterLogEnum.ResourceGroup;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
        /// <summary>
        /// 删除1-n个收藏 以NodeId
        /// </summary>
        /// <param name="nodeType"></param>
        /// <param name="nodeIdList"></param>
        /// <param name="customerToken"></param>
        /// <returns></returns>
        public ResponseBaseDto DeleteUserFavorite(int nodeType, int[] nodeIdList, string customerToken)
        {
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            ResponseBaseDto    dto  = new ResponseBaseDto();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = "用户删除收藏";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token失效";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                if (nodeType == 0 || nodeIdList.Length == 0)
                {
                    dto.Code    = (int)CodeEnum.NoComplete;
                    dto.Message = "用户数据提交不完整!";
                    return(dto);
                }
                string nodeidListStr = "";
                for (int i = 0; i < nodeIdList.Length; i++)
                {
                    if (i != nodeIdList.Length - 1)
                    {
                        nodeidListStr += nodeIdList[i] + ",";
                    }
                    else
                    {
                        nodeidListStr += nodeIdList[i];
                    }
                }
                userFavoriteServer.DeleteUserFavorite(tcp.CustomerId, nodeType, nodeidListStr);
                oLog.Remarks    = tcp.CustomerName + "批量删除收藏类型:" + nodeType + " 收藏nodeId:" + nodeidListStr;
                oLog.TargetType = (int)OperaterLogEnum.Favorite;
                dto.Code        = (int)CodeEnum.Success;
                dto.Message     = "已完成批量删除!";
                oLog.Remarks   += dto.Message;
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常!,删除收藏失败!";
                myLog.ErrorFormat("DeleteUserFavorite方法异常,收藏类型:{0},收藏NodeId集合:{0}", ex, nodeType, nodeIdList.ToString());
            }
            return(dto);
        }
Exemple #6
0
        /// <summary>
        ///  前台管理员对指定的主用户查询登陆日志
        /// </summary>
        /// <param name="requestCount">请求条数</param>
        /// <param name="startCount">起始条数</param>
        /// <param name="customerToken">token</param>
        /// <param name="Total">总条数</param>
        /// <param name="operaterLogFlag">ref  结果集对象</param>
        /// <returns></returns>
        public ResponseBaseDto GetPrimaryOrSubLoginInfo(Customer psCustomer, int requestCount, int startCount,
                                                        string customerToken, ref int Total, ref IList <OperaterLog> operaterLogFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    List <int> customerIdList = new List <int>();
                    //当前用户Id
                    customerIdList.Add(psCustomer.CustomerId);
                    string actionWhere = "登录";
                    startCount     -= 1;
                    startCount      = startCount < 0 ? 0 : startCount;
                    operaterLogFlag = operaterLogServer.OperaterLogForPage(customerIdList, requestCount, startCount, actionWhere);
                    Total           = operaterLogServer.OperaterLogForPageCount(customerIdList, actionWhere);
                    dto.Code        = (int)CodeEnum.Success;
                    dto.Message     = "用户登陆信息已获取完成!";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,用户登陆信息获取失败!";
                myLog.WarnFormat("GetPrimaryOrSubLoginInfo方法异常,用户id(查询者):{0},用户id(被查询者):{1},起始条数:{2},请求条数:{3}",
                                 ex, tcp.CustomerId, psCustomer.CustomerId, startCount, requestCount);
            }
            return(dto);
        }
Exemple #7
0
        internal ResponseBaseDto CheckCustomer(ResponseBaseDto dto, string customerToken, ref TokenCacheProperty tcp)
        {
            UserTokenCache utc = UserTokenCache.GetInstance();

            tcp = utc.FindByCustomerToken(customerToken);
            Customer customer = new Customer();

            if (tcp == null)
            {
                dto.Message = "请求的用户未找到";
                dto.Code    = (int)CodeEnum.NoUser;
                return(dto);
            }
            else if (tcp.IsEnable == 0)
            {
                dto.Message = "此账户已被冻结,无法使用此功能";
                dto.Code    = (int)CodeEnum.NoAuthorization;
                return(dto);
            }//Wait....
            return(dto);
        }
Exemple #8
0
        /// <summary>
        ///  添加通道
        /// <param name="Channel">通道名,通道的设备Id,通道的编号</param>
        /// <param name="CustomerToken">用户的唯一Token</param>
        /// <returns>0 表示成功   3 代表服务器异常  5代表失效</returns>
        public ResponseBaseDto AddChannel(Channel channel, string customerToken, ref int channelId)
        {
            ResponseBaseDto dto = new ResponseBaseDto();
            //校验token
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try {
                    channelId = channelServer.InsertChannel(channel);
                    if (channelId != 0)
                    {
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "添加通道分组已完成";
                    }
                    else
                    {
                        dto.Code    = (int)CodeEnum.ApplicationErr;
                        dto.Message = "网络中断,未添加成功";
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("AddChannel方法异常", ex);
                }
            }
            return(dto);
        }
        /// <summary>
        /// 分页查询收藏信息
        /// </summary>
        /// <param name="startCount">起始条数</param>
        /// <param name="requestCount">请求条数</param>
        /// <param name="customerToken">token</param>
        /// <param name="userfavoriteFlag">ref 实际收藏结果</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        public ResponseBaseDto GetUserFavoriteByPage(int startCount, int requestCount, string customerToken,
                                                     ref List <UserFavoriteResponse> userFavoriteRespnseFlag, ref int total)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token失效";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                customerId  = tcp.CustomerId;
                startCount -= 1;
                startCount  = startCount < 0 ? 0 : startCount;
                IList <UserFavorite> userFavoriteFlag = userFavoriteServer.SelectUserFavoriteByPage(tcp.CustomerId, startCount, requestCount);
                total = userFavoriteServer.SelectUserFavoriteByPageCount(tcp.CustomerId);
                for (int i = 0; i < userFavoriteFlag.Count; i++)
                {
                    UserFavoriteResponse ufr = new UserFavoriteResponse();
                    ufr.CustomerId         = userFavoriteFlag[i].CustomerId;
                    ufr.UserFavoriteId     = userFavoriteFlag[i].UserFavoriteId;
                    ufr.UserFavoriteType   = userFavoriteFlag[i].UserFavoriteType;
                    ufr.UserFavoriteTypeId = userFavoriteFlag[i].UserFavoriteTypeId;
                    ufr.AliasName          = userFavoriteFlag[i].AliasName;
                    ufr.FavoriteTime       = userFavoriteFlag[i].FavoriteTime.ToString();//无法输出datetime类型,进行转换
                    //如果是通道的情况需加入通道封面
                    if (ufr.UserFavoriteType == (int)UserFavoriteTypeEnum.Channel)
                    {
                        IList <Channel> channelFlag =
                            channelServer.SelectChannelByChannelId(new Channel()
                        {
                            ChannelId = ufr.UserFavoriteTypeId
                        });
                        if (channelFlag != null && channelFlag.Count > 0)
                        {
                            ufr.ImagePath = channelFlag[0].ImagePath == string.Empty ? "default.jpg" : channelFlag[0].ImagePath;
                        }
                    }
                    userFavoriteRespnseFlag.Add(ufr);
                }
                dto.Code    = (int)CodeEnum.Success;
                dto.Message = "已完成收藏信息获取";
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常!,查询收藏失败!";
                myLog.WarnFormat("GetUserFavoriteByPage方法异常,用户Id:{0},请求的起始条数:{1},请求条数:{2}", ex, customerId, startCount, requestCount);
            }
            return(dto);
        }
Exemple #10
0
        /// <summary>
        ///  以用户Id返回所有设备
        /// </summary>
        /// <param name="customer">CustomerId</param>
        /// <param name="customerToken">token</param>
        /// <param name="deviceFlag">返回结果 设备</param>
        /// <returns></returns>
        public ResponseBaseDto GetDeviceByCustomerId(string customerToken, ref List <DeviceResponse> deviceResponseFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.TokenTimeOut;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else if (tcp.SignInType != (int)CustomerSignInTypeEnum.PrimaryCustomer)
                {
                    dto.Code    = (int)CodeEnum.NoUser;
                    dto.Message = "没有权限";
                    return(dto);
                }
                else
                {
                    Customer customer = new Customer();
                    customerId          = tcp.CustomerId;
                    customer.CustomerId = tcp.CustomerId;
                    List <int> authorizeDeviceIdList = new  List <int>();
                    //当前主账号下的设备
                    IList <Device> deviceFlag = deviceServer.SelectDeviceCustomerId(customer);
                    //准备返回的结果集
                    deviceResponseFlag = new List <DeviceResponse>();
                    //添加授权的设备
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    for (int j = 0; j < permissionFlag.Count; j++)
                    {
                        //判定当前用户对授权设备是否是可用的
                        if (permissionFlag[j].IsEnable == 1 && permissionFlag[j].NodeType == 1)
                        {
                            IList <Device> otherDeviceFalg =
                                deviceServer.SelectDeviceByDeviceId(new Device()
                            {
                                DeviceId = permissionFlag[j].NodeId
                            });
                            if (otherDeviceFalg != null && otherDeviceFalg.Count == 1)
                            {
                                authorizeDeviceIdList.Add(otherDeviceFalg[0].DeviceId);
                                deviceFlag.Add(otherDeviceFalg[0]);
                            }
                        }
                    }
                    Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                    var seviceAddr = bllHelper.GetServerModelStr();
                    for (int i = 0; i < deviceFlag.Count; i++)
                    {
                        DeviceResponse dr = new DeviceResponse();
                        Bsr.Cloud.Model.Entities.Device device = deviceFlag[i];
                        dr.DeviceId     = device.DeviceId;
                        dr.DeviceName   = device.DeviceName;
                        dr.DeviceType   = device.DeviceType;
                        dr.SerialNumber = device.SerialNumber;
                        dr.HardwareType = device.HardwareType;
                        dr.IsAuthorize  = 0;
                        if (authorizeDeviceIdList.Contains(device.DeviceId))
                        {
                            dr.IsAuthorize = 1;
                        }
                        deviceResponseFlag.Add(dr);
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "设备已获取完成";
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetDeviceByCustomerId方法异常, 用户Id:{0}", ex, customerId);
            }
            return(dto);
        }
Exemple #11
0
        /// <summary>
        ///  删除一个分组并移除分组下的所有(虚)通道
        /// </summary>
        /// <param name="resourceGroup">通道分组Id</param>
        public ResponseBaseDto RemoveResourceGroup(ResourceGroup resourceGroup, string customerToken)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            TokenCacheProperty tcp = new TokenCacheProperty();
            string             groupChannelIdList = "";
            //校验token
            OperaterLog oLog = new OperaterLog();

            oLog.Action = "删除分组(所有)";
            UserTokenCache utc = UserTokenCache.GetInstance();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.Remarks = dto.Message;
                    oLog.Result  = dto.Code;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                //查找当前分组下的所有子分组
                IList <ResourceGroup> allResourceList = new List <ResourceGroup>();
                try
                {
                    GetchildResourceGroup(resourceGroup, ref allResourceList);
                    IList <ResourceGroup> rgFlag = resourceGroupServer.SelectResourceGorupByResourceGroupId(resourceGroup);
                    if (rgFlag != null && rgFlag.Count != 0)
                    {
                        allResourceList.Add(rgFlag[0]);
                    }
                    for (int i = 0; i < allResourceList.Count; i++)
                    {
                        ResourceGroup rg = allResourceList[i];//重复命名:rg
                        //判定当前分组下通道
                        IList <GroupChannel> groupChannelFlag =
                            groupChannelServer.SelectGroupChannelByResourceGroupId(rg);
                        for (int j = 0; j < groupChannelFlag.Count; j++)
                        {
                            GroupChannel groupChannel = groupChannelFlag[j];
                            //关联时必须先删除关系表
                            groupChannelServer.DeleteGroupChannel(groupChannel);
                            groupChannelIdList += groupChannel.GroupChannelId + " ";
                        }
                        resourceGroupServer.DeleteResourceGorup(rg);
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "分组移除完成!";
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("RemoveResourceGroup方法异常,分组id:{0},分组关系id:{1}", ex, resourceGroup.ResourceGroupId, groupChannelIdList);
                }
            }
            oLog.TargetType = (int)OperaterLogEnum.ResourceGroup;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #12
0
        /// <summary>
        /// 删除一个分组下的一个通道(虚) DeleteSingleChannelByChannelId 2014/12/15
        /// </summary>
        /// <param name="resourceGroup">resourceGroup.resourceGroupId</param>
        /// <param name="channel">channel.ChannelId</param>
        /// <param name="customerToken">token</param>
        /// <returns></returns>
        public ResponseBaseDto DeleteSingleChannelByChannelId(ResourceGroup resourceGroup, Channel channel, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "删除通道";
            UserTokenCache utc = UserTokenCache.GetInstance();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        oLog.Remarks = dto.Message;
                        oLog.Result  = dto.Code;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    GroupChannel groupChannel = new GroupChannel();
                    groupChannel.channel = new Channel()
                    {
                        ChannelId = channel.ChannelId
                    };
                    groupChannel.resourceGroup = new ResourceGroup()
                    {
                        ResourceGroupId = resourceGroup.ResourceGroupId
                    };
                    IList <GroupChannel> groupChannelFlag =
                        groupChannelServer.SelectGroupChannelByChannelIdAndResourceGroupId(groupChannel);
                    if (groupChannelFlag == null && groupChannelFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "需要删除的通道不存在";
                    }
                    else
                    {
                        groupChannelServer.DeleteGroupChannel(groupChannelFlag[0]);
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "通道" + groupChannelFlag[0].channel.ChannelName + "已被删除";
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,删除通道失败!";
                    myLog.ErrorFormat("DeleteSingleChannelByChannelId方法异常,分组Id:{0},通道Id:{1}", ex, resourceGroup.ResourceGroupId, channel.ChannelId);
                }
            }
            oLog.TargetType = (int)OperaterLogEnum.ResourceGroup;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #13
0
        /// <summary>
        ///  更新设备名称 UpdateDeviceByDeviceName
        /// </summary>
        /// <param name="device"></param>
        /// <param name="customerToken"></param>
        /// <returns></returns>
        public ResponseBaseDto UpdateDeviceByDeviceName(Device device, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = "修改设备名";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Device;
                    oLog.Result     = dto.Code;
                    oLog.Remarks    = dto.Message;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    IList <Device> deviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                    oLog.TargetId = device.DeviceId;
                    if (deviceFlag == null || deviceFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = device.DeviceName + "设备不存在";
                    }
                    else if (deviceFlag[0].CustomerId != tcp.CustomerId)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "用户没有权限修改设备 " + device.DeviceName;
                    }
                    else
                    {
                        try
                        {
                            //修改BP4Server的设备名
                            UpdateDeviceNameMethod(deviceFlag[0].BPServerDeviceId, deviceFlag[0].DeviceName);
                        }
                        catch (Exception ex)
                        {
                            dto.Code    = (int)CodeEnum.ApplicationErr;
                            dto.Message = "设备已离线!离线状态无法修改设备名";
                            myLog.ErrorFormat("UpdateDeviceByDeviceName(BP4Server设备已离线)设备id:{0},新设备名:{1}",
                                              ex, device.DeviceId, device.DeviceName);
                            return(dto);
                        }
                        deviceFlag[0].DeviceName = device.DeviceName;
                        deviceServer.UpdateDevice(deviceFlag[0]);
                        dto.Code    = 0;
                        dto.Message = "修改设备 " + device.DeviceName + " 完成!";
                    }
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,修改设备名时,远程连接超时!";
                myLog.ErrorFormat("UpdateDeviceByDeviceName方法异常, 设备id:{0},新设备名:{1}",
                                  ex, device.DeviceId, device.DeviceName);
            }
            oLog.TargetType = (int)OperaterLogEnum.Device;
            oLog.Result     = dto.Code;
            oLog.Remarks    = dto.Message;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #14
0
        /// <summary>
        ///  1添加设备 2初次添加设备通道
        /// </summary>
        /// <returns>ResponseBaseDto</returns>
        public ResponseBaseDto AddDevice(string deviceName, string serialNumber, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = " 添加设备 ";
            try
            {
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                //获取 判定token
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "Token已失效";
                }
                else
                {
                    Device device = new Device();
                    device.SerialNumber = serialNumber;
                    IList <Device> deviceFlag = deviceServer.SelectDeviceSerialNumber(device);

                    if (device != null && deviceFlag.Count != 0)
                    {
                        //设备被添加过
                        dto.Code     = (int)CodeEnum.NoHardWare;
                        dto.Message  = "此设备正在被使用中";
                        oLog.Result  = dto.Code;
                        oLog.Remarks = dto.Message;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    //参数 0=IP  3等于 CN
                    AddDeviceResponseDto result = AddDeviceMethod(serialNumber);
                    if (result != null && result.Success == true)
                    {
                        //添加本地设备列表
                        Bsr.Cloud.Model.Entities.Device dev = new Model.Entities.Device();
                        dev.SerialNumber     = result.DeviceDto.AddDeviceEntity.SerialNumber;
                        dev.BPServerDeviceId = result.DeviceDto.AddDeviceEntity.Id;
                        if (deviceName == null || deviceName == "")
                        {
                            deviceName = "BStar";
                        }
                        dev.DeviceName = deviceName;
                        // 序列号添加时填3,需用IDeviceEntity.getDeviceType获取真正实际类型
                        dev.DeviceType   = result.DeviceDto.AddDeviceEntity.AddMode;
                        dev.HardwareType = result.DeviceDto.AddDeviceEntity.HardwareType;
                        dev.CustomerId   = tcp.CustomerId;
                        dev.UserName     = result.DeviceDto.AddDeviceEntity.User;
                        dev.PassWord     = result.DeviceDto.AddDeviceEntity.Password;
                        //以规则需要定义服务器位置
                        BPServerConfig bpServerConfig = new BPServerConfig();
                        bpServerConfig.Domain = "default";
                        IList <BPServerConfig> bpServerConfigFlag = bpServerConfigServer.GetBPServerConfigByDomain(bpServerConfig);
                        if (bpServerConfigFlag != null && bpServerConfigFlag.Count != 0)
                        {
                            dev.BPServerConfigId = bpServerConfigFlag[0].BPServerConfigId;
                        }
                        else
                        {
                            dev.BPServerConfigId = 1; //需修改
                        }
                        int deviceId = deviceServer.InsertDevice(dev);

                        //日志动作的目标对象Id
                        oLog.TargetId = deviceId;
                        //通道添加
                        IList <CameraEntity> channelFlag = result.DeviceDto.AddDeviceEntity.Cameras;
                        for (int i = 0; i < channelFlag.Count; i++)
                        {
                            Bsr.Cloud.Model.Entities.Channel channel = new Model.Entities.Channel();
                            CameraEntity ce = channelFlag[i];
                            channel.DeviceId          = deviceId;
                            channel.ChannelNumber     = ce.ChannelNo;
                            channel.ChannelName       = ce.Name;
                            channel.IsEnable          = 1;
                            channel.BPServerChannelId = ce.Id;
                            channel.ImagePath         = "default.jpg";
                            channelServer.InsertChannel(channel);
                        }
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "设备" + deviceName + "已添加完成!";
                    }
                    else
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = result.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,添加设备时,远程连接超时!";
                myLog.ErrorFormat("AddDevice方法异常,设备名:{0}, 设备序列号:{1}", ex, deviceName, serialNumber);
            }
            oLog.TargetType = (int)OperaterLogEnum.Device;
            oLog.Result     = dto.Code;
            oLog.Remarks    = dto.Message;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
        /// <summary>
        /// 修改通道的默认图片
        /// </summary>
        /// <param name="channelId">通道的id</param>
        /// <param name="imageByte">图片的二进制数据</param>
        /// <param name="extName">图片扩展名</param>
        /// <param name="customerToken">用户的token</param>
        /// <returns></returns>
        public ResponseBaseDto UpdateChanneImagePathlByChannelId(int channelId,
                                                                 byte[] imageByte, string extName, string customerToken, ref string imagePath)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action   = "更新通道图片";
            oLog.TargetId = channelId;
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Channel;
                    oLog.Remarks    = dto.Message;
                    oLog.Result     = dto.Code;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    //大图(源图)
                    //检查存放源图片的目录是否存在,不存在则创建
                    var bigImagePath = string.Format(@"{0}\channelImage", AppDomain.CurrentDomain.BaseDirectory);
                    Directory.CreateDirectory(bigImagePath);

                    //小图(封面)
                    //检查存放图片的目录是否存在,不存在则创建
                    var smallImagepath = string.Format(@"{0}\channelImage\small", AppDomain.CurrentDomain.BaseDirectory);
                    Directory.CreateDirectory(smallImagepath);

                    //生成随机且唯一的image文件名,将数据保存
                    string imageFile = string.Format("{0}_{1}.{2}",
                                                     PwdMD5.StringToMD5(DateTime.Now.ToString()), channelId, extName);

                    //打开文件,写入图片数据
                    string     bigImageFullPath   = string.Format(@"{0}\{1}", bigImagePath, imageFile);
                    string     smallImageFullPath = string.Format(@"{0}\{1}", smallImagepath, imageFile);
                    FileStream bigfs = new System.IO.FileStream(bigImageFullPath, FileMode.Create, FileAccess.Write);
                    bigfs.Write(imageByte, 0, imageByte.Length);
                    bigfs.Close();

                    #region 将图片进行尺寸的压缩
                    byte[] dstImageByte;
                    ImageConvertibleInfo icInfo = new ImageConvertibleInfo();
                    icInfo.srcByte   = imageByte;
                    icInfo.dstWidth  = 320;     // 目标图片像素宽
                    icInfo.dstHeight = 240;     // 目标图片像素高
                    icInfo.dstFmt    = extName; // 目标图片格式

                    int rs = 0;
                    if ((rs = ImageConvertion.Convert(icInfo, out dstImageByte)) != 0)
                    {
                        myLog.WarnFormat("图片压缩成{0}失败,错误码:{1}", icInfo.dstFmt, rs);
                    }
                    else
                    {
                        imageByte = dstImageByte; // 将压缩后的图片数据重新赋给imageByte
                    }
                    #endregion

                    FileStream smallfs = new System.IO.FileStream(smallImageFullPath, FileMode.Create, FileAccess.Write);
                    smallfs.Write(dstImageByte, 0, imageByte.Length);
                    smallfs.Close();
                    // 通过通道的id找到数据库记录,将文件名更新
                    Channel channel = new Channel()
                    {
                        ChannelId = channelId
                    };
                    IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(channel);

                    if (channelFlag == null)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "需要修改的通道不存在";
                    }
                    else
                    {
                        // 将原来指向的文件名删除。
                        // 如果是默认的文件名则不做删除。
                        if (channelFlag[0].ImagePath != null && !channelFlag[0].ImagePath.Contains("default"))
                        {
                            File.Delete(bigImagePath + "\\" + channelFlag[0].ImagePath);
                            File.Delete(smallImagepath + "\\" + channelFlag[0].ImagePath);
                        }

                        channelFlag[0].ImagePath = imageFile;
                        channelServer.UpdateChannel(channelFlag[0]);
                        dto.Code    = 0;
                        dto.Message = "修改通道图片完成!";
                        // 返回的图片路径是: "channelImage/图片名.jpg"
                        imagePath = string.Format(@"channelImage/{0}", imageFile);
                    }
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("UpdateChanneImagePathlByChannelId方法异常,通道id:{0}", ex, channelId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Channel;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
        /// <summary>
        ///  修改通道名
        /// </summary>
        /// <param name="channel">Channel.ChannelId</param>
        /// <param name="customerToken">token</param>
        /// <returns></returns>
        public ResponseBaseDto UpdateChannelByChannelId(Channel channel, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "修改通道名";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Channel;
                    oLog.Remarks    = dto.Message;
                    oLog.Result     = dto.Code;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "子用户状态无法修改通道名!";
                    return(dto);
                }
                else
                {
                    IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(channel);
                    oLog.TargetId = channel.ChannelId;
                    if (channelFlag == null)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "需要修改的通道不存在!";
                    }
                    else
                    {
                        try
                        {
                            Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                            var seviceAddr = bllHelper.GetServerModelStr();
                            serviceFactory.GetProxy <ICamera>(new Uri(seviceAddr)).Use(
                                p =>
                            {
                                p.UpdateName(channelFlag[0].BPServerChannelId, channel.ChannelName);
                            }
                                );
                        }
                        catch (Exception ex)
                        {
                            dto.Code    = (int)CodeEnum.ApplicationErr;
                            dto.Message = "修改失败,连接服务器超时!";
                            myLog.ErrorFormat("UpdateChannelByChannelId(Adapter服务器端没有做出响应)通道Id:{0},待修改的通道名:{1}", ex, channel.ChannelId, channel.ChannelName);
                            return(dto);
                        }
                        string originalChannelName = channelFlag[0].ChannelName;
                        channelFlag[0].ChannelName = channel.ChannelName;
                        channelServer.UpdateChannel(channelFlag[0]);
                        dto.Code    = 0;
                        dto.Message = "通道名 " + originalChannelName + "修改为 " + channel.ChannelName + " 已完成!";
                    }
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "无法连接服务器,请保证您的网络通畅!";
                myLog.ErrorFormat("UpdateChannelByChannelId方法异常,通道Id:{0},待修改的通道名:{1}", ex, channel.ChannelId, channel.ChannelName);
            }
            oLog.TargetType = (int)OperaterLogEnum.Channel;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
        /// <summary>
        /// 添加收藏
        /// </summary>
        /// <param name="userFavorite">收藏实体对象</param>
        /// <param name="customerToken">token</param>
        /// <param name="userFavoriteId">ref 已完成添加的收藏Id</param>
        /// <returns></returns>
        public ResponseBaseDto AddUserFavorite(UserFavorite userFavorite, string customerToken, ref int userFavoriteId)
        {
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            ResponseBaseDto    dto  = new ResponseBaseDto();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = "用户添加收藏";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token失效";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }

                userFavorite.CustomerId   = tcp.CustomerId;
                userFavorite.FavoriteTime = DateTime.Now;
                switch (userFavorite.UserFavoriteType)
                {
                case 1: oLog.Remarks = "通道,通道Id:"; break;

                case 2: oLog.Remarks = "事件,事件Id:"; break;

                case 3: oLog.Remarks = "视频,视频文件Id:"; break;
                }
                oLog.Remarks += userFavorite.UserFavoriteId;
                //判定添加收藏是否已经存在
                IList <UserFavorite> userFavoriteFlag = userFavoriteServer.SelectCustomerByTid(userFavorite);
                if (userFavoriteFlag != null && userFavoriteFlag.Count > 0)
                {
                    dto.Code    = (int)CodeEnum.ExistFavorite;
                    dto.Message = "收藏已经存在!";
                    return(dto);
                }
                //添加用户收藏
                userFavoriteId = userFavoriteServer.InsertUserFavorite(userFavorite);
                if (userFavoriteId > 0)
                {
                    dto.Code      = (int)CodeEnum.Success;
                    dto.Message   = "已加入收藏!";
                    oLog.Remarks += dto.Message;
                }
                else
                {
                    dto.Code      = (int)CodeEnum.ApplicationErr;
                    dto.Message   = "加入收藏失败!";
                    oLog.Remarks += dto.Message;
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常!,加入收藏失败!";
                myLog.ErrorFormat("AddUserFavorite方法异常,用户:{0},UserFavoriteType:{1},UserFavoriteTypeId:{2}",
                                  ex, userFavorite.CustomerId, userFavorite.UserFavoriteType, userFavorite.UserFavoriteTypeId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Favorite;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            return(dto);
        }
Exemple #18
0
        /// <summary>
        /// 查询用户分组
        /// </summary>
        /// <param name="customer">customerid</param>
        /// <param name="customerToken">token</param>
        /// <param name="ResourceGroup">返回数据 分组</param>
        /// <returns></returns>
        public ResponseBaseDto GetGroupByCustomerId(string customerToken, ref IList <ResourceGroupResponse> resourceGroupResponse)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        return(dto);
                    }
                    else
                    {
                        Customer customer = new Customer();
                        customer.CustomerId = tcp.CustomerId;
                        int primaryCustomerId = tcp.CustomerId;
                        IList <ResourceGroup> resourceGroup = new List <ResourceGroup>();
                        bool             isPrimaryCustomer  = true;// 主用户 is true
                        IList <Customer> customerFlag       = customerServer.SelectCustomerByCustomerId(customer);
                        if (customerFlag[0].ParentId != 0 && customerFlag[0].SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                        {
                            //子账户将查询主用户的分组信息
                            primaryCustomerId = customerFlag[0].ParentId;
                            isPrimaryCustomer = false;
                        }
                        //子用户起来后添加权限逻辑
                        var allResourceGroup = resourceGroupServer.SelectResourceGorupByCustomerId(primaryCustomerId);
                        // 主账号直接返回
                        if (isPrimaryCustomer == true)
                        {
                            resourceGroup = allResourceGroup;
                        }
                        else
                        {
                            // 子账号要过滤掉没有镜头的空分组
                            IList <ResourceGroup> validResourceGroup = resourceGroupServer.GetResourceGroupBySubCustomerId(tcp.CustomerId, primaryCustomerId);
                            // 返回的resourceGroup个数至少是validResourceGroup,
                            // 所以先复制出来
                            foreach (var it in validResourceGroup)
                            {
                                resourceGroup.Add(it);
                            }
                            // 遍历validResourceGroup, 把其节点中,父节点不在resourceGroup内的,加进去。
                            foreach (var it in validResourceGroup)
                            {
                                CheckAndCopy(allResourceGroup, ref resourceGroup, it);
                            }
                        }
                        //加载分组是否有下一级
                        for (int i = 0; i < resourceGroup.Count; i++)
                        {
                            var result = from rs in resourceGroup
                                         where resourceGroup[i].ResourceGroupId == rs.ParentResourceGroupId
                                         select rs;
                            ResourceGroupResponse rg = new ResourceGroupResponse();
                            if (result.Count() != 0)
                            {
                                rg.IsNext = 1;
                            }
                            rg.CustomerId            = resourceGroup[i].CustomerId;
                            rg.ResourceGroupId       = resourceGroup[i].ResourceGroupId;
                            rg.ResourceGroupName     = resourceGroup[i].ResourceGroupName;
                            rg.ParentResourceGroupId = resourceGroup[i].ParentResourceGroupId;
                            resourceGroupResponse.Add(rg);
                        }
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "分组数据获取完成";
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetGroupByCustomerId方法异常,用户Id:{0}", ex, tcp.CustomerId);
                }
            }
            return(dto);
        }
Exemple #19
0
        /// <summary>
        ///  获取设备状态
        /// </summary>
        /// <param name="deviceIdList">Device.DeviceId</param>
        /// <param name="deviceResponseFlag">ref 集合对象</param>
        /// <returns></returns>
        public ResponseBaseDto GetServerDeviceState(int[] deviceIdList, string customerToken, ref List <DeviceResponse> deviceResponseFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效";
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    IList <DeviceTokenDto> deviceTokenDtoFlag = new List <DeviceTokenDto>();
                    for (int i = 0; i < deviceIdList.Length; i++)
                    {
                        //缓存里是否有这个设备
                        DeviceResponse deviceResponse = deviceCache.FindByDeviceKey(GetDeivceKey(deviceIdList[i]));
                        if (deviceResponse != null)
                        {
                            deviceResponseFlag.Add(deviceResponse);
                        }
                        else
                        {
                            DeviceTokenDto deviceTokenDto = new DeviceTokenDto();
                            //服务器的设备ID
                            IList <Device> dFlag =
                                deviceServer.SelectDeviceByDeviceId(new Device()
                            {
                                DeviceId = deviceIdList[i]
                            });
                            if (dFlag != null && dFlag.Count != 0)
                            {
                                deviceTokenDto.ID = dFlag[0].BPServerDeviceId;
                                deviceTokenDtoFlag.Add(deviceTokenDto);
                            }
                        }
                    }
                    try
                    {
                        Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                        string seviceAddr = bllHelper.GetServerModelStr();
                        IDictionary <int, DeviceStateDto> deviceState = null;
                        serviceFactory.GetProxy <IDevice>(new Uri(seviceAddr)).Use(
                            p =>
                        {
                            deviceState = p.RefreshDevices(deviceTokenDtoFlag);
                        }
                            );
                        for (int i = 0; i < deviceTokenDtoFlag.Count; i++)
                        {
                            DeviceStateDto dsDto        = deviceState[(deviceTokenDtoFlag[i].ID)];
                            IList <Device> dbDeviceFlag =
                                deviceServer.SelectDeviceByBPServerDeviceId(new Device()
                            {
                                BPServerDeviceId = deviceTokenDtoFlag[i].ID
                            });
                            if (dbDeviceFlag != null && dbDeviceFlag.Count == 1)
                            {
                                Device         device         = dbDeviceFlag[i];
                                DeviceResponse deviceResponse = new DeviceResponse();
                                deviceResponse.DeviceId = device.DeviceId;
                                if (dsDto.IsOnline == true)
                                {
                                    deviceResponse.BPServerDeviceState = 1;
                                }
                                else
                                {
                                    deviceResponse.BPServerDeviceState = 0;
                                }
                                //数据放入缓存
                                DateTime dt = DateTime.Now.AddSeconds(300);//失效时间定义为5分钟
                                deviceCache.AddDeviceCache(GetDeivceKey(dbDeviceFlag[0].DeviceId), deviceResponse, dt);
                                deviceResponseFlag.Add(deviceResponse);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        dto.Code    = (int)CodeEnum.ApplicationErr;
                        dto.Message = "服务未开启";
                        myLog.WarnFormat("GetServerGetDeviceState方法异常,BP4Server服务未开启!", ex);
                    }

                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "设备状态已获取完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetServerGetDeviceState方法异常,设备Id{0}", ex, deviceIdList.ToString());
            }
            return(dto);
        }
Exemple #20
0
        /// <summary>
        /// 检索设备以设备名称和SN码 模糊查询 SearchDevice
        /// </summary>
        /// <param name="keyWord">关键字</param>
        /// <param name="customerToken">Token</param>
        /// <param name="deviceFlag">ref 设备结果集</param>
        /// <returns></returns>
        public ResponseBaseDto SearchDevice(string keyWord, string customerToken,
                                            ref IList <Device> deviceFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.TokenTimeOut;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    //针对用户下的设备进行查询不以用户查询
                    Customer customer = new Customer();
                    customer.CustomerId = tcp.CustomerId;
                    deviceFlag          = deviceServer.SelectDeviceCustomerId(customer);

                    //查询出权限表中可以使用的设备Id
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    //当前用户下所有可以使用的设备
                    for (int i = 0; i < permissionFlag.Count; i++)
                    {
                        Permission permission = permissionFlag[0];
                        if (permission.NodeType == (int)PermissionNodeTypeEnum.Device && permission.IsEnable == 1)
                        {
                            Device device = new Device();
                            device.DeviceId = permission.NodeId;
                            IList <Device> otherDeviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                            if (otherDeviceFlag != null && otherDeviceFlag.Count == 1)
                            {
                                deviceFlag.Add(otherDeviceFlag[0]);
                            }
                        }
                    }
                    List <int> deviceIdList = new List <int>();
                    for (int j = 0; j < deviceFlag.Count; j++)
                    {
                        deviceIdList.Add(deviceFlag[j].DeviceId);
                    }
                    if (keyWord == null)
                    {
                        keyWord = string.Empty;
                    }

                    deviceFlag  = deviceServer.SelectDeviceSerialNumber(keyWord, deviceIdList);
                    dto.Message = "设备已查找完成";
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("SearchDevice方法异常,查找关键字:{0}", ex, keyWord);
            }
            return(dto);
        }
Exemple #21
0
        /// <summary>
        /// 为各客户端提供播放流需要的相关信息 GetStreamerParameterByCustomerToken
        /// </summary>
        /// <param name="channel">channel.ChannelId</param>
        /// <param name="customerToken">Token</param>
        /// <param name="streamerParmeter">ref 流媒体播放参数</param>
        /// <returns></returns>
        public ResponseBaseDto GetStreamerParameterByCustomerToken(Channel channel, string customerToken, ref BP4StreamerParameter streamerParmeter)
        {
            ResponseBaseDto dto = new ResponseBaseDto();

            try
            {
                UserTokenCache utc = UserTokenCache.GetInstance();
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                }
                else
                {
                    /*  channel.ChannelId 通道Id
                     *  channel.DeviceId 设备Id
                     *  bpServerConfig.BPServerConfigId 设备调用时需要的源
                     *  3个参数不可缺少
                     */
                    if (channel == null)
                    {
                        dto.Code    = (int)CodeEnum.NoComplete;
                        dto.Message = "提交数据不完整";
                        return(dto);
                    }
                    IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(channel);
                    if (channelFlag == null || channelFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "未找到需要的通道";
                        return(dto);
                    }
                    Device device = new Device();
                    device.DeviceId = channelFlag[0].DeviceId;
                    IList <Device> deviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                    if (deviceFlag == null || deviceFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "未找到需要的设备";
                        return(dto);
                    }
                    BPServerConfig bpServerConfig = new BPServerConfig();
                    bpServerConfig.BPServerConfigId = deviceFlag[0].BPServerConfigId;
                    IList <BPServerConfig> bpServerConfigFlag = bpServerConfigServer.GetBPServerConfigByKey(bpServerConfig);
                    if (bpServerConfigFlag == null || bpServerConfigFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "没有找到需要请求流媒体的服务端";
                        return(dto);
                    }
                    //进行必须的流媒体配置
                    streamerParmeter.LoginModel             = new BP4DeviceLoginModel();
                    streamerParmeter.RealStreamModel        = new BP4RealStreamModel();
                    streamerParmeter.CustomerToken          = customerToken;
                    streamerParmeter.LoginModel.Address     = deviceFlag[0].SerialNumber;//设备的SN码 IP不可使用
                    streamerParmeter.LoginModel.AddressType = 5;
                    streamerParmeter.PlayerType             = 2;
                    if (deviceFlag[0].UserName != null && deviceFlag[0].UserName != "")
                    {
                        streamerParmeter.LoginModel.UserName = deviceFlag[0].UserName;
                    }
                    if (deviceFlag[0].PassWord != null && deviceFlag[0].PassWord != "")
                    {
                        streamerParmeter.LoginModel.Password = MDKey.Encrypt(deviceFlag[0].PassWord);
                    }
                    streamerParmeter.RealStreamModel.Channel   = channelFlag[0].ChannelNumber; //该通道所属设备的插槽号
                    streamerParmeter.RealStreamModel.ChannelId = channel.ChannelId;            //本地的通道Id

                    if (bpServerConfigFlag[0].StreamerPublicAddress.IndexOf(":") != -1)
                    {
                        string[] streamerAddress = bpServerConfigFlag[0].StreamerPublicAddress.Split(':');
                        streamerParmeter.RestServIp   = streamerAddress[0];
                        streamerParmeter.RestServPort = Convert.ToInt32(streamerAddress[1]);
                    }
                    streamerParmeter.RealStreamModel.SubStream = 0;
                    streamerParmeter.RealStreamModel.TransProc = 0;
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "流媒体参数已准备完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetStreamerParameterByCustomerToken方法异常,通道Id:{0}", ex, channel.ChannelId);
            }
            return(dto);
        }
Exemple #22
0
        /// <summary>
        ///  更新分组名称 UpdateResourceGorupByName
        /// </summary>
        /// <param name="resourceGroup">ResourceGroupId, 需要修改的节点名称</param>
        /// <param name="customerToken"></param>
        /// <returns></returns>
        public ResponseBaseDto UpdateResourceGorupByName(ResourceGroup resourceGroup, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = "更新分组名称";
            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        oLog.Remarks = dto.Message;
                        oLog.Result  = dto.Code;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    if (resourceGroup.ResourceGroupId == 0 && resourceGroup.ResourceGroupName == null)
                    {
                        dto.Code     = (int)CodeEnum.NoComplete;
                        dto.Message  = "数据请求不完整";
                        oLog.Remarks = dto.Message;
                        oLog.Result  = dto.Code;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    else
                    {
                        IList <ResourceGroup> resourceGroupFlag =
                            resourceGroupServer.SelectResourceGorupByResourceGroupId(resourceGroup);
                        if (resourceGroupFlag != null && resourceGroupFlag.Count != 0)
                        {
                            ResourceGroup rg = resourceGroupFlag[0];
                            rg.ResourceGroupId   = resourceGroup.ResourceGroupId;
                            rg.ResourceGroupName = resourceGroup.ResourceGroupName;
                            resourceGroupServer.UpdateResourceGorupByName(rg);
                            dto.Code     = (int)CodeEnum.Success;
                            dto.Message  = "分组名称更新完成!";
                            oLog.Remarks = "已将分组名为:" + rg.ResourceGroupName + "修改为:" + resourceGroup.ResourceGroupName;
                        }
                        else
                        {
                            dto.Code    = (int)CodeEnum.NoData;
                            dto.Message = "用户数据不存在!";
                        }
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,更新分组名称失败!";
                    myLog.ErrorFormat("UpdateResourceGorupByName方法异常,用户Id:{0},分组id:{1},分组名:{2}", ex, tcp.CustomerId, resourceGroup.ResourceGroupId, resourceGroup.ResourceGroupName);
                }
            }
            if (oLog.Remarks == null || oLog.Remarks == "")
            {
                oLog.Remarks = dto.Message;
            }
            oLog.TargetType = (int)OperaterLogEnum.ResourceGroup;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #23
0
        //------------------------------------------------------
        #region 移动分组下所有通道 UpdateChannelListByResourceGroupId Date:2014/12/15
        /// <summary>
        /// 移动分组下的所有通道 UpdateChannelListByResourceGroupId
        /// Date:2014/12/15
        /// </summary>
        /// <param name="resourceGroup">ResourceGroupId</param>
        /// <param name="channelIdList">通道数组</param>
        /// <param name="customerToken">token</param>
        /// <returns></returns>
        public ResponseBaseDto UpdateChannelListByResourceGroupId(ResourceGroup resourceGroup, int[] channelIdList, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            TokenCacheProperty tcp  = new TokenCacheProperty();
            OperaterLog        oLog = new OperaterLog();

            oLog.Action = "移动分组下通道";
            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        oLog.Remarks = dto.Message;
                        oLog.Result  = dto.Code;
                        bllHelper.AddOperaterLog(oLog, tcp);
                        return(dto);
                    }
                    //查找关联其他通道信息
                    string channelNameListStr = "";
                    string channelMoveErrName = "";
                    for (int i = 0; i < channelIdList.Length; i++)
                    {
                        GroupChannel groupChannel = new GroupChannel();
                        groupChannel.CustomerId = tcp.CustomerId;
                        groupChannel.channel    = new Channel()
                        {
                            ChannelId = channelIdList[i]
                        };
                        groupChannel.resourceGroup = new ResourceGroup {
                            ResourceGroupId = resourceGroup.ResourceGroupId
                        };
                        IList <GroupChannel> groupChannelFlag = groupChannelServer.SelectGroupChannelByChannelIdAndCustomerId(groupChannel);
                        channelNameListStr += "[" + groupChannel.channel.ChannelName + "] ";
                        channelNameListStr += channelIdList[i] + "]";
                        if (groupChannelFlag != null && groupChannelFlag.Count != 0)
                        {
                            groupChannelFlag[0].resourceGroup.ResourceGroupId =
                                groupChannel.resourceGroup.ResourceGroupId;
                            groupChannelServer.UpdateGroupChannel(groupChannelFlag[0]);
                        }
                        else
                        {
                            try
                            {
                                groupChannelServer.InertGroupChannel(groupChannel);
                            }
                            catch
                            {
                                channelMoveErrName += "[" + groupChannel.channel.ChannelName + "]";
                            }
                            dto.Code    = (int)CodeEnum.Success;
                            dto.Message = "已完成通道移动!" + channelMoveErrName + "通道已有过分组";
                        }
                    }
                    IList <ResourceGroup> resourceGroupFlag = resourceGroupServer.SelectResourceGorupByResourceGroupId(resourceGroup);
                    if (resourceGroupFlag != null && resourceGroupFlag.Count != 0 &&
                        channelNameListStr.Length > 0)
                    {
                        channelNameListStr = channelNameListStr.Substring(0, channelNameListStr.Length - 1);
                        dto.Message        = "已将通道" + channelNameListStr + "移动至分组" + resourceGroupFlag[0].ResourceGroupName;
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,通道移动失败";
                    myLog.ErrorFormat("UpdateChannelListByResourceGroupId方法异常,分组id:{0},通道id集合:{1}", ex, resourceGroup.ResourceGroupId, channelIdList.ToString());
                }
            }
            oLog.TargetType = (int)OperaterLogEnum.ResourceGroup;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
        /// <summary>
        /// 通道分页
        /// </summary>
        /// <param name="startCount">从那一条数据开始</param>
        /// <param name="requestCount">需要多少条</param>
        /// <param name="customerToken"></param>
        /// <param name="Total">返回总数据数</param>
        /// <param name="channelFlag">返回通道</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByPage(int startCount, int requestCount,
                                                string keyWord, string customerToken,
                                                ref IList <GroupChannelResponse> groupChannelResponseFlag, ref int Total)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    //查询当前用户下的设备
                    Customer customer = new Customer();
                    customer.CustomerId = tcp.CustomerId;
                    int primaryCustomerId = tcp.CustomerId;
                    int subCustomerId     = tcp.CustomerId;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        primaryCustomerId   = tcp.ParentId;
                        customer.CustomerId = tcp.ParentId;
                    }

                    IList <Device> deviceFlag = deviceServer.SelectDeviceCustomerId(customer);
                    //查询出权限表中可以使用的设备Id
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    //当前用户下所有可以使用的设备
                    for (int i = 0; i < permissionFlag.Count; i++)
                    {
                        Permission permission = permissionFlag[i];
                        if (permission.NodeType == (int)PermissionNodeTypeEnum.Device && permission.IsEnable == 1)
                        {
                            Device device = new Device();
                            device.DeviceId = permission.NodeId;
                            IList <Device> otherDeviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                            if (otherDeviceFlag != null && otherDeviceFlag.Count == 1)
                            {
                                deviceFlag.Add(otherDeviceFlag[0]);
                            }
                        }
                    }
                    string     deviceIdListStr = "";
                    List <int> deviceIdList    = new List <int>();
                    for (int j = 0; j < deviceFlag.Count; j++)
                    {
                        if (j != deviceFlag.Count - 1)
                        {
                            deviceIdListStr += deviceFlag[j].DeviceId + ",";
                        }
                        else
                        {
                            deviceIdListStr += deviceFlag[j].DeviceId.ToString();
                        }
                        deviceIdList.Add(deviceFlag[j].DeviceId);
                    }
                    startCount -= 1;
                    startCount  = startCount < 0 ? 0 : startCount;

                    IList <Channel> channelFlag = null;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        //子用户登陆权限
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            channelFlag = channelServer.SelectSubChannelByDeviceIdListPage(subCustomerId, deviceIdListStr, startCount, requestCount, keyWord);
                            Total       = channelServer.SelectSubChannelByDeviceIdListPageCount(subCustomerId, deviceIdListStr, keyWord);
                        }
                    }
                    else if (tcp.SignInType == (int)CustomerSignInTypeEnum.PrimaryCustomer)
                    {
                        //主用户登陆后数据
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            channelFlag = channelServer.SelectChannelByDeviceIdListPage(deviceIdListStr, startCount, requestCount, keyWord);
                            Total       = channelServer.SelectChannelByDeviceIdListPageCount(deviceIdListStr, keyWord);
                        }
                    }

                    //填充 需要的 授权字段
                    groupChannelResponseFlag = ConvertGroupChannelResponse(tcp, primaryCustomerId, channelFlag);
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道数据获取完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("GetChannelByPage方法异常,用户id:{0},起始条数:{1},请求条数:{2},关键字:{3}",
                                 ex, tcp.CustomerId, startCount, requestCount, keyWord);
            }
            return(dto);
        }
Exemple #25
0
        /// <summary>
        /// 查询分组下(包括子分组)的所有通道 分页 GetChannelByPageOrResourceGroupId
        /// </summary>
        /// <param name="resourceGroup"></param>
        /// <param name="customerToken"></param>
        /// <param name="groupChannel"></param>
        /// <param name="Total"></param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByPageOrResourceGroupId
            (ResourceGroup resourceGroup, int startCount, int requestCount, string keyWord,
            string customerToken, ref IList <GroupChannelResponse> groupChannelResponseFlag, ref int total)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        return(dto);
                    }
                    //查询当前用户的分组
                    List <int>            resourceGroupIdFlag = new List <int>();
                    IList <ResourceGroup> allResourceList     = new List <ResourceGroup>();
                    bool   isSubCustomer     = false;
                    int    primaryCustomerId = 0;
                    string deviceIdListStr   = "";
                    startCount -= 1;
                    startCount  = startCount < 0 ? 0 : startCount;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        isSubCustomer     = true;
                        primaryCustomerId = tcp.ParentId;
                    }
                    else
                    {
                        isSubCustomer     = false;
                        primaryCustomerId = tcp.CustomerId;
                    }
                    //查找是否有授权的设备
                    Customer primaryCustomer = new Customer()
                    {
                        CustomerId = primaryCustomerId
                    };
                    IList <Device> primaryDeviceFlag =
                        deviceServer.SelectDeviceCustomerId(primaryCustomer);
                    //查询出权限表中可以使用的设备Id
                    IList <Permission> primaryPermissionFlag = permissionServer.SelectPermissionByCustomerId(primaryCustomer);
                    //当前用户下所有可以使用的设备
                    for (int i = 0; i < primaryPermissionFlag.Count; i++)
                    {
                        Permission permission = primaryPermissionFlag[0];
                        if (permission.NodeType == (int)PermissionNodeTypeEnum.Device && permission.IsEnable == 1)
                        {
                            Device device = new Device();
                            device.DeviceId = permission.NodeId;
                            IList <Device> otherDeviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                            if (otherDeviceFlag != null && otherDeviceFlag.Count == 1)
                            {
                                primaryDeviceFlag.Add(otherDeviceFlag[0]);
                            }
                        }
                    }
                    //将设备集合对象中的设备ID修改为 21,22,33
                    for (int j = 0; j < primaryDeviceFlag.Count; j++)
                    {
                        if (j != primaryDeviceFlag.Count - 1)
                        {
                            deviceIdListStr += primaryDeviceFlag[j].DeviceId + ",";
                        }
                        else
                        {
                            deviceIdListStr += primaryDeviceFlag[j].DeviceId.ToString();
                        }
                    }
                    //如果用户的分组为0(isGroup=1,ResourceGroupId=0),将查询未分组的通道
                    if (resourceGroup != null && resourceGroup.ResourceGroupId == 0 &&
                        deviceIdListStr != string.Empty && deviceIdListStr != "")
                    {
                        IList <Channel> channelFlag = new List <Channel>();
                        GetChannelByNoGroup(primaryCustomerId, deviceIdListStr, isSubCustomer,
                                            startCount, requestCount, keyWord, ref channelFlag, ref total);
                        groupChannelResponseFlag =
                            channelBLL.ConvertGroupChannelResponse(tcp, primaryCustomerId, channelFlag);
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "通道获取完成!";
                        return(dto);
                    }

                    GetchildResourceGroup(resourceGroup, ref allResourceList);
                    allResourceList.Add(resourceGroup);
                    for (int i = 0; i < allResourceList.Count; i++)
                    {
                        resourceGroupIdFlag.Add(allResourceList[i].ResourceGroupId);
                    }
                    string resourceGroupIdListStr = string.Empty;
                    for (int j = 0; j < resourceGroupIdFlag.Count; j++)
                    {
                        if (j != resourceGroupIdFlag.Count - 1)
                        {
                            resourceGroupIdListStr += resourceGroupIdFlag[j] + ",";
                        }
                        else
                        {
                            resourceGroupIdListStr += resourceGroupIdFlag[j].ToString();
                        }
                    }
                    IList result = null;
                    if (isSubCustomer)
                    {
                        //子用户有权限
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            result = groupChannelServer.SelectSubChannelByPageOrResourceGroupId
                                         (tcp.CustomerId, startCount, requestCount, keyWord, resourceGroupIdListStr);
                            total = groupChannelServer.SelectSubChannelByPageOrResourceGroupIdCount(tcp.CustomerId, keyWord, resourceGroupIdListStr);
                        }
                    }
                    else
                    {
                        //检索关键字,当前用户可用的组集合,当前可用设备的集合
                        //返回 List<object[]>输出时需装箱
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            result = groupChannelServer.SelectChannelByPageOrResourceGroupId
                                         (startCount, requestCount, keyWord, deviceIdListStr, resourceGroupIdListStr);
                            total = groupChannelServer.SelectChannelByPageOrResourceGroupIdCount(keyWord, deviceIdListStr, resourceGroupIdListStr);
                        }
                    }
                    //通道数据装箱
                    if (result != null)
                    {
                        for (int i = 0; i < result.Count; i++)
                        {
                            object[]             data = (object[])result[i];
                            GroupChannelResponse gcr  = new GroupChannelResponse();
                            gcr.ChannelId       = (int)data[0];
                            gcr.ResourceGroupId = (int)data[1];
                            gcr.ChannelName     = (string)data[2];
                            gcr.ChannelNumber   = (int)data[3];
                            gcr.DeviceId        = (int)data[4];
                            gcr.IsEnable        = (int)data[5];
                            gcr.ImagePath       = (string)data[6];
                            groupChannelResponseFlag.Add(gcr);
                        }
                    }
                    //填充 需要的 授权字段
                    groupChannelResponseFlag = ConvertGroupChannelResponse(primaryCustomerId, groupChannelResponseFlag);
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道获取完成!";
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetChannelByPageOrResourceGroupId方法异常, 组id:{0}, 起始值:{1},请求数量:{2}, 关键字:{3}",
                                     ex, resourceGroup.ResourceGroupId, startCount, requestCount, keyWord);
                }
            }
            return(dto);
        }
        /// <summary>
        /// 查询单一通道信息 GetSingleChannel
        /// </summary>
        /// <param name="customerToken">token</param>
        /// <param name="channel">通道信息</param>
        /// <returns></returns>
        public ResponseBaseDto GetSingleChannel(int channelId, string customerToken, ref GroupChannelResponse groupChannelResponse)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    int             primaryCustomerId = 0;
                    IList <Channel> channelFlag       = channelServer.SelectChannelByChannelId(new Channel()
                    {
                        ChannelId = channelId
                    });
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        IList <Permission> permissionFlag = permissionServer.SelectPermissionByCidAndNid(
                            new Customer()
                        {
                            CustomerId = tcp.CustomerId
                        },
                            new Permission()
                        {
                            NodeType = (int)PermissionNodeTypeEnum.Channel, NodeId = channelId
                        });
                        if (permissionFlag == null || permissionFlag.Count == 0)
                        {
                            dto.Code    = (int)CodeEnum.NoAuthorization;
                            dto.Message = "您当前账户里没有此观看权限!";
                            return(dto);
                        }
                        primaryCustomerId = tcp.ParentId;
                    }
                    else if (tcp.SignInType == (int)CustomerSignInTypeEnum.PrimaryCustomer)
                    {
                        if (channelFlag == null || channelFlag.Count == 0)
                        {
                            dto.Code    = (int)CodeEnum.NoAuthorization;
                            dto.Message = "您当前账户里没有此观看权限!";
                            return(dto);
                        }
                        IList <Device> deviceFlag = deviceServer.SelectDeviceByDeviceId(new Device()
                        {
                            DeviceId = channelFlag[0].DeviceId
                        });
                        if (deviceFlag == null || deviceFlag.Count == 0 || deviceFlag[0].CustomerId != tcp.CustomerId)
                        {
                            dto.Code    = (int)CodeEnum.NoAuthorization;
                            dto.Message = "您当前账户里没有此观看权限!";
                            return(dto);
                        }
                        primaryCustomerId = tcp.CustomerId;
                    }
                    if (channelFlag != null && channelFlag.Count == 1)
                    {
                        var result = ConvertGroupChannelResponse(tcp, primaryCustomerId, channelFlag);
                        if (result != null && result.Count == 1)
                        {
                            groupChannelResponse = result[0];
                        }
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道数据获取完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("GetSingleChannel方法异常,通道Id:{0}", ex, channelId);
            }
            return(dto);
        }
Exemple #27
0
        /// <summary>
        ///  查询分组下所有通道(包括子分组下) GetChannelByResourceGroupIdList Date:2014/12/15
        /// </summary>
        /// <param name="resourceGroup">组节点Id</param>
        /// <param name="customerToken">token</param>
        /// <param name="resourceGroupChannel">返回数据  通道关系集合</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByResourceGroupIdList
            (ResourceGroup resourceGroup, string customerToken, ref IList <GroupChannel> groupChannel)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        return(dto);
                    }
                    //以List<ResourceGroupId>查询
                    List <int>            resourceGroupIdFlag = new List <int>();
                    IList <ResourceGroup> allResourceList     = new List <ResourceGroup>();
                    GetchildResourceGroup(resourceGroup, ref allResourceList);
                    allResourceList.Add(resourceGroup);
                    for (int i = 0; i < allResourceList.Count; i++)
                    {
                        resourceGroupIdFlag.Add(allResourceList[i].ResourceGroupId);
                    }
                    groupChannel = groupChannelServer.SelectGroupChannelByResourceGroupIdList(resourceGroupIdFlag);

                    //权限
                    Customer customer = new Customer();
                    customer.CustomerId = tcp.CustomerId;
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    for (int n = 0; n < permissionFlag.Count; n++)
                    {
                        for (int m = 0; m < groupChannel.Count; m++)
                        {
                            //判定此用户里这个通道的IsEnable
                            if (permissionFlag[n].NodeType == (int)PermissionNodeTypeEnum.Channel &&
                                permissionFlag[n].NodeId == groupChannel[m].channel.ChannelId)
                            {
                                //1表示可以使用, 0表示不可以被使用
                                if (permissionFlag[n].IsEnable == 0)
                                {
                                    groupChannel.RemoveAt(m);
                                }
                            }
                        }
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道获取完成";
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetChannelByResourceGroupIdList方法异常,分组id:{0}", ex, resourceGroup.ResourceGroupId);
                }
            }
            return(dto);
        }
        /// <summary>
        /// 设置通道码流
        /// </summary>
        /// <param name="channelId">通道id</param>
        /// <param name="streamType">码流类型</param>
        /// <param name="customerToken">用户token</param>
        /// <returns></returns>
        public ResponseBaseDto UpdateChannelEncoderInfo(int channelId, int streamType, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "设置通道码流";
            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Channel;
                    oLog.Remarks    = dto.Message;
                    oLog.Result     = dto.Code;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(new Channel()
                    {
                        ChannelId = channelId
                    });
                    oLog.TargetId = channelId;
                    if (channelFlag == null)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "需要修改的通道不存在";
                    }
                    else if (streamType == 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "未选中码流类型";
                    }
                    else
                    {
                        try
                        {
                            //获取已预制的码流配置
                            IDictionary <int, AVEncoderInfoDto> avEncoderInfoList = GetXMLChannelEncoderList();
                            AVEncoderInfoDto enCoderInfo = avEncoderInfoList[streamType];
                            //调用BP4Server 设置码流
                            Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                            var seviceAddr = bllHelper.GetServerModelStr();
                            serviceFactory.GetProxy <ICamera>(new Uri(seviceAddr)).Use(
                                p =>
                            {
                                if (streamType == 1)
                                {
                                    //主码流
                                    p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1), enCoderInfo);
                                }
                                else if (streamType == 2 || streamType == 3)
                                {
                                    //选择码流类型(streamType)在BP4Server中 2和3都属于子码流
                                    p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1 << 1), enCoderInfo);
                                }
                                else
                                {
                                    //第3码流
                                    p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1 << 2), enCoderInfo);
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            dto.Code    = (int)CodeEnum.ApplicationErr;
                            dto.Message = "通道所属设备已离线!离线状态无法修改通道码流";
                            myLog.ErrorFormat("UpdateChannelEncoderInfo(BP4Server设备已离线)通道Id:{0}", ex, channelId);
                            return(dto);
                        }
                    }
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("UpdateChannelEncoderInfo方法异常,用户Id:{0},通道Id:{1}", ex, tcp.CustomerId, channelId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Channel;
            oLog.Remarks    = dto.Message;
            oLog.Result     = dto.Code;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }
Exemple #29
0
        /// <summary>
        ///  删除个设备(慎用)
        /// </summary>
        /// <param name="customer">customerId</param>
        /// <param name="DeviceId">设备本地数据库Id</param>
        /// <param name="customerToken"></param>
        /// <returns></returns>
        public ResponseBaseDto DeleteDeviceByDeviceId(Device device, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "删除设备";
            try
            {
                //获取 判定token
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "Token已失效 ";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Device;
                    oLog.Result     = dto.Code;
                    oLog.Remarks    = dto.Message;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    //查询本地的deviceId
                    IList <Device> deviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                    if (deviceFlag == null || deviceFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "删除时没有检索到需要的设备";
                    }
                    else if (deviceFlag[0].CustomerId != tcp.CustomerId)
                    {
                        dto.Code    = (int)CodeEnum.NoAuthorization;
                        dto.Message = "删除时用户没有拥有对此设备权限";
                    }
                    else
                    {
                        oLog.TargetId = deviceFlag[0].DeviceId;
                        bool bFlag = ClearDevice(deviceFlag[0]);
                        if (bFlag)
                        {
                            dto.Code    = (int)CodeEnum.Success;
                            dto.Message = "用户删除设备 " + deviceFlag[0].DeviceName + " 完成!";
                        }
                        else //if(bFlag==false)
                        {
                            dto.Code    = (int)CodeEnum.ServerNoToken;
                            dto.Message = "删除设备设备失败!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后操作";
                myLog.ErrorFormat("DeleteDeviceByDeviceId方法异常, 设备id:{0}", ex, device.DeviceId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Device;
            oLog.Result     = dto.Code;
            oLog.Remarks    = dto.Message;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }