Example #1
0
        public void SetItem(string key, object data)
        {
            _ = key ?? throw new ArgumentNullException(nameof(key));
            _ = data ?? throw new ArgumentNullException(nameof(data));

            _jsInProcessRuntime.Invoke <object>("localStorage.setItem", key, JsonConvert.SerializeObject(data));
        }
Example #2
0
        public T GetItem <T>(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (_jSInProcessRuntime == null)
            {
                throw new InvalidOperationException("IJSInProcessRuntime not available");
            }

            var serialisedData = _jSInProcessRuntime.Invoke <string>("localStorage.getItem", key);

            if (string.IsNullOrWhiteSpace(serialisedData))
            {
                return(default(T));
            }

            if (serialisedData.StartsWith("{") && serialisedData.EndsWith("}") ||
                serialisedData.StartsWith("\"") && serialisedData.EndsWith("\"") ||
                typeof(T) != typeof(string))
            {
                return(JsonSerializer.Deserialize <T>(serialisedData, _jsonOptions));
            }
            else
            {
                return((T)(object)serialisedData);
            }
        }
Example #3
0
        /// <summary>
        /// Returns true if the page is in a state considered to be hidden to the user, and false otherwise.
        /// </summary>
        /// <returns></returns>
        public bool IsHidden()
        {
            var result = jSInProcessRuntime.Invoke <bool?>("CurrieTechnologies.Blazor.PageVisibility.IsHidden");

            if (result == null)
            {
                throw new JSException("Visibility not supported");
            }

            return(result.Value);
        }
        /// <summary>
        /// 注册本地化数据
        /// </summary>
        public CultureInfo Register()
        {
            var browserLocale = _jsInProcessRuntime.Invoke <string>("DC.Localisation.GetBrowserLocale");
            var culture       = new CultureInfo(browserLocale);

            return(culture);
        }
Example #5
0
        public T GetItem <T>(string key)
        {
            var json = _jsRuntime.Invoke <string>("localStorage.getItem", key);

            if (json == null)
            {
                return(default);
Example #6
0
 internal RenderingContext(CanvasComponentBase reference, string contextName, object parameters = null)
 {
     Canvas       = reference.CanvasReference;
     _contextName = contextName;
     _runtime     = (IJSInProcessRuntime)reference.JSRuntime;
     _runtime.Invoke <object>($"{NamespacePrefix}.{_contextName}.{AddAction}", Canvas, parameters);
 }
Example #7
0
    public AppClient(IJSRuntime _runtime)
    {
        runtime = (IJSInProcessRuntime)_runtime;

        var s  = runtime.Invoke <string>("localStorage.getItem", typeof(DB).FullName);
        var bs = s != null?Convert.FromBase64String(s) : null;

        if (bs != null)
        {
            using (var mm = new MemoryStream())
            {
                using (var zip = new GZipStream(new MemoryStream(bs), CompressionMode.Decompress))
                {
                    zip.CopyTo(mm);
                }
                bs = mm.ToArray();
            }
        }
        db = new DB(bs ?? new byte[0]);
        var cfg = db.GetConfig();

        cfg.EnsureTable <Record>("Table", "Id");

        db.MinConfig().FileIncSize = 1;
        db.SetBoxRecycler((socket, outBox, normal) =>
        {
            time++;
            msg = $"{Save()},  Time:({time})";
        });
        auto = db.Open();
    }
Example #8
0
    public static ISprite Create(
        string textureKey,
        string frameKey,
        Point position,
        SpriteOptions options,
        IJSInProcessRuntime jsRuntime)
    {
        var spriteKey = Guid.NewGuid().ToString();
        List <IDisposable> disposables = new();

        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerDownRef = null;
        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerOutRef  = null;
        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerOverRef = null;

        if (options.OnPointerDown is not null)
        {
            onPointerDownRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerDown));

            disposables.Add(onPointerDownRef);
        }

        if (options.OnPointerOut is not null)
        {
            onPointerOutRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerOut));

            disposables.Add(onPointerOutRef);
        }

        if (options.OnPointerOver is not null)
        {
            onPointerOverRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerOver));

            disposables.Add(onPointerOverRef);
        }

        var size = jsRuntime.Invoke <Size>(
            PhaserConstants.Functions.AddSprite,
            spriteKey,
            textureKey,
            frameKey,
            position,
            options.Origin,
            options.Depth,
            onPointerDownRef,
            onPointerOutRef,
            onPointerOverRef,
            options.ScrollFactor);

        return(new PhaserSprite(
                   spriteKey,
                   position,
                   size,
                   frameKey,
                   disposables,
                   jsRuntime));
    }
 public static string GetOuterHtmlById(IJSInProcessRuntime JS, string id)
 {
     CheckJS(JS);
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentNullException(nameof(id));
     }
     return(JS.Invoke <string>("JSLib.getOuterHtmlById", id));
 }
        /// <summary>
        /// Invokes the specified JavaScript function synchronously.
        /// </summary>
        /// <param name="jsRuntime">The <see cref="IJSInProcessRuntime"/>.</param>
        /// <param name="identifier">An identifier for the function to invoke. For example, the value <c>"someScope.someFunction"</c> will invoke the function <c>window.someScope.someFunction</c>.</param>
        /// <param name="args">JSON-serializable arguments.</param>
        public static void InvokeVoid(this IJSInProcessRuntime jsRuntime, string identifier, params object[] args)
        {
            if (jsRuntime == null)
            {
                throw new ArgumentNullException(nameof(jsRuntime));
            }

            jsRuntime.Invoke <object>(identifier, args);
        }
        public void ValidateSession()
        {
            var abosulteUri = new Uri(uriHelperService.GetAbsoluteUri());
            var isLoggedIn  = jsInProcessRuntimeService.Invoke <bool>("isLoggedIn", null);

            if (!isLoggedIn && !abosulteUri.Query.Contains("code"))
            {
                if (clientSettings.LoginRequired)
                {
                    uriHelperService.NavigateTo(BuildAuthorizeUrl());
                }
                else
                {
                    SessionState = SessionStates.Inactive;
                    InvokeOnSessionStateChanged();
                }
            }
            else
            {
                jsInProcessRuntimeService.Invoke <object>("drawAuth0Iframe", new DotNetObjectRef(this), $"{BuildAuthorizeUrl()}&response_mode=web_message&prompt=none");
            }
        }
Example #12
0
    private int Save()
    {
        var bs = db.GetBuffer();

        using (var mm = new MemoryStream())
        {
            using (var zip = new GZipStream(mm, CompressionMode.Compress))
            {
                zip.Write(bs, 0, bs.Length);
                zip.Flush();
            }
            bs = mm.ToArray();
        }
        runtime.Invoke <string>("localStorage.setItem", typeof(DB).FullName, Convert.ToBase64String(bs));
        return(bs.Length);
    }
Example #13
0
        void ISyncLocalStorageService.SetItem(string key, object data)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (_jSInProcessRuntime == null)
            {
                throw new InvalidOperationException("IJSInProcessRuntime not available");
            }

            _jSInProcessRuntime.Invoke <object>("Blazored.LocalStorage.SetItem", key, Json.Serialize(data));
        }
Example #14
0
        public override void Load()
        {
            try
            {
                var cookieValue = runtime.Invoke <string>("cookieConfiguration.getCookie", cookieName);
                if (!string.IsNullOrWhiteSpace(cookieValue))
                {
                    var tree = JObject.Parse(cookieValue);
                    var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                    TraverseTree(tree, data, cookieName);

                    Data = data;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static void UseBrowserLocalization(this IComponentsApplicationBuilder app)
        {
            string locale = null;
            IJSInProcessRuntime jsinProcessRuntime = app.Services.GetService(typeof(IJSRuntime)) as IJSInProcessRuntime;

            if (jsinProcessRuntime != null)
            {
                locale = jsinProcessRuntime.Invoke <string>("BlazorXamarin.Blazor.TypeScript.Localization.getLocale");
            }

            if (string.IsNullOrWhiteSpace(locale))
            {
                locale = "en";
            }

            CultureInfo culture = new CultureInfo(locale);

            CultureInfo.CurrentCulture   = culture;
            CultureInfo.CurrentUICulture = culture;
        }
Example #16
0
        public void SetItem(string key, object data)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (_jSInProcessRuntime == null)
            {
                throw new InvalidOperationException("IJSInProcessRuntime not available");
            }

            var e = RaiseOnChangingSync(key, data);

            if (e.Cancel)
            {
                return;
            }

            _jSInProcessRuntime.Invoke <object>("localStorage.setItem", key, JsonSerializer.Serialize(data, _jsonOptions));

            RaiseOnChanged(key, e.OldValue, data);
        }
        /// <summary>
        /// 同步存储
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="data">内容</param>
        void ISyncLocalStorageService.SetItem(string key, object data)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (_jsInProcessRuntime == null)
            {
                throw new InvalidOperationException("IJSInProcessRunTime不可用");
            }

            var e = RaiseOnChangingSync(key, data);

            if (e.Cancel)
            {
                return;
            }

            _jsInProcessRuntime.Invoke <object>("DC.Storage.SetItem", storageType, key, Json.Serialize(data));

            RaiseOnChanged(key, e.OldValue, data);
        }
        void ISyncLocalStorageService.SetItem(string key, object data)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (_jSInProcessRuntime == null)
            {
                throw new InvalidOperationException("IJSInProcessRuntime not available");
            }

            RaiseOnChanging(key, data, out ChangingEventArgs e);

            if (e.Cancel)
            {
                return;
            }

            _jSInProcessRuntime.Invoke <object>("Blazored.LocalStorage.SetItem", key, Json.Serialize(data));

            RaiseOnChanged(key, e.OldValue, data);
        }
Example #19
0
 public string HighlightSyntax(string code, string language)
 {
     return(jsInterop.Invoke <string>("hljs_interop.highlightSyntax", code, new[] { language }));
 }
Example #20
0
 protected T InvokeCustom <T>(string jsFunction, params object[] args)
 {
     return(jsRuntime.Invoke <T>($"window.UIComponents.{jsFunction}", args));
 }
 private object EvaluateGeneric <TValue>(long treeId, long targetObjectId, IEnumerable <object> expressionList)
 => _jsRuntime.Invoke <TValue>(DynamicJSInterop.Evaluate, treeId, targetObjectId, expressionList) !;
Example #22
0
 public bool Exists()
 {
     return(_jsRuntime.Invoke <bool>("spriteExists", _sceneName, _spriteName));
 }
 public string GetItem(string key)
 {
     CheckForInProcessRuntime();
     return(_jSInProcessRuntime.Invoke <string>("localStorage.getItem", key));
 }
Example #24
0
 public bool Confirm(string message) =>
 _jsInProcessRuntime.Invoke <bool>("confirm", message);
Example #25
0
 public static bool IsFeatureAvailable(this IJSInProcessRuntime interop, string windowType) => interop.Invoke <bool>("Shiny.isFeatureAvailable", windowType);
Example #26
0
 internal static JsonElement GetKeyValueMetatags(this IJSInProcessRuntime jsRuntime, string key, string value)
 {
     return(jsRuntime.Invoke <JsonElement>("eval", GetMetatagsJS(key, value)));
 }
Example #27
0
 internal static JsonElement GetFileJS(this IJSInProcessRuntime jsRuntime, string path)
 {
     return(jsRuntime.Invoke <JsonElement>("eval", GetFileJS(path)));
 }
Example #28
0
 /// <summary>
 /// Determines if a modal is shown.
 /// </summary>
 public bool IsVisible()
 {
     return(jSInProcessRuntime.Invoke <bool>("CurrieTechnologies.Blazor.SweetAlert2.IsVisible"));
 }
Example #29
0
 public void Initialize(string elementId, string initialCode, string language) =>
 Runtime.Invoke <object>("monacoInterop.initialize", elementId, initialCode, language);
 public bool IsVisible()
 => _jsRuntime.Invoke <bool>("isSceneVisible", _scene.GetName());