Пример #1
0
 public void AddClient(LWM2MClient client)
 {
     lock (_NewClients)
     {
         _NewClients.Enqueue(client);
     }
     _TriggerProcessRequests.Set();
 }
Пример #2
0
 public void ClientUpdate(LWM2MClient client)
 {
     if (client.OrganisationID != 0)
     {
         ServiceEventMessage message = new ServiceEventMessage();
         FillDeviceParameters(client, message);
         BusinessLogicFactory.ServiceMessages.Publish(RouteKeys.CLIENT_UPDATE, message, TMessagePublishMode.Confirms);
     }
 }
Пример #3
0
 public void ClientConnectionExpired(LWM2MClient client)
 {
     if (client.OrganisationID != 0)
     {
         ServiceEventMessage message = new ServiceEventMessage();
         FillDeviceParameters(client, message);
         BusinessLogicFactory.ServiceMessages.Publish(RouteKeys.CLIENT_CONNECTION_EXPIRED, message, TMessagePublishMode.Confirms);
     }
 }
Пример #4
0
 public void MetricsUpdate(LWM2MClient client)
 {
     if (client.OrganisationID != 0)
     {
         ServiceEventMessage message = new ServiceEventMessage();
         FillDeviceParameters(client, message);
         client.Metrics.FillParameters(message);
         BusinessLogicFactory.ServiceMessages.Publish(RouteKeys.CLIENT_METRICS, message, TMessagePublishMode.Confirms);
         client.Metrics.ResetIncrementalMetrics();
     }
 }
Пример #5
0
        private void ProcessRegisterRequest(Exchange exchange)
        {
            Request request = exchange.Request;
            LWM2MClient client = new LWM2MClient();
            client.Server = _ServerEndPoint;
            client.Address = request.Source;
            client.Parse(request.UriQueries);
            ObjectTypes objectTypes = new ObjectTypes();
            objectTypes.Parse(request.PayloadString);
            client.SupportedTypes = objectTypes;
            client.EndPoint = exchange.EndPoint;
            if (_SecureChannel != null)
            {
                CertificateInfo certificateInfo = _SecureChannel.GetClientCertificateInfo(client.Address);
                if (certificateInfo == null)
                {
                    string pskIdentity = _SecureChannel.GetClientPSKIdentity(client.Address);
                    if (!string.IsNullOrEmpty(pskIdentity))
                    {
                        Guid clientID;
                        PSKIdentity identity = DataAccessFactory.Identities.GetPSKIdentity(pskIdentity);
                        if (identity != null)
                        {
                            if (StringUtils.GuidTryDecode(pskIdentity, out clientID))
                            {
                                client.ClientID = clientID;
                            }
                            client.OrganisationID = identity.OrganisationID;
                        }
                    }
                }
                else
                {
                    Console.WriteLine(certificateInfo.Subject.CommonName);
                    Console.WriteLine(certificateInfo.Subject.Organistion);
                    Guid clientID;
                    if (Guid.TryParse(certificateInfo.Subject.CommonName,  out clientID))
                    {
                        client.ClientID = clientID;
                    }
                    int organisationID;
                    if (int.TryParse(certificateInfo.Subject.Organistion, out organisationID))
                    {
                        client.OrganisationID = organisationID;
                    }
                }
            }
            if (client.ClientID != Guid.Empty && (client.OrganisationID > 0 || !SecureOnly) && !DataAccessFactory.Clients.IsBlacklisted(client.ClientID))
            {
                BusinessLogicFactory.Clients.AddClient(client);
            }

            Response response = Response.CreateResponse(request, StatusCode.Created);
            //response.AddOption(Option.Create(OptionType.LocationPath, string.Concat("rd/",StringUtils.GuidEncode(client.ClientID))));
            response.AddOption(Option.Create(OptionType.LocationPath, "rd"));
            response.AddOption(Option.Create(OptionType.LocationPath, StringUtils.GuidEncode(client.ClientID)));

            exchange.SendResponse(response);

            ApplicationEventLog.Write(LogLevel.Information, string.Concat("Client registered ", client.Name, " address ", client.Address.ToString()));
        }
Пример #6
0
 public void ObservationNotify(LWM2MClient client, Model.Object lwm2mObject)
 {
     if (client.OrganisationID != 0)
     {
         ServiceEventMessage message = new ServiceEventMessage();
         FillDeviceParameters(client, message);
         message.Parameters.Add("Object", lwm2mObject);
         BusinessLogicFactory.ServiceMessages.Publish(RouteKeys.OBSERVATION_NOTIFICATION, message, TMessagePublishMode.Confirms);
     }
 }
Пример #7
0
 private void ProcessRequestBootstrap(Exchange exchange)
 {
     Request request = exchange.Request;
     LWM2MClient client = new LWM2MClient();  // TODO: fix warning
     client.Address = request.Source;
     client.EndPoint = exchange.EndPoint;
     client.Parse(request.UriQueries);
     BusinessLogicFactory.Clients.AddClient(client);
     Response response = Response.CreateResponse(request, StatusCode.Changed);
     exchange.SendResponse(response);
 }
Пример #8
0
        private void ValidateClient(LWM2MClient client)
        {
            UpdateClientActivity(client);

            if (client.ClientID != Guid.Empty)
            {
                // TODO: for now simply add the client to the DB. In the future we will want to validate the client first.
                DataAccessFactory.Clients.SaveClient(client, TObjectState.Add);
                BusinessLogicFactory.Events.ClientConnected(client);
                LWM2MClient existingClient;
                if (_ClientByDeviceID.TryRemove(client.ClientID, out existingClient))
                {
                    if (existingClient != client)
                        existingClient.Cancel();
                }
                _ClientByDeviceID.TryAdd(client.ClientID, client);
            }
        }
Пример #9
0
 public void ClientChangedSupportedTypes(LWM2MClient client)
 {
     BusinessLogicFactory.Events.ClientUpdate(client);
     lock (_ClientsToValidate)
     {
         _ClientsToValidate.Enqueue(client);
     }
     _TriggerProcessRequests.Set();
 }
Пример #10
0
 public void AddClient(LWM2MClient client)
 {
     _Clients.TryAdd(client.ClientID, client);
     lock (_ClientsToValidate)
     {
         _ClientsToValidate.Enqueue(client);
     }
     _TriggerProcessRequests.Set();
 }