Ejemplo n.º 1
0
        private async Task TestConnection()
        {
            if (this.TestResult != null)
            {
                return;
            }

            m_lblTestResult.Visible = true;

            if (string.IsNullOrEmpty(this.AccountName) || string.IsNullOrEmpty(this.AccessToken))
            {
                m_lblTestResult.Text = AzureResources.Form_Test_Credentials_Required;
                return;
            }

            this.Enabled         = false;
            m_lblTestResult.Text = AzureResources.Form_Test_Testing_Connection;

            this.TestResult = null;

            try
            {
                var error       = false;
                var credentials = new StorageCredentials(this.AccountName, this.AccessToken);
                switch (this.StorageType)
                {
                case StorageType.AzureBlob:
                    error = await AzureBlobStorageProvider.TestContainer(credentials, this.ItemName);

                    break;

                case StorageType.AzureFile:
                    error = await AzureFileStorageProvider.TestShare(credentials, this.ItemName);

                    break;

                default:
                    error = true;
                    break;
                }

                if (error)
                {
                    throw new Exception("Could not connect to container.");
                }

                m_lblTestResult.Text = AzureResources.Form_Test_Succeeded;
                this.TestResult      = true;
            }
            catch (Exception ex)
            {
                m_lblTestResult.Text = AzureResources.Form_Test_Failed;
                this.TestResult      = false;
            }
            finally
            {
                this.Enabled = true;
            }
        }
Ejemplo n.º 2
0
        // For connection testing
        public static async Task <bool> TestShare(StorageCredentials credentials, string containerName)
        {
            var provider = new AzureFileStorageProvider();

            var fileShare = await provider.GetShare(credentials, containerName);

            var rootDir = fileShare.GetRootDirectoryReference();
            await rootDir.ListFilesAndDirectoriesSegmentedAsync(null);

            return(false);
        }