Exemplo n.º 1
0
        public void StoreData(BaseData baseData, BatteryUsage batteryUsage)
        {
            WriteMainData(baseData, batteryUsage);
            var currentData = ReadMainData();

            WriteAuthToken(baseData);
            var authTokenList = ReadAuthToken();
        }
Exemplo n.º 2
0
        public void WriteMainData(BaseData baseData, BatteryUsage batteryUsage)
        {
            if (!Directory.Exists(PathDataStorage))
            {
                Directory.CreateDirectory(PathDataStorage);
            }

            var currentData = new MainData
            {
                RegionTier        = baseData.RegionTier,
                RegionDescription = baseData.RegionDescription,
                AccountId         = baseData.AccountId,
                ClientId          = baseData.ClientId,
                Networks          = new List <Network>()
            };

            for (int i = 0; i < batteryUsage.networks.Length; i++)
            {
                var cameras = new List <Camera>();
                for (int n = 0; n < batteryUsage.networks[i].cameras.Length; n++)
                {
                    cameras.Add(new Camera
                    {
                        Name = batteryUsage.networks[i].cameras[n].name,
                        Id   = batteryUsage.networks[i].cameras[n].id
                    });
                }

                currentData.Networks.Add(new Network
                {
                    Name    = batteryUsage.networks[i].name,
                    Id      = batteryUsage.networks[i].network_id,
                    Cameras = cameras
                });
            }

            currentData.TimestampLastWritten = DateTime.Now;
            var currentDataAsString = JsonConvert.SerializeObject(currentData);

            File.WriteAllText(PathAndFileNameMainDataStorage, currentDataAsString);
        }