Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
0
        /// <summary>
        /// Gets resource information from the data source based on the unique identifier for the syndication resource.
        /// </summary>
        /// <param name="providerResourceKey">The unique identifier that identifies the syndication resource to get information for.</param>
        /// <returns>An object that implements the <see cref="ISyndicationResource"/> interface populated with the specified resources's information from the data source.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException">The <paramref name="providerResourceKey"/> does not represent a valid <see cref="System.Guid"/> structure.</exception>
        public override ISyndicationResource GetResource(Object providerResourceKey)
        {
            Guid resourceKey = Guid.Empty;

            Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey");

            if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey))
            {
                throw new ArgumentException(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey), "providerResourceKey");
            }

            lock (providerSyncObject)
            {
                return(this.ResourceGet(resourceKey));
            }
        }
Exemple #5
0
        /// <summary>
        /// Builds the physical file path for a syndication resource XML data file using the supplied <see cref="Guid"/> and <see cref="SyndicationContentFormat"/>.
        /// </summary>
        /// <param name="resourceKey">The globally unique identifier for the syndication resource that is used to as the file name.</param>
        /// <param name="format">The <see cref="SyndicationContentFormat"/> enumeration value that determines the file extension that is used.</param>
        /// <returns>The physical file path for a syndication resource XML data file using the supplied <see cref="Guid"/> and <see cref="SyndicationContentFormat"/>.</returns>
        /// <remarks>
        ///     If the physical file path for a syndication resource XML data file defines a directory path that does not exist,
        ///     the <see cref="BuildResourcePath(Guid, SyndicationContentFormat)"/> method will attempt to create the directory.
        /// </remarks>
        private string BuildResourcePath(Guid resourceKey, SyndicationContentFormat format)
        {
            string applicationDirectory  = this.ApplicationPath.TrimEnd("\\".ToCharArray());
            string resourceFileExtension = XmlSyndicationResourceProvider.ContentFormatAsFileExtension(format);

            string path = String.Format(null, "{0}\\{1}{2}", applicationDirectory, resourceKey.ToString(), resourceFileExtension);

            FileInfo pathInfo = new FileInfo(path);

            if (!pathInfo.Directory.Exists)
            {
                pathInfo.Directory.Create();
            }

            return(path);
        }
Exemple #6
0
        /// <summary>
        /// Adds a new syndication resource to the data source.
        /// </summary>
        /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param>
        /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param>
        /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public override SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource)
        {
            Guid resourceKey = Guid.Empty;

            Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey");
            Guard.ArgumentNotNull(resource, "resource");

            if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey))
            {
                System.Diagnostics.Trace.TraceError(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey));
                return(SyndicationResourceCreateStatus.InvalidProviderResourceKey);
            }

            lock (providerSyncObject)
            {
                return(this.ResourceAdd(resourceKey, resource));
            }
        }