Пример #1
0
        /// <summary>
        /// When overridden in a derived class, returns a read-only stream to the virtual resource.
        /// </summary>
        /// <returns>
        /// A read-only stream to the virtual file.
        /// </returns>
        public Stream Open()
        {
            string resourceName;

            // Get this assembly.
            Assembly assembly = typeof(ResourceController).Assembly;
            Stream   output   = EmbeddedResourceHelper.GetResource(assembly, this.virtualPath, out resourceName);

            if (output == null)
            {
                // We need to loop through the loaded criteria and check each one.
                Assembly localAssembly = assembly;
                IEnumerable <IPersonalisationGroupCriteria> criteria =
                    PersonalisationGroupMatcher
                    .GetAvailableCriteria().Where(a => a.GetType().Assembly != localAssembly);

                foreach (IPersonalisationGroupCriteria criterion in criteria)
                {
                    string resource = EmbeddedResourceHelper.SanitizeCriteriaResourceName(this.virtualPath);

                    assembly     = criterion.GetType().Assembly;
                    resourceName = assembly.GetManifestResourceNames().FirstOrDefault(r => r.InvariantEndsWith(resource));

                    if (!string.IsNullOrWhiteSpace(resourceName))
                    {
                        return(EmbeddedResourceHelper.GetResource(assembly, resource, out resourceName));
                    }
                }
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Returns a value indicating whether the virtual file exists for the given path.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool FileExists(string virtualPath)
        {
            if (!virtualPath.EndsWith(AppConstants.ResourceExtension, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            return(EmbeddedResourceHelper.ResourceExists(virtualPath));
        }