Skip to content

Commit

Permalink
Merge pull request #786 from skadefro/master
Browse files Browse the repository at this point in the history
add url detector to nm
  • Loading branch information
skadefro authored Apr 28, 2024
2 parents 3ec364d + b1e0149 commit 9a5582e
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 2 deletions.
1 change: 1 addition & 0 deletions OpenRPA.FileWatcher/Views/FileWatcherView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class FileWatcherView : UserControl, INotifyPropertyChanged
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
Entity.isDirty = true;
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
public FileWatcherView(FileWatcherDetectorPlugin plugin)
Expand Down
1 change: 1 addition & 0 deletions OpenRPA.Interfaces/Views/KeyboardDetectorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class KeyboardDetectorView : UserControl, INotifyPropertyChanged
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
Entity.isDirty = true;
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
public KeyboardDetectorView(KeyboardDetectorPlugin plugin)
Expand Down
1 change: 1 addition & 0 deletions OpenRPA.Java/Views/JavaClickDetectorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public partial class JavaClickDetectorView : UserControl, INotifyPropertyChanged
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
Entity.isDirty = true;
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
public JavaClickDetectorView(JavaClickDetectorPlugin plugin)
Expand Down
50 changes: 50 additions & 0 deletions OpenRPA.NM/NMHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace OpenRPA.NM
{
Expand Down Expand Up @@ -519,13 +520,61 @@ private static void tabcreated(NativeMessagingMessage msg)
try
{
tabs.Add(msg.tab);
DetectorCheck(tab);
}
finally
{
System.Threading.Monitor.Exit(tabs);
}
}
}
private static DateTime lastURLDetector = DateTime.Now;
private static void DetectorCheck(NativeMessagingMessageTab tab)
{
try
{
TimeSpan ts = DateTime.Now.Subtract(lastURLDetector);
if (ts.TotalSeconds < 2) return;
if (tab == null || string.IsNullOrEmpty(tab.url)) return;
URLDetectorPlugin plugin = null;
foreach (var p in Plugins.detectorPlugins)
{
if (p is URLDetectorPlugin _plugin)
{
plugin = _plugin;
}
}
if (plugin == null || string.IsNullOrEmpty(plugin.URL)) return;
RegexOptions options = RegexOptions.None;
if(plugin.IgnoreCase)
{
options = RegexOptions.IgnoreCase;
}
var ma = Regex.Match(tab.url, plugin.URL, options);
if (!ma.Success) return;
lastURLDetector = DateTime.Now;
var e = new URLDetectorEvent(tab.url);
plugin.RaiseDetector(e);
foreach (var wi in Plugin.client.WorkflowInstances.ToList())
{
if (wi.isCompleted) continue;
if (wi.Bookmarks != null)
{
foreach (var b in wi.Bookmarks)
{
if (b.Key == "DownloadDetectorPlugin")
{
wi.ResumeBookmark(b.Key, e, true);
}
}
}
}
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
}
private static void tabupdated(NativeMessagingMessage msg)
{
var tab = FindTabById(msg.browser, msg.tab.id);
Expand All @@ -551,6 +600,7 @@ private static void tabupdated(NativeMessagingMessage msg)
tab.url = msg.tab.url;
tab.width = msg.tab.width;
tab.windowId = msg.tab.windowId;
DetectorCheck(tab);
}
private static void tabremoved(NativeMessagingMessage msg)
{
Expand Down
5 changes: 5 additions & 0 deletions OpenRPA.NM/OpenRPA.NM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<None Remove="Snippets\GoogleSearchPaging.xaml" />
<None Remove="Views\DownloadDetectorView.xaml" />
<None Remove="Views\RecordPluginView.xaml" />
<None Remove="Views\URLDetectorView.xaml" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\designer\gettable.png" />
Expand Down Expand Up @@ -145,6 +146,10 @@
<Page Include="Activities\OpenURLDesigner.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\URLDetectorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DownloadDetectorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
63 changes: 63 additions & 0 deletions OpenRPA.NM/Resources/strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions OpenRPA.NM/Resources/strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,33 @@
<data name="debug_console_output_help" xml:space="preserve">
<value>Write debug informtation to browser console</value>
</data>
<data name="detector_button_open_selector" xml:space="preserve">
<value>Open Selector</value>
</data>
<data name="detector_button_select" xml:space="preserve">
<value>Select</value>
</data>
<data name="detector_name" xml:space="preserve">
<value>Name</value>
</data>
<data name="detector_url" xml:space="preserve">
<value>URL</value>
</data>
<data name="plugin_detect_html_table" xml:space="preserve">
<value>Detect html table</value>
</data>
<data name="plugin_detect_html_table_help" xml:space="preserve">
<value>Auto add Get Table if clicked on HTML table doing recording</value>
</data>
<data name="plugin_ignore_case" xml:space="preserve">
<value>Ignore lower and uppercase doing match ?</value>
</data>
<data name="plugin_ignore_case_help" xml:space="preserve">
<value>Ignore Case</value>
</data>
<data name="plugin_urldetector_general_help" xml:space="preserve">
<value>Type a url or use Select button to grab by clicking a page. URL can also be a regular expression for more complex cases.</value>
</data>
<data name="plugin_wait_for_tab_after_set_value" xml:space="preserve">
<value>Wait after set value</value>
</data>
Expand Down
129 changes: 129 additions & 0 deletions OpenRPA.NM/URLDetectorPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Newtonsoft.Json;
using OpenRPA.Input;
using OpenRPA.Interfaces;
using OpenRPA.Interfaces.entity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace OpenRPA.NM
{
public class URLDetectorPlugin : ObservableObject, IDetectorPlugin
{
public IDetector Entity { get; set; }
public string Name
{
get
{
if (Entity != null && !string.IsNullOrEmpty(Entity.name)) return Entity.name;
return "URLDetector";
}
}
public string URL
{
get
{
if (Entity == null) return null;
if (!Entity.Properties.ContainsKey("URL")) return null;
var _val = Entity.Properties["URL"];
if (_val == null) return null;
return _val.ToString();
}
}
public bool IgnoreCase
{
get
{
if (Entity == null) return false;
if (!Entity.Properties.ContainsKey("IgnoreCase")) return false;
var _val = Entity.Properties["URL"];
if (_val == null) return IgnoreCase;
return _val.ToString().ToLower() == "true";
}
set
{
Entity.Properties["IgnoreCase"] = value.ToString();
NotifyPropertyChanged("IgnoreCase");
}
}
private Views.URLDetectorView view;
public UserControl editor
{
get
{
if (view == null)
{
view = new Views.URLDetectorView(this);
view.PropertyChanged += (s, e) =>
{
NotifyPropertyChanged("Entity");
NotifyPropertyChanged("Name");
NotifyPropertyChanged("URL");
};
}
return view;
}
}
public event DetectorDelegate OnDetector;
public void RaiseDetector(Download download)
{
if (!Running) return;
var e = new DetectorEvent(download);
OnDetector?.Invoke(this, e, EventArgs.Empty);
}
public void RaiseDetector(URLDetectorEvent e)
{
if (!Running) return;
OnDetector?.Invoke(this, e, EventArgs.Empty);
}
FileSystemWatcher watcher = null;
private IOpenRPAClient client = null;
public void Initialize(IOpenRPAClient client, IDetector InEntity)
{
this.client = client;
Entity = InEntity;
watcher = new FileSystemWatcher();
Start();
}
public bool Running { get; set; } = false;
public void Start()
{
try
{
Running = true;
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
}
public void Stop()
{
Running = false;
}
public void Initialize(IOpenRPAClient client)
{
}
}
public class URLDetectorEvent : IDetectorEvent
{
public IElement element { get; set; }
public string host { get; set; }
public string fqdn { get; set; }
public string url { get; set; }
public string result { get; set; }
public URLDetectorEvent(string url)
{
host = Environment.MachineName.ToLower();
fqdn = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName.ToLower();
this.url = url;
result = url;
}

}

}
33 changes: 33 additions & 0 deletions OpenRPA.NM/Views/URLDetectorView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<UserControl x:Class="OpenRPA.NM.Views.URLDetectorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:or="clr-namespace:OpenRPA.NM.Resources"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="67,20,0,0" Text="{x:Static or:strings.detector_name}" VerticalAlignment="Top" Width="110" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="183,20,0,0" Text="{Binding Path=EntityName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="222" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="67,50,0,0" Text="{x:Static or:strings.detector_url}" VerticalAlignment="Top" Width="110" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="183,50,0,0" Text="{Binding Path=URL, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="222" />

<TextBlock Height="23" HorizontalAlignment="Left" Margin="35,80,0,0" Text="{x:Static or:strings.plugin_ignore_case}" VerticalAlignment="Top" Width="110" />
<CheckBox Height="23" HorizontalAlignment="Left" Margin="151,80,0,0" VerticalAlignment="Top" Width="222" x:Name="plugin_ignore_case"
Checked="plugin_ignore_caseChanged" Unchecked="plugin_ignore_caseChanged" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="180,80,0,0" Text="{x:Static or:strings.plugin_ignore_case_help}" VerticalAlignment="Top" />



<TextBlock Height="23" HorizontalAlignment="Left" Margin="180,110,0,0" Text="{x:Static or:strings.plugin_urldetector_general_help}" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="180,140,0,0" Text="Example" VerticalAlignment="Top" />

<TextBox Height="23" HorizontalAlignment="Left" Margin="183,170,0,0" Text="^https://www.google.com/search\?q=" VerticalAlignment="Top" Width="222" />

<Button Content="{x:Static or:strings.detector_button_select}" HorizontalAlignment="Left" Margin="67,110,0,0" VerticalAlignment="Top" Width="100" RenderTransformOrigin="0.769,-0.134" Click="Select_Click" />
<!--<Button Content="{x:Static or:strings.detector_button_open_selector}" HorizontalAlignment="Left" Margin="67,134,0,0" VerticalAlignment="Top" Width="100" RenderTransformOrigin="0.769,-0.134" Click="Open_Selector_Click" />-->



</Grid>
</UserControl>
Loading

0 comments on commit 9a5582e

Please sign in to comment.