public async Task InitializeAsync()
 {
     try
     {
         await _userInterfaceService.ShowBusyIndicatorAsync();
         Model = await _restService.GetAsync<DevicesModel>(new Uri("api/devicemanager/devices", UriKind.Relative));
         var sortedModel = new DevicesModel();
         BuildHierarchy(Model, sortedModel, Model.DeviceList.Where(d => d.ParentID == null).Select(d => d.ID).FirstOrDefault(), 0);
         Model = sortedModel;
         await _userInterfaceService.HideBusyIndicatorAsync();
     }
     catch (Exception ex)
     {
         await _userInterfaceService.ShowFeedbackAsync(ex);
     }
 }
 private void BuildHierarchy(DevicesModel model, DevicesModel sortedModel, string parentId, int level)
 {
     foreach (var device in model.DeviceList.Where(d => d.ParentID == parentId))
     {
         device.Level = level;
         if (string.IsNullOrEmpty(device.Description))
             device.Description = device.ID;
         if (String.IsNullOrEmpty(device.Class))
             device.Class = "Unknown";
         sortedModel.DeviceList.Add(device);
         var children = Model.DeviceList.Where(d => d.ParentID == device.ID);
         if (children.Count() > 0)
         {
             device.HasChildren = true;
             BuildHierarchy(Model, sortedModel, device.ID, level + 1);
         }
     }   // for each device
 }