/// <summary> /// Loads a sandbox configuration list. /// </summary> /// <returns>true: Success / false : Failed</returns> public async Task <bool> LoadAsync() { await semaphore.WaitAsync().ConfigureAwait(false); try { var localFile = await localFolder.TryGetItemAsync(wsbConfigListFileName); if (localFile is IStorageFile storageFile) { using (var s = await storageFile.OpenStreamForReadAsync()) using (var sr = new StreamReader(s)) { WSBConfigCollection.Clear(); using (var xr = XmlReader.Create(sr)) { var xElement = XElement.Load(xr); foreach (var configItem in xElement.Elements(WSBConfigModel.RootNodeName)) { WSBConfigCollection.Add(WSBConfigManagerModel.FromXElement(configItem)); } LoadCongiugurationListCompleted?.Invoke(this, null); } } } return(true); } catch (Exception) { return(false); } finally { semaphore.Release(); } }
/// <summary> /// Imports a sandbox configuration list. /// </summary> /// <returns>true: Success / false : Failed</returns> public async Task <bool> ImportAsync(IStorageFile storageFile) { await semaphore.WaitAsync().ConfigureAwait(false); try { var uuidSet = new HashSet <string>(WSBConfigCollection.Select(configItem => configItem.UUID)); using (var s = await storageFile.OpenStreamForReadAsync()) using (var sr = new StreamReader(s)) { using (var xr = XmlReader.Create(sr)) { var xElement = XElement.Load(xr); foreach (var configItem in xElement.Elements(WSBConfigModel.RootNodeName)) { var newConfigModel = WSBConfigManagerModel.FromXElement(configItem); if (uuidSet.Contains(newConfigModel.UUID)) { // If there is a UUID conflict, the newly added UUID will be regenerated. newConfigModel.ResetUUID(); } WSBConfigCollection.Add(newConfigModel); uuidSet.Add(newConfigModel.UUID); } LoadCongiugurationListCompleted?.Invoke(this, null); } } return(true); } catch (Exception) { return(false); } finally { semaphore.Release(); } }