Пример #1
0
        private void LoadHandler_OnLoadError(object sender, CfxOnLoadErrorEventArgs e)
        {
            if (e.ErrorCode == CfxErrorCode.Aborted)
            {
                //Aborted is raised during hot-reload
                //We will not poluate log nor stop the application
                return;
            }

            _Logger.Error($@"Unable to load ""{e.FailedUrl}"": ""{e.ErrorCode}"". Please check that the resource exists, has the correct ""Content"" and ""Build Type"" value or is correctly served.");
            if (!e.Frame.IsMain)
            {
                return;
            }

            _Logger.Error("Closing application");
            _Dispatcher.RunAsync(async() =>
            {
                //Delay here to be sure to finish all chromium related task
                //before closing application. This will avoid additional exception
                //due to inconsistent state.
                await Task.Delay(10);
                Application.Current.Shutdown(-1);
            });
        }
Пример #2
0
        public void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue)
        {
            try
            {
                var res = _SessionCache.GetGlobalCached(objectchanged) as JsGenericObject;
                if (res == null)
                {
                    return;
                }

                var propertyAccessor = new PropertyAccessor(res.CValue, propertyName, _Logger);
                if (!propertyAccessor.IsSettable)
                {
                    _Logger.Info(() => $"Unable to set C# from javascript object: property: {propertyName} is readonly.");
                    return;
                }

                var targetType = propertyAccessor.GetTargetType();
                var glue       = GetCachedOrCreateBasic(newValue, targetType);

                Context.RunOnUIContextAsync(() =>
                {
                    using (_IsListening ? _ListenerRegister.GetPropertySilenter(res.CValue) : null)
                    {
                        propertyAccessor.Set(glue.CValue);
                        res.UpdateCSharpProperty(propertyName, glue);
                    }
                });
            }
            catch (Exception e)
            {
                _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}");
            }
        }
Пример #3
0
        public async void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue)
        {
            try
            {
                var res = _SessionCache.GetCached(objectchanged) as JsGenericObject;
                if (res == null)
                {
                    return;
                }

                var propertyAccessor = new PropertyAccessor(res.CValue, propertyName, _Logger);
                if (!propertyAccessor.IsSettable)
                {
                    _Logger.Info(() => $"Unable to set C# from javascript object: property: {propertyName} is readonly.");
                    return;
                }

                var targetType    = propertyAccessor.GetTargetType();
                var glue          = GetCachedOrCreateBasic(newValue, targetType);
                var bridgeUpdater = glue.IsBasicNotNull() ? null : new BridgeUpdater();

                await Context.RunOnUIContextAsync(() =>
                {
                    using (var relisten = glue.IsBasicNotNull() ? null : ReListen(bridgeUpdater))
                        using (_IsListening ? _ListenerRegister.GetPropertySilenter(res.CValue) : null)
                        {
                            var oldValue = propertyAccessor.Get();
                            propertyAccessor.Set(glue.CValue);
                            var actualValue = propertyAccessor.Get();

                            if (Object.Equals(actualValue, glue.CValue))
                            {
                                res.UpdateGlueProperty(propertyName, glue);
                                return;
                            }

                            if (!Object.Equals(oldValue, actualValue))
                            {
                                CSharpPropertyChanged(res.CValue, new PropertyChangedEventArgs(propertyName));
                            }
                        }
                });

                if (!(bridgeUpdater?.HasUpdatesOnJavascriptContext == true))
                {
                    return;
                }

                await Context.RunOnJavascriptContextAsync(() =>
                {
                    bridgeUpdater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
                });
            }
            catch (Exception e)
            {
                _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}");
            }
        }
        private void Crashed(object sender, BrowserCrashedArgs e)
        {
            var dest = _CurrentWebControl.HTMLWindow.Url;
            var vm   = Binding.Root;
            var mode = Binding.Mode;

            _webSessionLogger.Error("WebView crashed trying recover");

            CleanWebControl(ref _CurrentWebControl);
            Binding = null;

            Navigate(dest, vm, mode);
        }
Пример #5
0
        public bool Eval(string code, out IJavascriptObject res)
        {
            var resValue = V8Context.Eval(code, string.Empty, 1, out var v8Res, out var exception);

            res = v8Res?.Convert();
            if (exception != null)
            {
                _Logger?.Error($"Error during javascript code evaluation. Code: {code}, Exception: {exception.Message}");
            }
            return(resValue);
        }
Пример #6
0
        public PackUriResourceHandler(Uri packUri, IWebSessionLogger logger)
        {
            StreamResourceInfo resInfo = null;

            try
            {
                resInfo = System.Windows.Application.GetResourceStream(packUri);
            }
            catch (Exception exception)
            {
                logger?.Error(() => $"Unable to find pack ressource:{packUri} exception:{exception}");
            }

            GetResponseHeaders += (s1, e1) =>
            {
                if (resInfo == null)
                {
                    e1.Response.Status     = 404;
                    e1.Response.StatusText = "Not Found";
                    return;
                }

                e1.ResponseLength      = resInfo.Stream.Length;
                e1.Response.MimeType   = GetMineType(resInfo, packUri);
                e1.Response.Status     = 200;
                e1.Response.StatusText = "OK";
            };

            ReadResponse += (s2, e2) =>
            {
                if (resInfo == null)
                {
                    e2.SetReturnValue(false);
                    return;
                }

                var buffer    = new byte[e2.BytesToRead];
                var bytesRead = resInfo.Stream.Read(buffer, 0, e2.BytesToRead);
                System.Runtime.InteropServices.Marshal.Copy(buffer, 0, e2.DataOut, bytesRead);
                e2.BytesRead = bytesRead;
                e2.SetReturnValue(true);
            };

            ProcessRequest += (s3, e3) =>
            {
                e3.Callback.Continue();
                e3.SetReturnValue(true);
            };
        }
Пример #7
0
        public PackUriResourceHandler(Uri packUri, IWebSessionLogger logger)
        {
            _Uri = packUri;
            try
            {
                _StreamResourceInfo = System.Windows.Application.GetResourceStream(packUri);
            }
            catch (Exception exception)
            {
                logger?.Error(() => $"Unable to find pack ressource:{packUri} exception:{exception}");
            }

            GetResponseHeaders += PackUriResourceHandler_GetResponseHeaders;
            ReadResponse       += PackUriResourceHandler_ReadResponse;
            ProcessRequest     += PackUriResourceHandler_ProcessRequest;
            CanGetCookie       += PackUriResourceHandler_CanGetCookie;
            CanSetCookie       += PackUriResourceHandler_CanSetCookie;
        }
Пример #8
0
 public void LogCriticalTest()
 {
     _nullLogger.Error(string.Empty);
 }
Пример #9
0
 private void LogJavascriptSetException(Exception exception)
 {
     _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {exception.Message}");
 }
 public void AddProperty(IJavascriptObject father, string propertyName, IJavascriptObject value)
 {
     _Logger.Error("adding property not supported by knockout pluggin");
 }
Пример #11
0
 private void Crashed(object sender, BrowserCrashedArgs e)
 {
     _webSessionLogger.Error("WebView crashed trying recover");
     Reload(true);
 }