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
4 changes: 3 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,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,6 +343,8 @@ public override SynchronizationContext CreateCopy()
}
}

// TODO: IRegisteredObject not supported in ASP.NET Core - migrate to IHostedService
/*
internal class BackgroundWorkHost : IRegisteredObject
{
private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -421,4 +422,5 @@ private void FinalShutdown()
}

}
*/
}
23 changes: 14 additions & 9 deletions src/Libraries/SmartStore.Core/Async/LocalAsyncState.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
ο»Ώusing System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Threading;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;

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(Options.Create(new MemoryCacheOptions()));
private readonly MemoryCache _cancelTokens = new MemoryCache(Options.Create(new MemoryCacheOptions()));

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

public virtual IEnumerable<T> GetAll<T>()
{
// TODO: MemoryCache in .NET 8 is not enumerable. Need to track keys separately.
throw new NotImplementedException("GetAll is not supported with Microsoft.Extensions.Caching.Memory. Consider tracking keys separately.");
/*
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>();
*/
}


Expand All @@ -60,17 +65,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
{
SlidingExpiration = duration,
Priority = CacheItemPriority.NotRemovable
Priority = CacheItemPriority.NeverRemove
};
var key = BuildKey<T>(name);

// On expiration or removal: remove corresponding cancel token also.
policy.RemovedCallback = (x) => OnRemoveCancelTokenSource(key);
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 +160,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
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
34 changes: 14 additions & 20 deletions src/Libraries/SmartStore.Core/Caching/MemoryCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
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 Microsoft.Extensions.Options;
using SmartStore.Core.Infrastructure.DependencyManagement;
using SmartStore.Utilities;
using SmartStore.Utilities.Threading;
Expand All @@ -33,7 +34,7 @@ public MemoryCacheManager(Work<ICacheScopeAccessor> scopeAccessor)

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

public bool IsDistributedCache => false;
Expand Down Expand Up @@ -207,34 +208,27 @@ 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
{
Priority = CacheItemPriority.Normal
};

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

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

// TODO: ChangeMonitors not supported in Microsoft.Extensions.Caching.Memory
// Need to implement cache dependencies differently using IChangeToken
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));
}
// INFO: Cache dependencies need to be reimplemented using IChangeToken
// For now, dependencies are ignored
}

//cacheItemPolicy.RemovedCallback = OnRemoveEntry;

return cacheItemPolicy;
return options;
}

//private void OnRemoveEntry(CacheEntryRemovedArguments args)
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/SmartStore.Core/Caching/RequestCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/Libraries/SmartStore.Core/Data/Hooks/HookedEntity.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ο»Ώusing System;
using System.Data.Entity.Infrastructure;
using Microsoft.EntityFrameworkCore;
using EfState = System.Data.Entity.EntityState;

namespace SmartStore.Core.Data.Hooks
Expand All @@ -14,7 +14,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 +61,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 +78,7 @@ public Type ContextType
get;
}

public DbEntityEntry Entry
public EntityEntry Entry
{
get;
}
Expand Down
2 changes: 1 addition & 1 deletion 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
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
1 change: 0 additions & 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,6 @@ public static IReadOnlyCollection<string> GetVisibilityAffectingPropertyNames()
/// Gets or sets a language identifier for which the blog post should be displayed.
/// </summary>
[DataMember]
[Index]
public int? LanguageId { get; set; }

/// <summary>
Expand Down
1 change: 0 additions & 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,6 @@ public partial class Category : BaseEntity, ICategoryNode, IAuditable, ISoftDele
/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
[Index]
public bool Deleted { get; set; }

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Libraries/SmartStore.Core/Domain/Catalog/Manufacturer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public partial class Manufacturer : BaseEntity, IAuditable, ISoftDeletable, ILoc
/// Gets or sets a value indicating whether the entity is subject to ACL.
/// </summary>
[DataMember]
[Index]
public bool SubjectToAcl { get; set; }

/// <summary>
Expand All @@ -121,7 +120,6 @@ public partial class Manufacturer : BaseEntity, IAuditable, ISoftDeletable, ILoc
/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
[Index]
public bool Deleted { get; set; }

/// <summary>
Expand Down
10 changes: 0 additions & 10 deletions src/Libraries/SmartStore.Core/Domain/Catalog/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public static IReadOnlyCollection<string> GetVisibilityAffectingPropertyNames()
/// Gets or sets the visibility level of the product.
/// </summary>
[DataMember]
[Index]
public ProductVisibility Visibility { get; set; }

/// <summary>
Expand Down Expand Up @@ -216,7 +215,6 @@ public string Sku
/// Gets or sets the manufacturer part number
/// </summary>
[DataMember]
[Index]
public string ManufacturerPartNumber
{
[DebuggerStepThrough]
Expand All @@ -228,7 +226,6 @@ public string ManufacturerPartNumber
/// Gets or sets the Global Trade Item Number (GTIN). These identifiers include UPC (in North America), EAN (in Europe), JAN (in Japan), and ISBN (for books).
/// </summary>
[DataMember]
[Index]
public string Gtin
{
[DebuggerStepThrough]
Expand Down Expand Up @@ -669,30 +666,23 @@ public decimal Height
/// Gets or sets a value indicating whether the entity is published
/// </summary>
[DataMember]
[Index("IX_Product_Published_Deleted_IsSystemProduct", 1)]
public bool Published { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
[Index]
[Index("IX_Product_Published_Deleted_IsSystemProduct", 2)]
public bool Deleted { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the entity is a system product.
/// </summary>
[DataMember]
[Index]
[Index("IX_Product_SystemName_IsSystemProduct", 2)]
[Index("IX_Product_Published_Deleted_IsSystemProduct", 3)]
public bool IsSystemProduct { get; set; }

/// <summary>
/// Gets or sets the product system name.
/// </summary>
[DataMember]
[Index("IX_Product_SystemName_IsSystemProduct", 1)]
public string SystemName { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ public partial class ProductAttribute : BaseEntity, ILocalizedEntity, ISearchAli
/// Gets or sets whether the attribute can be filtered
/// </summary>
[DataMember]
[Index]
public bool AllowFiltering { get; set; }

/// <summary>
/// Gets or sets the display order
/// </summary>
[DataMember]
[Index]
public int DisplayOrder { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public partial class ProductCategory : BaseEntity
/// Gets or sets a value indicating whether the product is featured
/// </summary>
[DataMember]
[Index]
public bool IsFeaturedProduct { get; set; }

/// <summary>
Expand All @@ -38,7 +37,6 @@ public partial class ProductCategory : BaseEntity
/// Indicates whether the mapping is created by the user or by the system.
/// </summary>
[DataMember]
[Index]
public bool IsSystemMapping { get; set; }

/// <summary>
Expand Down
Loading