コード例 #1
0
        public ResourceBackupStatus CheckBackupStatus()
        {
            string fileShareName = (string)ProviderData[ProtectionCheckParams.Name];
            string azureStorageAccountResourceGroupName =
                (string)ProviderData[ProtectionCheckParams.ResourceGroupName];

            ODataQuery <ProtectedItemQueryObject> queryParams =
                new ODataQuery <ProtectedItemQueryObject>(
                    q => q.BackupManagementType
                    == ServiceClientModel.BackupManagementType.AzureStorage &&
                    q.ItemType == DataSourceType.AzureFileShare);

            var vaultIds = ServiceClientAdapter.ListVaults();

            foreach (var vaultId in vaultIds)
            {
                ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);

                var items = ServiceClientAdapter.ListProtectedItem(
                    queryParams,
                    vaultName: vaultIdentifier.ResourceName,
                    resourceGroupName: vaultIdentifier.ResourceGroupName);

                if (items.Any(
                        item =>
                {
                    ResourceIdentifier storageIdentifier =
                        new ResourceIdentifier(item.Properties.SourceResourceId);
                    var itemStorageAccountRgName = storageIdentifier.ResourceGroupName;

                    return(item.Name.Split(';')[1].ToLower() == fileShareName.ToLower() &&
                           itemStorageAccountRgName.ToLower() == azureStorageAccountResourceGroupName.ToLower());
                }))
                {
                    return(new ResourceBackupStatus(
                               fileShareName,
                               azureStorageAccountResourceGroupName,
                               vaultId,
                               true));
                }
            }

            return(new ResourceBackupStatus(
                       fileShareName,
                       azureStorageAccountResourceGroupName,
                       null,
                       false));
        }