Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Upgrade to .NET 8 on Iteration 33
  • Loading branch information
Version Upgrade committed Oct 14, 2025
commit 91e36474cbffba24d617d3aefee3534aeecd7a43
238 changes: 158 additions & 80 deletions src/Libraries/SmartStore.Core/Async/AsyncRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Hosting;
using Microsoft.AspNetCore.Hosting;
using Autofac;
using SmartStore.Core.Infrastructure;

Expand Down Expand Up @@ -108,12 +108,13 @@ public TResult Run<TResult>(Task<TResult> task, Action<Task<TResult>> continuati

#endregion

private static readonly BackgroundWorkHost _host = new BackgroundWorkHost();
// TODO: Migrate to IHostApplicationLifetime
// private static readonly BackgroundWorkHost _host = new BackgroundWorkHost();

/// <summary>
/// Gets the global cancellation token which signals the application shutdown
/// </summary>
public static CancellationToken AppShutdownCancellationToken => _host.ShutdownCancellationTokenSource.Token;
public static CancellationToken AppShutdownCancellationToken => CancellationToken.None; // TODO: Use IHostApplicationLifetime.ApplicationStopping

public static AsyncRunner Create()
{
Expand Down Expand Up @@ -344,81 +345,158 @@ public override SynchronizationContext CreateCopy()
}
}

internal class BackgroundWorkHost : IRegisteredObject
{
private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
private int _numRunningWorkItems;

public BackgroundWorkHost()
{
HostingEnvironment.RegisterObject(this);
}

public CancellationTokenSource ShutdownCancellationTokenSource => _shutdownCancellationTokenSource;

public void Stop(bool immediate)
{
int num;
lock (this)
{
_shutdownCancellationTokenSource.Cancel();
num = _numRunningWorkItems;
}
if (num == 0)
{
FinalShutdown();
}
}

public CancellationTokenSource CreateCompositeCancellationTokenSource(CancellationToken userCancellationToken)
{
if (userCancellationToken == CancellationToken.None)
{
return _shutdownCancellationTokenSource;
}
return CancellationTokenSource.CreateLinkedTokenSource(_shutdownCancellationTokenSource.Token, userCancellationToken);
}

public void Register(Task work, CancellationToken cancellationToken)
{
if (!cancellationToken.IsCancellationRequested)
{
lock (this)
{
if (cancellationToken.IsCancellationRequested)
{
return;
}
_numRunningWorkItems++;
}

work.ContinueWith(
WorkItemComplete,
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
}

private void WorkItemComplete(Task work)
{
int num;
bool isCancellationRequested;
lock (this)
{
num = --_numRunningWorkItems;
isCancellationRequested = _shutdownCancellationTokenSource.IsCancellationRequested;
}
if (num == 0 && isCancellationRequested)
{
FinalShutdown();
}
}

private void FinalShutdown()
{
HostingEnvironment.UnregisterObject(this);
}

}
// TODO: Migrate to IHostedService
// internal class BackgroundWorkHost : IRegisteredObject
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
// TODO: Migrate to IHostedService
// private int _numRunningWorkItems;
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// public BackgroundWorkHost()
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// HostingEnvironment.RegisterObject(this);
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// public CancellationTokenSource ShutdownCancellationTokenSource => _shutdownCancellationTokenSource;
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// public void Stop(bool immediate)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// int num;
// TODO: Migrate to IHostedService
// lock (this)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// _shutdownCancellationTokenSource.Cancel();
// TODO: Migrate to IHostedService
// num = _numRunningWorkItems;
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// if (num == 0)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// FinalShutdown();
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// public CancellationTokenSource CreateCompositeCancellationTokenSource(CancellationToken userCancellationToken)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// if (userCancellationToken == CancellationToken.None)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// return _shutdownCancellationTokenSource;
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// return CancellationTokenSource.CreateLinkedTokenSource(_shutdownCancellationTokenSource.Token, userCancellationToken);
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// public void Register(Task work, CancellationToken cancellationToken)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// if (!cancellationToken.IsCancellationRequested)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// lock (this)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// if (cancellationToken.IsCancellationRequested)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// return;
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// _numRunningWorkItems++;
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// work.ContinueWith(
// TODO: Migrate to IHostedService
// WorkItemComplete,
// TODO: Migrate to IHostedService
// CancellationToken.None,
// TODO: Migrate to IHostedService
// TaskContinuationOptions.ExecuteSynchronously,
// TODO: Migrate to IHostedService
// TaskScheduler.Default);
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// private void WorkItemComplete(Task work)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// int num;
// TODO: Migrate to IHostedService
// bool isCancellationRequested;
// TODO: Migrate to IHostedService
// lock (this)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// num = --_numRunningWorkItems;
// TODO: Migrate to IHostedService
// isCancellationRequested = _shutdownCancellationTokenSource.IsCancellationRequested;
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// if (num == 0 && isCancellationRequested)
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// FinalShutdown();
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// private void FinalShutdown()
// TODO: Migrate to IHostedService
// {
// TODO: Migrate to IHostedService
// HostingEnvironment.UnregisterObject(this);
// TODO: Migrate to IHostedService
// }
// TODO: Migrate to IHostedService
//
// TODO: Migrate to IHostedService
// }
}
6 changes: 3 additions & 3 deletions src/Libraries/SmartStore.Core/Async/LocalAsyncState.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using Microsoft.Extensions.Caching.Memory;
using System.Threading;

namespace SmartStore.Core.Async
Expand Down Expand Up @@ -60,7 +60,7 @@ public virtual void Set<T>(T state, string name = null, bool neverExpires = fals
{
// add new entry
var duration = neverExpires ? TimeSpan.Zero : TimeSpan.FromMinutes(15);
var policy = new CacheItemPolicy
var policy = new MemoryCacheEntryOptions
{
SlidingExpiration = duration,
Priority = CacheItemPriority.NotRemovable
Expand Down Expand Up @@ -155,7 +155,7 @@ public virtual void SetCancelTokenSource<T>(CancellationTokenSource cancelTokenS
OnRemoveCancelTokenSource(key);
}

var policy = new CacheItemPolicy { Priority = CacheItemPriority.NotRemovable };
var policy = new MemoryCacheEntryOptions { Priority = CacheItemPriority.NotRemovable };

_cancelTokens.Set(key, cancelTokenSource, policy);
}
Expand Down
1 change: 0 additions & 1 deletion src/Libraries/SmartStore.Core/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Core.Objects;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
Expand Down
8 changes: 4 additions & 4 deletions src/Libraries/SmartStore.Core/Caching/MemoryCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using Microsoft.Extensions.Caching.Memory;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task<T> GetAsync<T>(string key, Func<Task<T>> acquirer, TimeSpan? d

public void Put(string key, object value, TimeSpan? duration = null, IEnumerable<string> dependencies = null)
{
_cache.Set(key, value ?? FakeNull, GetCacheItemPolicy(duration, dependencies));
_cache.Set(key, value ?? FakeNull, GetMemoryCacheEntryOptions(duration, dependencies));
}

public bool Contains(string key)
Expand Down Expand Up @@ -207,7 +207,7 @@ public virtual ISet GetHashSet(string key, Func<IEnumerable<string>> acquirer =
return result;
}

private CacheItemPolicy GetCacheItemPolicy(TimeSpan? duration, IEnumerable<string> dependencies)
private MemoryCacheEntryOptions GetMemoryCacheEntryOptions(TimeSpan? duration, IEnumerable<string> dependencies)
{
var absoluteExpiration = ObjectCache.InfiniteAbsoluteExpiration;

Expand All @@ -216,7 +216,7 @@ private CacheItemPolicy GetCacheItemPolicy(TimeSpan? duration, IEnumerable<strin
absoluteExpiration = DateTime.UtcNow + duration.Value;
}

var cacheItemPolicy = new CacheItemPolicy
var cacheItemPolicy = new MemoryCacheEntryOptions
{
AbsoluteExpiration = absoluteExpiration,
SlidingExpiration = ObjectCache.NoSlidingExpiration
Expand Down
6 changes: 3 additions & 3 deletions src/Libraries/SmartStore.Core/Caching/RequestCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Microsoft.AspNetCore.Http;
using SmartStore.Utilities;

namespace SmartStore.Core.Caching
Expand All @@ -14,9 +14,9 @@ public class RequestCache : DisposableObject, IRequestCache

private readonly IDictionary _emptyDictionary = new Dictionary<string, object>();

private readonly HttpContextBase _context;
private readonly HttpContext _context;

public RequestCache(HttpContextBase context)
public RequestCache(HttpContext context)
{
_context = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Web.Routing;
using Microsoft.AspNetCore.Routing;
using SmartStore.Utilities;

namespace SmartStore.ComponentModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.Web.Routing;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json.Linq;
using SmartStore.Core.Domain.Catalog;
using SmartStore.Core.Domain.Shipping;
Expand Down
1 change: 0 additions & 1 deletion src/Libraries/SmartStore.Core/Data/DataSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using System.IO;
using System.Linq;
using System.Threading;
Expand Down
Loading