Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Jan 26, 2024
1 parent d126cfe commit 9669e04
Show file tree
Hide file tree
Showing 75 changed files with 429 additions and 483 deletions.
3 changes: 2 additions & 1 deletion src/Imageflow.Server/ImageflowMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public ImageflowMiddleware(
new MiddlewareOptionsServerBuilder(container, logger, retainedLogStore, options, env).PopulateServices();


var startDiag = new StartupDiagnostics(serviceProvider);
var startDiag = new StartupDiagnostics(container);
startDiag.LogIssues(logger);
startDiag.Validate(logger);

imageServer = container.GetRequiredService<IImageServer<RequestStreamAdapter,ResponseStreamAdapter, HttpContext>>();
options.Licensing.Initialize(this.options);
Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server/Internal/GlobalInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Imazen.Abstractions.DependencyInjection;
using Imazen.Common.Instrumentation.Support;
using Imazen.Common.Instrumentation.Support.InfoAccumulators;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Serving;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server/Internal/Licensing.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Imazen.Common.Licensing;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Serving;

namespace Imageflow.Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Imazen.Abstractions.Logging;
using Imazen.Common.Storage;
using Imazen.Routing.Compatibility.ImageflowServer;
using Imazen.Routing.Engine;
using Imazen.Routing.Health;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Layers;
using Imazen.Routing.RequestRouting;
using Imazen.Routing.RequestRouting.Layers;
using Imazen.Routing.RequestRouting.Promises;
using Imazen.Routing.Promises;
using Imazen.Routing.Requests;
using Imazen.Routing.Serving;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -48,7 +48,9 @@ public void PopulateServices()
serverContainer.Register<ImageflowMiddlewareOptions>(options);
serverContainer.CopyFromOuter<IBlobCache>();
serverContainer.CopyFromOuter<IBlobCacheProvider>();
#pragma warning disable CS0618 // Type or member is obsolete
serverContainer.CopyFromOuter<IBlobProvider>();
#pragma warning restore CS0618 // Type or member is obsolete
serverContainer.CopyFromOuter<IBlobWrapperProvider>();
var perfTracker = new NullPerformanceTracker();
serverContainer.Register<IPerformanceTracker>(perfTracker);
Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server/Internal/QueryCollectionWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Serving;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server/Internal/RequestStreamAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO.Pipelines;
using System.Net;
using Imazen.Abstractions.HttpStrings;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Serving;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server/Internal/ResponseStreamAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Buffers;
using System.IO.Pipelines;
using Imazen.Routing.HttpAbstractions;
using Imazen.Routing.Serving;
using Microsoft.AspNetCore.Http;

Expand Down
2 changes: 1 addition & 1 deletion src/Imageflow.Server/LegacyOptions/PathMapping.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Imazen.Routing.RequestRouting.Layers;
using Imazen.Routing.Layers;

namespace Imageflow.Server
{
Expand Down
2 changes: 1 addition & 1 deletion src/Imageflow.Server/UpdatedUrlEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Imazen.Routing.RequestRouting;
using Imazen.Routing.Requests;
using Microsoft.Extensions.Primitives;
using Compat = Imazen.Routing.Compatibility.ImageflowServer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;

namespace Imazen.Abstractions.DependencyInjection;
Expand All @@ -17,89 +14,83 @@ public interface IImageServerContainer : IServiceProvider
bool Contains<T>();
}

public class ImageServerContainer : IImageServerContainer
public class ImageServerContainer(IServiceProvider? outerProvider) : IImageServerContainer
{
private readonly Dictionary<Type, List<object>> _services = new Dictionary<Type, List<object>>();
private readonly Dictionary<Type, List<object>> services = new();

public ImageServerContainer(IServiceProvider? outerProvider)
{
this.outerProvider = outerProvider;
}

public IServiceProvider? GetOuterProvider()
{
return outerProvider;
}

private IServiceProvider? outerProvider;

public IEnumerable<T> GetInstanceOfEverythingLocal<T>()
{
return _services.SelectMany(kvp => kvp.Value.Where(v => v is T).Cast<T>());
return services.SelectMany(kvp => kvp.Value.Where(v => v is T).Cast<T>());
}

public bool Contains<T>()
{
return _services.ContainsKey(typeof(T));
return services.ContainsKey(typeof(T));
}

public void Register<TService>(Func<TService> instanceCreator) where TService : class
{
var instance = instanceCreator();
if (instance == null) throw new ArgumentNullException(nameof(instanceCreator));
if (_services.ContainsKey(typeof(TService)))
if (services.ContainsKey(typeof(TService)))
{
_services[typeof(TService)].Add(instance);
services[typeof(TService)].Add(instance);
}
else
{
_services[typeof(TService)] = new List<object> { instance };
services[typeof(TService)] = [instance];
}
}
public void RegisterAll<TService>(IEnumerable<TService> instances)
{
if (_services.ContainsKey(typeof(TService)))
if (services.ContainsKey(typeof(TService)))
{
_services[typeof(TService)].AddRange(instances.Cast<object>());
services[typeof(TService)].AddRange(instances.Cast<object>());
}
else
{
_services[typeof(TService)] = instances.Cast<object>().ToList();
services[typeof(TService)] = instances.Cast<object>().ToList();
}
}

public void Register<TService>(TService instance) where TService : class
{
if (instance == null) throw new ArgumentNullException(nameof(instance));
if (_services.ContainsKey(typeof(TService)))
if (services.ContainsKey(typeof(TService)))
{
_services[typeof(TService)].Add(instance);
services[typeof(TService)].Add(instance);
}
else
{
_services[typeof(TService)] = new List<object> { instance };
services[typeof(TService)] = [instance];
}
}

public IEnumerable<TService> Resolve<TService>()
{
return _services[typeof(TService)].Cast<TService>();
return services[typeof(TService)].Cast<TService>();
}



public object GetService(Type serviceType)
public object? GetService(Type serviceType)
{
if (serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
var actualServiceType = serviceType.GetGenericArguments()[0];
if (_services.TryGetValue(actualServiceType, out var instances))
if (services.TryGetValue(actualServiceType, out var instances))
{
var method = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(actualServiceType);
var castMethod = typeof(Enumerable).GetMethod("Cast");
var method = castMethod!.MakeGenericMethod(actualServiceType);
return method.Invoke(null, new object[] { instances });
}
}
else if (_services.TryGetValue(serviceType, out var instances))
else if (services.TryGetValue(serviceType, out var instances))
{
return instances.First();
}
Expand Down
10 changes: 8 additions & 2 deletions src/Imazen.Abstractions/Logging/ReLogStoreReportOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace Imazen.Abstractions.Logging
{
public class ReLogStoreReportOptions

public enum ReLogStoreReportType
{

QuickSummary,
FullReport
}
public record ReLogStoreReportOptions
{
public ReLogStoreReportType ReportType { get; init; } = ReLogStoreReportType.QuickSummary;
}
}
2 changes: 1 addition & 1 deletion src/Imazen.Routing/Caching/BlobCacheEngineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Imageflow.Server.Caching;
namespace Imazen.Routing.Caching;
internal class BlobCacheEngineOptions{
public int MaxQueueBytes { get; set; } = 1024 * 1024 * 300; //300mb seems reasonable (was 100mb)
public int WaitForIdenticalRequestsTimeoutMs { get; set; } = 100000;
Expand Down
137 changes: 0 additions & 137 deletions src/Imazen.Routing/Caching/CacheManager.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/Imazen.Routing/Caching/ExistenceProbableMap.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Buffers;
using System.Security.Cryptography;
using System.Text;
using Imazen.Common.Instrumentation.Support;
using Imazen.Abstractions.BlobCache;
using Imazen.Abstractions.Blobs;
using Imazen.Abstractions.Resulting;
using Imazen.Common.Instrumentation.Support;


namespace Imageflow.Server.Caching
namespace Imazen.Routing.Caching
{
/// <summary>
/// Uses a (2MB) ConcurrentBitArray of size 2^24 to track whether a key is likely to exist in the cache.
Expand Down
Loading

0 comments on commit 9669e04

Please sign in to comment.