Skip to content

Commit

Permalink
Merge pull request #785 from skadefro/master
Browse files Browse the repository at this point in the history
Fix index/Total updates in BreakableLoop / Drop WebSockets package, will break windows xp, but remove a package
  • Loading branch information
skadefro authored Apr 23, 2024
2 parents 4a13e75 + 0934913 commit 3ec364d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 84 deletions.
92 changes: 29 additions & 63 deletions OpenRPA.Interfaces/BreakableLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,93 +41,59 @@ private void OnContinue(NativeActivityContext context, Bookmark bookmark, object
context.ResumeBookmark(_bookmark, value);
}
}
public void SetTotal(NativeActivityContext context, int Value)
{
var input = GetDescriptor<int>(context, "Total");
if (input == null) return;
input.SetValue(context.DataContext, Value);
}
public void IncIndex(NativeActivityContext context)
{
var input = GetTotalDescriptor(context);
var input = GetDescriptor<int>(context, "Index");
if (input == null) return;
if (input != null)
try
{
try
var _index = 0;
var value = input.GetValue(context.DataContext);
if (value != null)
{
var _index = 0;
var value = input.GetValue(context.DataContext);
if (value != null)
if (value is int wfview)
{
if (value is int wfview)
{
_index = (int)value;
}
else if(int.TryParse(value.ToString(), out int current))
{
_index = current;
}
_index = (int)value;
}
_index++;
input.SetValue(context.DataContext, _index);
}
catch (Exception ex)
{
Log.Warning("Updating loop Index failed with " + ex.ToString());
}
}
}
public Variable GetTotalVariable(NativeActivityContext context)
{
if (Variables.Count < 1) return null;
for (var i = 0; i < Variables.Count; i++)
{
var variable = Variables[i];
if (variable.Name == "Total" && variable.Type == typeof(int))
{
return variable;
else if(int.TryParse(value.ToString(), out int current))
{
_index = current;
}
}
_index++;
input.SetValue(context.DataContext, _index);
}
return null;
}
public PropertyDescriptor GetTotalDescriptor(NativeActivityContext context)
{
if (Variables.Count < 1) return null;
for (var i = 0; i < Variables.Count; i++)
catch (Exception ex)
{
var variable = Variables[i];
if (variable.Name == "Total" && variable.Type == typeof(int))
{
return context.DataContext.GetProperties()[variable.Name];
}
Log.Warning("Updating loop Index failed with " + ex.ToString());
}
return null;
}
public Variable GetIndexVariable(NativeActivityContext context)
public Variable GetVariable<T>(NativeActivityContext context, string Name)
{
if (Variables.Count < 1) return null;
if(context == null) return null;
if (string.IsNullOrEmpty(Name)) return null;
for (var i = 0; i < Variables.Count; i++)
{
var variable = Variables[i];
if (variable.Name == "Index" && variable.Type == typeof(int))
if (variable.Name.ToLower() == Name.ToLower() && variable.Type == typeof(T))
{
return variable;
}
}
return null;
}
public PropertyDescriptor GetIndexDescriptor(NativeActivityContext context)
{
if (Variables.Count < 1) return null;
for (var i = 0; i < Variables.Count; i++)
{
var variable = Variables[i];
if (variable.Name == "Index" && variable.Type == typeof(int))
{
return context.DataContext.GetProperties()[variable.Name];
}
}
return null;
}
public void SetTotal(NativeActivityContext context, int Value)
public PropertyDescriptor GetDescriptor<T>(NativeActivityContext context, string Name)
{
var input = GetTotalDescriptor(context);
if (input == null) return;
input.SetValue(context.DataContext, Value);
var v = GetVariable<T>(context, Name);
if(v == null) return null;
return context.DataContext.GetProperties()[v.Name];
}
[System.ComponentModel.Browsable(false)]
public System.Collections.ObjectModel.Collection<Variable> Variables { get; set; } = new System.Collections.ObjectModel.Collection<Variable>();
Expand Down
3 changes: 2 additions & 1 deletion OpenRPA.Interfaces/IWebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public interface IWebSocketClient
event QueueMessageDelegate OnQueueMessage;
event QueueClosedDelegate OnQueueClosed;
int MessageQueueSize { get; }
System.Net.WebSockets.WebSocket ws { get; }
//System.Net.WebSockets.WebSocket ws { get; }
System.Net.WebSockets.WebSocketState State { get; }
TokenUser user { get; set; }
bool signedin { get; }
string url { get; set; }
Expand Down
3 changes: 0 additions & 3 deletions OpenRPA.Net/OpenRPA.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
<ItemGroup>
<None Include="Resources\open_rpa128.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRPA.Interfaces\OpenRPA.Interfaces.csproj" />
</ItemGroup>
Expand Down
30 changes: 21 additions & 9 deletions OpenRPA.Net/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class WebSocketClient : IWebSocketClient
{
static SemaphoreSlim ProcessingSemaphore = new SemaphoreSlim(1, 1);
static SemaphoreSlim SendStringSemaphore = new SemaphoreSlim(1, 1);
public WebSocket ws { get; private set; } = null;
// public WebSocket ws { get; private set; } = null;
public ClientWebSocket ws { get; private set; } = null;

public int websocket_package_size = 4096;
public string url { get; set; }
private CancellationTokenSource src = new CancellationTokenSource();
Expand All @@ -36,6 +38,14 @@ public class WebSocketClient : IWebSocketClient
public TokenUser user { get; set; }
public bool signedin { get; private set; }
public string jwt { get; private set; }
public System.Net.WebSockets.WebSocketState State
{
get
{
if (ws == null) return WebSocketState.None;
return ws.State;
}
}
public bool isConnected
{
get
Expand Down Expand Up @@ -79,14 +89,16 @@ public async Task Connect()
if (ws == null)
{
// ws = (ClientWebSocket)SystemClientWebSocket.CreateClientWebSocket();
if (VersionHelper.IsWindows8OrGreater())
{
ws = new ClientWebSocket();
}
else
{
ws = new System.Net.WebSockets.Managed.ClientWebSocket();
}
ws = new ClientWebSocket();
// <PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
//if (VersionHelper.IsWindows8OrGreater())
//{
// ws = new ClientWebSocket();
//}
//else
//{
// ws = new System.Net.WebSockets.Managed.ClientWebSocket();
//}
src = new CancellationTokenSource();
}
if (ws.State == System.Net.WebSockets.WebSocketState.Connecting || ws.State == System.Net.WebSockets.WebSocketState.Open) return;
Expand Down
4 changes: 1 addition & 3 deletions OpenRPA/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,7 @@ public string wsstate
{
if (string.IsNullOrEmpty(Config.local.wsurl)) return "";
if (global.webSocketClient == null) return "null";
if (global.webSocketClient.ws == null) return "ws null";
return global.webSocketClient.ws.State.ToString();
return global.webSocketClient.State.ToString();
}
}
public string wsmsgqueue
Expand All @@ -861,7 +860,6 @@ public string wsmsgqueue
{
if (string.IsNullOrEmpty(Config.local.wsurl)) return "";
if (global.webSocketClient == null) return "";
if (global.webSocketClient.ws == null) return "";
if (global.webSocketClient.MessageQueueSize == 0) return "";
return "(" + global.webSocketClient.MessageQueueSize.ToString() + ")";
}
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.57.2</Version>
<Version>1.4.57.4</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>openrpa.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
8 changes: 4 additions & 4 deletions OpenRPA/RobotInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,14 +1494,14 @@ async internal Task Connect()
{
try
{
if (global.webSocketClient != null && global.webSocketClient.ws != null && global.webSocketClient.ws.State == System.Net.WebSockets.WebSocketState.Connecting) return;
if (global.webSocketClient != null && global.webSocketClient.ws != null && global.webSocketClient.ws.State == System.Net.WebSockets.WebSocketState.Open) return;
if (global.webSocketClient != null && global.webSocketClient.State == System.Net.WebSockets.WebSocketState.Connecting) return;
if (global.webSocketClient != null && global.webSocketClient.State == System.Net.WebSockets.WebSocketState.Open) return;
await Task.Delay(ReconnectDelay);
ReconnectDelay += 5000;
if (ReconnectDelay > 60000 * 2) ReconnectDelay = 60000 * 2;
connect_attempts++;
if (global.webSocketClient != null && global.webSocketClient.ws != null && global.webSocketClient.ws.State == System.Net.WebSockets.WebSocketState.Connecting) return;
if (global.webSocketClient != null && global.webSocketClient.ws != null && global.webSocketClient.ws.State == System.Net.WebSockets.WebSocketState.Open) return;
if (global.webSocketClient != null && global.webSocketClient.State == System.Net.WebSockets.WebSocketState.Connecting) return;
if (global.webSocketClient != null && global.webSocketClient.State == System.Net.WebSockets.WebSocketState.Open) return;
SetStatus("Connecting to " + Config.local.wsurl);
await global.webSocketClient.Connect();
}
Expand Down

0 comments on commit 3ec364d

Please sign in to comment.