Example #1
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()));
        }
 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);
 }