Skip to content

Commit

Permalink
Merge pull request #592 from skadefro/observable-test
Browse files Browse the repository at this point in the history
Observable test
  • Loading branch information
skadefro authored Apr 14, 2022
2 parents 7a05002 + 9bc70f8 commit 852e128
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 86 deletions.
24 changes: 21 additions & 3 deletions OpenRPA.Interfaces/ExtendedObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void UpdateItem(T Item, T NewItem)
{
T originalItem = Item;
var index = Items.IndexOf(Item);
NewItem.CopyPropertiesTo(Item);
NewItem.CopyPropertiesTo(Item, false);
GenericTools.RunUI(() =>
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, Item, originalItem, index));
Expand Down Expand Up @@ -517,13 +517,31 @@ public static List<T> ToListOfType<T>(this IEnumerable source)
{
return source?.OfType<T>().ToList() ?? new List<T>();
}
public static void CopyPropertiesTo(this object fromObject, object toObject)
public static void CopyPropertiesTo(this object fromObject, object toObject, bool SimpleOnly)
{
PropertyInfo[] toObjectProperties = toObject.GetType().GetProperties();
foreach (PropertyInfo propTo in toObjectProperties)
{
PropertyInfo propFrom = fromObject.GetType().GetProperty(propTo.Name);
if (propFrom != null && propFrom.CanWrite)


var JsonIgnore = propTo.GetCustomAttributes(typeof(Newtonsoft.Json.JsonIgnoreAttribute), false);
if (JsonIgnore != null) continue;
bool copy = false;
if(SimpleOnly) {
if (propTo.PropertyType == typeof(int)) copy = true;
if (propTo.PropertyType == typeof(Int64)) copy = true;
if (propTo.PropertyType == typeof(double)) copy = true;
if (propTo.PropertyType == typeof(long)) copy = true;
if (propTo.PropertyType == typeof(float)) copy = true;
if (propTo.PropertyType == typeof(bool)) copy = true;
if (propTo.PropertyType == typeof(string)) copy = true;
}
else
{
copy = true;
}
if (propFrom != null && propFrom.CanWrite && copy)
propTo.SetValue(toObject, propFrom.GetValue(fromObject, null), null);
}
}
Expand Down
6 changes: 5 additions & 1 deletion OpenRPA/Activities/InvokeOpenFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public InvokeOpenFlow()
protected override void Execute(NativeActivityContext context)
{
string WorkflowInstanceId = context.WorkflowInstanceId.ToString();
string _workflow = workflow.Get(context);
if (string.IsNullOrEmpty(_workflow)) throw new Exception("Workflow property is mandatory for Invoke Openflow");
bool waitforcompleted = WaitForCompleted.Get(context);
string bookmarkname = null;
IDictionary<string, object> _payload = new System.Dynamic.ExpandoObject();
Expand Down Expand Up @@ -120,7 +122,8 @@ protected override void Execute(NativeActivityContext context)
if (!string.IsNullOrEmpty(bookmarkname))
{
int expiration = Expiration.Get(context);
var result = global.webSocketClient.QueueMessage(workflow.Get(context), _payload, RobotInstance.instance.robotqueue, bookmarkname, expiration);
Log.Output("Invoke Openflow sending message to queue " + _workflow);
var result = global.webSocketClient.QueueMessage(_workflow, _payload, RobotInstance.instance.robotqueue, bookmarkname, expiration);
if (expiration < 1) expiration = 5000;
result.Wait(expiration + 500);
}
Expand All @@ -138,6 +141,7 @@ protected override void Execute(NativeActivityContext context)
}
void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object obj)
{
Log.Output("Invoke Openflow resumed with bookmark");
bool waitforcompleted = WaitForCompleted.Get(context);
if (!waitforcompleted) return;
// context.RemoveBookmark(bookmark.Name);
Expand Down
4 changes: 2 additions & 2 deletions OpenRPA/Activities/InvokeOpenRPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected override void Execute(NativeActivityContext context)
if (killifrunning)
foreach (var i in global.OpenRPAClient.WorkflowInstances.ToList())
{
if (!i.isCompleted && i.Workflow._id == workflow._id)
if (i.Workflow != null && !i.isCompleted && i.Workflow._id == workflow._id)
{
i.Abort("Killed by KillIfRunning from " + Instance.Workflow.name);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object
}
}
}
else
else if (instance.projectid != null)
{
Dictionary<string, object> arguments = (from argument in Arguments
where argument.Value.Direction != ArgumentDirection.In
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/Activities/StopOpenRPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override void Execute(NativeActivityContext context)
{
if (!string.IsNullOrEmpty(workflowid))
{
if (i.Workflow._id == workflowid || i.Workflow.RelativeFilename == workflowid)
if (i.Workflow != null && i.Workflow._id == workflowid || i.Workflow.RelativeFilename == workflowid)
{
i.Abort("Killed by StopOpenRPA command from " + Instance.Workflow.name);
result++;
Expand Down
19 changes: 13 additions & 6 deletions OpenRPA/AgentWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
{
isRemote = true;
Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
var data = JObject.FromObject(instance.Parameters);
JObject data = null;
if (instance.Parameters != null) data = JObject.FromObject(instance.Parameters);
command.command = "invoke" + instance.state;
command.workflowid = instance.WorkflowId;
command.data = data;
Expand Down Expand Up @@ -389,13 +390,19 @@ public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
if (instance.hasError || instance.isCompleted)
{
string message = "";
if (instance.runWatch != null)
if(instance.Workflow != null)
{
message += instance.Workflow.name + " " + instance.state + " in " + string.Format("{0:mm\\:ss\\.fff}", instance.runWatch.Elapsed);
}
else
if (instance.runWatch != null)
{
message += instance.Workflow.name + " " + instance.state + " in " + string.Format("{0:mm\\:ss\\.fff}", instance.runWatch.Elapsed);
}
else
{
message += instance.Workflow.name + " " + instance.state;
}
} else
{
message += instance.Workflow.name + " " + instance.state;
message += "MISSING WORKFLOW!!!! " + instance.state;
}
if (!string.IsNullOrEmpty(instance.errormessage)) message += Environment.NewLine + "# " + instance.errormessage;
Log.Information(message);
Expand Down
4 changes: 2 additions & 2 deletions OpenRPA/LocallyCached.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task Save<T>(bool skipOnline = false) where T : apibase
if (string.IsNullOrEmpty(_id) || isLocalOnly == true)
{
var result = await global.webSocketClient.InsertOne(collectionname, 0, false, entity);
EnumerableExtensions.CopyPropertiesTo(result, entity);
EnumerableExtensions.CopyPropertiesTo(result, entity, true);
_backingFieldValues["isDirty"] = false;
Log.Verbose("Inserted to openflow and returned as version " + entity._version + " " + entity._type + " " + entity.name);
}
Expand All @@ -71,7 +71,7 @@ public async Task Save<T>(bool skipOnline = false) where T : apibase
var result = await global.webSocketClient.InsertOrUpdateOne(collectionname, 0, false, null, entity);
if (result != null)
{
EnumerableExtensions.CopyPropertiesTo(result, entity);
EnumerableExtensions.CopyPropertiesTo(result, entity, true);
_backingFieldValues["isDirty"] = false;
Log.Verbose("Updated in openflow and returned as version " + entity._version + " " + entity._type + " " + entity.name);
}
Expand Down
3 changes: 2 additions & 1 deletion OpenRPA/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3473,7 +3473,8 @@ public async void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
{
isRemote = true;
Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
var data = JObject.FromObject(instance.Parameters);
JObject data = null;
if(instance.Parameters != null) data = JObject.FromObject(instance.Parameters);
command.command = "invoke" + instance.state;
command.workflowid = instance.WorkflowId;
command.data = data;
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/OpenRPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>Base UI of OpenRPA, used as part of OpenRPA robot</Description>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/open-rpa/openrpa</PackageProjectUrl>
<Version>1.4.7</Version>
<Version>1.4.8</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>open_rpa128.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
2 changes: 2 additions & 0 deletions OpenRPA/RobotInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,13 @@ public async Task LoadServerData()
{
if (i._version > exists._version)
{
if (i.Workflow == null) i.Workflow = Workflows.Where(x => x._id == i.WorkflowId).FirstOrDefault() as Workflow;
i.isDirty = false;
await i.Save<WorkflowInstance>();
}
else if (i._version < exists._version)
{
if (exists.Workflow == null) exists.Workflow = Workflows.Where(x => x._id == exists.WorkflowId).FirstOrDefault() as Workflow;
await exists.Save<WorkflowInstance>();
}
else
Expand Down
6 changes: 4 additions & 2 deletions OpenRPA/Views/WFDesigner.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,8 @@ public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
if (!string.IsNullOrEmpty(instance.queuename) && !string.IsNullOrEmpty(instance.correlationId))
{
Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
var data = JObject.FromObject(instance.Parameters);
JObject data = null;
if (instance.Parameters != null) data = JObject.FromObject(instance.Parameters);
command.command = "invoke" + instance.state;
command.workflowid = instance.WorkflowId;
command.data = data;
Expand Down Expand Up @@ -1323,7 +1324,8 @@ public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
}
}
}
string message = (instance.Workflow.name + " " + instance.state);
string message = ("MISSING WORKFLOW!!!! " + instance.state);
if(instance.Workflow != null ) message = (instance.Workflow.name + " " + instance.state);
if (!string.IsNullOrEmpty(instance.errorsource))
{
message += " at " + instance.errorsource;
Expand Down
4 changes: 2 additions & 2 deletions OpenRPA/Views/WorkflowInstances.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public Workflow Workflow
}
}
}
private WorkflowInstance[] _Instances = new WorkflowInstance[] { };
public WorkflowInstance[] Instances
private IWorkflowInstance[] _Instances = new IWorkflowInstance[] { };
public IWorkflowInstance[] Instances
{
get
{
Expand Down
5 changes: 3 additions & 2 deletions OpenRPA/Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ public List<WorkflowInstance> LoadedInstances
}
private WorkflowInstance[] _Instances = new WorkflowInstance[] { };
[JsonIgnore, BsonIgnore]
public WorkflowInstance[] Instances
public IWorkflowInstance[] Instances
{
get
{
return RobotInstance.instance.dbWorkflowInstances.Find(x => x.WorkflowId == _id).OrderByDescending(x => x._modified).Take(10).ToArray();
return RobotInstance.instance.WorkflowInstances.Where(x => x.WorkflowId == _id).OrderByDescending(x => x._modified).Take(10).ToArray();
// return RobotInstance.instance.dbWorkflowInstances.Find(x => x.WorkflowId == _id).OrderByDescending(x => x._modified).Take(10).ToArray();
// return RobotInstance.instance.dbWorkflowInstances.Find(x => x.WorkflowId == _id, 0, 10).ToArray();
}
}
Expand Down
Loading

0 comments on commit 852e128

Please sign in to comment.