public override object GetDetails(string path, string[] names, IEnumerable <object> selectedItems = null)
        {
            AjaxFileExplorerResponse DetailsResponse = new AjaxFileExplorerResponse();

            try
            {
                bool isFile = false;
                AzureFileDetails[] fDetails    = new AzureFileDetails[names.Length];
                AzureFileDetails   fileDetails = new AzureFileDetails();
                if (selectedItems != null)
                {
                    foreach (FileExplorerDirectoryContent item in selectedItems)
                    {
                        isFile = item.isFile;
                        break;
                    }
                }
                if (isFile)
                {
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(path + names[0]);
                    blockBlob.FetchAttributes();
                    fileDetails.Name          = blockBlob.Name;
                    fileDetails.Extension     = blockBlob.Name.Split('.')[1];
                    fileDetails.FullName      = blockBlob.Uri.ToString();
                    fileDetails.Format        = blockBlob.Properties.ContentType.ToString();
                    fileDetails.Length        = blockBlob.Properties.Length;
                    fileDetails.LastWriteTime = blockBlob.Properties.LastModified.Value.LocalDateTime.ToString();
                }
                else
                {
                    CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path);
                    fileDetails.Name     = names[0];
                    fileDetails.FullName = sampleDirectory.Uri.ToString() + names[0];
                    fileDetails.Format   = sampleDirectory.GetType().ToString();
                    fileDetails.Length   = 0;
                }
                fDetails[0]             = fileDetails;
                DetailsResponse.details = fDetails;
                return(DetailsResponse);
            }
            catch (Exception ex) { throw ex; }
        }
        // Reads the storage files
        protected async Task <FileManagerResponse> GetFilesAsync(string path, string filter, FileManagerDirectoryContent[] selectedItems)
        {
            FileManagerResponse readResponse           = new FileManagerResponse();
            List <FileManagerDirectoryContent> details = new List <FileManagerDirectoryContent>();
            FileManagerDirectoryContent        cwd     = new FileManagerDirectoryContent();

            try
            {
                string[]           extensions      = ((filter.Replace(" ", "")) ?? "*").Split(",|;".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path);
                cwd.Name       = sampleDirectory.Prefix.Split(sampleDirectory.Parent.Prefix)[sampleDirectory.Prefix.Split(sampleDirectory.Parent.Prefix).Length - 1].Replace("/", "");
                cwd.Type       = "File Folder";
                cwd.FilterPath = selectedItems.Length > 0 ? selectedItems[0].FilterPath : "";
                cwd.Size       = 0;
                cwd.HasChild   = await HasChildDirectory(path);

                readResponse.CWD = cwd;
                BlobResultSegment items = await AsyncReadCall(path, "Read");

                foreach (IListBlobItem item in items.Results)
                {
                    bool includeItem = true;
                    if (!(extensions[0].Equals("*.*") || extensions[0].Equals("*")) && item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob file = (CloudBlockBlob)item;
                        if (!(Array.IndexOf(extensions, "*." + (file.Name.ToString().Trim().Split('.'))[(file.Name.ToString().Trim().Split('.')).Count() - 1]) >= 0))
                        {
                            includeItem = false;
                        }
                    }
                    if (includeItem)
                    {
                        FileManagerDirectoryContent entry = new FileManagerDirectoryContent();
                        if (item.GetType() == typeof(CloudBlockBlob))
                        {
                            CloudBlockBlob file = (CloudBlockBlob)item;
                            entry.Name         = file.Name.Replace(path, "");
                            entry.Type         = System.IO.Path.GetExtension(file.Name.Replace(path, ""));
                            entry.IsFile       = true;
                            entry.Size         = file.Properties.Length;
                            entry.DateModified = file.Properties.LastModified.Value.LocalDateTime;
                            entry.HasChild     = false;
                            entry.FilterPath   = selectedItems.Length > 0 ? path.Replace(this.rootPath, "") : "/";
                            details.Add(entry);
                        }
                        else if (item.GetType() == typeof(CloudBlobDirectory))
                        {
                            CloudBlobDirectory directory = (CloudBlobDirectory)item;
                            entry.Name     = directory.Prefix.Replace(path, "").Replace("/", "");
                            entry.Type     = "Directory";
                            entry.IsFile   = false;
                            entry.Size     = 0;
                            entry.HasChild = await HasChildDirectory(directory.Prefix);

                            entry.FilterPath = selectedItems.Length > 0 ? path.Replace(this.rootPath, "") : "/";
                            details.Add(entry);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(readResponse);
            }
            readResponse.Files = details;
            return(readResponse);
        }
Example #3
0
        // Reads the storage files
        public async Task <FileManagerResponse> ReadAsync(string path, string filter, FileManagerDirectoryContent[] selectedItems)
        {
            OperationContext    context                = new OperationContext();
            BlobRequestOptions  options                = new BlobRequestOptions();
            FileManagerResponse ReadResponse           = new FileManagerResponse();
            List <FileManagerDirectoryContent> details = new List <FileManagerDirectoryContent>();

            FileManagerDirectoryContent cwd = new FileManagerDirectoryContent();

            try
            {
                filter = filter.Replace(" ", "");
                var extensions = (filter ?? "*").Split(",|;".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path);

                cwd.Name       = sampleDirectory.Prefix.Split(sampleDirectory.Parent.Prefix)[sampleDirectory.Prefix.Split(sampleDirectory.Parent.Prefix).Length - 1].Replace("/", "");
                cwd.Type       = "File Folder";
                cwd.FilterPath = selectedItems.Length > 0 ? selectedItems[0].FilterPath : "";
                cwd.Size       = 0;
                cwd.HasChild   = await HasChildDirectory(path);

                ReadResponse.CWD = cwd;
                string Oper  = "Read";
                var    items = await AsyncReadCall(path, Oper);

                foreach (var item in items.Results)
                {
                    bool canAdd = false;
                    if (extensions[0].Equals("*.*") || extensions[0].Equals("*"))
                    {
                        canAdd = true;
                    }
                    else if (item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob file  = (CloudBlockBlob)item;
                        var            names = file.Name.ToString().Trim().Split('.');
                        if (Array.IndexOf(extensions, "*." + names[names.Count() - 1]) >= 0)
                        {
                            canAdd = true;
                        }
                        else
                        {
                            canAdd = false;
                        }
                    }
                    else
                    {
                        canAdd = true;
                    }
                    if (canAdd)
                    {
                        if (item.GetType() == typeof(CloudBlockBlob))
                        {
                            CloudBlockBlob file = (CloudBlockBlob)item;
                            FileManagerDirectoryContent entry = new FileManagerDirectoryContent();
                            entry.Name         = file.Name.Replace(path, "");
                            entry.Type         = System.IO.Path.GetExtension(file.Name.Replace(path, ""));
                            entry.IsFile       = true;
                            entry.Size         = file.Properties.Length;
                            entry.DateModified = file.Properties.LastModified.Value.LocalDateTime;
                            entry.HasChild     = false;
                            entry.FilterPath   = selectedItems.Length > 0 ? path.Replace(this.rootPath, "") : "/";
                            details.Add(entry);
                        }
                        else if (item.GetType() == typeof(CloudBlobDirectory))
                        {
                            CloudBlobDirectory          directory = (CloudBlobDirectory)item;
                            FileManagerDirectoryContent entry     = new FileManagerDirectoryContent();
                            entry.Name     = directory.Prefix.Replace(path, "").Replace("/", "");
                            entry.Type     = "Directory";
                            entry.IsFile   = false;
                            entry.Size     = 0;
                            entry.HasChild = await HasChildDirectory(directory.Prefix);

                            entry.FilterPath = selectedItems.Length > 0 ? path.Replace(this.rootPath, "") : "/";
                            details.Add(entry);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(ReadResponse);
            }
            ReadResponse.Files = (IEnumerable <FileManagerDirectoryContent>)details;

            return(ReadResponse);
        }