Example #1
0
        public static void InitializeHttpHandlers(string config = null)
        {
            if (!HostingEnvironment.IsHosted)
            {
                throw new InvalidOperationException("Application not hosted.");
            }

            var section = GetSection(config);

            if (section != null)
            {
                var discHandler = section.Handlers.GetHandler("disc");
                if (discHandler != null)
                {
                    var props = discHandler.GetProperties();
                    foreach (var m in section.Modules.Cast <ModuleConfigurationElement>().Where(m => m.Type == "disc"))
                    {
                        DiscDataHandler.RegisterVirtualPath(
                            PathUtils.ResolveVirtualPath(m.VirtualPath),
                            PathUtils.ResolvePhysicalPath(m.Path, props));

                        foreach (var d in m.Domains.Cast <DomainConfigurationElement>().Where(d => d.Type == "disc" || string.IsNullOrEmpty(d.Type)))
                        {
                            DiscDataHandler.RegisterVirtualPath(
                                PathUtils.ResolveVirtualPath(d.VirtualPath),
                                PathUtils.ResolvePhysicalPath(d.Path, props));
                        }
                    }
                }
            }
        }
Example #2
0
        public static void InitializeHttpHandlers(string config = null)
        {
            if (!HostingEnvironment.IsHosted)
            {
                throw new InvalidOperationException("Application not hosted.");
            }

            var section = GetSection(config);

            if (section != null)
            {
                //old scheme
                var discHandler = section.Handlers.GetHandler("disc");
                if (discHandler != null)
                {
                    var props = discHandler.GetProperties();
                    foreach (var m in section.Modules.Cast <ModuleConfigurationElement>().Where(m => m.Type == "disc"))
                    {
                        if (m.Path.Contains(Constants.STORAGE_ROOT_PARAM))
                        {
                            DiscDataHandler.RegisterVirtualPath(
                                PathUtils.ResolveVirtualPath(m.VirtualPath),
                                PathUtils.ResolvePhysicalPath(m.Path, props),
                                m.Public);
                        }

                        foreach (var d in m.Domains.Cast <DomainConfigurationElement>().Where(d => (d.Type == "disc" || string.IsNullOrEmpty(d.Type)) && d.Path.Contains(Constants.STORAGE_ROOT_PARAM)))
                        {
                            DiscDataHandler.RegisterVirtualPath(
                                PathUtils.ResolveVirtualPath(d.VirtualPath),
                                PathUtils.ResolvePhysicalPath(d.Path, props));
                        }
                    }
                }

                //new scheme
                foreach (var m in section.Modules.Cast <ModuleConfigurationElement>())
                {
                    //todo: add path criterion
                    if (m.Type == "disc" || !m.Public || m.Path.Contains(Constants.STORAGE_ROOT_PARAM))
                    {
                        StorageHandler.RegisterVirtualPath(
                            m.Name,
                            string.Empty,
                            m.Public);
                    }

                    //todo: add path criterion
                    foreach (var d in m.Domains.Cast <DomainConfigurationElement>().Where(d => d.Path.Contains(Constants.STORAGE_ROOT_PARAM)))
                    {
                        StorageHandler.RegisterVirtualPath(
                            m.Name,
                            d.Name,
                            d.Public);
                    }
                }
            }
        }
        public static void InitializeHttpHandlers(this IEndpointRouteBuilder builder, string config = null)
        {
            //TODO:
            //if (!HostingEnvironment.IsHosted)
            //{
            //    throw new InvalidOperationException("Application not hosted.");
            //}

            var section = builder.ServiceProvider.GetService <Configuration.Storage>();

            if (section != null)
            {
                //old scheme
                var discHandler = section.GetHandler("disc");
                if (discHandler != null && section.Module != null)
                {
                    var props = discHandler.Property != null?discHandler.Property.ToDictionary(r => r.Name, r => r.Value) : new Dictionary <string, string>();

                    foreach (var m in section.Module.Where(m => m.Type == "disc"))
                    {
                        if (m.Path.Contains(Constants.STORAGE_ROOT_PARAM))
                        {
                            builder.RegisterDiscDataHandler(
                                PathUtils.ResolveVirtualPath(m.VirtualPath),
                                PathUtils.ResolvePhysicalPath(m.Path, props),
                                m.Public);
                        }

                        if (m.Domain != null)
                        {
                            foreach (var d in m.Domain.Where(d => (d.Type == "disc" || string.IsNullOrEmpty(d.Type)) && d.Path.Contains(Constants.STORAGE_ROOT_PARAM)))
                            {
                                builder.RegisterDiscDataHandler(
                                    PathUtils.ResolveVirtualPath(d.VirtualPath),
                                    PathUtils.ResolvePhysicalPath(d.Path, props));
                            }
                        }
                    }
                }

                //new scheme
                if (section.Module != null)
                {
                    foreach (var m in section.Module)
                    {
                        //todo: add path criterion
                        if (m.Type == "disc" || !m.Public || m.Path.Contains(Constants.STORAGE_ROOT_PARAM))
                        {
                            builder.RegisterStorageHandler(
                                m.Name,
                                string.Empty,
                                m.Public);
                        }

                        //todo: add path criterion
                        if (m.Domain != null)
                        {
                            foreach (var d in m.Domain.Where(d => d.Path.Contains(Constants.STORAGE_ROOT_PARAM)))
                            {
                                builder.RegisterStorageHandler(
                                    m.Name,
                                    d.Name,
                                    d.Public);
                            }
                        }
                    }
                }
            }
        }