Exemplo n.º 1
0
        /////////////////////////////////////////////////////////
        #region initialize
        protected override void Initialize()
        {
            var netRef = DotNetObjectRef.Create(this);
            var events = GetEventNames();

            _jsRef = Invoke <string>("initCollectionView", netRef, _host, _props, events);
        }
 public static Task <T> Init <T>(IJSRuntime jsRuntime, DotNetObjectRef <object> helper)
 {
     // Implemented in exampleJsInterop.js
     return(jsRuntime.InvokeAsync <T>(
                "comp.init",
                helper));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Show picker popup
        /// </summary>
        public void Open()
        {
            OldStartValue = StartDate;
            OldEndValue   = EndDate;

            var selectedRange = Ranges?.FirstOrDefault(r =>
                                                       r.Value.Start.Date == StartDate?.Date &&
                                                       r.Value.End.Date == EndDate?.Date);

            if (selectedRange != null)
            {
                ChosenLabel = selectedRange.Value.Key;
            }
            else
            {
                ChosenLabel = CustomRangeLabel;
                ShowCalendars();
            }

            Visible = true;

            Issue11159 fixer = new Issue11159(JSRuntime);
            DotNetObjectRef <DatePickerComponentBase> reference = fixer.CreateDotNetObjectRef(this);

            JSRuntime.InvokeAsync <object>("clickAndPositionHandler.addClickOutsideEvent", Id, ParentId, reference);

            JSRuntime.InvokeAsync <object>("clickAndPositionHandler.getPickerPosition", Id, ParentId,
                                           Enum.GetName(typeof(DropsType), Drops).ToLower(), Enum.GetName(typeof(SideType), Opens).ToLower());

            OnOpened.InvokeAsync(null);
        }
Exemplo n.º 4
0
 public static object[] EchoThreeParameters(
     ComplexParameter parameter1,
     byte parameter2,
     DotNetObjectRef <TestDTO> parameter3)
 {
     return(new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue() });
 }
Exemplo n.º 5
0
 public void RegisterJsEvents()
 {
     foreach (var item in listDragTarget)
     {
         BvgJsInterop.HandleDrop(item.ElementID, item.ID, DotNetObjectRef.Create(classForJS));
     }
 }
 public Task CallHelloHelperSayHello(string name)
 {
     // sayHello is implemented in wwwroot/exampleJsInterop.js
     return(_jsRuntime.InvokeAsync <object>(
                "exampleJsFunctions.sayHello",
                DotNetObjectRef.Create(new HelloHelper(name))));
 }
Exemplo n.º 7
0
 public void OnClose(Func <Exception, Task> callback)
 {
     this.closeCallback = new HubCloseCallback(callback);
     this.runtime.InvokeSync <object>(ON_CLOSE_METHOD,
                                      this.InternalConnectionId,
                                      DotNetObjectRef.Create(this.closeCallback));
 }
Exemplo n.º 8
0
 public InfoBox(Geocoordinate center, InfoboxOptions options, string id)
 {
     Id     = Guid.NewGuid().ToString();
     Center = center;
     JSRuntime.Current.InvokeAsync <object>(_infoboxRegister, Id, center, options);
     thisRef = new DotNetObjectRef(this);
 }
Exemplo n.º 9
0
        public void SerializesDotNetObjectWrappersInKnownFormat()
        {
            // Arrange
            var runtime = new TestJSRuntime();
            var obj1    = new object();
            var obj2    = new object();
            var obj3    = new object();

            // Act
            // Showing we can pass the DotNetObject either as top-level args or nested
            var obj1Ref          = new DotNetObjectRef(obj1);
            var obj1DifferentRef = new DotNetObjectRef(obj1);

            runtime.InvokeAsync <object>("test identifier",
                                         obj1Ref,
                                         new Dictionary <string, object>
            {
                { "obj2", new DotNetObjectRef(obj2) },
                { "obj3", new DotNetObjectRef(obj3) },
                { "obj1SameRef", obj1Ref },
                { "obj1DifferentRef", obj1DifferentRef },
            });

            // Assert: Serialized as expected
            var call = runtime.BeginInvokeCalls.Single();

            Assert.Equal("test identifier", call.Identifier);
            Assert.Equal("[\"__dotNetObject:1\",{\"obj2\":\"__dotNetObject:2\",\"obj3\":\"__dotNetObject:3\",\"obj1SameRef\":\"__dotNetObject:1\",\"obj1DifferentRef\":\"__dotNetObject:4\"}]", call.ArgsJson);

            // Assert: Objects were tracked
            Assert.Same(obj1, runtime.ArgSerializerStrategy.FindDotNetObject(1));
            Assert.Same(obj2, runtime.ArgSerializerStrategy.FindDotNetObject(2));
            Assert.Same(obj3, runtime.ArgSerializerStrategy.FindDotNetObject(3));
            Assert.Same(obj1, runtime.ArgSerializerStrategy.FindDotNetObject(4));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new instance of <see cref="DotNetStaticClickHandler"/>
        /// </summary>
        /// <param name="clickHandler">The delegate for a click handler.</param>
        public DotNetInstanceClickHandler(InstanceClickHandler clickHandler)
        {
            if (clickHandler == null)
            {
                throw new ArgumentNullException(nameof(clickHandler));
            }

            // the method needs to be public
            if (!clickHandler.Method.IsPublic)
            {
                throw new ArgumentException("The click handler needs to be public", nameof(clickHandler));
            }

            // the method needs to have the attribute JSInvokable
            var isJsInvokable = clickHandler
                                .Method
                                .CustomAttributes.Any(data => data.AttributeType == typeof(JSInvokableAttribute));

            if (!isJsInvokable)
            {
                throw new ArgumentException("The passed in method must have the 'JSInvokable' attribute",
                                            nameof(clickHandler));
            }

            //AssemblyName = assembly.GetName().Name;
            // clickHandler.Method.DeclaringType.Assembly.GetName().Name;
            InstanceRef = DotNetObjectRef.Create(clickHandler.Target);
            MethodName  = clickHandler.Method.Name;
        }
Exemplo n.º 11
0
 public static void VoidWithThreeParameters(
     ComplexParameter parameter1,
     byte parameter2,
     DotNetObjectRef <TestDTO> parameter3)
 {
     Invocations[nameof(VoidWithThreeParameters)] = new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue() };
 }
Exemplo n.º 12
0
 public static Dictionary <string, DotNetObjectRef <TestDTO> > ReturnDotNetObjectByRef()
 {
     return(new Dictionary <string, DotNetObjectRef <TestDTO> >
     {
         { "Some sync instance", DotNetObjectRef.Create(new TestDTO(1000)) }
     });
 }
Exemplo n.º 13
0
        protected string _propName; // name of the property in the parent control

        protected override void Initialize()
        {
            var netRef = DotNetObjectRef.Create(this);
            var events = GetEventNames();

            _jsRef = Invoke <string>("initMarkupProperty", netRef, _host, _propName, _className, _props, events);
        }
Exemplo n.º 14
0
 public static Task <object[]> EchoThreeParametersAsync(
     ComplexParameter parameter1,
     byte parameter2,
     DotNetObjectRef <TestDTO> parameter3)
 {
     return(Task.FromResult(new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue() }));
 }
Exemplo n.º 15
0
        protected override async Task OnFirstAfterRenderAsync()
        {
            dotNetObjectRef = dotNetObjectRef ?? JSRunner.CreateDotNetObjectRef(new NumericEditAdapter(this));
            await JSRunner.InitializeNumericEdit(dotNetObjectRef, ElementId, ElementRef, Decimals, DecimalsSeparator, Step);

            await base.OnFirstAfterRenderAsync();
        }
Exemplo n.º 16
0
        public override async Task InitAsync(string mapId)
        {
            thisRef = new DotNetObjectRef(this);
            var param = new { InputPanelId, ItineraryPanelId, ModuleRef = thisRef };

            await InitModuleAsync(mapId, ModuleId, InitFunctionName, param);
        }
Exemplo n.º 17
0
 public static Task VoidWithThreeParametersAsync(
     ComplexParameter parameter1,
     byte parameter2,
     DotNetObjectRef <TestDTO> parameter3)
 {
     Invocations[nameof(VoidWithThreeParametersAsync)] = new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue() };
     return(Task.CompletedTask);
 }
 protected DotNetObjectRef <T> CreateDotNetObjectRef <T>(T value) where T : class
 {
     lock (CreateDotNetObjectRefSyncObj)
     {
         JSRuntime.SetCurrentJSRuntime(jsRuntime);
         return(DotNetObjectRef.Create(value));
     }
 }
Exemplo n.º 19
0
        public void CanAssociateWithSameRuntimeMultipleTimes()
        {
            var objRef    = new DotNetObjectRef(new object());
            var jsRuntime = new TestJsRuntime();

            objRef.EnsureAttachedToJsRuntime(jsRuntime);
            objRef.EnsureAttachedToJsRuntime(jsRuntime);
        }
Exemplo n.º 20
0
 private DotNetObjectRef <SpeechSynthesis> GetObjectRef()
 {
     if (_ObjectRefOfThis == null)
     {
         _ObjectRefOfThis = DotNetObjectRef.Create(this);
     }
     return(_ObjectRefOfThis);
 }
Exemplo n.º 21
0
 public static object[] EchoSixParameters(ComplexParameter parameter1,
                                          byte parameter2,
                                          DotNetObjectRef <TestDTO> parameter3,
                                          int parameter4,
                                          long parameter5,
                                          float parameter6)
 {
     return(new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue(), parameter4, parameter5, parameter6 });
 }
Exemplo n.º 22
0
 public static Task <object[]> EchoSixParametersAsync(ComplexParameter parameter1,
                                                      byte parameter2,
                                                      DotNetObjectRef <TestDTO> parameter3,
                                                      int parameter4,
                                                      long parameter5,
                                                      float parameter6)
 {
     return(Task.FromResult(new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue(), parameter4, parameter5, parameter6 }));
 }
Exemplo n.º 23
0
        public async Task InitAsync()
        {
            Logger.LogDebug("Init JsonRequestHandler");
            const string InitializeJavaScriptInteropName = "InitializeJavaScriptInterop";

            Logger.LogDebug(InitializeJavaScriptInteropName);
            Microsoft.JSInterop.JSRuntime.SetCurrentJSRuntime(JSRuntime);
            await JSRuntime.InvokeAsync <object>(InitializeJavaScriptInteropName, DotNetObjectRef.Create(this));
        }
Exemplo n.º 24
0
        public static async Task <Dictionary <string, DotNetObjectRef <TestDTO> > > ReturnDotNetObjectByRefAsync()
        {
            await Task.Yield();

            return(new Dictionary <string, DotNetObjectRef <TestDTO> >
            {
                { "Some async instance", DotNetObjectRef.Create(new TestDTO(1001)) }
            });
        }
Exemplo n.º 25
0
 public static void VoidWithFiveParameters(
     ComplexParameter parameter1,
     byte parameter2,
     DotNetObjectRef <TestDTO> parameter3,
     int parameter4,
     long parameter5)
 {
     Invocations[nameof(VoidWithFiveParameters)] = new object[] { parameter1, parameter2, parameter3.Value.GetNonSerializedValue(), parameter4, parameter5 };
 }
 internal DotNetObjectRef <SpeechSynthesisUtterance> GetObjectRef()
 {
     _ObjectRefCounter++;
     if (_ObjectRefCounter == 1)
     {
         _ObjectRef = DotNetObjectRef.Create(this);
     }
     return(_ObjectRef);
 }
Exemplo n.º 27
0
        // TODO: Find out a more smart way to register to global connect/disconnect events from the WebUSB API regardless if there are subscribers to the events.
        public async Task Initialize()
        {
            if (!this._initialized)
            {
                await this.JSRuntime.InvokeAsync <object>(REGISTER_USB_METHOD, DotNetObjectRef.Create(this));

                this._initialized = true;
            }
        }
 private void ReleaseObjectRef()
 {
     _ObjectRefCounter--;
     if (_ObjectRefCounter == 0)
     {
         _ObjectRef.Dispose();
         _ObjectRef = null;
     }
 }
Exemplo n.º 29
0
 public HubConnection(IJSRuntime runtime, HttpConnectionOptions options)
 {
     this.runtime = runtime;
     this.Options = options;
     this.InternalConnectionId = Guid.NewGuid().ToString();
     runtime.InvokeSync <object>(CREATE_CONNECTION_METHOD,
                                 this.InternalConnectionId,
                                 DotNetObjectRef.Create(this.Options));
 }
Exemplo n.º 30
0
 public BaseMatHidden()
 {
     CallAfterRender(async() =>
     {
         dotNetObjectRef = dotNetObjectRef ?? CreateDotNetObjectRef(this);
         await Js.InvokeAsync <object>("matBlazor.matHidden.init", Id, dotNetObjectRef);
         await UpdateVisible();
     });
 }