//Initialize "devices" list and Channel and volumeDevices public async Task initialize(StorageFolder devices_folder_) { is_initialized = true; // Device Manager Metadata Initialization devices_folder = devices_folder_; devices_info_file = (StorageFile) await devices_folder.TryGetItemAsync("devices_info.txt"); if(devices_info_file == null) { System.Diagnostics.Debug.WriteLine("No Devices info file!"); return; } IList<string> input = await FileIO.ReadLinesAsync(devices_info_file); int num_channel_devices = Convert.ToInt32(input[0]); int cur_index = 1; String device_name; StorageFile cur_device_input_file; // Channel Device Initialization for(int i = 0; i < num_channel_devices; ++i) { device_name = input[cur_index++]; try { cur_device_input_file = (StorageFile)await get_input_file_from_name(device_name, 'c'); ChannelDevice c_device = new ChannelDevice(device_name, cur_device_input_file); channel_devices.Add(c_device); } catch(Exception except) { System.Diagnostics.Debug.WriteLine(except.Message); } } // Get Current Channel Device int chan_index = 0; bool found = false; string cur_chan_device_name = input[cur_index++]; foreach(ChannelDevice cur in channel_devices) { if(cur.get_name().Equals(cur_chan_device_name)) { found = true; break; } chan_index++; } if (!found) { // Throw Exception about channel device not found } else { channelController = channel_devices[chan_index]; await channelController.initialize(); } // Volume Device Initialization int num_vol_devices = Convert.ToInt32(input[cur_index++]); for(int i = 0; i < num_vol_devices; ++i) { device_name = input[cur_index++]; cur_device_input_file = await get_input_file_from_name(device_name, 'v'); VolumeDevice v_device = new VolumeDevice(device_name, cur_device_input_file); volume_devices.Add(v_device); } int vol_index = 0; string cur_vol_device_name = input[cur_index++]; found = false; foreach(VolumeDevice cur_v in volume_devices) { if(cur_v.get_name().Equals(cur_vol_device_name)) { found = true; break; } vol_index++; } if(!found) { // TODO: Throw Error } else { volumeController = volume_devices[vol_index]; await volumeController.initialize(); } }
public async Task<bool> selectChannelDevice(string name) { int index = getChannelDeviceIndex(ref name); if(index == -1) { return false; } channelController = channel_devices[index]; if (!channelController.is_initialized) { await channelController.initialize(); } saveDeviceList(); return true; }