// public INavigationService NavigationService { get; set; } #endregion private ViewLifetimeControl(CoreWindow newWindow) { CoreDispatcher = newWindow.Dispatcher; WindowWrapper = WindowEx.Current(); Id = ApplicationView.GetApplicationViewIdForWindow(newWindow); // This class will automatically tell the view when its time to close // or stay alive in a few cases RegisterForEvents(); }
private IJsScriptExecutor CreateExecutor(IWindowEx window) { switch (_jsEngine) { case JsEngines.Jint: return(JintFactory.Create(new ScriptExecutionContext(window))); case JsEngines.Jurassic: return(JurassicFactory.Create(new ScriptExecutionContext(window))); default: throw new Exception("Invalid engine specified: " + _jsEngine); } }
private IJsScriptExecutor CreateExecutor(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXhr = null) { switch (_jsEngine) { case JsEngines.Jint: return(new Knyaz.Optimus.ScriptExecuting.Jint.JintJsScriptExecutor(window, createXhr ?? (_ => null))); case JsEngines.Jurassic: return(new Scripting.Jurassic.JurassicJsScriptExecutor(window, createXhr ?? (_ => null))); default: throw new Exception("Invalid engine specified: " + _jsEngine); } }
public static MonitorUtils Current(IWindowEx windowWrapper = null) { windowWrapper = windowWrapper ?? throw new ArgumentNullException(nameof(windowWrapper)); if (!Cache.ContainsKey(windowWrapper)) { var item = new MonitorUtils(windowWrapper); Cache.Add(windowWrapper, item); windowWrapper.ApplicationView.Consolidated += new WeakReferenceEx <MonitorUtils, ApplicationView, object>(item) { EventAction = (i, s, e) => Cache.Remove(windowWrapper), DetachAction = (i, w) => windowWrapper.ApplicationView.Consolidated -= w.Handler }.Handler; } return(Cache[windowWrapper]); }
private void CreateEngine(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXmlHttpRequest) { _jsEngine = new JintJsEngine(window); _jsEngine.Execute("var window = this"); _jsEngine.Execute("var self = window"); _jsEngine.Execute("function Image(w, h) { var img = document.createElement('img'); img.width = w || 0; img.height = h||0; return img;}"); foreach (var type in ScriptingSettings.Default.GlobalTypes) { _jsEngine.AddGlobalType(type); } _jsEngine.AddGlobalType <Event>(new [] { typeof(string), typeof(EventInitOptions) }, args => new Event(window.Document, args[0]?.ToString(), args.Length > 1 ? (EventInitOptions)args[1] : null)); Func <Stream, object> parseJsonFn = s => _jsEngine.ParseJson(s.ReadToEnd()); _jsEngine.AddGlobalType("XMLHttpRequest", x => createXmlHttpRequest(parseJsonFn)); }
private MonitorUtils(IWindowEx windowWrapper) { var di = windowWrapper.DisplayInformation; di.OrientationChanged += new WeakReferenceEx <MonitorUtils, DisplayInformation, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => di.OrientationChanged -= w.Handler }.Handler; var av = windowWrapper.ApplicationView; av.VisibleBoundsChanged += new WeakReferenceEx <MonitorUtils, ApplicationView, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler }.Handler; Inches = new InchesInfo(windowWrapper); Pixels = new PixelsInfo(windowWrapper); }
private DeviceUtils(IWindowEx windowWrapper) { MonitorUtils = MonitorUtils.Current(windowWrapper); WindowWrapper = windowWrapper ?? throw new ArgumentNullException(nameof(windowWrapper)); var di = windowWrapper.DisplayInformation; di.OrientationChanged += new Common.WeakReferenceEx <DeviceUtils, DisplayInformation, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => di.OrientationChanged -= w.Handler }.Handler; var av = windowWrapper.ApplicationView; av.VisibleBoundsChanged += new Common.WeakReferenceEx <DeviceUtils, ApplicationView, object>(this) { EventAction = (i, s, e) => i.Changed?.Invoke(i, EventArgs.Empty), DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler }.Handler; }
public ScriptExecutionContext(IWindowEx window) { Window = window; }
public PixelsInfo(IWindowEx windowWrapper) { WindowWrapper = windowWrapper; }
public InchesInfo(IWindowEx windowWrapper) { WindowWrapper = windowWrapper; }
public ScriptExecutionContext(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXhr) { Window = window; CreateXhr = createXhr; }
private void Execute(IWindowEx window, string code) => CreateExecutor(window).Execute(code);
private object Evaluate(IWindowEx window, string code) => CreateExecutor(window).Evaluate(code);
public JintJsScriptExecutor(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXmlHttpRequest) { CreateEngine(window ?? throw new ArgumentNullException(nameof(window)), createXmlHttpRequest); }