示例#1
0
        /// <summary>
        /// Gets a collection of all the resources in the data source that conform to the specified <see cref="SyndicationContentFormat"/>.
        /// </summary>
        /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the content format to filter resources by.</param>
        /// <returns>
        ///     A <see cref="Collection{T}"/> of <see cref="ISyndicationResource"/> objects that represent the syndication resources that conform to the specified <paramref name="format"/>.
        /// </returns>
        private Collection <ISyndicationResource> ResourcesGet(SyndicationContentFormat format)
        {
            Collection <ISyndicationResource> resources = new Collection <ISyndicationResource>();

            DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath);

            if (applicationDirectory.Exists)
            {
                FileInfo[] files = applicationDirectory.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (file.Exists)
                    {
                        SyndicationContentFormat contentFormat = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension);
                        if (contentFormat == format)
                        {
                            using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                            {
                                ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(contentFormat, stream);
                                if (resource != null)
                                {
                                    resources.Add(resource);
                                }
                            }
                        }
                    }
                }
            }

            return(resources);
        }
示例#2
0
        /// <summary>
        /// Retrieves a <see cref="ISyndicationResource"/> from the data store that has the specified key.
        /// </summary>
        /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier for the resource to be retrieved.</param>
        /// <returns>
        ///     The <see cref="ISyndicationResource"/> that has the specified <paramref name="resourceKey"/>.
        ///     If no resource exists for the specified <paramref name="resourceKey"/>, returns a <b>null</b> reference.
        /// </returns>
        private ISyndicationResource ResourceGet(Guid resourceKey)
        {
            ISyndicationResource resource = null;

            if (!this.ResourceKeyExists(resourceKey))
            {
                return(null);
            }

            DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath);

            if (applicationDirectory.Exists)
            {
                FileInfo[] files = applicationDirectory.GetFiles(String.Format(null, "{0}.*", resourceKey.ToString()));
                if (files != null && files.Length == 1 && files[0].Exists)
                {
                    using (FileStream stream = new FileStream(files[0].FullName, FileMode.Open, FileAccess.Read))
                    {
                        SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(files[0].Extension);
                        if (format != SyndicationContentFormat.None)
                        {
                            resource = XmlSyndicationResourceProvider.BuildResource(format, stream);
                        }
                    }
                }
            }

            return(resource);
        }
示例#3
0
        /// <summary>
        /// Gets a collection of all the resources in the data source in pages of data.
        /// </summary>
        /// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex"/> is zero-based.</param>
        /// <param name="pageSize">The size of the page of results to return.</param>
        /// <param name="totalRecords">The total number of syndication resources in the data store.</param>
        /// <returns>
        ///     A <see cref="Collection{T}"/> that contains a page of <see cref="ISyndicationResource"/> objects
        ///     with a size of <paramref name="pageSize"/>, beginning at the page specified by <paramref name="pageIndex"/>.
        /// </returns>
        private Collection <ISyndicationResource> ResourcesGet(int pageIndex, int pageSize, out int totalRecords)
        {
            Collection <ISyndicationResource> resources      = new Collection <ISyndicationResource>();
            Collection <ISyndicationResource> pagedResources = new Collection <ISyndicationResource>();

            DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath);

            if (applicationDirectory.Exists)
            {
                FileInfo[] files = applicationDirectory.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (file.Exists)
                    {
                        SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension);
                        if (format != SyndicationContentFormat.None)
                        {
                            using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                            {
                                ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(format, stream);
                                if (resource != null)
                                {
                                    resources.Add(resource);
                                }
                            }
                        }
                    }
                }
            }

            totalRecords = resources.Count;

            if (pageSize > resources.Count)
            {
                pagedResources = new Collection <ISyndicationResource>(resources);
            }
            else
            {
                ISyndicationResource[] array = new ISyndicationResource[resources.Count];
                resources.CopyTo(array, 0);

                int startIndex = (pageIndex == 0 ? 0 : (pageSize + pageIndex - 1));
                for (int i = startIndex; i < pageSize; i++)
                {
                    if (i > array.Length - 1)
                    {
                        break;
                    }
                    pagedResources.Add(array[i]);
                }
            }

            return(pagedResources);
        }