public StorageLocation?GetSettingLocation(string key) { StorageLocation?result = null; lockSlim.EnterReadLock(); try { if (localStore.Status == SettingsStoreStatus.Ready && localStore.Contains(key)) { result = StorageLocation.Local; } else if (localStore != roamingStore && roamingStore.Status == SettingsStoreStatus.Ready && roamingStore.Contains(key)) { result = StorageLocation.Roaming; } else if (transientStore.Status == SettingsStoreStatus.Ready && transientStore.Contains(key)) { result = StorageLocation.Transient; } } finally { lockSlim.ExitReadLock(); } return(result); }
/// <summary> /// Generates a serializable continuation token from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the continuation token is deserialized.</param> public void ReadXml(XmlReader reader) { CommonUtility.AssertNotNull("reader", reader); // Read the xml root node reader.MoveToContent(); reader.ReadStartElement(); // Read the additional xml node that will be present if an XmlSerializer was used to serialize this token reader.MoveToContent(); if (reader.Name == Constants.ContinuationConstants.ContinuationTopElement) { reader.ReadStartElement(); } // Read the ContinuationToken content while (reader.IsStartElement()) { switch (reader.Name) { case Constants.ContinuationConstants.VersionElement: this.Version = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.TypeElement: this.Type = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.TargetLocationElement: string targetLocation = reader.ReadElementContentAsString(); StorageLocation location; if (Enum.TryParse(targetLocation, out location)) { this.TargetLocation = location; } else { throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedLocation, targetLocation)); } break; case Constants.ContinuationConstants.NextPartitionKeyElement: this.NextPartitionKey = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.NextRowKeyElement: this.NextRowKey = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.NextTableNameElement: this.NextTableName = reader.ReadElementContentAsString(); break; default: throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedElement, reader.Name)); } } }
public SerializableSetting( string name, object settingValue, StorageLocation?storageLocation) { Name = AssertArg.IsNotNull(name, nameof(name)); SettingValue = settingValue; StorageLocation = storageLocation; }
/// <summary> /// Generates a serializable continuation token from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the continuation token is deserialized.</param> public async Task ReadXmlAsync(XmlReader reader) { CommonUtility.AssertNotNull("reader", reader); // Read the xml root node await reader.MoveToContentAsync().ConfigureAwait(false); await reader.ReadStartElementAsync().ConfigureAwait(false); // Read the additional xml node that will be present if an XmlSerializer was used to serialize this token await reader.MoveToContentAsync().ConfigureAwait(false); if (reader.Name == Constants.ContinuationConstants.ContinuationTopElement) { await reader.ReadStartElementAsync().ConfigureAwait(false); } // Read the ContinuationToken content while (await reader.IsStartElementAsync().ConfigureAwait(false)) { switch (reader.Name) { case Constants.ContinuationConstants.VersionElement: this.Version = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContinuationConstants.NextMarkerElement: this.NextMarker = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; case Constants.ContinuationConstants.TargetLocationElement: string targetLocation = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); StorageLocation location; if (Enum.TryParse(targetLocation, out location)) { this.TargetLocation = location; } else if (!string.IsNullOrEmpty(targetLocation)) { throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedLocation, targetLocation)); } break; case Constants.ContinuationConstants.TypeElement: this.Type = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); break; default: throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedElement, reader.Name)); } } }
private static char Serialize(StorageLocation?location) { if (!location.HasValue) { return('*'); // Primary or Secondary } else { StorageLocation locationValue = location.Value; switch (locationValue) { case StorageLocation.Primary: return('P'); case StorageLocation.Secondary: return('S'); default: throw new ArgumentOutOfRangeException("location", "Unknown StorageLocation."); } } }
/// <summary> /// Generates a serializable continuation token from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the continuation token is deserialized.</param> public void ReadXml(XmlReader reader) { CommonUtility.AssertNotNull("reader", reader); // Read the xml root node reader.MoveToContent(); reader.ReadStartElement(); // Read the additional xml node that will be present if an XmlSerializer was used to serialize this token reader.MoveToContent(); if (reader.Name == Constants.ContinuationConstants.ContinuationTopElement) { reader.ReadStartElement(); } // Read the ContinuationToken content while (reader.IsStartElement()) { switch (reader.Name) { case Constants.ContinuationConstants.VersionElement: this.Version = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.NextMarkerElement: this.NextMarker = reader.ReadElementContentAsString(); break; case Constants.ContinuationConstants.TargetLocationElement: string targetLocation = reader.ReadElementContentAsString(); StorageLocation location; if (Enum.TryParse(targetLocation, out location)) { this.TargetLocation = location; } else { throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedLocation, targetLocation)); } break; case Constants.ContinuationConstants.TypeElement: this.Type = reader.ReadElementContentAsString(); break; default: throw new XmlException(string.Format(CultureInfo.InvariantCulture, SR.UnexpectedElement, reader.Name)); } } }