Beispiel #1
0
 public Server(LWM2MServer lwm2mServer)
 {
     Lifetime = lwm2mServer.Lifetime;
     DefaultMinimumPeriod = lwm2mServer.DefaultMinimumPeriod;
     DefaultMaximumPeriod = lwm2mServer.DefaultMaximumPeriod;
     DisableTimeout = lwm2mServer.DisableTimeout;
     NotificationStoringWhenOffline = lwm2mServer.NotificationStoringWhenOffline;
     Binding = lwm2mServer.Binding;
     EndPoints = new List<Security>();
     if (!string.IsNullOrEmpty(lwm2mServer.Url))
     {
         Security security = new Security();
         security.ServerURI = lwm2mServer.Url;
         if (lwm2mServer.Url.StartsWith("coaps"))
         {
             security.SecurityMode = TSecurityMode.Certificate;
         }
         else
             security.SecurityMode = TSecurityMode.NoSecurity;
         EndPoints.Add(security);
     }
 }
Beispiel #2
0
 public static Security Deserialise(XmlReader reader)
 {
     Security result = new Security();
     string value;
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             switch (reader.Name)
             {
                 case "ServerURI":
                     result.ServerURI = reader.ReadInnerXml();
                     break;
                 case "BootstrapServer":
                     value = reader.ReadInnerXml();
                     bool bootstrapServer;
                     if (bool.TryParse(value, out bootstrapServer))
                         result.BootstrapServer = bootstrapServer;
                     break;
                 case "SecurityMode":
                     value = reader.ReadInnerXml();
                     TSecurityMode securityMode;
                     if (Enum.TryParse<TSecurityMode>(value, true, out securityMode))
                         result.SecurityMode = securityMode;
                     break;
                 case "ClientPublicKey":
                     value = reader.ReadInnerXml();
                     if (!string.IsNullOrEmpty(value))
                         result.ClientPublicKey = Convert.FromBase64String(value);
                     break;
                 case "ServerPublicKey":
                     value = reader.ReadInnerXml();
                     if (!string.IsNullOrEmpty(value))
                         result.ServerPublicKey = Convert.FromBase64String(value);
                     break;
                 case "SecretKey":
                     value = reader.ReadInnerXml();
                     if (!string.IsNullOrEmpty(value))
                         result.SecretKey = Convert.FromBase64String(value);
                     break;
                 case "SMSSecurityMode":
                     value = reader.ReadInnerXml();
                     TSMSSecurityMode smsSecurityMode;
                     if (Enum.TryParse<TSMSSecurityMode>(value, true, out smsSecurityMode))
                         result.SMSSecurityMode = smsSecurityMode;
                     break;
                 case "SMSBindingKeyParameters":
                     value = reader.ReadInnerXml();
                     if (!string.IsNullOrEmpty(value))
                         result.SMSBindingKeyParameters = Convert.FromBase64String(value);
                     break;
                 case "SMSBindingSecretKeys":
                     value = reader.ReadInnerXml();
                     if (!string.IsNullOrEmpty(value))
                         result.SMSBindingSecretKeys = Convert.FromBase64String(value);
                     break;
                 case "ServerSMSNumber":
                     value = reader.ReadInnerXml();
                     ulong serverSMSNumber;
                     if (ulong.TryParse(value, out serverSMSNumber))
                         result.ServerSMSNumber = serverSMSNumber;
                     break;
                 case "ShortServerID":
                     value = reader.ReadInnerXml();
                     int shortServerID;
                     if (int.TryParse(value, out shortServerID))
                         result.ShortServerID = shortServerID;
                     break;
                 case "ClientHoldOffTime":
                     value = reader.ReadInnerXml();
                     uint clientHoldOffTime;
                     if (uint.TryParse(value, out clientHoldOffTime))
                         result.ClientHoldOffTime = clientHoldOffTime;
                     break;
                 default:
                     break;
             }
         }
     }
     return result;
 }