Example #1
0
 private List <SIPSorcery.SIP.App.SIPAccount> SipAccountStorage_RPCGBServerConfigReceived()
 {
     try
     {
         string SystemConfigurationServiceAddress = EnvironmentVariables.SystemConfigurationServiceAddress ?? "systemconfigurationservice:8080";
         logger.Debug("System Configuration Service Address: " + SystemConfigurationServiceAddress);
         //var channel = new  Channel(SystemConfigurationServiceAddress, ChannelCredentials.Insecure);
         var channel = GrpcChannel.ForAddress(SystemConfigurationServiceAddress);
         var client  = new Manage.ManageClient(channel);
         GetIntegratedPlatformConfigRequest  req = new GetIntegratedPlatformConfigRequest();
         GetIntegratedPlatformConfigResponse rep = client.GetIntegratedPlatformConfig(req);
         logger.Debug("GetIntegratedPlatformConfigResponse: " + rep.Config.ToString());
         GBPlatformConfig item = rep.Config;
         List <GB28181.SIPSorcery.SIP.App.SIPAccount> _lstSIPAccount = new List <GB28181.SIPSorcery.SIP.App.SIPAccount>();
         GB28181.SIPSorcery.SIP.App.SIPAccount        obj            = new GB28181.SIPSorcery.SIP.App.SIPAccount();
         obj.Id = Guid.NewGuid();
         //obj.Owner = item.Name;
         obj.GbVersion         = string.IsNullOrEmpty(item.GbVersion) ? "GB-2016" : item.GbVersion;
         obj.LocalID           = string.IsNullOrEmpty(item.LocalID) ? "34020000002000000001" : item.LocalID;
         obj.LocalIP           = HostsEnv.GetRawIP();
         obj.LocalPort         = string.IsNullOrEmpty(item.LocalPort) ? Convert.ToUInt16(5060) : Convert.ToUInt16(item.LocalPort);
         obj.RemotePort        = string.IsNullOrEmpty(item.RemotePort) ? Convert.ToUInt16(5060) : Convert.ToUInt16(item.RemotePort);
         obj.Authentication    = string.IsNullOrEmpty(item.Authentication) ? false : bool.Parse(item.Authentication);
         obj.SIPUsername       = string.IsNullOrEmpty(item.SIPUsername) ? "admin" : item.SIPUsername;
         obj.SIPPassword       = string.IsNullOrEmpty(item.SIPPassword) ? "123456" : item.SIPPassword;
         obj.MsgProtocol       = System.Net.Sockets.ProtocolType.Udp;
         obj.StreamProtocol    = System.Net.Sockets.ProtocolType.Udp;
         obj.TcpMode           = GB28181.SIPSorcery.Net.RTP.TcpConnectMode.passive;
         obj.MsgEncode         = string.IsNullOrEmpty(item.MsgEncode) ? "GB2312" : item.MsgEncode;
         obj.PacketOutOrder    = string.IsNullOrEmpty(item.PacketOutOrder) ? true : bool.Parse(item.PacketOutOrder);
         obj.KeepaliveInterval = string.IsNullOrEmpty(item.KeepaliveInterval) ? Convert.ToUInt16(5000) : Convert.ToUInt16(item.KeepaliveInterval);
         obj.KeepaliveNumber   = string.IsNullOrEmpty(item.KeepaliveNumber) ? Convert.ToByte(3) : Convert.ToByte(item.KeepaliveNumber);
         _lstSIPAccount.Add(obj);
         logger.Debug("GetIntegratedPlatformConfigResponse SIPAccount: {LocalID:" + obj.LocalID + ", LocalIP:" + obj.LocalIP + ", LocalPort:" + obj.LocalPort + ", RemotePort:"
                      + obj.RemotePort + ", SIPUsername:"******", SIPPassword:"******", KeepaliveInterval:" + obj.KeepaliveInterval + "}");
         return(_lstSIPAccount);
     }
     catch (Exception ex)
     {
         logger.Warn("GetIntegratedPlatformConfigRequest: " + ex.Message);
         //logger.Debug("Can't get gb info from device-mgr, it will get gb info from config.");
         return(null);
     }
 }
        private void _sipRegistrarCore_RPCDmsRegisterReceived(SIPTransaction sipTransaction, GB28181.SIPSorcery.SIP.App.SIPAccount sIPAccount)
        {
            try
            {
                Device     _device    = new Device();
                SIPRequest sipRequest = sipTransaction.TransactionRequest;
                _device.Guid = Guid.NewGuid().ToString();
                _device.IP   = sipTransaction.TransactionRequest.RemoteSIPEndPoint.Address.ToString();//IPC
                _device.Name = "gb" + _device.IP;
                _device.LoginUser.Add(new LoginUser()
                {
                    LoginName = sIPAccount.SIPUsername ?? "admin", LoginPwd = sIPAccount.SIPPassword ?? "123456"
                });
                _device.Port         = Convert.ToUInt32(sipTransaction.TransactionRequest.RemoteSIPEndPoint.Port); //5060
                _device.GBID         = sipTransaction.TransactionRequestFrom.URI.User;                             //42010000001180000184
                _device.PtzType      = 0;
                _device.ProtocolType = 0;
                _device.ShapeType    = ShapeType.Dome;
                //var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.MaxMessageLength, int.MaxValue) };
                //  var channel = new Channel(EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080", ChannelCredentials.Insecure);
                var channel = GrpcChannel.ForAddress(EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080");

                logger.Debug("Device Management Service Address: " + (EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080"));
                var client = new Manage.ManageClient(channel);
                AddDeviceRequest _AddDeviceRequest = new AddDeviceRequest();
                _AddDeviceRequest.Device.Add(_device);
                _AddDeviceRequest.LoginRoleId = "XXXX";
                var reply = client.AddDevice(_AddDeviceRequest);
                if (reply.Status == OP_RESULT_STATUS.OpSuccess)
                {
                    logger.Debug("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] have completed registering DMS service.");
                }
                else
                {
                    logger.Error("_sipRegistrarCore_RPCDmsRegisterReceived: " + reply.Status.ToString());
                }
            }
            catch (Exception ex)
            {
                logger.Error("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] register DMS failed: " + ex.Message);
            }
        }
Example #3
0
        /// <summary>
        /// 设备注册事件
        /// </summary>
        /// <param name="sipTransaction"></param>
        /// <param name="sIPAccount"></param>
        private void _sipRegistrarCore_RPCDmsRegisterReceived(SIPTransaction sipTransaction, GB28181.SIPSorcery.SIP.App.SIPAccount sIPAccount)
        {
            try
            {
                _SIPAccount = sIPAccount;
                string deviceid = sipTransaction.TransactionRequestFrom.URI.User;

                //GB SIPTransactions Dictionary
                GBSIPTransactions.Remove(deviceid);
                GBSIPTransactions.Add(deviceid, sipTransaction);

                //Device Catalog Query
                _sipCoreMessageService.DeviceCatalogQuery(deviceid);

                ////query device info from db
                //string edit = IsDeviceExisted(deviceid) ? "updated" : "added";

                ////Device Dms Register
                //DeviceDmsRegister(sipTransaction,"gb");

                ////Device Edit Event
                //DeviceEditEvent(deviceid, edit);
            }
            catch (Exception ex)
            {
                logger.Error("_sipRegistrarCore_RPCDmsRegisterReceived Exception: " + ex.Message);
            }
        }