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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Libraries/SmartStore.Core/Async/AsyncRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Hosting;
using Autofac;
using SmartStore.Core.Infrastructure;

Expand Down Expand Up @@ -344,14 +343,14 @@ public override SynchronizationContext CreateCopy()
}
}

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

public BackgroundWorkHost()
{
HostingEnvironment.RegisterObject(this);
// No longer using HostingEnvironment.RegisterObject in .NET Core
}

public CancellationTokenSource ShutdownCancellationTokenSource => _shutdownCancellationTokenSource;
Expand Down Expand Up @@ -417,7 +416,13 @@ private void WorkItemComplete(Task work)

private void FinalShutdown()
{
HostingEnvironment.UnregisterObject(this);
// No longer using HostingEnvironment.UnregisterObject in .NET Core
_shutdownCancellationTokenSource.Dispose();
}

public void Dispose()
{
_shutdownCancellationTokenSource?.Dispose();
}

}
Expand Down
40 changes: 19 additions & 21 deletions src/Libraries/SmartStore.Core/Async/LocalAsyncState.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Threading;
using Microsoft.Extensions.Caching.Memory;

namespace SmartStore.Core.Async
{
public partial class LocalAsyncState : IAsyncState
{
private readonly MemoryCache _states = new MemoryCache("SmartStore.AsyncState.Progress");
private readonly MemoryCache _cancelTokens = new MemoryCache("SmartStore.AsyncState.CancelTokenSources");
private readonly MemoryCache _states = new MemoryCache(new MemoryCacheOptions());
private readonly MemoryCache _cancelTokens = new MemoryCache(new MemoryCacheOptions());

public virtual bool Exists<T>(string name = null)
{
Expand All @@ -32,20 +32,18 @@ public virtual T Get<T>(string name = null)

public virtual IEnumerable<T> GetAll<T>()
{
var keyPrefix = BuildKey<T>(null);
return _states
.Where(x => x.Key.StartsWith(keyPrefix))
.Select(x => x.Value)
.OfType<AsyncStateInfo>()
.Select(x => x.Progress)
.OfType<T>();
// Note: MemoryCache in .NET Core doesn't support enumeration
// This is a limitation that needs to be addressed with a different caching strategy
// For now, return empty collection
return Enumerable.Empty<T>();
}


public virtual void Set<T>(T state, string name = null, bool neverExpires = false)
{
Guard.NotNull(state, nameof(state));

var key = BuildKey<T>(name);
var value = GetStateInfo<T>(name);

if (value != null)
Expand All @@ -60,17 +58,17 @@ 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 options = new MemoryCacheEntryOptions();

if (!neverExpires)
{
SlidingExpiration = duration,
Priority = CacheItemPriority.NotRemovable
};
var key = BuildKey<T>(name);

// On expiration or removal: remove corresponding cancel token also.
policy.RemovedCallback = (x) => OnRemoveCancelTokenSource(key);
options.SlidingExpiration = duration;
}

options.Priority = CacheItemPriority.NeverRemove;
options.RegisterPostEvictionCallback((k, v, r, s) => OnRemoveCancelTokenSource(key));

_states.Set(key, new AsyncStateInfo { Progress = state, Duration = duration }, policy);
_states.Set(key, new AsyncStateInfo { Progress = state, Duration = duration }, options);
}
}

Expand Down Expand Up @@ -155,9 +153,9 @@ public virtual void SetCancelTokenSource<T>(CancellationTokenSource cancelTokenS
OnRemoveCancelTokenSource(key);
}

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

_cancelTokens.Set(key, cancelTokenSource, policy);
_cancelTokens.Set(key, cancelTokenSource, options);
}

public bool Cancel<T>(string name = null)
Expand Down
20 changes: 7 additions & 13 deletions 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 Expand Up @@ -30,18 +29,13 @@ public virtual string GetEntityName()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Type GetUnproxiedType()
{
#region Old
//var t = GetType();
//if (t.AssemblyQualifiedName.StartsWith("System.Data.Entity."))
//{
// // it's a proxied type
// t = t.BaseType;
//}

//return t;
#endregion

return ObjectContext.GetObjectType(GetType());
var t = GetType();
// Check if it's an EF Core proxy
if (t.Namespace != null && t.Namespace.StartsWith("Castle.Proxies"))
{
t = t.BaseType;
}
return t;
}

/// <summary>
Expand Down
31 changes: 8 additions & 23 deletions src/Libraries/SmartStore.Core/Caching/MemoryCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using SmartStore.Core.Infrastructure.DependencyManagement;
using SmartStore.Utilities;
using SmartStore.Utilities.Threading;
Expand All @@ -33,7 +33,7 @@ public MemoryCacheManager(Work<ICacheScopeAccessor> scopeAccessor)

private MemoryCache CreateCache()
{
return new MemoryCache("SmartStore");
return new MemoryCache(new MemoryCacheOptions());
}

public bool IsDistributedCache => false;
Expand Down Expand Up @@ -207,34 +207,19 @@ public virtual ISet GetHashSet(string key, Func<IEnumerable<string>> acquirer =
return result;
}

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

if (duration.HasValue)
{
absoluteExpiration = DateTime.UtcNow + duration.Value;
options.AbsoluteExpirationRelativeToNow = duration.Value;
}

var cacheItemPolicy = new CacheItemPolicy
{
AbsoluteExpiration = absoluteExpiration,
SlidingExpiration = ObjectCache.NoSlidingExpiration
};

if (dependencies != null && dependencies.Any())
{
// INFO: we can only depend on existing items, otherwise this entry will be removed immediately.
dependencies = dependencies.Where(x => x != null && _cache.Contains(x));
if (dependencies.Any())
{
cacheItemPolicy.ChangeMonitors.Add(_cache.CreateCacheEntryChangeMonitor(dependencies));
}
}

//cacheItemPolicy.RemovedCallback = OnRemoveEntry;
// Note: .NET Core MemoryCache doesn't support change monitors for dependencies
// This functionality would need to be implemented differently

return cacheItemPolicy;
return options;
}

//private void OnRemoveEntry(CacheEntryRemovedArguments args)
Expand Down
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Core/Caching/RequestCache.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // Disabled for .NET 8 - uses HttpRequestBase/HttpContextBase
ο»Ώusing System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -132,3 +133,4 @@ protected override void OnDispose(bool disposing)
}
}
}
#endif
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Core/Collections/TreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // Disabled for .NET 8 - depends on TreeNodeBase
ο»Ώusing System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -255,3 +256,4 @@ private object GetPropValue(string name, object instance)
}
}
}
#endif
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Core/Collections/TreeNodeBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // Disabled for .NET 8 migration
ο»Ώusing System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -698,3 +699,4 @@ public virtual T Clone(bool deep)
protected abstract T CreateInstance();
}
}
#endif
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
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Core/Data/DataProviderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // Disabled for .NET 8 migration
ο»Ώnamespace SmartStore.Core.Data
{
public abstract class DataProviderFactory
Expand All @@ -17,3 +18,4 @@ protected DataSettings Settings
public abstract IDataProvider LoadDataProvider();
}
}
#endif
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Core/Data/DataSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // Disabled for .NET 8 migration
ο»Ώusing System;
using System.Collections.Generic;
using System.Data.SqlClient;
Expand Down Expand Up @@ -354,3 +355,4 @@ protected virtual string SerializeSettings()
#endregion
}
}
#endif
13 changes: 7 additions & 6 deletions src/Libraries/SmartStore.Core/Data/Hooks/HookedEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ο»Ώusing System;
using System.Data.Entity.Infrastructure;
using EfState = System.Data.Entity.EntityState;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using EfState = Microsoft.EntityFrameworkCore.EntityState;

namespace SmartStore.Core.Data.Hooks
{
Expand All @@ -14,7 +15,7 @@ public interface IHookedEntity
/// <summary>
/// Gets the hooked entity entry
/// </summary>
DbEntityEntry Entry { get; }
EntityEntry Entry { get; }

/// <summary>
/// Gets the hooked entity instance
Expand Down Expand Up @@ -61,12 +62,12 @@ public class HookedEntity : IHookedEntity
{
private Type _entityType;

public HookedEntity(IDbContext context, DbEntityEntry entry)
public HookedEntity(IDbContext context, EntityEntry entry)
: this(context.GetType(), entry)
{
}

internal HookedEntity(Type contextType, DbEntityEntry entry)
internal HookedEntity(Type contextType, EntityEntry entry)
{
ContextType = contextType;
Entry = entry;
Expand All @@ -78,7 +79,7 @@ public Type ContextType
get;
}

public DbEntityEntry Entry
public EntityEntry Entry
{
get;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/SmartStore.Core/Data/IDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

namespace SmartStore.Core.Data
Expand Down Expand Up @@ -151,7 +151,7 @@ IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params ob
/// <typeparam name="TEntity">Type of entity</typeparam>
/// <param name="entity">The entity instance</param>
/// <param name="requestedState">The requested new state</param>
void ChangeState<TEntity>(TEntity entity, System.Data.Entity.EntityState requestedState) where TEntity : BaseEntity;
void ChangeState<TEntity>(TEntity entity, Microsoft.EntityFrameworkCore.EntityState requestedState) where TEntity : BaseEntity;

/// <summary>
/// Reloads the entity from the database overwriting any property values with values from the database.
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Data/IDbContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Linq.Expressions;
using SmartStore.Core;
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Data/IQueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ο»Ώusing System;
using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Linq.Expressions;
using SmartStore.Core;
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Data/RepositoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Domain/Blogs/BlogPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static IReadOnlyCollection<string> GetVisibilityAffectingPropertyNames()
/// Gets or sets a language identifier for which the blog post should be displayed.
/// </summary>
[DataMember]
[Index]
// [Index] removed for .NET 8 - use Fluent API
public int? LanguageId { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Domain/Catalog/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public partial class Category : BaseEntity, ICategoryNode, IAuditable, ISoftDele
/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
[Index]
// [Index] removed for .NET 8 - use Fluent API
public bool Deleted { get; set; }

/// <summary>
Expand Down
Loading