コード例 #1
0
        /// <summary>
        /// Creates <see cref="IHierarchyItemAsync"/> instance by path.
        /// </summary>
        /// <param name="path">Item relative path including query string.</param>
        /// <returns>Instance of corresponding <see cref="IHierarchyItemAsync"/> or null if item is not found.</returns>
        public override async Task <IHierarchyItemAsync> GetHierarchyItemAsync(string path)
        {
            path = path.Trim(new[] { ' ', '/' });

            //remove query string.
            int ind = path.IndexOf('?');

            if (ind > -1)
            {
                path = path.Remove(ind);
            }
            if (!await DataLakeStoreService.ExistsAsync(path))
            {
                Logger.LogDebug("Could not find item that corresponds to path: " + path);
                return(null); // no hierarchy item that corresponds to path parameter was found in the repository
            }

            IHierarchyItemAsync item;

            if (await DataLakeStoreService.IsDirectoryAsync(path))
            {
                item = await DavFolder.GetFolderAsync(this, path);
            }
            else
            {
                item = await DavFile.GetFileAsync(this, path);
            }
            return(item);
        }
コード例 #2
0
        /// <summary>
        /// Represents an item that supports search according to DASL standard.
        /// </summary>
        public async Task <PageResults> SearchAsync(string searchString, SearchOptions options, List <PropertyName> propNames, long?offset, long?nResults)
        {
            bool includeSnippet = propNames.Any(s => s.Name == snippetProperty);
            List <IHierarchyItemAsync> searchResponse = new List <IHierarchyItemAsync>();
            IList <SearchResult>       searchResults  = await context.CognitiveSearchService.SearchAsync(searchString, options, includeSnippet);

            long totalItems = searchResults.Count;

            if (offset.HasValue && nResults.HasValue)
            {
                searchResults = searchResults.Skip((int)offset.Value).Take((int)nResults.Value).ToArray();
            }
            foreach (SearchResult searchResult in searchResults)
            {
                DataCloudItem dataLakeItem = await context.DataLakeStoreService.GetItemAsync(searchResult.Path);

                dataLakeItem.Snippet = searchResult.Snippet;
                IHierarchyItemAsync child;
                if (dataLakeItem.IsDirectory)
                {
                    child = new DavFolder(dataLakeItem, context, dataLakeItem.Path);
                }
                else
                {
                    child = new DavFile(dataLakeItem, context, dataLakeItem.Path);
                    if (includeSnippet)
                    {
                        (child as DavFile).Snippet = dataLakeItem.Snippet;
                    }
                }
                searchResponse.Add(child);
            }
            return(new PageResults(searchResponse, totalItems));
        }
コード例 #3
0
        /// <summary>
        /// Creates <see cref="IHierarchyItemAsync"/> instance by path.
        /// </summary>
        /// <param name="path">Item relative path including query string.</param>
        /// <returns>Instance of corresponding <see cref="IHierarchyItemAsync"/> or null if item is not found.</returns>
        public override async Task <IHierarchyItemAsync> GetHierarchyItemAsync(string path)
        {
            path = path.Trim(new[] { ' ', '/' });

            //remove query string.
            int ind = path.IndexOf('?');

            if (ind > -1)
            {
                path = path.Remove(ind);
            }

            try
            {
                if (!await DataLakeStoreService.ExistsAsync(path))
                {
                    Logger.LogDebug("Could not find item that corresponds to path: " + path);
                    return(null); // no hierarchy item that corresponds to path parameter was found in the repository
                }
            }
            catch (RequestFailedException ex)
            {
                // token is not valid or access is denied
                if (ex.Status == 401)
                {
                    await HttpContext.SignOutAsync();

                    return(null);
                }
                else
                {
                    throw ex;
                }
            }

            IHierarchyItemAsync item;

            if (await DataLakeStoreService.IsDirectoryAsync(path))
            {
                item = await DavFolder.GetFolderAsync(this, path);
            }
            else
            {
                item = await DavFile.GetFileAsync(this, path);
            }
            return(item);
        }
コード例 #4
0
        /// <summary>
        /// Called when children of this folder with paging information are being listed.
        /// </summary>
        /// <param name="propNames">List of properties to retrieve with the children. They will be queried by the engine later.</param>
        /// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
        /// <param name="nResults">The number of items to return.</param>
        /// <param name="orderProps">List of order properties requested by the client.</param>
        /// <returns>Items requested by the client and a total number of items in this folder.</returns>
        public virtual async Task <PageResults> GetChildrenAsync(IList <PropertyName> propNames, long?offset, long?nResults, IList <OrderProperty> orderProps)
        {
            // Enumerates all child files and folders.
            // You can filter children items in this implementation and
            // return only items that you want to be visible for this
            // particular user.
            IList <IHierarchyItemAsync> children  = new List <IHierarchyItemAsync>();
            IList <DataCloudItem>       childData = await context.DataLakeStoreService.GetChildrenAsync(Path);

            long totalItems = childData.Count;

            // Apply sorting.
            childData = SortChildren(childData, orderProps);
            // Apply paging.
            if (offset.HasValue && nResults.HasValue)
            {
                childData = childData.Skip((int)offset.Value).Take((int)nResults.Value).ToArray();
            }
            foreach (DataCloudItem dataLakeItem in childData)
            {
                IHierarchyItemAsync child;
                if (dataLakeItem.IsDirectory)
                {
                    child = new DavFolder(dataLakeItem, context, dataLakeItem.Path);
                }
                else
                {
                    DataCloudItem item = await context.DataLakeStoreService.GetItemAsync(dataLakeItem.Path);

                    dataLakeItem.Properties  = item.Properties;
                    dataLakeItem.ContentType = item.ContentType;
                    child = new DavFile(dataLakeItem, context, dataLakeItem.Path);
                }
                children.Add(child);
            }
            return(new PageResults(children, totalItems));
        }