Skip to content

Commit f901e98

Browse files
committed
Cron Expression 2
1 parent bf08b3f commit f901e98

25 files changed

Lines changed: 556 additions & 302 deletions

File tree

src/Libraries/SmartStore.Core/Data/IDbContext.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params ob
9393
void DetachEntity<TEntity>(TEntity entity) where TEntity : BaseEntity, new();
9494

9595
/// <summary>
96-
/// Detaches all entities from the current object context
96+
/// Detaches all entities of type <c>TEntity</c> from the current object context
9797
/// </summary>
9898
/// <returns>The count of detached entities</returns>
99-
int DetachAll();
99+
int DetachEntities<TEntity>() where TEntity : class;
100100

101101
/// <summary>
102102
/// Change the state of an entity object
@@ -131,6 +131,11 @@ IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params ob
131131
public static class IDbContextExtensions
132132
{
133133

134+
public static int DetachAll(this IDbContext ctx)
135+
{
136+
return ctx.DetachEntities<BaseEntity>();
137+
}
138+
134139
/// <summary>
135140
/// Changes the object state to unchanged
136141
/// </summary>

src/Libraries/SmartStore.Data/EfRepository.cs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -129,52 +129,35 @@ public virtual void Update(T entity)
129129
if (entity == null)
130130
throw new ArgumentNullException("entity");
131131

132+
if (InternalContext.Entry(entity).State == System.Data.Entity.EntityState.Detached)
133+
{
134+
this.Entities.Attach(entity);
135+
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
136+
}
137+
132138
if (this.AutoCommitEnabledInternal)
133-
{
134-
if (!InternalContext.Configuration.AutoDetectChangesEnabled)
135-
{
136-
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
137-
}
139+
{
138140
_context.SaveChanges();
139-
}
140-
else
141-
{
142-
try
143-
{
144-
this.Entities.Attach(entity);
145-
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
146-
}
147-
finally { }
148-
}
141+
}
149142
}
150143

151144
public virtual void UpdateRange(IEnumerable<T> entities)
152145
{
153146
if (entities == null)
154147
throw new ArgumentNullException("entities");
155148

156-
if (this.AutoCommitEnabledInternal)
149+
entities.Each(entity =>
157150
{
158-
if (!InternalContext.Configuration.AutoDetectChangesEnabled)
151+
if (InternalContext.Entry(entity).State == System.Data.Entity.EntityState.Detached)
159152
{
160-
entities.Each(entity =>
161-
{
162-
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
163-
});
164-
}
165-
_context.SaveChanges();
166-
}
167-
else
153+
this.Entities.Attach(entity);
154+
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
155+
}
156+
});
157+
158+
if (this.AutoCommitEnabledInternal)
168159
{
169-
try
170-
{
171-
entities.Each(entity =>
172-
{
173-
this.Entities.Attach(entity);
174-
InternalContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
175-
});
176-
}
177-
finally { }
160+
_context.SaveChanges();
178161
}
179162
}
180163

src/Libraries/SmartStore.Data/ObjectContextBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@ protected internal bool IsSqlServer2012OrHigher()
523523
}
524524
}
525525

526-
public int DetachAll()
526+
public int DetachEntities<TEntity>() where TEntity : class
527527
{
528528
var attachedEntities = this.ChangeTracker.Entries()
529-
.Where(x => x.State != System.Data.Entity.EntityState.Detached)
529+
.Where(x => x.State != System.Data.Entity.EntityState.Detached && x.Entity is TEntity)
530530
.ToList();
531531
attachedEntities.Each(x => this.Entry(x.Entity).State = System.Data.Entity.EntityState.Detached);
532532
return attachedEntities.Count;

src/Libraries/SmartStore.Services/ExportImport/ImportManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using SmartStore.Core.Domain.Media;
1919
using SmartStore.Services.Stores;
2020
using SmartStore.Core.Domain.Stores;
21+
using SmartStore.Core;
2122

2223
namespace SmartStore.Services.ExportImport
2324
{

src/Libraries/SmartStore.Services/Tasks/ITaskScheduler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ITaskScheduler
1919
/// The interval in which the scheduler triggers the sweep url
2020
/// (which determines pending tasks and executes them in the scope of a regular HTTP request).
2121
/// </summary>
22-
TimeSpan SweepInterval { get; set; }
22+
int SweepIntervalMinutes { get; set; }
2323

2424
/// <summary>
2525
/// The fully qualified base url
@@ -42,7 +42,7 @@ public interface ITaskScheduler
4242
/// <summary>
4343
/// Starts/initializes the scheduler
4444
/// </summary>
45-
void Start();
45+
void Start();
4646

4747
/// <summary>
4848
/// Stops the scheduler

src/Libraries/SmartStore.Services/Tasks/InitializeSchedulerFilter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public void OnAuthorization(AuthorizationContext filterContext)
5050
taskScheduler.SetBaseUrl(storeService, filterContext.HttpContext);
5151
}
5252

53-
var sweepInterval = CommonHelper.GetAppSetting<int>("sm:TaskSchedulerSweepInterval", 60);
54-
taskScheduler.SweepInterval = TimeSpan.FromSeconds(sweepInterval);
55-
53+
taskScheduler.SweepIntervalMinutes = CommonHelper.GetAppSetting<int>("sm:TaskSchedulerSweepInterval", 1);
5654
taskScheduler.Start();
5755

5856
logger.Information("Initialized TaskScheduler with base url '{0}'".FormatInvariant(taskScheduler.BaseUrl));

src/Libraries/SmartStore.Services/Tasks/TaskScheduler.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@ namespace SmartStore.Services.Tasks
1616

1717
public class DefaultTaskScheduler : DisposableObject, ITaskScheduler, IRegisteredObject
1818
{
19-
private string _baseUrl;
19+
private bool _intervalFixed;
20+
private int _sweepInterval;
21+
private string _baseUrl;
2022
private System.Timers.Timer _timer;
2123
private bool _shuttingDown;
2224
private int _errCount;
2325
private readonly ConcurrentDictionary<string, bool> _authTokens = new ConcurrentDictionary<string, bool>();
2426

2527
public DefaultTaskScheduler()
2628
{
27-
_timer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
29+
_sweepInterval = 1;
30+
_timer = new System.Timers.Timer();
2831
_timer.Elapsed += Elapsed;
2932

3033
HostingEnvironment.RegisterObject(this);
3134
}
3235

33-
public TimeSpan SweepInterval
36+
public int SweepIntervalMinutes
3437
{
35-
get { return TimeSpan.FromMilliseconds(_timer.Interval); }
36-
set { _timer.Interval = value.TotalMilliseconds; }
38+
get { return _sweepInterval; }
39+
set { _sweepInterval = value; }
3740
}
3841

3942
public string BaseUrl
@@ -49,16 +52,30 @@ public string BaseUrl
4952

5053
public void Start()
5154
{
52-
lock (_timer)
55+
if (_timer.Enabled)
56+
return;
57+
58+
lock (_timer)
5359
{
5460
CheckUrl(_baseUrl);
61+
_timer.Interval = GetFixedInterval();
5562
_timer.Start();
5663
}
5764
}
5865

66+
private double GetFixedInterval()
67+
{
68+
// Gets seconds to next sweep minute
69+
int seconds = (_sweepInterval * 60) - DateTime.Now.Second;
70+
return seconds * 1000;
71+
}
72+
5973
public void Stop()
6074
{
61-
lock (_timer)
75+
if (!_timer.Enabled)
76+
return;
77+
78+
lock (_timer)
6279
{
6380
_timer.Stop();
6481
}
@@ -98,7 +115,13 @@ private void Elapsed(object sender, System.Timers.ElapsedEventArgs e)
98115
{
99116
if (_timer.Enabled)
100117
{
101-
CallEndpoint(_baseUrl + "/Sweep");
118+
if (!_intervalFixed)
119+
{
120+
_timer.Interval = TimeSpan.FromMinutes(_sweepInterval).TotalMilliseconds;
121+
_intervalFixed = true;
122+
}
123+
124+
CallEndpoint(_baseUrl + "/Sweep");
102125
}
103126
}
104127
finally

src/Presentation/SmartStore.Web.Framework/Controllers/ContollerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static string RenderPartialViewToString(this ControllerBase controller, o
4949
/// <returns>Result</returns>
5050
public static string RenderPartialViewToString(this ControllerBase controller, string viewName, object model)
5151
{
52-
return RenderPartialViewToString(controller, null, model, null);
52+
return RenderPartialViewToString(controller, viewName, model, null);
5353
}
5454
/// <summary>
5555
/// Render partial view to string

src/Presentation/SmartStore.Web/Administration/Content/variables.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
@headingsFontFamily: 'Segoe UI Semibold', 'Segoe UI', Arial, Helvetica, sans-serif; //inherit; // empty to use BS default, @baseFontFamily
6666
@headingsFontWeight: 600; //bold; // instead of browser default, bold
67-
@headingsColor: #777; //#009fff; //inherit; // empty to use BS default, @textColor
67+
@headingsColor: @textColor; //#009fff; //inherit; // empty to use BS default, @textColor
6868

6969

7070
// Component sizing

src/Presentation/SmartStore.Web/Administration/Controllers/CustomerRoleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public ActionResult Edit(CustomerRoleModel model, bool continueEditing)
197197
return continueEditing ? RedirectToAction("Edit", customerRole.Id) : RedirectToAction("List");
198198
}
199199

200-
//If we got this far, something failed, redisplay form
200+
// If we got this far, something failed, redisplay form
201201
return View(model);
202202
}
203203
catch (Exception exc)

0 commit comments

Comments
 (0)