protected GroupDevice CoAsynGetGroup(string detail)
        {
            GroupDevice newUncompletGroup = new GroupDevice(this);

            _asynGetGroupRunner.EnqueueMessage(new KeyValuePair <string, GroupDevice>(detail, newUncompletGroup));
            return(newUncompletGroup);
        }
Ejemplo n.º 2
0
 public GroupDetailViewModel(INavigation nav, GroupDevice item = null)
 {
     m_navigation       = nav;
     Title              = BuildBreadCrumb(nav, item.Owner);
     Item               = item;
     Items              = new ObservableRangeCollection <Model.Device>(item.Devices.OrderByDescending(x => x.TotalUsage).Select(x => x).ToList());
     GoToDetailsCommand = new Command <string>(ExecuteGoToDetailsCommand);
 }
Ejemplo n.º 3
0
 public RadioPackage(GroupDevice targetGroup,
                     string radioName,
                     Dictionary <string, byte[]> _attrDefaultValues)
     : base("RadioPackage", _attrDefaultValues)
 {
     _targetGroup = targetGroup;
     _radioName   = radioName;
 }
        internal GroupDevice GetGroup(string detail)
        {
            //配置请求包
            ServerRequestPackage    reqtPkg       = new ServerRequestPackage(true);
            IOnlineGroupListRequest reqtInterface = reqtPkg.Active_OnlineGroupListRequest();

            reqtInterface.OnlineGroupRequest();

            BinTransferLayer   binprocessor = _mclLayerProcessor.BinTransferProcessor;
            ServerReplyPackage replyPkg     = null;

            try
            {
                replyPkg = binprocessor.SynSendMessage(reqtPkg, 100000);
            }
            catch (Exception ex)
            {
                throw new GetOnlineGroupExcetion(ex.ToString());
            }
            IOnlineGroupReply replyInterface = replyPkg.Active_OnlineGroupReply();
            bool   ret;
            string errorDetail;
            List <CSCommunicateClass.GroupInfo> onlineGroupInfo;

            replyInterface.OnlineGroupRet(out ret, out errorDetail, out onlineGroupInfo);
            if (true == ret)
            {
                foreach (CSCommunicateClass.GroupInfo item in onlineGroupInfo)
                {
                    if (item.Detail.Equals(detail))
                    {
                        GroupDevice gropInst = new GroupDevice(_mclLayerProcessor);
                        GroupDevice.Parse(item, gropInst);

                        try
                        {
                            //check join statucs
                            List <CSCommunicateClass.ClientInfo> clients = null;
                            GetGroupMembers(gropInst, out clients);
                            if ((null != clients) && (0 < clients.Count))
                            {
                                gropInst.Joined = true;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            //nothing to do
                        }
                        return(gropInst);
                    }
                }
                throw new GetOnlineGroupExcetion("不存在指定名称的群组");
            }
            else
            {
                throw new GetOnlineGroupExcetion(errorDetail);
            }
        }
        protected GroupDevice CoAsynCreateGroup(string detail)
        {
            GroupDevice asynWaitGoup = new GroupDevice(this as MiddlewareCorelogicLayer);

            asynWaitGoup.Detail = detail;
            asynWaitGoup.Token  = null;
            asynWaitGoup.Ready  = false;
            _asynCreategroupRunner.EnqueueMessage(new KeyValuePair <string, GroupDevice>(detail, asynWaitGoup));
            return(asynWaitGoup);
        }
Ejemplo n.º 6
0
        public void ParseSerializeData(CCCommunicateClass.Seria_RadioPackage obj)
        {
            base.ParseSerializeData(obj as CCCommunicateClass.Seria_ParamPackage);
            this.RadioName = obj.RadioName;

            GroupDevice tmpGroupDevice = new GroupDevice();

            tmpGroupDevice.ParseSerializeData(obj.GroupInfo);
            this.Group = tmpGroupDevice;
        }
 protected void CoSynJoinGroup(GroupDevice group, GroupMemberRole role)
 {
     try
     {
         group.Join(role);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 protected void CoSynExitGroup(GroupDevice group)
 {
     try
     {
         group.Exit();
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 private void __CoAsynExitGroupRunning(GroupDevice group)
 {
     try
     {
         group.Exit();
     }
     catch (System.Exception ex)
     {
         group.excetion = ex as ExitGroupExcetion;
     }
 }
        protected GroupComunicatePackage CoCreateGroupCommunicatePackage(string radioName,
                                                                         ParamPackage radioParamPkg,
                                                                         GroupDevice targetGroup)
        {
            GroupComunicatePackage gropCommunicatPkg = new GroupComunicatePackage();

            gropCommunicatPkg.CommunicationName = radioName;
            gropCommunicatPkg.ParamPackage      = radioParamPkg;
            gropCommunicatPkg.TargetDevice      = targetGroup;
            gropCommunicatPkg.WaitResponse      = false;
            return(gropCommunicatPkg);
        }
        internal void JoinGroup(GroupDevice group, GroupMemberRole role)
        {
            //配置请求包
            ServerRequestPackage reqtPkg       = new ServerRequestPackage(true);
            IJoinGroupRequest    reqtInterface = reqtPkg.Active_JoinGroupRequest();

            if (group.Ready && !string.IsNullOrEmpty(group.Token))
            {
                reqtInterface.JoinGroup(group.Token, role);
            }
            else
            {
                throw new ArgumentNullException("Group token is null");
            }
            BinTransferLayer   binprocessor = _mclLayerProcessor.BinTransferProcessor;
            ServerReplyPackage replyPkg     = null;

            try
            {
                replyPkg = binprocessor.SynSendMessage(reqtPkg, 100000);
            }
            catch (System.Exception ex)
            {
                throw new JoinGroupExcetion(ex.ToString());
            }
            IJoinGroupReply replyInterface = replyPkg.Active_JoinGroupReply();
            bool            ret;
            string          detail;

            replyInterface.JoinGroupRet(out ret, out detail);
            if (true == ret)
            {
                //该部分逻辑内聚到Group内部

                ////加入成功
                //group.Joined = true;
                //try
                //{
                //    //从接口的使用习惯上考虑,立即返回成员列表
                //    group.Referesh();
                //}
                //catch (RefereshGroupInfo ex)
                //{
                //    //虽然刷新讯息抛出错误,但仍可以判定客户端已加入
                //    throw ex;
                //}
            }
            else
            {
                throw new JoinGroupExcetion(detail);
            }
        }
 protected GroupDevice CoSynGetGroup(string detail)
 {
     try
     {
         GroupDevice gropDevice = _groupCommunicateProcessor.GetGroup(detail);
         _localGroupDeviceBuffer.Add(gropDevice);
         return(gropDevice);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 13
0
 private void UpdateObject(GroupDevice _newGroupDevice, ref GroupDevice _oldGroupDevice)
 {
     try
     {
         foreach (PropertyInfo GroupDevicePropInfo in _newGroupDevice.GetType().GetProperties().ToList())
         {
             _oldGroupDevice.GetType().GetProperty(GroupDevicePropInfo.Name).SetValue(_oldGroupDevice, _newGroupDevice.GetType().GetProperty(GroupDevicePropInfo.Name).GetValue(_newGroupDevice));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        //private ThreadSafeSortedList<RequestPackage, C2CRequestPackage> _waitResponOutsideReqtPkg2CCReqtPkg = new ThreadSafeSortedList<RequestPackage, C2CRequestPackage>();
        #endregion

        #region Group

        #region CreateGroup
        protected GroupDevice CoSynCreateGroup(string detail)
        {
            GroupDevice synGropDevice = null;

            try
            {
                synGropDevice = GroupCommunicateProcessor.CreateGroup(detail);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            _localGroupDeviceBuffer.Add(synGropDevice);
            return(synGropDevice);
        }
Ejemplo n.º 15
0
        public void RegistMessage(BaseMessageType typMsg, Type t_Msg)
        {
            mMessageFactory.RegistMessage(typMsg, t_Msg);
            GroupDevice group = null;

            try
            {
                group = mGroupCommunicateProcessor.CreateGroup(mDispatcherPrefixi + "_" + typMsg.Name + "_" + Guid.NewGuid().ToString());
                mGroupCommunicateProcessor.JoinGroup(group, Communication.CommunicationConfig.GroupMemberRole.Speaker);
            }catch (Exception ex)
            {
                throw new Exception("试图注册消息时遭遇网络失败: " + ex.ToString());
            }
            mSpeakMsgID2Group.Add(typMsg.Id, group);
        }
Ejemplo n.º 16
0
 public GroupDevice AddNewGroupDevice(GroupDevice _GroupDevice)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             context.GroupDevice.Add(_GroupDevice);
             int numOfInserted = context.SaveChanges();
             return(numOfInserted > 0 ? _GroupDevice : null);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        private void __AsynCoGetGroupRunning(KeyValuePair <string, GroupDevice> detailAnduncompletGroup)
        {
            GroupDevice synGropDevice = null;

            try
            {
                synGropDevice = _groupCommunicateProcessor.GetGroup(detailAnduncompletGroup.Key);
            }
            catch (System.Exception ex)
            {
                detailAnduncompletGroup.Value.excetion = ex as GetOnlineGroupExcetion;
                detailAnduncompletGroup.Value.Ready    = false;
            }
            detailAnduncompletGroup.Value.Specific(synGropDevice);
            _localGroupDeviceBuffer.Add(synGropDevice);
        }
        internal void ExitGroup(GroupDevice group)
        {
            if (!group.Ready || string.IsNullOrEmpty(group.Token))
            {
                throw new ExitGroupExcetion((new NullReferenceException("Group token is null")).ToString());
            }
            //配置请求包
            ServerRequestPackage reqtPkg       = new ServerRequestPackage(true);
            IExitGroupRequest    reqtInterface = reqtPkg.Active_ExitGroupRequest();

            reqtInterface.ExitGroup(group.Token);

            BinTransferLayer   binprocessor = _mclLayerProcessor.BinTransferProcessor;
            ServerReplyPackage replyPkg     = null;

            try
            {
                replyPkg = binprocessor.SynSendMessage(reqtPkg, 100000);
            }
            catch (Exception ex)
            {
                throw new ExitGroupExcetion(ex.ToString());
            }
            IExitGroupRely replyInterface = replyPkg.Active_ExitGroupReply();
            bool           ret;
            string         errorDetail;

            replyInterface.ExitGroupRet(out ret, out errorDetail);
            if (true == ret)
            {
                //该部分逻辑内聚到Group内部

                //group.Joined = false;
                //try
                //{
                //    group.Referesh();
                //}catch(RefereshGroupInfo ex)
                //{
                //    throw ex;
                //}
            }
            else
            {
                throw new ExitGroupExcetion(errorDetail);
            }
        }
Ejemplo n.º 19
0
        private void __PerRadio_Elapsed(object sender, EventArgs e)
        {
            ParamPackage packageSended = PackMessage();
            GroupDevice  targetGroup   = null;

            foreach (GroupDevice item in groupDeviceList)
            {
                if (item.Detail == comboBox14.SelectedItem.ToString())
                {
                    targetGroup = item;
                }
            }
            string radioOp = this.comboBox8.SelectedItem.ToString();
            GroupComunicatePackage groupComunicatePackage = localDevice.CreateRadioCommunicatePackage(radioOp, packageSended, targetGroup);

            localDevice.Radio(groupComunicatePackage);
        }
Ejemplo n.º 20
0
        //退出Group
        private void button5_Click(object sender, EventArgs e)
        {
            GroupDevice targetGroup = null;

            foreach (GroupDevice item in groupDeviceList)
            {
                if (item.Detail == comboBox7.SelectedItem.ToString())
                {
                    targetGroup = item;
                }
            }
            if (targetGroup != null)
            {
                localDevice.ExitGroup(targetGroup, (CommunicatType)comboBox6.SelectedItem);
                joinedGroupDevice = null;
            }
        }
Ejemplo n.º 21
0
        //加入Group
        private void button4_Click(object sender, EventArgs e)
        {
            GroupDevice targetGroup = null;

            foreach (GroupDevice item in groupDeviceList)
            {
                if (item.Detail == comboBox3.SelectedItem.ToString())
                {
                    targetGroup = item;
                }
            }
            if (targetGroup != null)
            {
                localDevice.JoinGroup(targetGroup, (GroupMemberRole)comboBox4.SelectedItem, (CommunicatType)comboBox5.SelectedItem);
                joinedGroupDevice = targetGroup;
            }
        }
Ejemplo n.º 22
0
 public void SendMessage(BaseMessage msg)
 {
     if (mSpeakMsgID2Group.ContainsKey(msg.Type.Id))
     {
         GroupDevice group = mSpeakMsgID2Group[msg.Type.Id] as GroupDevice;
         try
         {
             mGroupCommunicateProcessor.Radio(new C2CMessageRadioPackage(group, msg));
         }catch (Exception ex)
         {
             throw new Exception("试图发送消息时遭遇网络失败: " + ex.ToString());
         }
     }
     else
     {
         throw new InvalidOperationException("未注册的消息类型: " + msg.Type.Name);
     }
 }
Ejemplo n.º 23
0
        //创建Group
        private void button3_Click(object sender, EventArgs e)
        {
            GroupDevice groupDevice = localDevice.CreateGroup(createGroupDetail, (CommunicatType)comboBox2.SelectedItem);

            if (groupDevice != null)
            {
                groupDeviceList.Add(groupDevice);
                if (!comboBox3.Items.Contains(groupDevice.Detail))
                {
                    comboBox3.Items.Add(groupDevice.Detail);
                }
                if (!comboBox7.Items.Contains(groupDevice.Detail))
                {
                    comboBox7.Items.Add(groupDevice.Detail);
                }
                if (!comboBox14.Items.Contains(groupDevice.Detail))
                {
                    comboBox14.Items.Add(groupDevice.Detail);
                }
            }
        }
        internal void GetGroupMembers(GroupDevice gropDevice, out List <CSCommunicateClass.ClientInfo> onlineGroupMembers)
        {
            //配置数据包
            ServerRequestPackage      servReqtPkg   = new ServerRequestPackage(true);
            IOnlineGroupClientRequest reqtInterface = servReqtPkg.Active_OnlineGroupClientRequest();

            reqtInterface.OnlineGroupClientRequest(gropDevice.Token);

            BinTransferLayer   binprocessor = _mclLayerProcessor.BinTransferProcessor;
            ServerReplyPackage servReplyPkg = null;

            try
            {
                servReplyPkg = binprocessor.SynSendMessage(servReqtPkg, 100000);
            }
            catch (System.Exception ex)
            {
                throw new GetOnlineGroupClientExcetion(ex.ToString());
            }
            IOnlineGroupClientReply replyInterface = servReplyPkg.Active_OnlineGroupClientReply();
            bool   ret;
            string errorDetail;

            try
            {
                replyInterface.OnlineGroupClientRet(out ret, out errorDetail, out onlineGroupMembers);
            }
            catch (Exception ex)
            {
                throw new GetOnlineGroupClientExcetion(ex.ToString());
            }
            if (true == ret)
            {
                //nothing to do
            }
            else
            {
                throw new GetOnlineGroupClientExcetion(errorDetail);
            }
        }
        internal GroupDevice CreateGroup(string detail)
        {
            //配置请求包
            ServerRequestPackage reqtPkg       = new ServerRequestPackage(true);
            ICreateGroupRequest  reqtInterface = reqtPkg.Active_CreateGroupRequest();

            reqtInterface.CreateNewGroup(detail);

            BinTransferLayer   binprocessor = _mclLayerProcessor.BinTransferProcessor;
            ServerReplyPackage replyPkg     = null;

            try
            {
                replyPkg = binprocessor.SynSendMessage(reqtPkg, 100000);
            }
            catch (System.Exception ex)
            {
                //throw timeout excetion
                throw new CreateGroupExcetion(ex.ToString());
            }
            ICreateGroupReply replyInterface = replyPkg.Active_CreateGroupReply();
            bool   ret;
            string detailOrToken;

            replyInterface.CreateGroupRet(out ret, out detailOrToken);
            if (true == ret)
            {
                GroupDevice retGrop = new GroupDevice(_mclLayerProcessor);
                retGrop.Token  = detailOrToken;
                retGrop.Detail = detail;
                retGrop.Ready  = true;
                return(retGrop);
            }
            else
            {
                throw new CreateGroupExcetion(detailOrToken);
            }
        }
Ejemplo n.º 26
0
        public GroupDevice UpdateGroupDevice(GroupDevice _GroupDevice)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var oldGroupDevice = context.GroupDevice.FirstOrDefault(u => u.Id == _GroupDevice.Id);
                    if (oldGroupDevice != null)
                    {
                        UpdateObject(_GroupDevice, ref oldGroupDevice);
                        var numberOfUpdatedGroupDevice = context.SaveChanges();
                        return(numberOfUpdatedGroupDevice > 0 ? _GroupDevice : null);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 protected void CoAsynExitGroup(GroupDevice group)
 {
     _asynExitGroupRunner.EnqueueMessage(group);
 }
 protected void CoAsynJoinGroup(GroupDevice group, GroupMemberRole role)
 {
     _asynJoinGroupRunner.EnqueueMessage(new KeyValuePair <GroupDevice, GroupMemberRole>(group, role));
 }
Ejemplo n.º 29
0
        public void Listen(ClientDevice messenger, BaseMessageType typMsg)
        {
            if (mListeningDevice2MsgID.ContainsKey(messenger.Detail) &&
                (mListeningDevice2MsgID[messenger.Detail] as List <uint>).Contains(typMsg.Id))
            {
                throw new InvalidOperationException("该设备消息已被监听");
            }

            C2CRequestPackage listenerVertificationRequestPkg =
                new C2CRequestPackage(mCoreLogicProcessor.SelfDevice,
                                      "ListenerVertificationRequest",
                                      true,
                                      new Dictionary <string, byte[]>()
            {
                { "MessageType",
                  BitConverter.GetBytes(typMsg.Id) }
            });
            RequestMTPackage mtReqtPkg = new RequestMTPackage(listenerVertificationRequestPkg,
                                                              mCoreLogicProcessor.SelfDevice,
                                                              messenger,
                                                              true);

            //验证流程
            MiddlewareTransferPackage mtReplyBasePkg = null;

            try
            {
                //100s limited time to wait this c2c response.
                mtReplyBasePkg = mMiddlewareCommunicateProcessor.SynSendMessage(mtReqtPkg, 10000);
            }catch (Exception ex)
            {
                throw new Exception("尝试监听一个设备消息时遭遇网络异常:" + ex.ToString());
            }
            ReplyMTPackage  mtReplyPkg  = mtReplyBasePkg as ReplyMTPackage;
            C2CReplyPackage c2cReplyPkg = mtReplyPkg.C2CReplyPackage;

            if (Communication.Package.ReplyPackage.Middleware_ReplyInfo.S_OK == c2cReplyPkg.ReplyState)
            {
                //加入监听群组
                string      gourp_detail   = Encoding.ASCII.GetString(c2cReplyPkg.ParamDefalutValues["group_detail"]);
                GroupDevice wilListenGroup = null;
                try
                {
                    wilListenGroup = mGroupCommunicateProcessor.GetGroup(gourp_detail);
                    mGroupCommunicateProcessor.JoinGroup(wilListenGroup,
                                                         Communication.CommunicationConfig.GroupMemberRole.Listener);
                }catch (Exception ex)
                {
                    throw new Exception("尝试监听一个设备消息时遭遇网络异常:" + ex.ToString());
                }

                if (!mListeningDevice2MsgID.ContainsKey(messenger.Detail))
                {
                    mListeningDevice2MsgID.Add(messenger.Detail, new List <uint>());
                }
                (mListeningDevice2MsgID[messenger.Detail] as List <uint>).Add(typMsg.Id);

                mListeningGroup2Device.Add(wilListenGroup.Detail, messenger);
            }
            else
            {
                throw new Exception("尝试监听一个设备消息时遭遇网络异常:" +
                                    Encoding.UTF8.GetString(c2cReplyPkg.ParamDefalutValues["excetion_detail"]));
            }
        }
 public C2CMessageRadioPackage(GroupDevice targetDevice, BaseMessage msg)
     : base(targetDevice, "C2CMessageRadioPackage_" + msg.Type.Name, null)
 {
     mMessage = msg;
 }