Beispiel #1
0
 public LocalStorageService(IJSRuntime jSRuntime, IOptions <LocalStorageOptions> options, IDataTransformer dataTransformer)
 {
     _jSRuntime          = jSRuntime;
     _jsonOptions        = options.Value.JsonSerializerOptions;
     _dataTransformer    = dataTransformer;
     _jSInProcessRuntime = jSRuntime as IJSInProcessRuntime;
 }
Beispiel #2
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();
    }
 public LocalStorageService(IJSRuntime jSRuntime, IOptions <LocalStorageOptions> options)
 {
     _jSRuntime          = jSRuntime;
     _jsonOptions        = options.Value.JsonSerializerOptions;
     _jSInProcessRuntime = jSRuntime as IJSInProcessRuntime;
     _jsonSecure         = options.Value.JsonEncryption;
 }
 private static void CheckJS(IJSInProcessRuntime JSInProcessRuntime)
 {
     if (JSInProcessRuntime == null)
     {
         throw new ArgumentNullException(nameof(JSInProcessRuntime));
     }
 }
Beispiel #5
0
 public LocalStorageService(IJSRuntime jSRuntime)
 {
     _jSRuntime          = jSRuntime;
     _jSInProcessRuntime = jSRuntime as IJSInProcessRuntime;
     _jsonOptions        = new JsonSerializerOptions();
     _jsonOptions.Converters.Add(new TimespanJsonConverter());
 }
Beispiel #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);
 }
Beispiel #7
0
 private void Init(IJSInProcessRuntime runtime, ElementReference?element, PoseNetOptions options, DetectionType?type)
 {
     Runtime         = runtime;
     DotNetObjectRef = DotNetObjectReference.Create(this);
     Hash            = PoseNetHash++;
     runtime.InvokeVoid("poseNetML5", Hash.ToString(), DotNetObjectRef, element, options, type);
 }
Beispiel #8
0
        public static async Task <AccessState> RequestPermission(this IJSInProcessRuntime interop, string permission, string windowType)
        {
            if (!interop.IsFeatureAvailable(windowType))
            {
                return(AccessState.NotSupported);
            }

            var result = await interop.Promise <string>("Shiny.requestPermission", permission);

            if (result == null)
            {
                return(AccessState.Unknown);
            }

            switch (result.ToLower())
            {
            case "granted":
                return(AccessState.Available);

            case "denied":
                return(AccessState.Denied);

            default:
                return(AccessState.Unknown);
            }
        }
Beispiel #9
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 IConfigurationBuilder AddRemoteJsonConfiguration(
     this IConfigurationBuilder builder,
     IJSInProcessRuntime jsRuntime,
     string path
     )
 {
     return(builder.Add(new RemoteJsonConfigurationSource(jsRuntime, path)));
 }
        /// <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);
        }
Beispiel #12
0
 public SweetAlertService(IJSRuntime jSRuntime, SweetAlertServiceOptions options)
 {
     this.jSRuntime          = jSRuntime;
     this.jSInProcessRuntime = jSRuntime as IJSInProcessRuntime;
     if (options.Theme != SweetAlertTheme.Default)
     {
         SetTheme(options.Theme);
     }
 }
Beispiel #13
0
        /// <summary>
        /// コンストラクタ。
        /// </summary>
        public Offscreen(Size2D size, IJSInProcessRuntime jsRuntime)
        {
            _jsOffscreen = JSObjectReference.From(jsRuntime,
                                                  "Sample.BlazorWasm.TextEditor.Offscreen.create", new { w = size.Width, h = size.Height });

            _writer = new Utf8JsonWriter(_utf8jsonMemory);

            Init();
        }
Beispiel #14
0
        private async void Init(IJSInProcessRuntime runtime, ElementReference?element, PoseNetOptions options, DetectionType?type)
        {
            Runtime         = runtime;
            DotNetObjectRef = DotNetObjectReference.Create(this);
            JSReference     = await Runtime.InvokeAsync <IJSInProcessObjectReference>("import", "./_content/BlazorML5/ml5PoseNet.js");

            Hash = PoseNetHash++;
            JSReference.InvokeVoid("poseNetML5", Hash.ToString(), DotNetObjectRef, element, options, type);
        }
 public AuthService(AuthConfig config, IJSRuntime jsRuntime)
 {
     _config = new MSALAuthConfig()
     {
         ClientId = config.ClientId,
         Scopes   = config.Scopes.ToArray()
     };
     _jsRuntime = (IJSInProcessRuntime)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));
 }
Beispiel #17
0
 public XQueryNavigationManager(NavigationManager navigationManager, IJSRuntime jsRuntime)
 {
     this.navigationManager = navigationManager;
     this.jsRuntime         = (IJSInProcessRuntime)jsRuntime;
     this.navigationManager.LocationChanged += (sender, e) =>
     {
         ResetDomMaps();
     };
 }
        public AuthenticationService(HttpClient httpClient, IJSRuntime jsRuntime, IUriHelper uriHelper, ClientSettings settings)
        {
            httpClientService         = httpClient;
            jsInProcessRuntimeService = (jsRuntime as IJSInProcessRuntime);
            uriHelperService          = uriHelper;
            clientSettings            = settings;

            ValidateSession();
        }
Beispiel #19
0
    private PhaserText(
        string key,
        Point position,
        IJSInProcessRuntime jsRuntime)
    {
        _jsRuntime = jsRuntime;

        Key      = key;
        Position = position;
    }
Beispiel #20
0
 public SelectedFileReader(HttpClient http,
                           IJSRuntime jsRuntime,
                           SelectedFile file,
                           FileBlobUrls fileBlobUrls)
 {
     _http         = http ?? throw new ArgumentNullException(nameof(http));
     _jsRuntime    = (IJSInProcessRuntime)jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime));
     File          = file ?? throw new ArgumentNullException(nameof(file));
     _fileBlobUrls = fileBlobUrls ?? throw new ArgumentNullException(nameof(fileBlobUrls));
 }
Beispiel #21
0
        public PersistenceFileSystem(IJSInProcessRuntime jsRuntime)
        {
            this.jsRuntime = jsRuntime;

            this.isFirstStart = Get("started") == null;
            if (this.isFirstStart)
            {
                Set("started", "*");
            }
        }
Beispiel #22
0
    public PhaserGraphics(
        int width,
        int height,
        IEnumerable <IDisposable> disposables,
        IJSInProcessRuntime jsInProcessRuntime)
    {
        _disposables        = disposables;
        _jsInProcessRuntime = jsInProcessRuntime;

        Width  = width;
        Height = height;
    }
Beispiel #23
0
        public CookieConfigurationOptions(string cookieName, IJSRuntime runtime)
        {
            CookieName = cookieName;

            if (runtime is IJSInProcessRuntime clientRuntime)
            {
                JSRuntime = clientRuntime;
            }
            else
            {
                throw new ArgumentException("CookieConfigurationProvider can only be used in client side Blazor applications. Please make sure the IJSRuntime object implements IJSInProcessRuntime", nameof(runtime));
            }
        }
Beispiel #24
0
        public CurrencyDataStore(HttpClient httpClient, IJSRuntime js, IConfiguration config)
        {
            this.httpClient = httpClient;
            this.js         = (IJSInProcessRuntime)js;
            fxDataFeedUrl   = config.GetSection("Services")["FxDataFeed"];
            Populate();

            if (IsStale || !LastUpdatedDate.HasValue)
            {
                // In the background, also attempt to refresh the data
                // If the user doesn't have a working network connection, this will fail, and that's fine
                _ = Refresh();
            }
        }
Beispiel #25
0
        public ImageClassifier(IJSInProcessRuntime runtime, ImageModel model, object serializableOptions = null)
        {
            Runtime = runtime;
            string modelStr;

            if (model == ImageModel.DarknetTiny)
            {
                modelStr = "Darknet-tiny";
            }
            else
            {
                modelStr = model.ToString();
            }
            Init(modelStr, serializableOptions);
        }
Beispiel #26
0
        public ConsoleLogger(string name, IJSInProcessRuntime jsRuntime)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (jsRuntime == null)
            {
                throw new ArgumentNullException(nameof(jsRuntime));
            }

            _name      = name;
            _jsRuntime = jsRuntime;
        }
Beispiel #27
0
    private PhaserSprite(
        string key,
        Point position,
        Size size,
        string frameKey,
        IEnumerable <IDisposable> disposables,
        IJSInProcessRuntime jsRuntime)
    {
        _jsRuntime   = jsRuntime;
        _disposables = disposables;

        Key      = key;
        Position = position;
        Size     = size;
        Frame    = frameKey;
    }
Beispiel #28
0
        public static Store <TState, TAction> AddReduxStore <TState, TAction>(
            this IServiceCollection configure,
            TState initialState,
            Reducer <TState, TAction> rootReducer,
            Action <ReduxOptions <TState> > options = null)
        {
            JSRuntime = configure.BuildServiceProvider().GetService <IJSInProcessRuntime>();

            var reduxOptions = new ReduxOptions <TState>();

            options?.Invoke(reduxOptions);
            var store = new Store <TState, TAction>(initialState, rootReducer, reduxOptions);

            configure.AddSingleton(store);
            return(store);
        }
        /// <summary>
        /// コンストラクタ。
        /// </summary>
        public CanvasContext(TextEditorComponent textEditorComponent, IJSInProcessRuntime jsRuntime, JSEvent jsEvent)
        {
            _textEditorComponent = textEditorComponent;
            _jsRuntime           = jsRuntime;

            _textEditorComponent.Created += size =>
            {
                jsEvent.RegisterActionListener("TextEditorComponent.resize", args => Resize?.Invoke(ToSize(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousedown", args => MouseDown?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mouseup", args => MouseUp?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousemove", args => MouseMove?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.mousewheel", args => MouseWheel?.Invoke(ToMouseState(args)));
                jsEvent.RegisterActionListener("TextEditorComponent.render", _ => RenderFrame?.Invoke(new RenderingContext(_textEditorComponent)));
                jsEvent.RegisterActionListener("InputMethod.focusin", args => GotFocus?.Invoke());
                jsEvent.RegisterActionListener("InputMethod.focusout", args => LostFocus?.Invoke());

                Created?.Invoke(size);
            };
        }
Beispiel #30
0
    public static IText Create(
        string text,
        Point position,
        TextOptions options,
        IJSInProcessRuntime jsRuntime)
    {
        var textKey = Guid.NewGuid().ToString();

        jsRuntime.InvokeVoid(
            PhaserConstants.Functions.AddText,
            textKey,
            position,
            text,
            options);

        return(new PhaserText(
                   textKey,
                   position,
                   jsRuntime));
    }