public static StringResources Deserialise(TlvReader reader)
 {
     StringResources result = null;
     if (reader.TlvRecord == null)
         reader.Read();
     if (reader.TlvRecord != null)
     {
         if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
         {
             result = new StringResources(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)
                         {
                             StringResource childResource = new StringResource(childReader.TlvRecord.Identifier.ToString());
                             childResource.Value = childReader.TlvRecord.ValueAsString();
                             result.Add(childResource);
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
示例#2
0
        public void LoadDefaultResources()
        {
            DeviceResources deviceResources = new DeviceResources();
            IntegerResources availablePowerSources = new IntegerResources(string.Empty);
            availablePowerSources.Add(new IntegerResource("0") { Value = 1 });
            availablePowerSources.Add(new IntegerResource("1") { Value = 5 });

            IntegerResources powerSourceVoltage = new IntegerResources(string.Empty);
            powerSourceVoltage.Add(new IntegerResource("0") { Value = 3800 });
            powerSourceVoltage.Add(new IntegerResource("1") { Value = 5000 });

            IntegerResources powerSourceCurrent = new IntegerResources(string.Empty);
            powerSourceCurrent.Add(new IntegerResource("0") { Value = 3800 });
            powerSourceCurrent.Add(new IntegerResource("1") { Value = 5000 });

            IntegerResources errorCode = new IntegerResources(string.Empty);
            errorCode.Add(new IntegerResource("0") { Value = 0 });

            deviceResources.Add(new DeviceResource() { Manufacturer = "Open Mobile Alliance", ModelNumber = "Lightweight M2M Client", SerialNumber = "345000123", FirmwareVersion = "1.0", AvailablePowerSources = availablePowerSources, PowerSourceVoltages = powerSourceVoltage, PowerSourceCurrents = powerSourceCurrent, BatteryLevel = 100, MemoryFree = 15, ErrorCodes = errorCode, CurrentTime = DateTime.UtcNow, UTCOffset = "+12:00", SupportedBindingandModes = "U" });

            ConnectivityMonitoringResources connectivityMonitoringResources = new ConnectivityMonitoringResources();
            IntegerResources availableNetworkBearer = new IntegerResources(string.Empty);
            availableNetworkBearer.Add(new IntegerResource("0") { Value = 0 });

            StringResources ipAddresses = new StringResources(string.Empty);
            ipAddresses.Add(new StringResource("0") { Value = "192.168.148.18" });

            StringResources routerIPAddresse = new StringResources(string.Empty);
            routerIPAddresse.Add(new StringResource("0") { Value = "192.168.148.1" });

            StringResources apn = new StringResources(string.Empty);
            apn.Add(new StringResource("0") { Value = "internet" });

            connectivityMonitoringResources.Add(new ConnectivityMonitoringResource() { NetworkBearer = 0, AvailableNetworkBearers = availableNetworkBearer, RadioSignalStrength = 92, LinkQuality = 2, IPAddresses = ipAddresses, RouterIPAddresses = routerIPAddresse, LinkUtilization = 5, APNs = apn });
            this.AddResources(deviceResources);
            this.AddResources(connectivityMonitoringResources);
            this.AddResources(new FirmwareUpdateResources());
            FlowObjectResources flowObjectResources = new FlowObjectResources();
            FlowObjectResource flowObjectResource = new FlowObjectResource() { DeviceType = "EVOKE Flow", TenantID = 1 };
            flowObjectResource.Updated +=  new EventHandler(FlowObject_Updated);
            flowObjectResources.Add(flowObjectResource);

            this.AddResources(flowObjectResources);
            this.AddResources(new FlowAccessResources());

            FlowCommandResources flowCommandResources = 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);
                }
            };
            flowCommandResources.ChildCreated += handler;
            this.AddResources(flowCommandResources);

            LocationResources locationResources = new LocationResources();
            locationResources.Add(new LocationResource() { Latitude = "-41.0", Longitude = "174.0", Altitude = "150", Uncertainty = "1.0", Velocity = new byte[] { 0, 45, 0, 0 }, Timestamp = DateTime.UtcNow });
            this.AddResources(locationResources);

            DeviceCapabilityResources deviceCapabilityResources = new DeviceCapabilityResources();
            deviceCapabilityResources.Add(new DeviceCapabilityResource("0") { Attached = true, Enabled = true, Group = 0, Description = "Temp", Property = "2;3" });
            deviceCapabilityResources.Add(new DeviceCapabilityResource("1") { Attached = true, Enabled = true, Group = 1, Description = "Control", Property = "1;2" });
            deviceCapabilityResources.Add(new DeviceCapabilityResource("2") { Attached = true, Enabled = false, Group = 2, Description = "Bluetooth", Property = "0" });
            deviceCapabilityResources.Add(new DeviceCapabilityResource("3") { Attached = false, Enabled = false, Group = 2, Description = "WiFi", Property = "2" });

            this.AddResources(deviceCapabilityResources);
        }