From 217fcb79fa32f858a06d8200697ddee7c5da625a Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 12 Dec 2019 01:32:37 +0200 Subject: Added IsAfterReset to ConnectionResponse PMR. Started working on PPC.Browser Module !!! --- .../PPC/Modules/Tango.PPC.Browser/BrowserModule.cs | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs new file mode 100644 index 000000000..51384ae54 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using Tango.BL.Enumerations; +using Tango.PPC.Common; +using Tango.PPC.Browser.Views; +using Tango.SharedUI.Helpers; + +namespace Tango.PPC.Browser +{ + /// + /// Represents a PPC . + /// + /// + [PPCModule(10)] + public class BrowserModule : PPCModuleBase + { + /// + /// Initializes a new instance of the class. + /// + public BrowserModule() + { + IsVisibleInMenu = true; + } + + /// + /// Gets the module name. + /// + public override string Name + { + get + { + return "Browser"; + } + } + + /// + /// Gets the module description. + /// + public override string Description + { + get + { + return "Browser module"; + } + } + + /// + /// Gets the module cover image. + /// + public override BitmapSource Image + { + get + { + return ResourceHelper.GetImageFromResources("Images/browser.png"); + } + } + + /// + /// Gets the module entry point view type. + /// + public override Type MainViewType + { + get + { + return typeof(MainView); + } + } + + /// + /// Gets the permission required to see and load this module. + /// + public override Permissions Permission + { + get + { + return Permissions.RunPPC; + } + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public override void Dispose() + { + //Dispose module here... + } + } +} -- cgit v1.3.1 From 5fdb4170c92072fa5a3ee32a779bea2ed83b8ef0 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 12 Dec 2019 13:00:45 +0200 Subject: Added more functionality to browser module. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../Attributes/BoundObjectAttribute.cs | 20 ++++ .../BoundsObjects/KeyboardHandler.cs | 41 ++++++++ .../Tango.PPC.Browser/BoundsObjects/MainBound.cs | 39 ------- .../PPC/Modules/Tango.PPC.Browser/BrowserModule.cs | 2 +- .../Helpers/BoundObjectsHelper.cs | 72 +++++++++++++ .../RequestHandlers/ChromiumRequestHandler.cs | 114 ++++++++++++++++++++ .../Modules/Tango.PPC.Browser/Scripts/keyboard.js | 21 ++++ .../PPC/Modules/Tango.PPC.Browser/Scripts/main.js | 21 ---- .../Tango.PPC.Browser/Tango.PPC.Browser.csproj | 16 +-- .../ViewContracts/IBrowserView.cs | 18 ++++ .../Modules/Tango.PPC.Browser/ViewModelLocator.cs | 6 +- .../Tango.PPC.Browser/ViewModels/BrowserViewVM.cs | 101 ++++++++++++++++++ .../Tango.PPC.Browser/ViewModels/MainViewVM.cs | 56 ---------- .../Tango.PPC.Browser/Views/BrowserView.xaml | 29 ++++++ .../Tango.PPC.Browser/Views/BrowserView.xaml.cs | 115 +++++++++++++++++++++ .../Modules/Tango.PPC.Browser/Views/MainView.xaml | 15 --- .../Tango.PPC.Browser/Views/MainView.xaml.cs | 79 -------------- .../PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs | 24 +++++ .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 3 +- 21 files changed, 571 insertions(+), 221 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 9ec032e48..147440cf5 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 3e5056420..58fd7e215 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs new file mode 100644 index 000000000..b4e822f1e --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Browser.Attributes +{ + public class BoundObjectAttribute : Attribute + { + public String Name { get; set; } + public String ScriptFile { get; set; } + + public BoundObjectAttribute(String name,String scriptFile) + { + Name = name; + ScriptFile = scriptFile; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs new file mode 100644 index 000000000..50df8ae0c --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Tango.PPC.Browser.Attributes; +using Tango.PPC.Common.Helpers; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Browser.BoundsObjects +{ + [BoundObject("keyboard", "keyboard.js")] + public class KeyboardHandler + { + public void openKeyboard(String inputType) + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + switch (inputType) + { + case "search": + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + break; + default: + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Next); + break; + } + })); + } + + public void closeKeyboard() + { + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + KeyboardHelper.CloseKeyboard(); + })); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs deleted file mode 100644 index 8743fa054..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using Tango.Touch.Keyboard; - -namespace Tango.PPC.Browser.BoundsObjects -{ - public class MainBound - { - public void openKeyboard(String inputType) - { - Application.Current.Dispatcher.BeginInvoke(new Action(() => - { - switch (inputType) - { - case "search": - KeyboardView.Keyboard.ActionKeyMode = KeyboardActionKeyMode.Go; - break; - default: - KeyboardView.Keyboard.ActionKeyMode = KeyboardActionKeyMode.Next; - break; - } - KeyboardView.Default.IsOpened = true; - })); - } - - public void closeKeyboard() - { - Application.Current.Dispatcher.BeginInvoke(new Action(() => - { - KeyboardView.Default.IsOpened = false; - })); - } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs index 51384ae54..a73700fef 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -66,7 +66,7 @@ namespace Tango.PPC.Browser { get { - return typeof(MainView); + return typeof(BrowserView); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs new file mode 100644 index 000000000..fe68ee848 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using Tango.PPC.Browser.Attributes; +using CefSharp; +using CefSharp.Wpf; +using Tango.Core.Helpers; +using System.Windows.Threading; + +namespace Tango.PPC.Browser.Helpers +{ + public static class BoundObjectsHelper + { + private static DispatcherTimer _timer; + private static Dispatcher _dispatcher; + private static ChromiumWebBrowser _browser; + + private static List _scripts = new List(); + + public static void RegisterAllBoundObjects(ChromiumWebBrowser browser, Dispatcher dispatcher) + { + _dispatcher = dispatcher; + _browser = browser; + + _timer = new DispatcherTimer(DispatcherPriority.Background, dispatcher); + _timer.Tick += _timer_Tick; + _timer.Interval = TimeSpan.FromSeconds(2); + _timer.Stop(); + + foreach (var type in typeof(BoundObjectsHelper).Assembly.GetTypes().Where(x => x.GetCustomAttribute() != null)) + { + var att = type.GetCustomAttribute(); + + var script = EmbeddedResourceHelper.GetEmbeddedResourceText($"Tango.PPC.Browser.Scripts.{att.ScriptFile}"); + _scripts.Add(script); + + browser.JavascriptObjectRepository.Register(att.Name, Activator.CreateInstance(type), true); + + browser.FrameLoadEnd += Browser_FrameLoadEnd; + } + } + + private static void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) + { + _timer.Stop(); + _timer.Start(); + } + + private static void _timer_Tick(object sender, EventArgs e) + { + try + { + _timer.Stop(); + + _dispatcher.BeginInvoke(new Action(() => + { + foreach (var script in _scripts) + { + _browser.GetMainFrame().ExecuteJavaScriptAsync(script); + } + })); + } + catch + { + _timer.Start(); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs new file mode 100644 index 000000000..fc6cb119c --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs @@ -0,0 +1,114 @@ +using CefSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Browser.RequestHandlers +{ + public class ChromiumRequestHandler : IRequestHandler + { + public event EventHandler AddressChanged; + + public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) + { + return false; + } + + public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect) + { + // You can check the Request object for the URL Here + return false; + } + + public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) + { + // You can also check the URL here + callback.Dispose(); + return CefReturnValue.Continue; + } + + public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) + { + callback.Dispose(); + return false; + } + + public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) + { + return false; + } + + public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath) + { + } + + public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) + { + return false; + } + + public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback) + { + callback.Dispose(); + return false; + } + + public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status) + { + } + + public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) + { + } + + public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) + { + // You can also check the request URL here + } + + public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl) + { + } + + public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + { + return false; + } + + + public IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + { + return null; + } + + + public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) + { + } + + public bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, ISelectClientCertificateCallback callback) + { + callback.Dispose(); + return false; + } + + public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) + { + AddressChanged?.Invoke(this, request.Url); + return false; + } + + public IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) + { + return null; + } + + public bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) + { + callback.Dispose(); + return false; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js new file mode 100644 index 000000000..21771eb8e --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js @@ -0,0 +1,21 @@ +(async function () { + await CefSharp.BindObjectAsync("keyboard", "bound"); + + var inputs = document.getElementsByTagName('input'); + var i = 0; + + do { + + var type = inputs[i].type; + + if (type == 'text' || type == 'email' || type == 'password' || type == 'search' || type == 'date' || type == 'url' || type == 'time' || type == 'tel' || type == 'number') { + inputs[i].onfocus = function () { + keyboard.openKeyboard(type); + } + inputs[i].onblur = function () { + keyboard.closeKeyboard(); + } + } + } + while (inputs[++i]) +})(); \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js deleted file mode 100644 index c43e0e272..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js +++ /dev/null @@ -1,21 +0,0 @@ -(async function () { - await CefSharp.BindObjectAsync("boundAsync", "bound"); - - var inputs = document.getElementsByTagName('input'); - var i = 0; - - do { - - var type = inputs[i].type; - - if (type == 'text' || type == 'email' || type == 'password' || type == 'search' || type == 'date' || type == 'url' || type == 'time' || type == 'tel' || type == 'number') { - inputs[i].onfocus = function () { - boundAsync.openKeyboard(type); - } - inputs[i].onblur = function () { - boundAsync.closeKeyboard(); - } - } - } - while (inputs[++i]) -})(); \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj index eb85fefa5..c799887a2 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj @@ -76,7 +76,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile @@ -85,8 +85,10 @@ GlobalVersionInfo.cs - + + + Code @@ -100,10 +102,12 @@ Settings.settings True + + - - - MainView.xaml + + + BrowserView.xaml ResXFileCodeGenerator @@ -163,7 +167,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs new file mode 100644 index 000000000..8369209a3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; +using Tango.SharedUI; + +namespace Tango.PPC.Browser.ViewContracts +{ + public interface IBrowserView : IPPCView + { + event EventHandler AddressChanged; + bool CanGoBack(); + void NavigateTo(String address); + void GoBack(); + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs index 30f936433..054310e99 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs @@ -15,17 +15,17 @@ namespace Tango.PPC.Browser /// static ViewModelLocator() { - TangoIOC.Default.Register(); + TangoIOC.Default.Register(); } /// /// Gets the main view VM. /// - public static MainViewVM MainViewVM + public static BrowserViewVM BrowserViewVM { get { - return TangoIOC.Default.GetInstance(); + return TangoIOC.Default.GetInstance(); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs new file mode 100644 index 000000000..f24301257 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs @@ -0,0 +1,101 @@ +using CefSharp; +using CefSharp.Wpf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.PPC.Browser.ViewContracts; +using Tango.PPC.Common; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Browser.ViewModels +{ + /// + /// Represents the main view VM and entry point for . + /// + /// + public class BrowserViewVM : PPCViewModel + { + private String _address; + public String Address + { + get { return _address; } + set { _address = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand GoCommand { get; set; } + + public BrowserViewVM() + { + if (!DesignMode) + { + try + { + var settings = new CefSettings(); + settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; + settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; + + Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); + } + catch (Exception ex) + { + //Log Here Not Throw! + throw; + } + } + + GoCommand = new RelayCommand(Go); + } + + public override void OnViewAttached() + { + base.OnViewAttached(); + View.AddressChanged += View_AddressChanged; + } + + private void View_AddressChanged(object sender, string address) + { + Address = address; + } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; + } + + public override void OnNavigatedFrom() + { + base.OnNavigatedFrom(); + KeyboardView.Default.OutputMode = KeyboardOutputMode.Wpf; + } + + public override Task OnNavigateBackRequest() + { + if (View.CanGoBack()) + { + View.GoBack(); + return Task.FromResult(false); + } + else + { + return Task.FromResult(true); + } + } + + /// + /// Called when the application has been started + /// + public override void OnApplicationStarted() + { + + } + + private void Go() + { + View.NavigateTo(Address); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs deleted file mode 100644 index afea97f73..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs +++ /dev/null @@ -1,56 +0,0 @@ -using CefSharp; -using CefSharp.Wpf; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common; -using Tango.Touch.Keyboard; - -namespace Tango.PPC.Browser.ViewModels -{ - /// - /// Represents the main view VM and entry point for . - /// - /// - public class MainViewVM : PPCViewModel - { - public MainViewVM() - { - try - { - var settings = new CefSettings(); - settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; - settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; - - Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); - } - catch (Exception ex) - { - //Log Here Not Throw! - throw; - } - } - - public override void OnNavigatedTo() - { - base.OnNavigatedTo(); - KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; - } - - public override void OnNavigatedFrom() - { - base.OnNavigatedFrom(); - KeyboardView.Default.OutputMode = KeyboardOutputMode.Wpf; - } - - /// - /// Called when the application has been started - /// - public override void OnApplicationStarted() - { - - } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml new file mode 100644 index 000000000..7b5854101 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs new file mode 100644 index 000000000..2717c77d3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using CefSharp; +using CefSharp.Wpf; +using Tango.Core.DI; +using Tango.Core.Helpers; +using Tango.PPC.Browser.BoundsObjects; +using Tango.PPC.Browser.ViewContracts; +using Tango.PPC.Common.Helpers; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Browser.Views +{ + /// + /// Interaction logic for MainView.xaml + /// + public partial class BrowserView : UserControl, IBrowserView + { + public event EventHandler AddressChanged; + + public BrowserView() + { + InitializeComponent(); + + TangoIOC.Default.Register(this); + + Helpers.BoundObjectsHelper.RegisterAllBoundObjects(Browser, Dispatcher); + + KeyboardView.Default.KeyboardOpened += Default_KeyboardOpened; + KeyboardView.Default.KeyboardClosed += Default_KeyboardClosed; + + var handler = new RequestHandlers.ChromiumRequestHandler(); + handler.AddressChanged += Handler_AddressChanged; + Browser.RequestHandler = handler; + } + + private void Handler_AddressChanged(object sender, string e) + { + Dispatcher.BeginInvoke(new Action(() => + { + AddressChanged?.Invoke(this, Browser.Address); + })); + } + + private void Default_KeyboardClosed(object sender, EventArgs e) + { + Browser.VerticalAlignment = VerticalAlignment.Stretch; + Browser.Height = double.NaN; + } + + private void Default_KeyboardOpened(object sender, EventArgs e) + { + Browser.VerticalAlignment = VerticalAlignment.Top; + Browser.Height = 780; + } + + public bool CanGoBack() + { + return Browser.CanGoBack; + } + + public void NavigateTo(string address) + { + Browser.Address = address; + } + + public void GoBack() + { + if (Browser.CanGoBack) + { + Browser.Back(); + } + } + + private async void TxtAddress_GotFocus(object sender, RoutedEventArgs e) + { + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + await Task.Delay(100); + txtAddress.SelectAll(); + } + + private void TxtAddress_LostFocus(object sender, RoutedEventArgs e) + { + KeyboardHelper.CloseKeyboard(); + } + + private void TxtAddress_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Return) + { + KeyboardHelper.CloseKeyboard(); + NavigateTo(txtAddress.Text); + } + } + + private void TxtAddress_MouseUp(object sender, MouseButtonEventArgs e) + { + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml deleted file mode 100644 index 903e21cce..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs deleted file mode 100644 index 917d16e49..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Windows.Threading; -using CefSharp; -using CefSharp.Wpf; -using Tango.Core.Helpers; -using Tango.PPC.Browser.BoundsObjects; -using Tango.Touch.Keyboard; - -namespace Tango.PPC.Browser.Views -{ - /// - /// Interaction logic for MainView.xaml - /// - public partial class MainView : UserControl - { - private DispatcherTimer _timer; - - public MainView() - { - InitializeComponent(); - - _timer = new DispatcherTimer(); - _timer.Tick += _timer_Tick; - _timer.Interval = TimeSpan.FromSeconds(2); - _timer.Stop(); - - Browser.JavascriptObjectRepository.Register("boundAsync", new MainBound(), true); - Browser.FrameLoadEnd += Browser_FrameLoadEnd; - - KeyboardView.Default.KeyboardOpened += Default_KeyboardOpened; - KeyboardView.Default.KeyboardClosed += Default_KeyboardClosed; - } - - private void Default_KeyboardClosed(object sender, EventArgs e) - { - Debug.WriteLine("Closed"); - Browser.VerticalAlignment = VerticalAlignment.Stretch; - Browser.Height = double.NaN; - } - - private void Default_KeyboardOpened(object sender, EventArgs e) - { - Debug.WriteLine("Opened"); - Browser.VerticalAlignment = VerticalAlignment.Top; - Browser.Height = 780; - } - - private void _timer_Tick(object sender, EventArgs e) - { - _timer.Stop(); - - Dispatcher.BeginInvoke(new Action(() => - { - var script = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.PPC.Browser.Scripts.main.js"); - Browser.ExecuteScriptAsync(script); - })); - } - - private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) - { - _timer.Stop(); - _timer.Start(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs new file mode 100644 index 000000000..8d1de9f0d --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Common.Helpers +{ + public static class KeyboardHelper + { + public static void OpenKeyboard(KeyboardActionKeyMode action, TouchKeyboardMode mode = TouchKeyboardMode.AlphaNumeric) + { + KeyboardView.Keyboard.ActionKeyMode = action; + KeyboardView.Keyboard.Mode = mode; + KeyboardView.Default.IsOpened = true; + } + + public static void CloseKeyboard() + { + KeyboardView.Default.IsOpened = true; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index b781e3c9a..ac3aa2618 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -149,6 +149,7 @@ + @@ -419,7 +420,7 @@ - + \ No newline at end of file -- cgit v1.3.1 From 791ecdccc3d9ecc6311d6b1440e462119e65dc92 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 12 Dec 2019 22:12:17 +0200 Subject: Improvements on browser module. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../PPC/Modules/Tango.PPC.Browser/BrowserModule.cs | 16 +++- .../Tango.PPC.Browser/Views/BrowserView.xaml | 55 +++++++++++++- .../Tango.PPC.Browser/Views/BrowserView.xaml.cs | 83 +++++++++++++++++++-- .../PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs | 2 +- .../Tango.Touch/Keyboard/TouchKeyboard.cs | 6 +- 7 files changed, 150 insertions(+), 12 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 082a4ad84..f7ef63b2d 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 281b804ac..080be181d 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs index a73700fef..4da2f4f98 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -8,6 +8,8 @@ using Tango.BL.Enumerations; using Tango.PPC.Common; using Tango.PPC.Browser.Views; using Tango.SharedUI.Helpers; +using Tango.Core.DI; +using Tango.PPC.Common.Application; namespace Tango.PPC.Browser { @@ -23,7 +25,7 @@ namespace Tango.PPC.Browser /// public BrowserModule() { - IsVisibleInMenu = true; + IsVisibleInMenu = false; } /// @@ -81,6 +83,18 @@ namespace Tango.PPC.Browser } } + public override void OnTechnicianEntered() + { + base.OnTechnicianEntered(); + IsVisibleInMenu = true; + } + + public override void OnTechnicianExited() + { + base.OnTechnicianExited(); + IsVisibleInMenu = false; + } + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml index 7b5854101..5c62d6915 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml @@ -18,12 +18,59 @@ - - - + + + + + + + + + + + + + + + + + - + + + + + + + Page Not Found + + The page at '' + could not be reached. + + Please check your internet connection. + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs index 2717c77d3..aeb1b5c41 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -46,14 +47,46 @@ namespace Tango.PPC.Browser.Views var handler = new RequestHandlers.ChromiumRequestHandler(); handler.AddressChanged += Handler_AddressChanged; Browser.RequestHandler = handler; + Browser.LoadError += Browser_LoadError; + Browser.LoadingStateChanged += Browser_LoadingStateChanged; } - private void Handler_AddressChanged(object sender, string e) + private void Browser_LoadError(object sender, LoadErrorEventArgs e) { - Dispatcher.BeginInvoke(new Action(() => + //if (e.ErrorCode == CefErrorCode.ConnectionTimedOut || e.ErrorCode == CefErrorCode.NameNotResolved) + //{ + InvokeUI(() => { - AddressChanged?.Invoke(this, Browser.Address); - })); + runError.Text = e.ErrorText; + gridError.Visibility = Visibility.Visible; + }); + //} + } + + private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) + { + if (!e.IsLoading) + { + InvokeUI(() => + { + KeyboardHelper.CloseKeyboard(); + }); + } + else + { + InvokeUI(() => + { + gridError.Visibility = Visibility.Hidden; + }); + } + } + + private void Handler_AddressChanged(object sender, string address) + { + InvokeUI(() => + { + AddressChanged?.Invoke(this, address); + }); } private void Default_KeyboardClosed(object sender, EventArgs e) @@ -75,7 +108,35 @@ namespace Tango.PPC.Browser.Views public void NavigateTo(string address) { - Browser.Address = address; + if (Browser.Address != address) + { + Uri uri; + + if (ValidHttpURL(address, out uri)) + { + Browser.Address = uri.ToString(); + } + else + { + Browser.Address = $"google.com/search?q={address.Replace(" ", "+")}"; + } + } + else + { + Browser.Reload(); + } + } + + public static bool ValidHttpURL(string s, out Uri resultURI) + { + if (!Regex.IsMatch(s, @"^https?:\/\/", RegexOptions.IgnoreCase)) + s = "http://" + s; + + if (Uri.TryCreate(s, UriKind.Absolute, out resultURI)) + return (resultURI.Scheme == Uri.UriSchemeHttp || + resultURI.Scheme == Uri.UriSchemeHttps); + + return false; } public void GoBack() @@ -111,5 +172,17 @@ namespace Tango.PPC.Browser.Views { KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); } + + private async void TxtAddress_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + await Task.Delay(100); + txtAddress.SelectAll(); + } + + private void InvokeUI(Action action) + { + Dispatcher.BeginInvoke(action); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs index 8d1de9f0d..202f0378e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Helpers/KeyboardHelper.cs @@ -18,7 +18,7 @@ namespace Tango.PPC.Common.Helpers public static void CloseKeyboard() { - KeyboardView.Default.IsOpened = true; + KeyboardView.Default.IsOpened = false; } } } diff --git a/Software/Visual_Studio/Tango.Touch/Keyboard/TouchKeyboard.cs b/Software/Visual_Studio/Tango.Touch/Keyboard/TouchKeyboard.cs index a35b91dd6..9a6b7227f 100644 --- a/Software/Visual_Studio/Tango.Touch/Keyboard/TouchKeyboard.cs +++ b/Software/Visual_Studio/Tango.Touch/Keyboard/TouchKeyboard.cs @@ -505,10 +505,14 @@ namespace Tango.Touch.Keyboard { Forms.SendKeys.SendWait(key); } - else + else if (key != " ") { Forms.SendKeys.SendWait("{" + key + "}"); } + else + { + Forms.SendKeys.SendWait(" "); + } Forms.SendKeys.Flush(); }); -- cgit v1.3.1 From 85e27ca4c292329a894a49ed950912285465fa2e Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 12 Dec 2019 23:03:21 +0200 Subject: Embedded browser module in technician instead of menu. Implemented browser module navigation support. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../PPC/Modules/Tango.PPC.Browser/BrowserModule.cs | 12 ------- .../Navigation/BrowserNavigationRequest.cs | 19 +++++++++++ .../Tango.PPC.Browser/Tango.PPC.Browser.csproj | 1 + .../Tango.PPC.Browser/ViewModels/BrowserViewVM.cs | 35 ++++++++++++++++++++- .../Tango.PPC.Browser/Views/BrowserView.xaml | 6 ++-- .../Tango.PPC.Browser/Views/BrowserView.xaml.cs | 23 ++++++++------ .../Tango.PPC.Technician/Images/browser.png | Bin 0 -> 2539 bytes .../Tango.PPC.Technician.csproj | 7 +++++ .../ViewModels/CatalogViewVM.cs | 23 +++++++++++++- .../Tango.PPC.Technician/Views/CatalogView.xaml | 12 +++++++ .../Tango.PPC.Technician/Views/PackagesView.xaml | 2 +- 13 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Navigation/BrowserNavigationRequest.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Images/browser.png (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index f7ef63b2d..6e83bb088 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 080be181d..1fab4f80d 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs index 4da2f4f98..cd8372277 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -83,18 +83,6 @@ namespace Tango.PPC.Browser } } - public override void OnTechnicianEntered() - { - base.OnTechnicianEntered(); - IsVisibleInMenu = true; - } - - public override void OnTechnicianExited() - { - base.OnTechnicianExited(); - IsVisibleInMenu = false; - } - /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Navigation/BrowserNavigationRequest.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Navigation/BrowserNavigationRequest.cs new file mode 100644 index 000000000..a8becf251 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Navigation/BrowserNavigationRequest.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Browser.Navigation +{ + public class BrowserNavigationRequest + { + public String Address { get; set; } + public bool DisplayAddressBar { get; set; } + + public BrowserNavigationRequest() + { + DisplayAddressBar = true; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj index c799887a2..58d525c32 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj @@ -89,6 +89,7 @@ + Code diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs index f24301257..9f66bb6a6 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs @@ -6,8 +6,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.PPC.Browser.Navigation; using Tango.PPC.Browser.ViewContracts; using Tango.PPC.Common; +using Tango.PPC.Common.Navigation; using Tango.Touch.Keyboard; namespace Tango.PPC.Browser.ViewModels @@ -16,8 +18,10 @@ namespace Tango.PPC.Browser.ViewModels /// Represents the main view VM and entry point for . /// /// - public class BrowserViewVM : PPCViewModel + public class BrowserViewVM : PPCViewModel, INavigationObjectReceiver { + private bool _isFromObject; + private String _address; public String Address { @@ -25,10 +29,19 @@ namespace Tango.PPC.Browser.ViewModels set { _address = value; RaisePropertyChangedAuto(); } } + private bool _displayAddressBar; + public bool DisplayAddressBar + { + get { return _displayAddressBar; } + set { _displayAddressBar = value; RaisePropertyChangedAuto(); } + } + public RelayCommand GoCommand { get; set; } public BrowserViewVM() { + DisplayAddressBar = true; + if (!DesignMode) { try @@ -64,6 +77,13 @@ namespace Tango.PPC.Browser.ViewModels { base.OnNavigatedTo(); KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; + + if (!_isFromObject) + { + DisplayAddressBar = true; + } + + _isFromObject = false; } public override void OnNavigatedFrom() @@ -97,5 +117,18 @@ namespace Tango.PPC.Browser.ViewModels { View.NavigateTo(Address); } + + public void OnNavigatedToWithObject(BrowserNavigationRequest obj) + { + _isFromObject = true; + + DisplayAddressBar = obj.DisplayAddressBar; + + if (obj.Address != null) + { + Address = obj.Address; + Go(); + } + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml index 5c62d6915..6e2076c98 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml @@ -13,7 +13,7 @@ d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:BrowserViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.BrowserViewVM}" Background="{StaticResource TangoPrimaryBackgroundBrush}"> - + @@ -54,12 +54,12 @@ - + Page Not Found - + The page at '' could not be reached. diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs index aeb1b5c41..e3f4c29e3 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs @@ -110,11 +110,11 @@ namespace Tango.PPC.Browser.Views { if (Browser.Address != address) { - Uri uri; + String uri; if (ValidHttpURL(address, out uri)) { - Browser.Address = uri.ToString(); + Browser.Address = uri; } else { @@ -127,15 +127,20 @@ namespace Tango.PPC.Browser.Views } } - public static bool ValidHttpURL(string s, out Uri resultURI) + public static bool ValidHttpURL(string s, out string result) { - if (!Regex.IsMatch(s, @"^https?:\/\/", RegexOptions.IgnoreCase)) - s = "http://" + s; - - if (Uri.TryCreate(s, UriKind.Absolute, out resultURI)) - return (resultURI.Scheme == Uri.UriSchemeHttp || - resultURI.Scheme == Uri.UriSchemeHttps); + if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) + { + result = s; + return true; + } + else if (s.StartsWith("www.")) + { + result = "http://" + s; + return true; + } + result = s; return false; } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Images/browser.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Images/browser.png new file mode 100644 index 000000000..ebb975b6f Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Images/browser.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Tango.PPC.Technician.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Tango.PPC.Technician.csproj index e4261334a..e11e34298 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Tango.PPC.Technician.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Tango.PPC.Technician.csproj @@ -173,6 +173,10 @@ {0BE74EEE-22CB-4DBA-B896-793B9E1A3AC0} Tango.PPC.Common + + {f02eaa84-ad59-465b-99a2-4422c13bfb72} + Tango.PPC.Browser + @@ -245,5 +249,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs index 97bae6f5b..ecd2c7b93 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs @@ -4,6 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.PPC.Browser; +using Tango.PPC.Browser.Navigation; +using Tango.PPC.Browser.Views; using Tango.PPC.Common; namespace Tango.PPC.Technician.ViewModels @@ -15,17 +18,23 @@ namespace Tango.PPC.Technician.ViewModels /// public RelayCommand NavigationCommand { get; set; } + /// + /// Gets or sets the browser command. + /// + public RelayCommand BrowserCommand { get; set; } + /// /// Initializes a new instance of the class. /// public CatalogViewVM() { NavigationCommand = new RelayCommand(NavigateToView); + BrowserCommand = new RelayCommand(OpenBrowserModule); } public override void OnApplicationStarted() { - + } /// @@ -36,5 +45,17 @@ namespace Tango.PPC.Technician.ViewModels { NavigationManager.NavigateTo(view); } + + /// + /// Opens the browser module. + /// + private void OpenBrowserModule() + { + NavigationManager.NavigateWithObject(new BrowserNavigationRequest() + { + Address = "https://twine-s.com/", + DisplayAddressBar = true, + }, true); + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/CatalogView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/CatalogView.xaml index b0a86d938..b8c74c374 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/CatalogView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/CatalogView.xaml @@ -104,6 +104,18 @@ + + + + + + Browser + + Open the browser module and navigate the web. + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/PackagesView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/PackagesView.xaml index f4708448c..a7944497b 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/PackagesView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/PackagesView.xaml @@ -26,7 +26,7 @@ - +