/// <summary>
        /// Helper function to convert ps backup container model from service response.
        /// </summary>
        public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionContainerResource protectionContainer)
        {
            ContainerBase containerModel = null;

            if (protectionContainer != null &&
                protectionContainer.Properties != null)
            {
                if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.IaaSVMContainer)))
                {
                    containerModel = new AzureVmContainer(protectionContainer);
                }
                else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
                {
                    containerModel = new MabContainer(protectionContainer);
                }
                else if (protectionContainer.Properties.GetType() ==
                         typeof(ServiceClientModel.AzureSqlContainer))
                {
                    containerModel = new AzureSqlContainer(protectionContainer);
                }
                else if (protectionContainer.Properties.GetType() ==
                         typeof(ServiceClientModel.AzureStorageContainer))
                {
                    containerModel = new AzureFileShareContainer(protectionContainer);
                }
                else if (protectionContainer.Properties.GetType() ==
                         typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer))
                {
                    containerModel = new AzureVmWorkloadContainer(protectionContainer);
                }
            }

            return(containerModel);
        }
        public void RegisterContainer()
        {
            string        vaultName = (string)ProviderData[VaultParams.VaultName];
            string        vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string        containerName          = (string)ProviderData[ContainerParams.Name];
            string        backupManagementType   = (string)ProviderData[ContainerParams.BackupManagementType];
            string        workloadType           = (string)ProviderData[ContainerParams.ContainerType];
            ContainerBase containerBase          =
                (ContainerBase)ProviderData[ContainerParams.Container];
            AzureVmWorkloadContainer container = (AzureVmWorkloadContainer)ProviderData[ContainerParams.Container];

            ProtectionContainerResource protectionContainerResource = null;

            //Trigger Discovery
            ODataQuery <BMSRefreshContainersQueryObject> queryParam = new ODataQuery <BMSRefreshContainersQueryObject>(
                q => q.BackupManagementType
                == ServiceClientModel.BackupManagementType.AzureWorkload);

            AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam);

            List <ProtectableContainerResource> unregisteredVmContainers =
                GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName);
            ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find(
                vmContainer => string.Compare(vmContainer.Name.Split(';').Last(),
                                              containerName, true) == 0);

            if (unregisteredVmContainer != null || container != null)
            {
                protectionContainerResource =
                    new ProtectionContainerResource(container != null ? container.Id : unregisteredVmContainer.Id,
                                                    container != null ? container.Name : unregisteredVmContainer.Name);
                AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer(
                    friendlyName: containerName,
                    backupManagementType: backupManagementType,
                    sourceResourceId: container != null ? container.SourceResourceId : unregisteredVmContainer.Properties.ContainerId,
                    workloadType: workloadType.ToString(),
                    operationType: container != null ? OperationType.Reregister : OperationType.Register);
                protectionContainerResource.Properties = azureVMContainer;
                AzureWorkloadProviderHelper.RegisterContainer(container != null ? container.Name : unregisteredVmContainer.Name,
                                                              protectionContainerResource,
                                                              vaultName,
                                                              vaultResourceGroupName);
            }
            else
            {
                throw new ArgumentException(string.Format(Resources.AzureWorkloadAlreadyRegisteredException));
            }
        }