Esempio n. 1
0
        public void deleteAll(CloudBlobContainer container, string pathInSyncFolder)
        {
            // update path on server
             pathInSyncFolder = pathInSyncFolder.Replace("\\", "/");

            // check if it is dir
            bool isDir = false;
            CloudBlobDirectory dir = container.GetDirectoryReference(pathInSyncFolder);
            List<IListBlobItem> blobs = dir.ListBlobs().ToList();

            if (blobs.Count != 0)
            {
                isDir = true;
            }

            try
            {

                if (!isDir)
                {
                    // this can only get the blob type, not the dir type
                    var item = container.GetBlobReferenceFromServer(pathInSyncFolder);

                    if (item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob blob = (CloudBlockBlob)item;
                        blob.DeleteIfExists(DeleteSnapshotsOption.IncludeSnapshots);
                        //blob.Delete();
                        //System.Windows.Forms.MessageBox.Show(string.Format("File: {0} Deleted!", pathInSyncFolder), "DBLike Server");

                    }
                    else if (item.GetType() == typeof(CloudPageBlob))
                    {
                        CloudPageBlob blob = (CloudPageBlob)item;
                        //blob.Delete();
                        blob.DeleteIfExists(DeleteSnapshotsOption.IncludeSnapshots);
                        //System.Windows.Forms.MessageBox.Show(string.Format("File: {0} Deleted!", pathInSyncFolder), "DBLike Server");
                        Program.ServerForm.addtoConsole(string.Format("File: {0} Deleted!", pathInSyncFolder));
                    }
                }
                else
                {
                    // get the directory reference
                    CloudBlobDirectory dira = container.GetDirectoryReference(pathInSyncFolder);
                    deleteFolder(container, dira);
                    //System.Windows.Forms.MessageBox.Show(string.Format("Deleted!\n Folder: {0}", pathInSyncFolder), "DBLike Server");
                    Program.ServerForm.addtoConsole(string.Format("Deleted!\n Folder: {0}", pathInSyncFolder));
                }

            }
            catch
            {
                System.Windows.Forms.MessageBox.Show(string.Format("File: {0} \n doesn't exist!", pathInSyncFolder), "DBLike Server");
                Program.ServerForm.addtoConsole(string.Format("File: {0} \n doesn't exist!", pathInSyncFolder));
            }
        }
Esempio n. 2
0
        //public String Text;

        public LogFolder(CloudBlobContainer DeploymentContainer, string folder)
        {
            Text = "";

            _server_ref = DeploymentContainer.GetDirectoryReference(folder);

           // Start();

        }
        public AzureBlobContentProvider(string connectionString, string basePath, ICacheManager<object> cacheManager)
        {
            _cacheManager = cacheManager;
            var parts = basePath.Split(new[] { "/", "\\" }, StringSplitOptions.RemoveEmptyEntries);

            _containerName = parts.FirstOrDefault();
            _baseDirectoryPath = string.Join("/", parts.Skip(1));

            if (!CloudStorageAccount.TryParse(connectionString, out _cloudStorageAccount))
            {
                throw new InvalidOperationException("Failed to get valid connection string");
            }
            _cloudBlobClient = _cloudStorageAccount.CreateCloudBlobClient();
            _container = _cloudBlobClient.GetContainerReference(_containerName);
            if (_baseDirectoryPath != null)
            {
                _directory = _container.GetDirectoryReference(_baseDirectoryPath);
            }
        }
        /// <summary>
        /// Creates a <see cref="CloudBlobDirectory"/> object using the specified account credentials.
        /// </summary>
        /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param>
        private void CreateCloudBlobDirectoryInstance(StorageCredentials credentials)
        {
            if (null == this.containerUri)
            {
                throw new InvalidOperationException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.ParameterCannotBeNullException,
                        "containerUri"));
            }

            CloudBlobContainer container = new CloudBlobContainer(this.containerUri, credentials);
            this.blobDir = container.GetDirectoryReference(this.relativeAddress);
        }
Esempio n. 5
0
        public void BlobTypesWithStorageUri()
        {
            StorageUri endpoint = new StorageUri(
                new Uri("http://" + AccountName + BlobService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix));

            CloudBlobClient client = new CloudBlobClient(endpoint, new StorageCredentials());
            Assert.IsTrue(endpoint.Equals(client.StorageUri));
            Assert.IsTrue(endpoint.PrimaryUri.Equals(client.BaseUri));

            StorageUri containerUri = new StorageUri(
                new Uri(endpoint.PrimaryUri + "container"),
                new Uri(endpoint.SecondaryUri + "container"));

            CloudBlobContainer container = client.GetContainerReference("container");
            Assert.IsTrue(containerUri.Equals(container.StorageUri));
            Assert.IsTrue(containerUri.PrimaryUri.Equals(container.Uri));
            Assert.IsTrue(endpoint.Equals(container.ServiceClient.StorageUri));

            container = new CloudBlobContainer(containerUri, client.Credentials);
            Assert.IsTrue(containerUri.Equals(container.StorageUri));
            Assert.IsTrue(containerUri.PrimaryUri.Equals(container.Uri));
            Assert.IsTrue(endpoint.Equals(container.ServiceClient.StorageUri));

            StorageUri directoryUri = new StorageUri(
                new Uri(containerUri.PrimaryUri + "/directory/"),
                new Uri(containerUri.SecondaryUri + "/directory/"));

            StorageUri subdirectoryUri = new StorageUri(
                new Uri(directoryUri.PrimaryUri + "subdirectory/"),
                new Uri(directoryUri.SecondaryUri + "subdirectory/"));

            CloudBlobDirectory directory = container.GetDirectoryReference("directory");
            Assert.IsTrue(directoryUri.Equals(directory.StorageUri));
            Assert.IsTrue(directoryUri.PrimaryUri.Equals(directory.Uri));
            Assert.IsNotNull(directory.Parent);
            Assert.IsTrue(containerUri.Equals(directory.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(directory.ServiceClient.StorageUri));

            CloudBlobDirectory subdirectory = directory.GetDirectoryReference("subdirectory");
            Assert.IsTrue(subdirectoryUri.Equals(subdirectory.StorageUri));
            Assert.IsTrue(subdirectoryUri.PrimaryUri.Equals(subdirectory.Uri));
            Assert.IsTrue(directoryUri.Equals(subdirectory.Parent.StorageUri));
            Assert.IsTrue(containerUri.Equals(subdirectory.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(subdirectory.ServiceClient.StorageUri));

            StorageUri blobUri = new StorageUri(
                new Uri(subdirectoryUri.PrimaryUri + "blob"),
                new Uri(subdirectoryUri.SecondaryUri + "blob"));

            CloudBlockBlob blockBlob = subdirectory.GetBlockBlobReference("blob");
            Assert.IsTrue(blobUri.Equals(blockBlob.StorageUri));
            Assert.IsTrue(blobUri.PrimaryUri.Equals(blockBlob.Uri));
            Assert.IsTrue(subdirectoryUri.Equals(blockBlob.Parent.StorageUri));
            Assert.IsTrue(containerUri.Equals(blockBlob.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(blockBlob.ServiceClient.StorageUri));

            blockBlob = new CloudBlockBlob(blobUri, null, client.Credentials);
            Assert.IsTrue(blobUri.Equals(blockBlob.StorageUri));
            Assert.IsTrue(blobUri.PrimaryUri.Equals(blockBlob.Uri));
            Assert.IsTrue(subdirectoryUri.Equals(blockBlob.Parent.StorageUri));
            Assert.IsTrue(containerUri.Equals(blockBlob.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(blockBlob.ServiceClient.StorageUri));

            CloudPageBlob pageBlob = subdirectory.GetPageBlobReference("blob");
            Assert.IsTrue(blobUri.Equals(pageBlob.StorageUri));
            Assert.IsTrue(blobUri.PrimaryUri.Equals(pageBlob.Uri));
            Assert.IsTrue(subdirectoryUri.Equals(pageBlob.Parent.StorageUri));
            Assert.IsTrue(containerUri.Equals(pageBlob.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(pageBlob.ServiceClient.StorageUri));

            pageBlob = new CloudPageBlob(blobUri, null, client.Credentials);
            Assert.IsTrue(blobUri.Equals(pageBlob.StorageUri));
            Assert.IsTrue(blobUri.PrimaryUri.Equals(pageBlob.Uri));
            Assert.IsTrue(subdirectoryUri.Equals(pageBlob.Parent.StorageUri));
            Assert.IsTrue(containerUri.Equals(pageBlob.Container.StorageUri));
            Assert.IsTrue(endpoint.Equals(pageBlob.ServiceClient.StorageUri));
        }
 internal List<string> GetBlobNamesForDirectory(CloudBlobContainer container, string directoryName)
 {
     var folder = container.GetDirectoryReference(directoryName);
     var blobs = folder.ListBlobs(true);
     var blobNames = new List<string>();
     foreach (var item in blobs)
     {
         if (item.GetType() == typeof(CloudBlockBlob))
         {
             var blob = (CloudBlockBlob)item;
             var blobNameParts = blob.Name.Split('/');
             blobNames.Add(blobNameParts[blobNameParts.Length-1]);
         }
         else if (item.GetType() == typeof(CloudPageBlob))
         {
             var pageBlob = (CloudPageBlob)item;
             var blobNameParts = pageBlob.Name.Split('/');
             blobNames.Add(blobNameParts[blobNameParts.Length - 1]);
         }
     }
     return blobNames;
 }
Esempio n. 7
0
 private async Task CreateNonEmptyDirectory(CloudBlobContainer container, string directoryName)
 {
     var dir = container.GetDirectoryReference(directoryName);
     var blob = dir.GetBlockBlobReference("blob");
     await CreateEmptyBlob(blob);
 }
Esempio n. 8
0
        /// <summary>
        /// Get All users active directory users List 
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public static Dictionary<string, string> GetSubDirectories(CloudBlobContainer container, string Prepend, string append, string subContainerName)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            try
            {
                var directory = container.GetDirectoryReference(@subContainerName);
                var folders = directory.ListBlobs().Where(b => b as CloudBlobDirectory != null).ToList();
                foreach (var folder in folders)
                {
                    string userName = folder.Uri.AbsolutePath.Replace(folder.Parent.Uri.AbsolutePath, "").Trim('/');
                    string userPath = Prepend + userName + append;

                    var blob = container.GetBlockBlobReference(userPath);
                    if (blob.Exists())
                    {
                        result.Add(userName, userPath);
                    }

                    //result.Add(userName, userPath);
                }
            }
            catch (Exception exception)
            {
                return result;
            }
            return result;
        }