public static DateTimeResources Deserialise(TlvReader reader) { DateTimeResources result = null; if (reader.TlvRecord == null) reader.Read(); if (reader.TlvRecord != null) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources) { result = new DateTimeResources(reader.TlvRecord.Identifier.ToString()); if (reader.TlvRecord.Value != null) { using (TlvReader childReader = new TlvReader(reader.TlvRecord.Value)) { while (childReader.Read()) { if (childReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance) { DateTimeResource childResource = new DateTimeResource(childReader.TlvRecord.Identifier.ToString()); childResource.Value = childReader.TlvRecord.ValueAsDateTime(); result.Add(childResource); } } } } } } return result; }
private List <Model.Object> ParseObjects(ObjectDefinition objectDefinition, int requestContentType, Response response) { List <Model.Object> result = new List <Model.Object>(); int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { TlvReader objectReader = new TlvReader(reader.TlvRecord.Value); Model.Object item = ObjectUtils.ParseObject(objectDefinition, objectReader); if (item != null) { item.InstanceID = reader.TlvRecord.Identifier.ToString(); result.Add(item); } } } } return(result); }
public static string GetValue(TlvReader reader, PropertyDefinition property) { string result = null; switch (property.DataType) { case TPropertyDataType.NotSet: break; case TPropertyDataType.String: result = reader.TlvRecord.ValueAsString(); break; case TPropertyDataType.Boolean: result = reader.TlvRecord.ValueAsBoolean().ToString(); break; case TPropertyDataType.Integer: result = reader.TlvRecord.ValueAsInt64().ToString(); break; case TPropertyDataType.Float: result = reader.TlvRecord.ValueAsDouble().ToString(); break; case TPropertyDataType.DateTime: result = reader.TlvRecord.ValueAsDateTime().ToString(XmlHelper.XMLDATEFORMAT); break; case TPropertyDataType.Opaque: result = Convert.ToBase64String(reader.TlvRecord.Value); break; case TPropertyDataType.Object: break; default: break; } return result; }
private Model.Object ParseObject(ObjectDefinition objectDefinition, int requestContentType, Response response) { Model.Object result = null; int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); result = ObjectUtils.ParseObject(objectDefinition, reader); } else if (contentType == MediaType.ApplicationJson) { JsonReader reader = new JsonReader(new MemoryStream(response.Payload)); result = ObjectUtils.ParseObject(objectDefinition, reader); } return(result); }
private Property ParseProperty(ObjectDefinition objectDefinition, PropertyDefinition propertyDefinition, int requestContentType, Response response) { Property result = null; int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); Model.Object lwm2mObject = ObjectUtils.ParseObject(objectDefinition, reader); if ((lwm2mObject != null) && (lwm2mObject.Properties.Count > 0)) { foreach (Property item in lwm2mObject.Properties) { if (item.PropertyDefinitionID == propertyDefinition.PropertyDefinitionID) { result = item; break; } } } } else if ((contentType == MediaType.TextPlain) || (contentType == TlvConstant.CONTENT_TYPE_PLAIN)) { string text = Encoding.UTF8.GetString(response.Payload); result = new Property(); result.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; result.PropertyID = propertyDefinition.PropertyID; result.Value = new PropertyValue(ObjectUtils.GetValue(text, propertyDefinition)); } else if ((contentType == MediaType.ApplicationJson) || (contentType == TlvConstant.CONTENT_TYPE_JSON)) { JsonReader reader = new JsonReader(new MemoryStream(response.Payload)); //LWM2MObject lwm2mObject = ObjectUtils.ParseObject(objectDefinition, reader); //if ((lwm2mObject != null) && (lwm2mObject.Properties.Count > 0)) //{ // foreach (LWM2MProperty item in lwm2mObject.Properties) // { // if (item.PropertyDefinitionID == propertyDefinition.PropertyDefinitionID) // { // result = item; // break; // } // } //} result = ObjectUtils.ParseProperty(propertyDefinition, reader); } return(result); }
public static bool Deserialise(TlvReader reader, OpaqueResource item) { bool result = false; if (reader.TlvRecord == null) reader.Read(); if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue) { item.Value = reader.TlvRecord.Value; result = true; } return result; }
public static BooleanResources Deserialise(Request request) { BooleanResources result = null; string name = request.UriPaths.Last(); if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV)) { using (TlvReader reader = new TlvReader(request.Payload)) { result = Deserialise(reader); } } return result; }
public static OpaqueResource Deserialise(Request request) { OpaqueResource result = null; string name = request.UriPaths.Last(); if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV)) { OpaqueResource resource = new OpaqueResource(name); using (TlvReader reader = new TlvReader(request.Payload)) { if (Deserialise(reader, resource)) result = resource; } } return result; }
public static string GetValue(TlvReader reader, PropertyDefinition property) { string result = null; switch (property.DataType) { case TPropertyDataType.NotSet: break; case TPropertyDataType.String: result = reader.TlvRecord.ValueAsString(); break; case TPropertyDataType.Boolean: result = reader.TlvRecord.ValueAsBoolean().ToString(); break; case TPropertyDataType.Integer: result = reader.TlvRecord.ValueAsInt64().ToString(); break; case TPropertyDataType.Float: result = reader.TlvRecord.ValueAsDouble().ToString(); break; case TPropertyDataType.DateTime: result = reader.TlvRecord.ValueAsDateTime().ToString(XmlHelper.XMLDATEFORMAT); break; case TPropertyDataType.Opaque: result = Convert.ToBase64String(reader.TlvRecord.Value); break; case TPropertyDataType.Object: break; default: break; } return(result); }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.SMSTxCounter: this.SMSTxCounter = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.SMSRxCounter: this.SMSRxCounter = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TxData: this.TxData = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.RxData: this.RxData = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.MaxMessageSize: this.MaxMessageSize = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.AverageMessageSize: this.AverageMessageSize = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.Latitude: this.Latitude = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Longitude: this.Longitude = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Altitude: this.Altitude = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Uncertainty: this.Uncertainty = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Velocity: this.Velocity = reader.TlvRecord.Value; result = true; break; case ResourceID.Timestamp: this.Timestamp = reader.TlvRecord.ValueAsDateTime(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.LWM2MServerURI: this.LWM2MServerURI = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.BootstrapServer: this.BootstrapServer = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.SecurityMode: this.SecurityMode = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.PublicKeyorIdentity: this.PublicKeyorIdentity = reader.TlvRecord.Value; result = true; break; case ResourceID.ServerPublicKeyorIdentity: this.ServerPublicKeyorIdentity = reader.TlvRecord.Value; result = true; break; case ResourceID.SecretKey: this.SecretKey = reader.TlvRecord.Value; result = true; break; case ResourceID.SMSSecurityMode: this.SMSSecurityMode = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.SMSBindingKeyParameters: this.SMSBindingKeyParameters = reader.TlvRecord.Value; result = true; break; case ResourceID.SMSBindingSecretKeys: this.SMSBindingSecretKeys = reader.TlvRecord.Value; result = true; break; case ResourceID.LWM2MServerSMSNumber: this.LWM2MServerSMSNumber = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ShortServerID: this.ShortServerID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ClientHoldOffTime: this.ClientHoldOffTime = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.Property: this.Property = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Group: this.Group = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.Description: this.Description = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Attached: this.Attached = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.Enabled: this.Enabled = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.NotifyEn: this.NotifyEn = reader.TlvRecord.ValueAsBoolean(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.DeviceID: this.DeviceID = reader.TlvRecord.Value; result = true; break; case ResourceID.ParentID: this.ParentID = reader.TlvRecord.Value; result = true; break; case ResourceID.DeviceType: this.DeviceType = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Name: this.Name = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Description: this.Description = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.FCAP: this.FCAP = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.TenantID: this.TenantID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TenantChallenge: this.TenantChallenge = reader.TlvRecord.Value; result = true; break; case ResourceID.HashIterations: this.HashIterations = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TenantHash: this.TenantHash = reader.TlvRecord.Value; result = true; break; case ResourceID.Status: this.Status = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
protected override void DoPut(CoapExchange exchange) { Request request = exchange.Request; bool processed = false; if ((request.ContentType == TlvConstant.CONTENT_TYPE_TLV)) { using (TlvReader reader = new TlvReader(request.Payload)) { this.Deserialise(reader); processed = true; } } if (processed) { Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed); exchange.Respond(response); if (Updated != null) Updated(this, null); } else { Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest); exchange.Respond(response); } }
private Property ParseProperty(ObjectDefinition objectDefinition, PropertyDefinition propertyDefinition, int requestContentType, Response response) { Property result = null; int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); Model.Object lwm2mObject = ObjectUtils.ParseObject(objectDefinition, reader); if ((lwm2mObject != null) && (lwm2mObject.Properties.Count > 0)) { foreach (Property item in lwm2mObject.Properties) { if (item.PropertyDefinitionID == propertyDefinition.PropertyDefinitionID) { result = item; break; } } } } else if ((contentType == MediaType.TextPlain) || (contentType == TlvConstant.CONTENT_TYPE_PLAIN)) { string text = Encoding.UTF8.GetString(response.Payload); result = new Property(); result.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; result.PropertyID = propertyDefinition.PropertyID; result.Value = new PropertyValue(ObjectUtils.GetValue(text, propertyDefinition)); } else if ((contentType == MediaType.ApplicationJson) || (contentType == TlvConstant.CONTENT_TYPE_JSON)) { JsonReader reader = new JsonReader(new MemoryStream(response.Payload)); //LWM2MObject lwm2mObject = ObjectUtils.ParseObject(objectDefinition, reader); //if ((lwm2mObject != null) && (lwm2mObject.Properties.Count > 0)) //{ // foreach (LWM2MProperty item in lwm2mObject.Properties) // { // if (item.PropertyDefinitionID == propertyDefinition.PropertyDefinitionID) // { // result = item; // break; // } // } //} result = ObjectUtils.ParseProperty(propertyDefinition, reader); } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.ObjectID: this.ObjectID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ObjectInstanceID: this.ObjectInstanceID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ACLs: this.ACLs = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.AccessControlOwner: this.AccessControlOwner = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
public static Model.Object ParseObject(ObjectDefinition objectDefinition, TlvReader reader) { Model.Object result = null; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { TlvReader objectReader = new TlvReader(reader.TlvRecord.Value); result = ParseObject(objectDefinition, objectReader); if (result != null) { result.InstanceID = reader.TlvRecord.Identifier.ToString(); } break; } if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { if (result == null) { result = new Model.Object(); result.ObjectID = objectDefinition.ObjectID; result.ObjectDefinitionID = objectDefinition.ObjectDefinitionID; } if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue) { string propertyID = reader.TlvRecord.Identifier.ToString(); PropertyDefinition property = objectDefinition.GetProperty(propertyID); if (property != null) { Property lwm2mProperty = new Property(); lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID; lwm2mProperty.PropertyID = property.PropertyID; lwm2mProperty.Value = new PropertyValue(GetValue(reader, property)); result.Properties.Add(lwm2mProperty); } } else if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources) { string propertyID = reader.TlvRecord.Identifier.ToString(); PropertyDefinition property = objectDefinition.GetProperty(propertyID); if (property != null) { Property lwm2mProperty = new Property(); lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID; lwm2mProperty.PropertyID = property.PropertyID; result.Properties.Add(lwm2mProperty); TlvReader arrayReader = new TlvReader(reader.TlvRecord.Value); while (arrayReader.Read()) { if (arrayReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance) { string value = GetValue(arrayReader, property); if (value != null) { if (lwm2mProperty.Values == null) lwm2mProperty.Values = new List<PropertyValue>(); PropertyValue propertyValue = new PropertyValue(); propertyValue.PropertyValueID = arrayReader.TlvRecord.Identifier.ToString(); propertyValue.Value = value; lwm2mProperty.Values.Add(propertyValue); } } } } } } } return result; }
private Model.Object ParseObject(ObjectDefinition objectDefinition, int requestContentType, Response response) { Model.Object result = null; int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); result = ObjectUtils.ParseObject(objectDefinition, reader); } else if (contentType == MediaType.ApplicationJson) { JsonReader reader = new JsonReader(new MemoryStream(response.Payload)); result = ObjectUtils.ParseObject(objectDefinition, reader); } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.ShortServerID: this.ShortServerID = reader.TlvRecord.ValueAsInt32(); result = true; break; case ResourceID.Lifetime: this.Lifetime = reader.TlvRecord.ValueAsInt32(); result = true; break; case ResourceID.DefaultMinimumPeriod: this.DefaultMinimumPeriod = reader.TlvRecord.ValueAsInt32(); result = true; break; case ResourceID.DefaultMaximumPeriod: this.DefaultMaximumPeriod = reader.TlvRecord.ValueAsInt32(); result = true; break; case ResourceID.DisableTimeout: this.DisableTimeout = reader.TlvRecord.ValueAsInt32(); result = true; break; case ResourceID.NotificationStoringWhenOffline: this.NotificationStoringWhenOffline = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.Binding: TBindingMode binding = TBindingMode.NotSet; string bindingText = reader.TlvRecord.ValueAsString(); switch (bindingText) { case "U": binding = TBindingMode.UDP; break; case "UQ": binding = TBindingMode.QueuedUDP; break; case "S": binding = TBindingMode.SMS; break; case "SQ": binding = TBindingMode.QueuedSMS; break; case "US": binding = TBindingMode.UDPSMS; break; case "UQS": binding = TBindingMode.QueuedUDPSMS; break; default: break; } this.Binding = binding; result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.ShortServerID: this.ShortServerID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.Lifetime: this.Lifetime = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.DefaultMinimumPeriod: this.DefaultMinimumPeriod = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.DefaultMaximumPeriod: this.DefaultMaximumPeriod = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.DisableTimeout: this.DisableTimeout = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.NotificationStoringWhenDisabledorOffline: this.NotificationStoringWhenDisabledorOffline = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.Binding: this.Binding = reader.TlvRecord.ValueAsString(); result = true; break; default: break; } } } return result; }
public virtual bool Deserialise(TlvReader reader) { return true; }
public void LoadResources() { if (Directory.Exists(RESOURCES_CACHE)) { foreach (string directory in Directory.GetDirectories(RESOURCES_CACHE)) { string id = Path.GetFileName(directory); int objectID; if (int.TryParse(id, out objectID)) { LWM2MResources resources = null; switch (objectID) { case 0: resources = _SecurityResources; break; case 1: resources = _ServerResources; break; case 3: resources = new DeviceResources(); break; case 4: resources = new ConnectivityMonitoringResources(); break; case 5: resources = new FirmwareUpdateResources(); break; case 6: resources = new LocationResources(); break; case 7: resources = new ConnectivityStatisticsResources(); break; case 15: resources = new DeviceCapabilityResources(); break; case 20000: resources = new FlowObjectResources(); break; case 20001: resources = new FlowAccessResources(); break; case 20005: resources = new FlowCommandResources(); EventHandler <ChildCreatedEventArgs> handler = (s, e) => { FlowCommandResource flowCommandResource = e.Resource as FlowCommandResource; if (flowCommandResource != null) { flowCommandResource.Updated += new EventHandler(FlowCommand_Updated); FlowCommand_Updated(flowCommandResource, null); } }; resources.ChildCreated += handler; break; default: break; } if (resources != null) { foreach (string fileName in Directory.GetFiles(directory, "*.tlv")) { LWM2MResource resource = null; switch (objectID) { case 0: resource = new SecurityResource(Path.GetFileNameWithoutExtension(fileName)); break; case 1: resource = new ServerResource(Path.GetFileNameWithoutExtension(fileName)); break; case 3: resource = new DeviceResource(); break; case 4: resource = new ConnectivityMonitoringResource(); break; case 5: resource = new FirmwareUpdateResource(); break; case 6: resource = new LocationResource(); break; case 7: resource = new ConnectivityStatisticsResource(); break; case 15: resource = new DeviceCapabilityResource(Path.GetFileNameWithoutExtension(fileName)); break; case 20000: resource = new FlowObjectResource(); resource.Updated += new EventHandler(FlowObject_Updated); break; case 20001: resource = new FlowAccessResource(); break; case 20005: resource = new FlowCommandResource(Path.GetFileNameWithoutExtension(fileName)); resource.Updated += new EventHandler(FlowCommand_Updated); break; default: break; } if (resource != null) { using (Stream stream = File.OpenRead(fileName)) { TlvReader reader = new TlvReader(stream); if (resource.Deserialise(reader)) { resources.Add(resource); } } if (objectID == 0) { SecurityResource securityResource = resource as SecurityResource; if (securityResource.SecurityMode == TSecurityMode.PreSharedKey) { UsePSK(System.Text.Encoding.UTF8.GetString(securityResource.ClientPublicKey), StringUtils.HexString(securityResource.SecretKey)); } } else if (objectID == 20000) { FlowObjectResource flowObjectResource = resource as FlowObjectResource; if (flowObjectResource != null) { flowObjectResource.TenantHash = null; } } } } this.AddResources(resources); } } } } else { LoadDefaultResources(); } }
public static Model.Object ParseObject(ObjectDefinition objectDefinition, TlvReader reader) { Model.Object result = null; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { TlvReader objectReader = new TlvReader(reader.TlvRecord.Value); result = ParseObject(objectDefinition, objectReader); if (result != null) { result.InstanceID = reader.TlvRecord.Identifier.ToString(); } break; } if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { if (result == null) { result = new Model.Object(); result.ObjectID = objectDefinition.ObjectID; result.ObjectDefinitionID = objectDefinition.ObjectDefinitionID; } if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue) { string propertyID = reader.TlvRecord.Identifier.ToString(); PropertyDefinition property = objectDefinition.GetProperty(propertyID); if (property != null) { Property lwm2mProperty = new Property(); lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID; lwm2mProperty.PropertyID = property.PropertyID; lwm2mProperty.Value = new PropertyValue(GetValue(reader, property)); result.Properties.Add(lwm2mProperty); } } else if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources) { string propertyID = reader.TlvRecord.Identifier.ToString(); PropertyDefinition property = objectDefinition.GetProperty(propertyID); if (property != null) { Property lwm2mProperty = new Property(); lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID; lwm2mProperty.PropertyID = property.PropertyID; result.Properties.Add(lwm2mProperty); TlvReader arrayReader = new TlvReader(reader.TlvRecord.Value); while (arrayReader.Read()) { if (arrayReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance) { string value = GetValue(arrayReader, property); if (value != null) { if (lwm2mProperty.Values == null) { lwm2mProperty.Values = new List <PropertyValue>(); } PropertyValue propertyValue = new PropertyValue(); propertyValue.PropertyValueID = arrayReader.TlvRecord.Identifier.ToString(); propertyValue.Value = value; lwm2mProperty.Values.Add(propertyValue); } } } } } } } return(result); }
protected override void DoPut(CoapExchange exchange) { if (exchange.Request.ContentType == TlvConstant.CONTENT_TYPE_TLV) { using (TlvReader reader = new TlvReader(exchange.Request.Payload)) { this.Deserialise(reader); } Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed); exchange.Respond(response); } else base.DoPut(exchange); }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.Package: this.Package = reader.TlvRecord.Value; result = true; break; case ResourceID.PackageURI: this.PackageURI = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.State: this.State = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.UpdateSupportedObjects: this.UpdateSupportedObjects = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.UpdateResult: this.UpdateResult = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.PackageName: this.PackageName = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.PackageVersion: this.PackageVersion = reader.TlvRecord.ValueAsString(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.InterfaceName: this.InterfaceName = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Enable: this.Enable = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.RadioEnabled: this.RadioEnabled = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.Status: this.Status = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.BSSID: this.BSSID = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.SSID: this.SSID = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.BroadcastSSID: this.BroadcastSSID = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.BeaconEnabled: this.BeaconEnabled = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.Mode: this.Mode = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.Channel: this.Channel = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.SupportedChannels: this.SupportedChannels = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.ChannelsInUse: this.ChannelsInUse = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.RegulatoryDomain: this.RegulatoryDomain = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Standard: this.Standard = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.AuthenticationMode: this.AuthenticationMode = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.EncryptionMode: this.EncryptionMode = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.WPAPreSharedKey: this.WPAPreSharedKey = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WPAKeyPhrase: this.WPAKeyPhrase = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WEPEncryptionType: this.WEPEncryptionType = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.WEPKeyIndex: this.WEPKeyIndex = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.WEPKeyPhrase: this.WEPKeyPhrase = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WEPKey1: this.WEPKey1 = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WEPKey2: this.WEPKey2 = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WEPKey3: this.WEPKey3 = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WEPKey4: this.WEPKey4 = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.RADIUSServer: this.RADIUSServer = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.RADIUSServerPort: this.RADIUSServerPort = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.RADIUSSecret: this.RADIUSSecret = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.WMMSupported: this.WMMSupported = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.WMMEnabled: this.WMMEnabled = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.MACControlEnabled: this.MACControlEnabled = reader.TlvRecord.ValueAsBoolean(); result = true; break; case ResourceID.MACAddressList: this.MACAddressList = StringResources.Deserialise(reader); result = true; break; case ResourceID.TotalBytesSent: this.TotalBytesSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TotalBytesReceived: this.TotalBytesReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TotalPacketsSent: this.TotalPacketsSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TotalPacketsReceived: this.TotalPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.TransmitErrors: this.TransmitErrors = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ReceiveErrors: this.ReceiveErrors = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.UnicastPacketsSent: this.UnicastPacketsSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.UnicastPacketsReceived: this.UnicastPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.MulticastPacketsSent: this.MulticastPacketsSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.MulticastPacketsReceived: this.MulticastPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.BroadcastPacketsSent: this.BroadcastPacketsSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.BroadcastPacketsReceived: this.BroadcastPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.DiscardPacketsSent: this.DiscardPacketsSent = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.DiscardPacketsReceived: this.DiscardPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.UnknownPacketsReceived: this.UnknownPacketsReceived = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.VendorSpecificExtensions: //this.VendorSpecificExtensions = reader.TlvRecord.Value; result = true; break; default: break; } } } return result; }
void ObserveResponse(object sender, ResponseEventArgs e) { lock (this) { #if DEBUG Console.WriteLine("NOTIFY Recieved"); #endif Request request = sender as Request; if (request != null) { Console.WriteLine(request.UriPath); ObserveRequest observeRequest = null; for (int index = 0; index < _ObserveRequests.Count; index++) { if (_ObserveRequests[index].Request.UriPath == request.UriPath) { observeRequest = _ObserveRequests[index]; break; } } string[] objectInstanceResource = request.UriPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (observeRequest != null) { #if DEBUG if (observeRequest.PropertyDefinition != null) Console.WriteLine(observeRequest.PropertyDefinition.Name); #endif if ((e.Response.ContentType == MediaType.TextPlain) || (e.Response.ContentType == TlvConstant.CONTENT_TYPE_PLAIN)) { #if DEBUG string payload = Encoding.UTF8.GetString(e.Response.Payload); Console.WriteLine(payload); #endif } else if (e.Response.ContentType == TlvConstant.CONTENT_TYPE_TLV) { Object lwm2mObject = null; if (e.Response.Payload != null) { TlvReader reader = new TlvReader(e.Response.Payload); lwm2mObject = ObjectUtils.ParseObject(observeRequest.ObjectDefinition, reader); } if ((lwm2mObject != null) && (objectInstanceResource.Length > 1) && (lwm2mObject.InstanceID == null)) { // Instance ID not in TLV, take from request URI lwm2mObject.InstanceID = objectInstanceResource[1]; } if ((lwm2mObject != null) && (lwm2mObject.Properties.Count > 0)) { #if DEBUG foreach (Property item in lwm2mObject.Properties) { if (observeRequest.PropertyDefinition == null || item.PropertyDefinitionID == observeRequest.PropertyDefinition.PropertyDefinitionID) { if (item.Value != null) { Console.WriteLine(item.Value.Value); } else if (item.Values != null) { string[] values = new string[item.Values.Count]; int index = 0; foreach (PropertyValue value in item.Values) { Console.WriteLine(value.Value); values[index++] = value.Value; } } break; } } #endif } if (lwm2mObject != null) BusinessLogicFactory.Events.ObservationNotify(this, lwm2mObject); } } } } }
private List<Model.Object> ParseObjects(ObjectDefinition objectDefinition, int requestContentType, Response response) { List<Model.Object> result = new List<Model.Object>(); int contentType; if (response.ContentType == -1) { contentType = requestContentType; } else { contentType = response.ContentType; } if (contentType == TlvConstant.CONTENT_TYPE_TLV) { TlvReader reader = new TlvReader(response.Payload); while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { TlvReader objectReader = new TlvReader(reader.TlvRecord.Value); Model.Object item = ObjectUtils.ParseObject(objectDefinition, objectReader); if (item != null) { item.InstanceID = reader.TlvRecord.Identifier.ToString(); result.Add(item); } } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.NetworkBearer: this.NetworkBearer = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.AvailableNetworkBearers: this.AvailableNetworkBearers = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.RadioSignalStrength: this.RadioSignalStrength = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.LinkQuality: this.LinkQuality = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.IPAddresses: this.IPAddresses = StringResources.Deserialise(reader); result = true; break; case ResourceID.RouterIPAddresses: this.RouterIPAddresses = StringResources.Deserialise(reader); result = true; break; case ResourceID.LinkUtilization: this.LinkUtilization = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.APNs: this.APNs = StringResources.Deserialise(reader); result = true; break; case ResourceID.CellID: this.CellID = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.SMNC: this.SMNC = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.SMCC: this.SMCC = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
public static LWM2MAccessControlResource Deserialise(Request request) { LWM2MAccessControlResource result = null; string name = request.UriPaths.Last(); if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV)) { result = new LWM2MAccessControlResource(name); using (TlvReader reader = new TlvReader(request.Payload)) { result.Deserialise(reader); } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.Manufacturer: this.Manufacturer = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.ModelNumber: this.ModelNumber = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.SerialNumber: this.SerialNumber = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.FirmwareVersion: this.FirmwareVersion = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.AvailablePowerSources: this.AvailablePowerSources = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.PowerSourceVoltages: this.PowerSourceVoltages = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.PowerSourceCurrents: this.PowerSourceCurrents = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.BatteryLevel: this.BatteryLevel = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.MemoryFree: this.MemoryFree = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.ErrorCodes: this.ErrorCodes = IntegerResources.Deserialise(reader); result = true; break; case ResourceID.CurrentTime: this.CurrentTime = reader.TlvRecord.ValueAsDateTime(); result = true; break; case ResourceID.UTCOffset: this.UTCOffset = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Timezone: this.Timezone = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.SupportedBindingandModes: this.SupportedBindingandModes = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.DeviceType: this.DeviceType = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.HardwareVersion: this.HardwareVersion = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.SoftwareVersion: this.SoftwareVersion = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.BatteryStatus: this.BatteryStatus = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.MemoryTotal: this.MemoryTotal = reader.TlvRecord.ValueAsInt64(); result = true; break; default: break; } } } return result; }
public void LoadResources() { if (Directory.Exists(RESOURCES_CACHE)) { foreach (string directory in Directory.GetDirectories(RESOURCES_CACHE)) { string id = Path.GetFileName(directory); int objectID; if (int.TryParse(id, out objectID)) { LWM2MResources resources = null; switch (objectID) { case 0: resources = _SecurityResources; break; case 1: resources = _ServerResources; break; case 3: resources = new DeviceResources(); break; case 4: resources = new ConnectivityMonitoringResources(); break; case 5: resources = new FirmwareUpdateResources(); break; case 6: resources = new LocationResources(); break; case 7: resources = new ConnectivityStatisticsResources(); break; case 15: resources = new DeviceCapabilityResources(); break; case 20000: resources = new FlowObjectResources(); break; case 20001: resources = new FlowAccessResources(); break; case 20005: resources = new FlowCommandResources(); EventHandler<ChildCreatedEventArgs> handler = (s, e) => { FlowCommandResource flowCommandResource = e.Resource as FlowCommandResource; if (flowCommandResource != null) { flowCommandResource.Updated += new EventHandler(FlowCommand_Updated); FlowCommand_Updated(flowCommandResource, null); } }; resources.ChildCreated += handler; break; default: break; } if (resources != null) { foreach (string fileName in Directory.GetFiles(directory, "*.tlv")) { LWM2MResource resource = null; switch (objectID) { case 0: resource = new SecurityResource(Path.GetFileNameWithoutExtension(fileName)); break; case 1: resource = new ServerResource(Path.GetFileNameWithoutExtension(fileName)); break; case 3: resource = new DeviceResource(); break; case 4: resource = new ConnectivityMonitoringResource(); break; case 5: resource = new FirmwareUpdateResource(); break; case 6: resource = new LocationResource(); break; case 7: resource = new ConnectivityStatisticsResource(); break; case 15: resource = new DeviceCapabilityResource(Path.GetFileNameWithoutExtension(fileName)); break; case 20000: resource = new FlowObjectResource(); resource.Updated += new EventHandler(FlowObject_Updated); break; case 20001: resource = new FlowAccessResource(); break; case 20005: resource = new FlowCommandResource(Path.GetFileNameWithoutExtension(fileName)); resource.Updated += new EventHandler(FlowCommand_Updated); break; default: break; } if (resource != null) { using(Stream stream = File.OpenRead(fileName)) { TlvReader reader = new TlvReader(stream); if (resource.Deserialise(reader)) resources.Add(resource); } if (objectID == 0) { SecurityResource securityResource = resource as SecurityResource; if (securityResource.SecurityMode == TSecurityMode.PreSharedKey) { UsePSK(System.Text.Encoding.UTF8.GetString(securityResource.ClientPublicKey), StringUtils.HexString(securityResource.SecretKey)); } } else if (objectID == 20000) { FlowObjectResource flowObjectResource = resource as FlowObjectResource; if (flowObjectResource != null) flowObjectResource.TenantHash = null; } } } this.AddResources(resources); } } } } else LoadDefaultResources(); }
public virtual void Deserialise(TlvReader reader) { }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.URL: this.URL = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.CustomerKey: this.CustomerKey = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.CustomerSecret: this.CustomerSecret = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.RememberMeToken: this.RememberMeToken = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.RememberMeTokenExpiry: this.RememberMeTokenExpiry = reader.TlvRecord.ValueAsDateTime(); result = true; break; default: break; } } } return result; }
public override bool Deserialise(TlvReader reader) { bool result = false; while (reader.Read()) { if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance) { if (string.Compare(this.Name, reader.TlvRecord.Identifier.ToString()) != 0) { this.Name = reader.TlvRecord.Identifier.ToString(); } reader = new TlvReader(reader.TlvRecord.Value); } else if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet)) { switch ((ResourceID)reader.TlvRecord.Identifier) { case ResourceID.CommandID: this.CommandID = reader.TlvRecord.Value; result = true; break; case ResourceID.CommandTypeID: this.CommandTypeID = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.Status: this.Status = reader.TlvRecord.ValueAsInt64(); result = true; break; case ResourceID.StatusCode: this.StatusCode = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.ParameterName: this.ParameterName = StringResources.Deserialise(reader); result = true; break; case ResourceID.ParameterValue: this.ParameterValue = StringResources.Deserialise(reader); result = true; break; case ResourceID.ResultContentType: this.ResultContentType = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.ResultContent: this.ResultContent = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.ErrorContentType: this.ErrorContentType = reader.TlvRecord.ValueAsString(); result = true; break; case ResourceID.ErrorContent: this.ErrorContent = reader.TlvRecord.ValueAsString(); result = true; break; default: break; } } } return result; }