Exemplo n.º 1
0
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static BackupStorageDescription GetFromJsonProperties(JsonReader reader)
        {
            BackupStorageDescription obj;
            var propName = reader.ReadPropertyName();

            if (!propName.Equals("StorageKind", StringComparison.Ordinal))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is StorageKind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("AzureBlobStore", StringComparison.Ordinal))
            {
                obj = AzureBlobBackupStorageDescriptionConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("FileShare", StringComparison.Ordinal))
            {
                obj = FileShareBackupStorageDescriptionConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown StorageKind.");
            }

            return(obj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, BackupStorageDescription obj)
        {
            var kind = obj.StorageKind;

            if (kind.Equals(BackupStorageKind.AzureBlobStore))
            {
                AzureBlobBackupStorageDescriptionConverter.Serialize(writer, (AzureBlobBackupStorageDescription)obj);
            }
            else if (kind.Equals(BackupStorageKind.FileShare))
            {
                FileShareBackupStorageDescriptionConverter.Serialize(writer, (FileShareBackupStorageDescription)obj);
            }
            else if (kind.Equals(BackupStorageKind.DsmsAzureBlobStore))
            {
                DsmsAzureBlobBackupStorageDescriptionConverter.Serialize(writer, (DsmsAzureBlobBackupStorageDescription)obj);
            }
            else if (kind.Equals(BackupStorageKind.ManagedIdentityAzureBlobStore))
            {
                ManagedIdentityAzureBlobBackupStorageDescriptionConverter.Serialize(writer, (ManagedIdentityAzureBlobBackupStorageDescription)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown StorageKind.");
            }
        }