Beispiel #1
0
        public int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            uint sig = BitConverter.ToUInt32(Buffer, cursor);

            cursor += TypeSizes.INT;

            if (sig == SIGNATURE)
            {
                version = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                uint entries = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                // decrypt old versions first (v4 first unencryted)
                // note: this might need different passwords for other versions
                if (version <= VERSION3)
                {
#if WINCLR && X86
                    uint streamlength = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    uint expectedresponse = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    Crush32.Decrypt(Buffer, cursor, (int)streamlength, version, expectedresponse, PASSWORDV3);
#else
                    throw new Exception(RooFile.ERRORCRUSHPLATFORM);
#endif
                }

                // now load strings
                StringResources.Clear();
                StringResources.Capacity = (int)entries + 100;
                for (int i = 0; i < entries; i++)
                {
                    RsbResourceID entry = new RsbResourceID(version, Buffer, cursor);
                    cursor += entry.ByteLength;

                    StringResources.Add(entry);
                }
            }
            else
            {
                throw new Exception("Wrong RSC file signature: " + sig + " (expected " + SIGNATURE + ").");
            }

            return(cursor - StartIndex);
        }
Beispiel #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);
        }