Exemplo n.º 1
0
 public static void ShowDataSectors(SkeliaClient client)
 {
     client.GetDataSectors().Items.ForEach(x => Console.WriteLine(x));
 }
Exemplo n.º 2
0
        private async void LoadDataSectors()
        {
            await Task.Run(() =>
            {
                String dirPath = System.IO.Path.Combine(AppConfig.FolderPathOf.RootStorageFolder, AppConfig.FolderPathOf.DataSectorsFolder);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                String filePath = System.IO.Path.Combine(dirPath, "DataSectors.json");
                List <DataSector> dataSectors = Client.GetDataSectors().Items;

                using (StreamWriter stream = File.CreateText(filePath))
                {
                    JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
                    {
                        Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
                    });
                    serializer.Serialize(stream, dataSectors);
                }
            });

            //
            await Task.Run(() =>
            {
                String dirPath = System.IO.Path.Combine(AppConfig.FolderPathOf.RootStorageFolder, AppConfig.FolderPathOf.DataSectorsFolder);
                if (!Directory.Exists(dirPath))
                {
                    return;
                }
                String filePath = System.IO.Path.Combine(dirPath, "DataSectors.json");

                List <DataSector> dataSectors = new List <DataSector>();
                using (StreamReader file = File.OpenText(filePath))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    dataSectors.AddRange((List <DataSector>)serializer.Deserialize(file, typeof(List <DataSector>)));
                }
                Dictionary <Int32, List <VM_Device> > devices = LoadDevices();
                Dictionary <Int32, VM_DeviceType> devTypes    = new Dictionary <int, VM_DeviceType>();
                foreach (var devs in devices.Values)
                {
                    foreach (var dev in devs)
                    {
                        if (devTypes.ContainsKey(dev.Type.Id))
                        {
                            continue;
                        }
                        devTypes.Add(dev.Type.Id, new VM_DeviceType(dev.Type));
                    }
                }

                Dispatcher.Invoke(() =>
                {
                    DataSectors.Clear();
                    dataSectors.ForEach(x => DataSectors.Add(new VM_DataSector(x)));
                    foreach (var x in DataSectors)
                    {
                        if (!devices.ContainsKey(x.Id))
                        {
                            continue;
                        }
                        foreach (var dev in devices[x.Id])
                        {
                            x.Devices.Add(dev);
                        }
                    }
                    DeviceTypes.Clear();
                    foreach (var devType in devTypes.Values)
                    {
                        DeviceTypes.Add(devType);
                    }
                });
            });
        }