public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jobj = JObject.Load(reader);
            var repo = existingValue as DotvvmResourceRepository;

            if (repo == null)
            {
                repo = new DotvvmResourceRepository();
            }
            foreach (var prop in jobj)
            {
                Type type;
                if (ResourceTypeNames.TryGetValue(prop.Key, out type))
                {
                    DeserializeResources((JObject)prop.Value, type, serializer, repo);
                }
                else if (UnknownResourceType != null)
                {
                    DeserializeResources((JObject)prop.Value, UnknownResourceType, serializer, repo);
                }
                else
                {
                    throw new NotSupportedException(string.Format("resource collection name {0} is not supported", prop.Key));
                }
            }
            return(repo);
        }
 void DeserializeResources(JObject jobj, Type resourceType, JsonSerializer serializer, DotvvmResourceRepository repo)
 {
     foreach (var resObj in jobj)
     {
         var resource = serializer.Deserialize(resObj.Value.CreateReader(), resourceType) as ResourceBase;
         repo.Register(resObj.Key, resource);
     }
 }
 public LocalResourceUrlManager(DotvvmConfiguration configuration, IResourceHashService hasher)
 {
     this.resourceRoute        = new DotvvmRoute("dotvvmResource/{hash}/{name:regex(.*)}", null, null, null, configuration);
     this.hasher               = hasher;
     this.resources            = configuration.Resources;
     this.alternateDirectories = configuration.Debug ? new ConcurrentDictionary <string, string>() : null;
     this.suppressVersionHash  = configuration.Debug;
 }
Example #4
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;
            }
        }
Example #5
0
 public LocalResourceUrlManager(DotvvmConfiguration configuration, IResourceHashService hasher)
 {
     this.resourceRoute = new DotvvmRoute(
         url: $"{HostingConstants.ResourceRouteName}/{{{HashParameterName}}}/{{{NameParameterName}:regex(.*)}}",
         virtualPath: "",
         defaultValues: null,
         presenterFactory: _ => throw new NotSupportedException(),
         configuration: configuration);
     this.hasher               = hasher;
     this.resources            = configuration.Resources;
     this.alternateDirectories = configuration.Debug ? new ConcurrentDictionary <string, string?>() : null;
     this.suppressVersionHash  = configuration.Debug;
 }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     var jobj = JObject.Load(reader);
     var repo = existingValue as DotvvmResourceRepository;
     if (repo == null) repo = new DotvvmResourceRepository();
     foreach (var prop in jobj)
     {
         Type type;
         if (ResourceTypeNames.TryGetValue(prop.Key, out type))
         {
             DeserializeResources((JObject)prop.Value, type, serializer, repo);
         }
         else
             throw new NotSupportedException(string.Format("resource collection name {0} is not supported", prop.Key));
     }
     return repo;
 }
 public DotvvmResourceRepository(DotvvmResourceRepository parent)
 {
     this.Parents.TryAdd("", parent);
 }
 public DotvvmResourceRepository(DotvvmResourceRepository parent) : this()
 {
     this.Resources = new ConcurrentDictionary <string, ResourceBase>();
     this.Parents.TryAdd("", parent);
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceManager"/> class.
 /// </summary>
 public ResourceManager(DotvvmResourceRepository repository)
 {
     this.repository = repository;
 }
 void DeserializeResources(JObject jobj, Type resourceType, JsonSerializer serializer, DotvvmResourceRepository repo)
 {
     foreach (var resObj in jobj)
     {
         var resource = serializer.Deserialize(resObj.Value.CreateReader(), resourceType) as ResourceBase;
         repo.Register(resObj.Key, resource);
     }
 }
        void DeserializeResources(JObject jobj, Type resourceType, JsonSerializer serializer, DotvvmResourceRepository repo)
        {
            foreach (var resObj in jobj)
            {
                try
                {
                    var resource = serializer.Deserialize(resObj.Value.CreateReader(), resourceType) as IResource;
                    if (resource is LinkResourceBase linkResource)
                    {
                        if (linkResource.Location == null)
                        {
                            linkResource.Location = new UnknownResourceLocation();
                        }
                    }

                    repo.Register(resObj.Key, resource);
                }
                catch (Exception ex)
                {
                    repo.Register(resObj.Key, new DeserializationErrorResource(ex, resObj.Value));
                }
            }
        }
 public DotvvmResourceRepository(DotvvmResourceRepository parent) : this()
 {
     this.Resources = new ConcurrentDictionary<string, ResourceBase>();
     this.Parents.TryAdd("", parent);
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotvvmConfiguration"/> class.
 /// </summary>
 internal DotvvmConfiguration()
 {
     DefaultCulture = Thread.CurrentThread.CurrentCulture.Name;
     Markup = new DotvvmMarkupConfiguration();
     RouteTable = new DotvvmRouteTable(this);
     Resources = new DotvvmResourceRepository();
     Security = new DotvvmSecurityConfiguration();
     Runtime = new DotvvmRuntimeConfiguration();
     Debug = true;
     Styles = new StyleRepository();
 }