Exemplo n.º 1
0
 public static void ShowDevices(SkeliaClient client)
 {
     foreach (var dev in client.GetDevices().Items.Select(x => x.Device).OrderBy(x => x.DataSector.Id))
     {
         Console.WriteLine($"{dev}\n\n");
     }
 }
Exemplo n.º 2
0
        private Dictionary <Int32, List <VM_Device> > LoadDevices()
        {
            Task <List <Device> > getDevices = new Task <List <Device> >(() =>
            {
                List <Device> devices = new List <Device>();
                String dirPath        = System.IO.Path.Combine(AppConfig.FolderPathOf.RootStorageFolder, AppConfig.FolderPathOf.DevicesFolder);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                String filePath = System.IO.Path.Combine(dirPath, "Devices.json");
                devices         = Client.GetDevices().Items.Select(x => x.Device).ToList();

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

            getDevices.Start();

            Dictionary <Int32, List <VM_Device> > devicesDict = new Dictionary <int, List <VM_Device> >();

            foreach (var dev in getDevices.Result)
            {
                if (!devicesDict.ContainsKey(dev.DataSector.Id))
                {
                    devicesDict.Add(dev.DataSector.Id, new List <VM_Device>());
                }
                devicesDict[dev.DataSector.Id].Add(new VM_Device(dev));
            }
            return(devicesDict);
        }