Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Possible to invoke ExecuteAction while UpdateObject was running #2231

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ namespace Origam.Server.Model.UIService
public class WorkflowNextInput
{
public Guid SessionFormIdentifier { get; set; }
public List<string> CachedFormIds { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion backend/Origam.Server/ServerCoreUIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public UIResult WorkflowNext(WorkflowNextInput workflowNextInput)
is WorkflowSessionStore workflowSessionStore)
{
return (UIResult) workflowSessionStore.ExecuteAction(
SessionStore.ACTION_NEXT, workflowNextInput.CachedFormIds);
SessionStore.ACTION_NEXT);
}
return null;
}
Expand Down
64 changes: 16 additions & 48 deletions backend/Origam.Server/Session Stores/FormSessionStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace Origam.Server
public class FormSessionStore : SaveableSessionStore
{
private string _delayedLoadingParameterName;
private bool _isProcessing;
private FormReferenceMenuItem _menuItem;
private object _getRowDataLock = new object();
private XmlDocument _preparedFormXml = null;
Expand Down Expand Up @@ -290,37 +289,23 @@ internal override object Save()
return base.Save();
}

public override object ExecuteAction(string actionId)
public override object ExecuteActionInternal(string actionId)
{
if (this.IsProcessing)
{
throw new Exception(Resources.ErrorCommandInProgress);
}
switch (actionId)
{
case ACTION_SAVE:
object result = Save();
//if (this.IsDelayedLoading)
//{
// this.CurrentRecordId = null;
//}
return result;

this.IsProcessing = true;
case ACTION_REFRESH:
return Refresh();

try
{
switch (actionId)
{
case ACTION_SAVE:
object result = Save();
//if (this.IsDelayedLoading)
//{
// this.CurrentRecordId = null;
//}
return result;

case ACTION_REFRESH:
return Refresh();

default:
throw new ArgumentOutOfRangeException("actionId", actionId, Resources.ErrorContextUnknownAction);
}
}
finally
{
this.IsProcessing = false;
default:
throw new ArgumentOutOfRangeException("actionId", actionId, Resources.ErrorContextUnknownAction);
}
}

Expand Down Expand Up @@ -541,20 +526,9 @@ public override void PrepareFormXml()
private object Refresh()
{
object currentRecordId = this.CurrentRecordId;

try
{
this.IsProcessing = true;
this.CurrentRecordId = null;
this.Clear();
}
finally
{
this.IsProcessing = false;
}

this.CurrentRecordId = null;
this.Clear();
LoadData();

// load current record again so CurrentRecordId remains set
// this is important e.g. for paged data loading so we know
// for which record initialPage should be returned
Expand Down Expand Up @@ -590,12 +564,6 @@ public string DelayedLoadingParameterName
get { return _delayedLoadingParameterName; }
set { _delayedLoadingParameterName = value; }
}

public bool IsProcessing
{
get { return _isProcessing; }
set { _isProcessing = value; }
}
#endregion

public override void OnDispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public override void Init()
this.DirtyEnabledEntities.Add("SD");
}

public override object ExecuteAction(string actionId)
public override object ExecuteActionInternal(string actionId)
{
switch (actionId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ internal virtual object Save()
public override IEnumerable<ChangeInfo> UpdateObject(
string entity, object id, string property, object newValue)
{
return UpdateObjectWithDependenies(entity, id,
property, newValue, true);
lock (_lock)
{
return UpdateObjectWithDependenies(entity, id,
property, newValue, true);
}
}

public IEnumerable<ChangeInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,18 @@ private void LoadData()
SetDataSource(data);
}

public override object ExecuteAction(string actionId)
public override object ExecuteActionInternal(string actionId)
{
if (this.IsProcessing)
switch (actionId)
{
throw new Exception(Resources.ErrorCommandInProgress);
}

this.IsProcessing = true;

try
{
switch (actionId)
{
case ACTION_REFRESH:
return Refresh();
case ACTION_REFRESH:
return Refresh();

case ACTION_NEXT:
return Next();
case ACTION_NEXT:
return Next();

default:
throw new ArgumentOutOfRangeException("actionId", actionId, Resources.ErrorContextUnknownAction);
}
}
finally
{
this.IsProcessing = false;
default:
throw new ArgumentOutOfRangeException("actionId", actionId, Resources.ErrorContextUnknownAction);
}
}

Expand Down Expand Up @@ -267,33 +253,14 @@ private void SetParameters(IDictionary parameters, DataRow row, AbstractSchemaIt

private object Refresh()
{
try
{
this.IsProcessing = true;

this.Clear();
}
finally
{
this.IsProcessing = false;
}

this.Clear();
LoadData();

return this.Data;
}

#endregion

#region Properties
private bool _isProcessing;

public bool IsProcessing
{
get { return _isProcessing; }
set { _isProcessing = value; }
}

public Guid DataStructureId
{
get { return _dataStructureId; }
Expand Down
31 changes: 30 additions & 1 deletion backend/Origam.Server/Session Stores/SessionStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using Newtonsoft.Json.Linq;
using Origam.Extensions;
using Origam.Service.Core;
using System.Linq.Expressions;

namespace Origam.Server
{
Expand Down Expand Up @@ -92,6 +93,13 @@ public abstract class SessionStore : IDisposable
private readonly Analytics analytics;
private bool _isDisposed;
private IDataDocument _xmlData;
private bool _isProcessing;

public bool IsProcessing
{
get { return _isProcessing; }
set { _isProcessing = value; }
}

public const string LIST_LOADED_COLUMN_NAME = "___ORIGAM_IsLoaded";
public const string ACTION_SAVE = "SAVE";
Expand Down Expand Up @@ -710,7 +718,28 @@ public virtual void LoadColumns(IList<string> columns)
}

public abstract void Init();
public abstract object ExecuteAction(string actionId);
public object ExecuteAction(string actionId)
{
if (this.IsProcessing)
{
throw new Exception(Resources.ErrorCommandInProgress);
}
this.IsProcessing = true;
try
{
lock (this._lock)
{
return ExecuteActionInternal(actionId);
}
}
finally
{
this.IsProcessing = false;
}
}

public abstract object ExecuteActionInternal(string actionId);

public abstract XmlDocument GetFormXml();

public virtual void PrepareFormXml()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public override void Init()
PrepareData();
}

public override object ExecuteAction(string actionId)
public override object ExecuteActionInternal(string actionId)
{
switch (actionId)
{
Expand Down