Skip to content

Commit

Permalink
Merge pull request #595 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 845e74f + a97fe9d commit cafa983
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 10 deletions.
54 changes: 49 additions & 5 deletions OpenRPA.Interfaces/ExtendedObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public ExtendedObservableCollection(List<T> list) : base(list)
{
}
public event PropertyChangedEventHandler ItemPropertyChanged;
public event EventHandler onFilterUpdated;

private void _ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
ItemPropertyChanged?.Invoke(sender, e);
Expand Down Expand Up @@ -170,6 +172,7 @@ protected override void InsertItem(int index, T item)
item.PropertyChanged += _ItemPropertyChanged;
GenericTools.RunUI(() =>
{
if (index >= Items.Count && index > 0) index = Items.Count - 1;
base.InsertItem(index, item);
});
}
Expand Down Expand Up @@ -254,6 +257,17 @@ public void UpdateCollection(IEnumerable<T> newCollection)
i++;
}
}
public void ForceUpdate()
{
GenericTools.RunUI(() =>
{
onFilterUpdated?.Invoke(this, new EventArgs());
//OnPropertyChanged(new PropertyChangedEventArgs("Count"));
//OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
//OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
});

}
}
public class ExtendedIBaseObservableCollection<T> : ExtendedObservableCollection<T> where T : INotifyPropertyChanged, IBase
{
Expand Down Expand Up @@ -296,12 +310,46 @@ public FilteredObservableCollection(ExtendedObservableCollection<T> collection,
foreach (var item in collection) if (_filter(item) == true) Items.Add(item);
collection.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBaseCollectionChanged);
basecollection.ItemPropertyChanged += Basecollection_ItemPropertyChanged;
basecollection.onFilterUpdated += Basecollection_onFilterUpdated;
}
public void Refresh()
{
Items.Clear();
foreach (var item in basecollection) if (_filter(item) == true) base.Add(item);
}

private void Basecollection_onFilterUpdated(object sender, EventArgs e)
{
List<T> addlist = new List<T>();
List<T> removelist = new List<T>();
try
{
foreach (var item in Items.ToList())
{
if (_filter(item) == false)
{
Items.Remove(item);
removelist.Add(item);
}
}
foreach (var item in basecollection.ToList())
{
if (Items.Contains(item)) continue;
if (_filter(item) == true)
{
Items.Add(item);
addlist.Add(item);
}
}

}
catch (Exception ex)
{
Log.Error(ex.Message);
}
if (removelist.Count > 0) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removelist));
if (addlist.Count > 0) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addlist));
}
private void Basecollection_ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
T item = (T)sender;
Expand Down Expand Up @@ -472,11 +520,7 @@ private void ReplaceItems(IList<IBase> oldItems, IList<IBase> newItems)
}
private void AddItems(IEnumerable<IBase> newItems, INotifyCollectionChanged sender)
{
foreach (var itemToAdd in newItems)
{
var indexOfNewItemToAdd = CalculateIndexForInsertNewItem(sender);
InsertItem(indexOfNewItemToAdd, itemToAdd);
}
AddRange(newItems);
}
private IEnumerable<IBase> GetItemsToDelete()
{
Expand Down
2 changes: 2 additions & 0 deletions OpenRPA.Net/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ public async Task<Message> SendMessage(Message msg)
// _messageQueue.Add(qm);
//}
Log.Network("(" + _messageQueue.Count + ") " + msg.command + " RSND: " + msg.id);
if (!_messageQueue.Contains(qm)) _messageQueue.Add(qm);
msg.SendMessage(this, 3);
}
else
Expand All @@ -666,6 +667,7 @@ public async Task<Message> SendMessage(Message msg)
else if (signedin)
{
Log.Network("(" + _messageQueue.Count + ") " + msg.command + " SEND: " + msg.id);
if (!_messageQueue.Contains(qm)) _messageQueue.Add(qm);
msg.SendMessage(this, 3);
}
}
Expand Down
2 changes: 2 additions & 0 deletions OpenRPA.SAP/Activities/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected override void Execute(CodeActivityContext context)
string client = Client.Get(context);
string language = Language.Get(context);
string systemname = SystemName.Get(context);
if (!SAPhook.Instance.isConnected) throw new Exception("OpenRPA is not connected to the SAP bridge");
SAPhook.Instance.RefreshConnections();
bool dologin = true;
SAPSession _session = null;
Expand All @@ -55,6 +56,7 @@ protected override void Execute(CodeActivityContext context)
}
if(_session==null)
{
if (!SAPhook.Instance.isConnected) throw new Exception("OpenRPA is not connected to the SAP bridge");
SAPhook.Instance.RefreshConnections();
if (SAPhook.Instance.Sessions != null)
foreach (var session in SAPhook.Instance.Sessions)
Expand Down
6 changes: 5 additions & 1 deletion OpenRPA.SAP/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
try
{
SAPhook.Instance.RefreshConnections();
if (SAPhook.Instance.Connections.Length < 1)
if(SAPhook.Instance.Connections == null)
{
SetStatus("Offline");
}
else if (SAPhook.Instance.Connections.Length < 1)
{
SetStatus("Online(-1)");
}
Expand Down
1 change: 1 addition & 0 deletions OpenRPA.SAP/SAPhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public override string ToString()
public bool isSapRunning { get; private set; } = false;
public void RefreshConnections()
{
if (!isConnected) return;
var msg = new SAPEvent("getconnections");
msg = SAPhook.Instance.SendMessage(msg, TimeSpan.FromSeconds(PluginConfig.bridge_timeout_seconds));
if (msg != null)
Expand Down
17 changes: 16 additions & 1 deletion OpenRPA/LocallyCached.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,23 @@ 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);
T result = default(T);
try
{
result = await global.webSocketClient.InsertOne(collectionname, 0, false, entity);
}
catch (Exception ex)
{
if(ex.Message.Contains("E11000 duplicate key error"))
{
result = await global.webSocketClient.InsertOrUpdateOne(collectionname, 0, false, null, entity);
} else
{
throw;
}
}
EnumerableExtensions.CopyPropertiesTo(result, entity, true);
isLocalOnly = false;
_backingFieldValues["isDirty"] = false;
Log.Verbose("Inserted to openflow and returned as version " + entity._version + " " + entity._type + " " + entity.name);
}
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.8</Version>
<Version>1.4.9</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>open_rpa128.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion OpenRPA/Views/OpenProject.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void NotifyPropertyChanged(string propertyName)
public event Action onSelectedItemChanged;
private IMainWindow main = null;
public List<System.Globalization.CultureInfo> Cultures { get; set; }

public ICommand PlayCommand
{
get
Expand Down Expand Up @@ -263,6 +262,8 @@ public string FilterText
set
{
_FilterText = value;
Projects.ForceUpdate();
RobotInstance.instance.Workflows.ForceUpdate();
//if (isFiltering)
//{
// ReFilter = true;
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/Views/WFDesigner.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public async Task<bool> SaveAsync()
WorkflowDesigner.Flush();
var modelItem = WorkflowDesigner.Context.Services.GetService<ModelService>().Root;
Workflow.name = modelItem.GetValue<string>("Name").Replace("_", " ");

Workflow.culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
Workflow.Xaml = WorkflowDesigner.Text;
var _hasChanged = HasChanged;
HasChanged = false;
Expand Down

0 comments on commit cafa983

Please sign in to comment.