public override object Search(string path, string filter, string searchString, bool caseSensitive, System.Collections.Generic.IEnumerable <object> selectedItems = null)
        {
            Items.Clear();
            AjaxFileExplorerResponse data = (AjaxFileExplorerResponse)Read(path, filter, selectedItems);

            Items.AddRange(data.files);
            getAllFiles(path, data, filter);
            data.files = Items.Where(item => new Regex(WildcardToRegex(searchString), (caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase)).IsMatch(item.name));
            return(data);
        }
        public override object CreateFolder(string path, string name, IEnumerable <object> selectedItems = null)
        {
            CloudBlockBlob blob = container.GetBlockBlobReference(path + name + "/temp.$$$");

            blob.UploadText(".");
            AjaxFileExplorerResponse     CreateResponse = new AjaxFileExplorerResponse();
            FileExplorerDirectoryContent content        = new FileExplorerDirectoryContent();

            content.name = name;
            var directories = new[] { content };

            CreateResponse.files = (IEnumerable <FileExplorerDirectoryContent>)directories;
            return(CreateResponse);
        }
        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; }
        }
        public virtual void getAllFiles(string path, AjaxFileExplorerResponse data, string filter)
        {
            AjaxFileExplorerResponse directoryList = new AjaxFileExplorerResponse();

            directoryList.files = (IEnumerable <FileExplorerDirectoryContent>)data.files.Where(item => item.isFile == false);
            for (int i = 0; i < directoryList.files.Count(); i++)
            {
                IEnumerable <FileExplorerDirectoryContent> selectedItem = new[] { directoryList.files.ElementAt(i) };
                AjaxFileExplorerResponse innerData = (AjaxFileExplorerResponse)Read(path + directoryList.files.ElementAt(i).name + "/", filter, selectedItem);
                innerData.files = innerData.files.Select(file => new FileExplorerDirectoryContent
                {
                    name       = file.name,
                    type       = file.type,
                    isFile     = file.isFile,
                    size       = file.size,
                    hasChild   = file.hasChild,
                    filterPath = (directoryList.files.ElementAt(i).filterPath + directoryList.files.ElementAt(i).name + "\\")
                });
                Items.AddRange(innerData.files);
                getAllFiles(path + directoryList.files.ElementAt(i).name + "/", innerData, filter);
            }
        }
        public override object Read(string path, string filter, IEnumerable <object> selectedItems = null)
        {
            AjaxFileExplorerResponse            ReadResponse = new AjaxFileExplorerResponse();
            List <FileExplorerDirectoryContent> details      = new List <FileExplorerDirectoryContent>();

            try
            {
                filter = filter.Replace(" ", "");
                var extensions = (filter ?? "*").Split(",|;".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                CloudBlobDirectory          sampleDirectory = container.GetDirectoryReference(path);
                IEnumerable <IListBlobItem> items           = sampleDirectory.ListBlobs(false, BlobListingDetails.Metadata);

                foreach (IListBlobItem item in items)
                {
                    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;
                            FileExplorerDirectoryContent entry = new FileExplorerDirectoryContent();
                            entry.name         = file.Name.Replace(path, "").Replace("/", "");
                            entry.type         = file.Properties.ContentType;
                            entry.isFile       = true;
                            entry.size         = file.Properties.Length;
                            entry.dateModified = file.Properties.LastModified.Value.LocalDateTime.ToString();
                            entry.hasChild     = false;
                            entry.filterPath   = "";
                            details.Add(entry);
                        }
                        else if (item.GetType() == typeof(CloudBlobDirectory))
                        {
                            CloudBlobDirectory           directory = (CloudBlobDirectory)item;
                            FileExplorerDirectoryContent entry     = new FileExplorerDirectoryContent();
                            entry.name   = directory.Prefix.Replace(path, "").Replace("/", "");
                            entry.type   = "Directory";
                            entry.isFile = false;
                            entry.size   = 0;
                            //entry.dateModified = directory.Properties.LastModified.ToString();
                            entry.hasChild   = HasChildDirectory(directory.Prefix);
                            entry.filterPath = "";
                            details.Add(entry);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ReadResponse.error = e.GetType().FullName + ", " + e.Message;
                return(ReadResponse);
            }
            ReadResponse.files = (IEnumerable <FileExplorerDirectoryContent>)details;
            return(ReadResponse);
        }