Exemple #1
0
 public static void EnsureMetadataEntryIsValid(string metadataKey, string metadataValue, string version)
 {
     if (!MetadataEncoding.IsValidMetadataKey(metadataKey, version))
     {
         throw new MetadataFormatException(string.Format("The metadata key {0} is not valid for version '{1}'.", metadataKey, version));
     }
     if (!MetadataEncoding.IsValidMetadataValue(metadataValue, version))
     {
         throw new MetadataFormatException(string.Format("The metadata value {0} is not valid for version '{1}'.", metadataValue, version));
     }
 }
Exemple #2
0
 public static void WriteMetadataToXml(XmlWriter xmlWriter, NameValueCollection metadata, bool isWritingRootMetadataElementEvenIfMetadataIsEmpty, string version)
 {
     if (xmlWriter == null)
     {
         throw new ArgumentNullException("xmlWriter");
     }
     if (metadata == null || metadata.Count <= 0)
     {
         if (isWritingRootMetadataElementEvenIfMetadataIsEmpty)
         {
             xmlWriter.WriteStartElement("Metadata");
             xmlWriter.WriteEndElement();
         }
         return;
     }
     xmlWriter.WriteStartElement("Metadata");
     string[] allKeys = metadata.AllKeys;
     for (int i = 0; i < (int)allKeys.Length; i++)
     {
         string str  = allKeys[i];
         string item = metadata[str];
         if (!MetadataEncoding.IsValidMetadataKey(str, version))
         {
             xmlWriter.WriteElementString("x-ms-invalid-name", str);
         }
         else if (MetadataEncoding.IsValidMetadataValue(item, version))
         {
             xmlWriter.WriteElementString(str, metadata[str]);
         }
         else
         {
             xmlWriter.WriteElementString("x-ms-invalid-value", item);
         }
     }
     xmlWriter.WriteEndElement();
 }