void IXmlSerializable.ReadXml(XmlReader i_Reader) { if (i_Reader.IsEmptyElement) { return; } // Move past container if (!i_Reader.Read()) { throw new XmlException("Error in Deserialization of Dictionary"); } while (i_Reader.NodeType != XmlNodeType.EndElement) { i_Reader.ReadStartElement(k_ItemNodeName); i_Reader.ReadStartElement(k_KeyNodeName); TKey key = (TKey)KeySerializer.Deserialize(i_Reader); i_Reader.ReadEndElement(); i_Reader.ReadStartElement(k_ValueNodeName); TVal value = (TVal)ValueSerializer.Deserialize(i_Reader); i_Reader.ReadEndElement(); i_Reader.ReadEndElement(); this.Add(key, value); i_Reader.MoveToContent(); } //reader.ReadEndElement(); i_Reader.ReadEndElement(); // Read End Element to close Read of containing node }
void IXmlSerializable.ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { return; } // Move past container if (!reader.Read()) { throw new XmlException("Error in Deserialization of Dictionary"); } // reader.ReadStartElement(DictionaryNodeName); while (reader.NodeType != XmlNodeType.EndElement) { reader.ReadStartElement(Map <TKey, TVal> .ItemNodeName); reader.ReadStartElement(Map <TKey, TVal> .KeyNodeName); var key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(Map <TKey, TVal> .ValueNodeName); var value = (TVal)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadEndElement(); Add(key, value); reader.MoveToContent(); } // reader.ReadEndElement(); reader.ReadEndElement(); // Read End Element to close Read of containing node }
void IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { if (reader.IsEmptyElement) { return; } // Move past container if (!reader.Read()) { throw new XmlException("Error in Deserialization of Dictionary"); } //reader.ReadStartElement(DictionaryNodeName); while (reader.NodeType != XmlNodeType.EndElement) { reader.ReadStartElement(ItemNodeName); reader.ReadStartElement(KeyNodeName); TKey key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(ValueNodeName); TVal valor = (TVal)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadEndElement(); this.Add(key, valor); reader.MoveToContent(); } //reader.ReadEndElement(); reader.ReadEndElement(); // Read End Element to close Read of containing node //Debug.Log("IXmlSerializable.ReadXml"); }
/// <summary>Generates an object from its XML representation.</summary> /// <param name="reader"> /// The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized. /// </param> void IXmlSerializable.ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { return; } // Move past container if (reader.NodeType == XmlNodeType.Element && !reader.Read()) { throw new XmlException("Error in Deserialization of SerializableDictionary"); } while (reader.NodeType != XmlNodeType.EndElement) { var key = (TKey)KeySerializer.Deserialize(reader); var value = (TVal)ValueSerializer.Deserialize(reader); Add(key, value); reader.MoveToContent(); } // Move past container if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); } else { throw new XmlException("Error in Deserialization of SerializableDictionary"); } }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param> void IXmlSerializable.ReadXml(XmlReader reader) { bool wasEmpty = reader.IsEmptyElement; reader.Read(); if (wasEmpty) { return; } while (reader.NodeType != XmlNodeType.EndElement) { reader.ReadStartElement(keyItem); reader.ReadStartElement(keyKey); var key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(keyValue); var value = (TValue)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); Add(key, value); reader.ReadEndElement(); reader.MoveToContent(); } reader.ReadEndElement(); }
void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { if (reader.IsEmptyElement) { return; } if (!reader.Read()) { throw new System.Xml.XmlException("Error in Deserialization of Dictionary"); } while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { reader.ReadStartElement(ItemNodeName); reader.ReadStartElement(KeyNodeName); TKey key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(ValueNodeName); TVal value = (TVal)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadEndElement(); Add(key, value); reader.MoveToContent(); } reader.ReadEndElement(); }
void IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { if (reader.IsEmptyElement) { return; } if (!reader.Read()) { throw new XmlException("Error in Deserialization of Dictionary"); } //HERE IS THE TRICK if (reader is KnownTypesXmlReader) { SetKnownTypes(((KnownTypesXmlReader)reader).ExtraTypes); } //reader.ReadStartElement(DictionaryNodeName); while (reader.NodeType != XmlNodeType.EndElement) { reader.ReadStartElement(ItemNodeName); reader.ReadStartElement(KeyNodeName); TKey key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(ValueNodeName); TVal value = (TVal)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadEndElement(); this.Add(key, value); reader.MoveToContent(); } //reader.ReadEndElement(); reader.ReadEndElement(); // Read End Element to close Read of containing node }
/// <summary> /// Returns all the keys in storage. /// </summary> /// <returns></returns> public async Task <IEnumerable <SerializedKey> > LoadKeysAsync() { var list = new List <SerializedKey>(); if (!_directory.Exists) { _directory.Create(); } var files = _directory.GetFiles(KeyFilePrefix + "*" + KeyFileExtension); foreach (var file in files) { var id = file.Name.Substring(4); try { using (var reader = new StreamReader(file.OpenRead())) { var json = await reader.ReadToEndAsync(); var item = KeySerializer.Deserialize <SerializedKey>(json); list.Add(item); } } catch (Exception ex) { _logger.LogError(ex, "Error reading file: " + file.Name); } } return(list); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// An enumerator that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() { foreach (var hashKey in RedisDb.HashKeys(RedisKey)) { var redisValue = RedisDb.HashGet(RedisKey, hashKey); yield return(new KeyValuePair <TKey, TValue>(KeySerializer.Deserialize <TKey>(hashKey), ValueSerializer.Deserialize <TValue>(redisValue))); } }
/// <summary> /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1" /> to an <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index. /// </summary> /// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param> public void CopyTo(KeyValuePair <TKey, TValue>[] array, int arrayIndex) { var values = RedisDb.HashGetAll(RedisKey); for (var i = 0; i < values.Length; i++) { var key = KeySerializer.Deserialize <TKey>(values[i].Name); var value = ValueSerializer.Deserialize <TValue>(values[i].Value); array[i + arrayIndex] = new KeyValuePair <TKey, TValue>(key, value); } }
/// <inheritdoc/> public KeyContainer Unprotect(SerializedKey key) { var data = key.DataProtected ? _dataProtectionProvider.Unprotect(key.Data) : key.Data; if (key.IsX509Certificate) { return(KeySerializer.Deserialize <X509KeyContainer>(data)); } if (key.Algorithm.StartsWith("R") || key.Algorithm.StartsWith("P")) { return(KeySerializer.Deserialize <RsaKeyContainer>(data)); } if (key.Algorithm.StartsWith("E")) { return(KeySerializer.Deserialize <EcKeyContainer>(data)); } throw new Exception($"Invalid Algorithm: {key.Algorithm} for kid: {key.Id}"); }
void IXmlSerializable.ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { return; } // Move past container if (!reader.Read()) { throw new XmlException("Error in Deserialization of Dictionary"); } //This is to ensure bad illegal chars are ignored when received via WCF if (reader.Settings != null) { reader.Settings.CheckCharacters = false; } //reader.ReadStartElement(DictionaryNodeName); while (reader.NodeType != XmlNodeType.EndElement) { reader.ReadStartElement(ItemNodeName); reader.ReadStartElement(KeyNodeName); var key = (TKey)KeySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement(ValueNodeName); var value = (TVal)ValueSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadEndElement(); Add(key, value); reader.MoveToContent(); } //reader.ReadEndElement(); reader.ReadEndElement(); // Read End Element to close Read of containing node }
public KeyContainer Unprotect(SerializedKey key) { return(KeySerializer.Deserialize <RsaKeyContainer>(key.Data)); }