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
  •  
  •  
  •  
29 changes: 28 additions & 1 deletion 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 @@ -344,6 +344,32 @@ public override SynchronizationContext CreateCopy()
}
}

// TODO: Migrate to IHostedService - IRegisteredObject not supported in .NET 8
// Temporary stub to allow compilation
internal class BackgroundWorkHost
{
private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();

public CancellationTokenSource ShutdownCancellationTokenSource => _shutdownCancellationTokenSource;

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

public void Register(Task work, CancellationToken cancellationToken)
{
// Stub implementation - just continue the task
work.ContinueWith(_ => { }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
}

/*
// Original implementation commented out
internal class BackgroundWorkHost : IRegisteredObject
{
private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -421,4 +447,5 @@ private void FinalShutdown()
}

}
*/
}
2 changes: 1 addition & 1 deletion 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
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
4 changes: 4 additions & 0 deletions src/Libraries/SmartStore.Core/Caching/MemoryCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Caching.Memory;
using System.Runtime.Caching;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
Expand All @@ -10,6 +11,9 @@
using SmartStore.Core.Infrastructure.DependencyManagement;
using SmartStore.Utilities;
using SmartStore.Utilities.Threading;
using MemoryCache = System.Runtime.Caching.MemoryCache;
using CacheItemPolicy = System.Runtime.Caching.CacheItemPolicy;
using ObjectCache = System.Runtime.Caching.ObjectCache;

namespace SmartStore.Core.Caching
{
Expand Down
135 changes: 4 additions & 131 deletions src/Libraries/SmartStore.Core/Caching/RequestCache.cs
Original file line number Diff line number Diff line change
@@ -1,134 +1,7 @@
ο»Ώusing System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using SmartStore.Utilities;
// TODO: Migrate to ASP.NET Core - System.Web types not supported
// This file has been temporarily disabled for .NET 8 migration

namespace SmartStore.Core.Caching
namespace SmartStore.Core
{
public class RequestCache : DisposableObject, IRequestCache
{
const string RegionName = "SmartStoreNET:";

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

private readonly HttpContextBase _context;

public RequestCache(HttpContextBase context)
{
_context = context;
}

public T Get<T>(string key)
{
return Get<T>(key, null);
}

public T Get<T>(string key, Func<T> acquirer)
{
var items = GetItems();

key = BuildKey(key);

if (items.Contains(key))
{
return (T)items[key];
}

if (acquirer != null)
{
var value = acquirer();
items.Add(key, value);
return value;
}

return default(T);
}

public void Put(string key, object value)
{
var items = GetItems();

key = BuildKey(key);

if (items.Contains(key))
items[key] = value;
else
items.Add(key, value);
}

public void Clear()
{
RemoveByPattern("*");
}

public bool Contains(string key)
{
return GetItems().Contains(BuildKey(key));
}

public void Remove(string key)
{
GetItems().Remove(BuildKey(key));
}

public void RemoveByPattern(string pattern)
{
var items = GetItems();

var keysToRemove = Keys(pattern).ToArray();

foreach (string key in keysToRemove)
{
items.Remove(BuildKey(key));
}
}

protected IDictionary GetItems()
{
return _context.Items ?? _emptyDictionary;
}

public IEnumerable<string> Keys(string pattern)
{
var items = GetItems();

if (items.Count == 0)
yield break;

var prefixLen = RegionName.Length;

pattern = pattern.NullEmpty() ?? "*";
var wildcard = new Wildcard(pattern, RegexOptions.IgnoreCase);

var enumerator = items.GetEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Key is string key)
{
if (key.StartsWith(RegionName))
{
key = key.Substring(prefixLen);
if (pattern == "*" || wildcard.IsMatch(key))
{
yield return key;
}
}
}
}
}

private string BuildKey(string key)
{
return RegionName + key.EmptyNull();
}

protected override void OnDispose(bool disposing)
{
if (disposing)
Clear();
}
}
// Placeholder - original implementation commented out
}
Loading