コード例 #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);
        }