예제 #1
0
        /// <summary>
        /// Adds the required resource with specified name.
        /// </summary>
        public void AddRequiredResource(string name)
        {
            var resource = repository.FindResource(name);

            if (resource == null)
            {
                ThrowResourceNotFound(name);
            }

            AddRequiredResourceCore(name, resource);
        }
예제 #2
0
        public ILocalResourceLocation FindResource(string url, IDotvvmRequestContext context, out string mimeType)
        {
            mimeType = null;
            if (DotvvmRoutingMiddleware.FindMatchingRoute(new[] { resourceRoute }, context, out var parameters) == null)
            {
                return(null);
            }

            var name = DecodeResourceName((string)parameters[NameParameterName]);
            var hash = (string)parameters[HashParameterName];

            if (resources.FindResource(name) is IResource resource)
            {
                var location = FindLocation(resource, out mimeType);
                if (GetVersionHash(location, context, name) == hash) // check if the resource matches so that nobody can guess the url by chance
                {
                    if (alternateDirectories != null)
                    {
                        alternateDirectories.GetOrAdd(hash, _ => (location as IDebugFileLocalLocation)?.GetFilePath(context));
                    }

                    return(location);
                }
            }

            return(TryLoadAlternativeFile(name, hash, context));
        }
예제 #3
0
        public static void SetEmbeddedResourceDebugFile(this DotvvmResourceRepository repo, string resourceName, string filePath)
        {
            var location = repo.FindResource(resourceName).As <ILinkResource>()?.GetLocations()?.OfType <EmbeddedResourceLocation>()?.FirstOrDefault();

            if (location != null)
            {
                location.DebugFilePath = filePath;
            }
        }