Example #1
0
        // 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();
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 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]);
 }
Example #5
0
        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));
        }
Example #6
0
        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);
        }
Example #7
0
        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;
        }
Example #8
0
 public ScriptExecutionContext(IWindowEx window)
 {
     Window = window;
 }
Example #9
0
 public PixelsInfo(IWindowEx windowWrapper)
 {
     WindowWrapper = windowWrapper;
 }
Example #10
0
 public InchesInfo(IWindowEx windowWrapper)
 {
     WindowWrapper = windowWrapper;
 }
Example #11
0
 public ScriptExecutionContext(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXhr)
 {
     Window    = window;
     CreateXhr = createXhr;
 }
Example #12
0
 private void Execute(IWindowEx window, string code) =>
 CreateExecutor(window).Execute(code);
Example #13
0
 private object Evaluate(IWindowEx window, string code) =>
 CreateExecutor(window).Evaluate(code);
Example #14
0
 public JintJsScriptExecutor(IWindowEx window, Func <Func <Stream, object>, XmlHttpRequest> createXmlHttpRequest)
 {
     CreateEngine(window ?? throw new ArgumentNullException(nameof(window)), createXmlHttpRequest);
 }