/// <summary> /// User while intializing view before it has been shown. /// </summary> /// <param name="view"></param> public void SetInitialView(TargetView view) { switch (view) { case TargetView.BreastCancerRiskFactors: InitialView = typeof(BreastCancerRiskFactors); break; case TargetView.CancerRisk: InitialView = typeof(BreastCancerRiskFactors); break; case TargetView.Orders: InitialView = typeof(OrdersView); break; case TargetView.PatientCommunication: InitialView = typeof(PatientCommunicationView); break; case TargetView.Recommendations: InitialView = typeof(Recommendations); break; case TargetView.RiskClinicFamilyHistory: InitialView = typeof(RiskClinicFamilyHistoryView); break; case TargetView.SimpleRiskModel: InitialView = typeof(SimpleRiskModelView); break; case TargetView.Tests: InitialView = typeof(TestsView); break; default: InitialView = typeof(RiskClinicFamilyHistoryView); break; } }
public void StylesheetsAreLoaded() { string stylesheet = null; TargetView.Event += (args) => { stylesheet = args; }; TargetView.ExecuteMethodOnRoot("checkStyleSheetLoaded", "1"); WaitFor(() => stylesheet != null, TimeSpan.FromSeconds(10), "stylesheet load"); Assert.IsTrue(stylesheet.Contains(".foo")); Assert.IsTrue(stylesheet.Contains(".baz")); // from dependency }
public async Task ResourceRequestIsCanceled() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.BeforeResourceLoad += (resourceHandler) => { resourceHandler.Cancel(); taskCompletionSource.SetResult(true); }; await Load(HtmlWithResource); await taskCompletionSource.Task; var failed = TargetView.EvaluateScript <bool>("scriptFailed"); // check that the value of x is what was declared before in the resource Assert.IsTrue(failed); }); }
public async Task InterceptedResourceRequestIsLoaded() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.BeforeResourceLoad += (resourceHandler) => { resourceHandler.RespondWith(ToStream("scriptLoaded = true"), "js"); // declare x taskCompletionSource.SetResult(true); }; await Load(HtmlWithResource); await taskCompletionSource.Task; var loaded = TargetView.EvaluateScript <bool>("scriptLoaded"); // check that the value of x is what was declared before in the resource Assert.IsTrue(loaded); }); }
public async Task DefaultStylesheetIsLoaded() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <string>(); TargetView.Event += (args) => { taskCompletionSource.SetResult(args); }; TargetView.ExecuteMethod("checkStyleSheetLoaded", "2"); var stylesheet = await taskCompletionSource.Task; StringAssert.Contains(".bar", stylesheet); }); }
public void DisposeDoesNotHang() { var disposed = false; TargetView.Event += (args) => { TargetView.Dispatcher.Invoke((() => { TargetView.Dispose(); disposed = true; })); }; TargetView.ExecuteMethodOnRoot("callEvent"); WaitFor(() => disposed, TimeSpan.FromSeconds(10), "view disposed"); }
void Recognizer_View_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Renderer") { var renderer = TargetView.GetRenderer(); if (renderer != null && !_isInitialized) { Initialize(); } else if (renderer == null && _isInitialized) { UnInitialize(); } } }
public async Task ListenersAreCalledInDispatcherThread() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); var listener = TargetView.AttachListener("event_name"); listener.UIHandler += delegate { taskCompletionSource.SetResult(Dispatcher.UIThread.CheckAccess()); }; await Load($"<html><script>{listener}</script><body></body></html>"); var canAccessDispatcher = await taskCompletionSource.Task; Assert.IsTrue(canAccessDispatcher, "Listeners are not being called in dispatcher thread!"); }); }
public async Task StylesheetsAreLoaded() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <string>(); TargetView.Event += (args) => { taskCompletionSource.SetResult(args); }; TargetView.ExecuteMethod("checkStyleSheetLoaded", "1"); var stylesheet = await taskCompletionSource.Task; Assert.IsTrue(stylesheet.Contains(".foo")); Assert.IsTrue(stylesheet.Contains(".baz")); // from dependency }); }
public void RegisteredJsObjectMethodExecutesInDispatcherThread() { const string DotNetObject = "DotNetObject"; bool? canAccessDispatcher = null; Func <int> functionToCall = () => { canAccessDispatcher = TargetView.Dispatcher.CheckAccess(); return(10); }; TargetView.RegisterJavascriptObject(DotNetObject, functionToCall, executeCallsInUI: true); LoadAndWaitReady($"<html><script>{DotNetObject}.invoke();</script><body></body></html>"); WaitFor(() => canAccessDispatcher != null, DefaultTimeout); Assert.IsTrue(canAccessDispatcher); }
protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options) { if (options.Style == SetJsonOptions.JsonStyle.Repository && string.IsNullOrEmpty(mGlobalId)) { setGlobalId(ParserIfc.EncodeGuid(Guid.NewGuid())); options.Encountered.Add(mGlobalId); } base.setJSON(obj, host, options); obj["ParentContext"] = ParentContext.getJson(this, options); if (!double.IsNaN(mTargetScale)) { obj["TargetScale"] = mTargetScale.ToString(); } obj["TargetView"] = TargetView.ToString(); setAttribute(obj, "UserDefinedTargetView", UserDefinedTargetView); }
public async Task RegisteredJsObjectMethodExecutesInDispatcherThread() { const string DotNetObject = "DotNetObject"; var taskCompletionSource = new TaskCompletionSource <bool>(); Func <int> functionToCall = () => { taskCompletionSource.SetResult(Dispatcher.UIThread.CheckAccess()); return(10); }; TargetView.RegisterJavascriptObject(DotNetObject, functionToCall, executeCallsInUI: true); await Load($"<html><script>{DotNetObject}.invoke();</script><body></body></html>"); var canAccessDispatcher = await taskCompletionSource.Task; Assert.IsTrue(canAccessDispatcher); }
protected Task Load(string html) { var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); void OnNavigated(string url, string frameName) { if (url != UrlHelper.AboutBlankUrl) { TargetView.Navigated -= OnNavigated; taskCompletionSource.SetResult(true); } } TargetView.Navigated += OnNavigated; TargetView.LoadHtml(html); return(taskCompletionSource.Task); }
protected void LoadAndWaitReady(string html, TimeSpan timeout, string timeoutMsg = null) { var navigated = false; void OnNavigated(string url, string frameName) { navigated = true; } try { TargetView.Navigated += OnNavigated; TargetView.LoadHtml(html); WaitFor(() => navigated, timeout, timeoutMsg); } finally { TargetView.Navigated -= OnNavigated; } }
public async Task RegisteredJsObjectMethodNullParamsSerialization() { await Run(async() => { const string DotNetObject = "DotNetObject"; var taskCompletionSource = new TaskCompletionSource <Tuple <string, string[]> >(); Action <string, string[]> functionToCall = (string arg1, string[] arg2) => { taskCompletionSource.SetResult(new Tuple <string, string[]>(arg1, arg2)); }; TargetView.RegisterJavascriptObject(DotNetObject, functionToCall); await Load($"<html><script>{DotNetObject}.invoke(null, ['hello', null, 'world']);</script><body></body></html>"); var obtainedArgs = await taskCompletionSource.Task; Assert.AreEqual(null, obtainedArgs.Item1); Assert.That(new[] { "hello", null, "world" }, Is.EquivalentTo(obtainedArgs.Item2)); }); }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(ContextIdentifier != null ? ContextIdentifier.ToStepValue() : "$"); parameters.Add(ContextType != null ? ContextType.ToStepValue() : "$"); parameters.Add("*"); parameters.Add("*"); parameters.Add("*"); parameters.Add("*"); parameters.Add(ParentContext != null ? ParentContext.ToStepValue() : "$"); parameters.Add(TargetScale != null ? TargetScale.ToStepValue() : "$"); parameters.Add(TargetView.ToStepValue()); parameters.Add(UserDefinedTargetView != null ? UserDefinedTargetView.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public async Task CustomRequestsAreHandledByAnotherThread() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <int>(); var mainThread = Thread.CurrentThread.ManagedThreadId; TargetView.CustomResourceRequested += delegate { taskCompletionSource.SetResult(Thread.CurrentThread.ManagedThreadId); return(null); }; TargetView.ExecuteMethod("loadCustomResource", "custom://resource//test.png"); var customResourceRequestThread = await taskCompletionSource.Task; Assert.AreNotEqual(mainThread, customResourceRequestThread, "Custom resource request thread should be different from main thread"); }); }
public async Task DisposeDoesNotHang() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.Event += delegate { Dispatcher.UIThread.InvokeAsync(() => { TargetView.Dispose(); taskCompletionSource.SetResult(true); }).Wait(); }; TargetView.ExecuteMethod("callEvent"); var eventCalled = await taskCompletionSource.Task; Assert.IsTrue(eventCalled, "View was not disposed!"); }); }
private void AdminViewGenerator() { //Ładowanie do bazy zrzutu z IDB; _ = new IDBView(_adminTab); //Wysyłanie Maili z Admina; SendMailView SendMail = new SendMailView { Location = new Point(1135, 85) }; _adminTab.Controls.Add(SendMail); //Automatyczne przliczaie STK w akcjach Z tenego roku AutoUpdateSTKView AutoSTK = new AutoUpdateSTKView { Location = new Point(425, 680) }; _adminTab.Controls.Add(AutoSTK); //Dodawania konta lub zmiany jego praw AddPersonView AccessView = new AddPersonView { Location = new Point(425, 15) }; _adminTab.Controls.Add(AccessView); //Sumowanie ilości miesięcznych PNC do odpowiednich grup SumPNC Sum = new SumPNC { Location = new Point(15, 525), }; _adminTab.Controls.Add(Sum); //Sprawdzania i dodawanie Targetów dla poszczególnych działów i łacznie dla całego PC TargetView Target = new TargetView { Location = new Point(830, 175), }; _adminTab.Controls.Add(Target); }
public void CustomRequestsAreHandledByAnotherThread() { var requestHandlerCalled = false; var mainThread = Thread.CurrentThread.ManagedThreadId; var customResourceRequestThread = -1; TargetView.CustomResourceRequested += (_, __) => { customResourceRequestThread = Thread.CurrentThread.ManagedThreadId; requestHandlerCalled = true; return(null); }; TargetView.ExecuteMethod("loadCustomResource", "custom://webview/test.png"); WaitFor(() => requestHandlerCalled, "custom request handler called"); Assert.IsTrue(requestHandlerCalled, "Request handler was called"); Assert.AreNotEqual(mainThread, customResourceRequestThread, "custom resource request thread should be different from main thread"); }
public void JavascriptEvaluationOnIframe() { LoadAndWaitReady( "<html>" + "<body>" + "<script>" + "var x = 1;" + "</script>" + "<iframe name='test' srcdoc='<html><body><script>var y = 2;</script></body></html>'></iframe>" + "</body>" + "</html>" ); var x = TargetView.EvaluateScript <int>("x", ""); var y = TargetView.EvaluateScript <int>("y", "test"); Assert.AreEqual(1, x); Assert.AreEqual(2, y); }
public async Task ExecuteBeforeReady() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.Event += delegate { taskCompletionSource.SetResult(true); }; TargetView.ExecuteMethod("callEvent"); Assert.IsFalse(TargetView.IsReady); Assert.IsFalse(taskCompletionSource.Task.IsCompleted); Window.Show(); var isReady = await taskCompletionSource.Task; Assert.IsTrue(isReady); }); }
public void SetInitialView(TargetView view) { switch (view) { case TargetView.ExpressFamilyHistory: InitialView = typeof(ExpressFamilyHistoryView); break; case TargetView.BreastCancerRiskFactors: InitialView = typeof(BreastCancerRiskFactors); break; case TargetView.PatientCommunication: InitialView = typeof(PatientCommunicationView); break; default: InitialView = typeof(ExpressFamilyHistoryView); break; } }
public void PreloadUsesWebViewFromCache() { var start = DateTime.Now; while ((DateTime.Now - start).TotalSeconds < 1) { DoEvents(); // let the cached webview have time to be created } var currentTime = TargetView.EvaluateMethod <double>("getCurrentTime"); using (var newView = new TestReactViewWithPreload()) { Window.Content = newView; WaitFor(() => newView.IsReady, "second view load"); var startTime = newView.EvaluateMethod <double>("getStartTime"); Assert.LessOrEqual(startTime, currentTime, "The second webview should have been loaded before"); } }
/// <summary> /// Called when the <see cref="TargetView"/> has just been loaded. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks> /// This method will call the <see cref="OnTargetViewLoadedAsync"/> which can be overriden for custom /// behavior. This method is required to protect from duplicate loaded events. /// </remarks> #pragma warning disable AvoidAsyncVoid // Avoid async void private async void OnTargetViewLoadedInternal(object sender, EventArgs e) #pragma warning restore AvoidAsyncVoid // Avoid async void { if (!CanLoad) { return; } Log.Debug($"Target view '{TargetViewType?.Name}' has been loaded"); var view = TargetView; if (view != null) { _viewManager.RegisterView(view); } IsTargetViewLoaded = true; var dataContext = view.DataContext; LastKnownDataContext = (dataContext != null) ? new WeakReference(dataContext) : null; await OnTargetViewLoadedAsync(sender, e); TargetView.EnsureVisualTree(); var targetViewAsViewModelContainer = TargetView as IViewModelContainer; if (targetViewAsViewModelContainer != null) { ViewToViewModelMappingHelper.InitializeViewToViewModelMappings(targetViewAsViewModelContainer); } TargetView.Dispatch(() => { #pragma warning disable 4014 // No need to await InitializeViewModelAsync(); #pragma warning restore 4014 }); IsLoading = false; }
public void Init(Unit unit) { _unit = unit; Id = _unit.Id; _partViewsManager = ManagerProvider.Instance.PartViewsManager; _unit.Partset.OnPartAttached += OnPartAttached; _unit.Partset.OnPartDetached += OnPartDetached; foreach (var pair in _unit.Partset.Slots) { if (pair.Value.Part != null) { OnPartAttached(pair.Value); } } TargetView = GetComponentInChildren <TargetView>(); }
public void RegisteredJsObjectMethodExecutesInDispatcherThreadWithoutBlocking() { const string DotNetObject = "DotNetObject"; bool functionCalled = false; Func <int> functionToCall = () => { TargetView.EvaluateScript <int>("1+1"); functionCalled = true; return(1); }; TargetView.RegisterJavascriptObject(DotNetObject, functionToCall, executeCallsInUI: true); LoadAndWaitReady("<html><script>function test() { DotNetObject.invoke(); return 1; }</script><body></body></html>"); var result = TargetView.EvaluateScriptFunction <int>("test"); WaitFor(() => functionCalled, DefaultTimeout); Assert.AreEqual(1, result); }
public void ListenersAreCalled() { var listener1Counter = 0; var listener2Counter = 0; var listener1 = TargetView.AttachListener("event1_name"); listener1.Handler += delegate { listener1Counter++; }; var listener2 = TargetView.AttachListener("event2_name"); listener2.Handler += delegate { listener2Counter++; }; listener2.Handler += delegate { listener2Counter++; }; LoadAndWaitReady($"<html><script>{listener1}{listener2}</script><body></body></html>"); WaitFor(() => listener1Counter > 0 && listener2Counter > 0); Assert.AreEqual(1, listener1Counter); Assert.AreEqual(2, listener2Counter); }
public void UnhandledExceptionEventIsCalledOnListenerError() { const string ExceptionMessage = "hey"; Exception exception = null; WithUnhandledExceptionHandling(() => { var listener = TargetView.AttachListener("event_name", () => throw new Exception(ExceptionMessage), executeInUI: false); LoadAndWaitReady($"<html><script>{listener}</script><body></body></html>"); WaitFor(() => exception != null); Assert.IsTrue(exception.Message.Contains(ExceptionMessage)); }, e => { exception = e; return(true); }); }
public async Task JsEvaluationReturnsDefaultValuesAfterWebViewDispose() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); await Load("<html><script>function test() { return 1; }</script><body></body></html>"); TargetView.Disposed += () => { taskCompletionSource.SetResult(true); }; TargetView.Dispose(); var disposeCalled = await taskCompletionSource.Task; var result = await TargetView.EvaluateScriptFunction <int>("test"); Assert.IsTrue(disposeCalled); Assert.AreEqual(result, 0); }); }
protected Task Load(string html) { var taskCompletionSource = new TaskCompletionSource <bool>(); void OnNavigated(string url, string frameName) { if (url != UrlHelper.AboutBlankUrl) { try { taskCompletionSource.SetResult(true); } finally { TargetView.Navigated -= OnNavigated; } } } TargetView.Navigated += OnNavigated; TargetView.LoadHtml(html); return(taskCompletionSource.Task); }
public async Task JavascriptEvaluationOnIframe() { await Run(async() => { await Load( "<html>" + "<body>" + "<script>" + "var x = 1;" + "</script>" + "<iframe name='test' srcdoc='<html><body><script>var y = 2;</script></body></html>'></iframe>" + "</body>" + "</html>" ); var x = await TargetView.EvaluateScript <int>("x", ""); var y = await TargetView.EvaluateScript <int>("test.y", ""); Assert.AreEqual(1, x); Assert.AreEqual(2, y); }); }
/// <summary> /// Populates the Status list, adds missing items if not contained in the Target Status picklist, and set the selected value. /// </summary> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param> private void LoadTargetStatusItems(GridViewRowEventArgs e, TargetView target) { DropDownList statusList = e.Row.FindControl("ddlTargetStatus") as DropDownList; statusList.Attributes.Add("onChange", string.Format("javascript:onStatusChange('{0}', '{1}', '{2}', '{3}');", statusList.ClientID, txtNewStatusValue.ClientID, cmdStatusChange.ClientID, target.TargetId)); ListItemCollection listItems = new ListItemCollection(); foreach (ListItem item in lbxStatus.Items) listItems.Add(item); if (target != null) { String value = target.Status; ListItem item = listItems.FindByText(value); if (item == null) { item = new ListItem {Text = value}; listItems.Add(item); } statusList.DataSource = listItems; statusList.SelectedValue = value; } }