Example #1
0
 public static void DeleteJsObjectRef(this IJSRuntime jsRuntime, int id)
 {
     jsRuntime.Invoke <object>(
         "JsInterop.deleteObjectRef",
         new object[]
     {
         id,
     });
 }
Example #2
0
        public static IDisposable AddJsEventListener(this IJSRuntime jsRuntime,
                                                     JsObjectRef jsObjectRef, string property, string event_, JsEventHandler callBack)
        {
            var listenerId = jsRuntime.Invoke <int>("JsInterop.addEventListener", jsObjectRef,
                                                    property, event_, callBack);

            return(new DisposableAction(() =>
                                        jsRuntime.InvokeVoid("JsInterop.removeEventListener", jsObjectRef, property,
                                                             event_, listenerId)));
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="MiniMongoDatabase"/>
        /// </summary>
        /// <param name="configurationFor"></param>
        /// <param name="jsRuntime"></param>
        /// <param name="logger"></param>
        public MiniMongoDatabase(
            IConfigurationFor <Configuration> configurationFor,
            IJSRuntime jsRuntime,
            ILogger logger)

        {
            _configuration = configurationFor;
            _jsRuntime     = jsRuntime;
            _jsRuntime.Invoke($"{_globalObject}.initialize", configurationFor.Instance.Database);
            _logger = logger;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventProcessorOffsetRepository"/> class.
        /// </summary>
        /// <param name="jSRuntime">The <see cref="IJSRuntime"/>.</param>
        /// <param name="logger"><see cref="ILogger"/> for logging.</param>
        public EventProcessorOffsetRepository(
            IJSRuntime jSRuntime,
            ILogger logger)
        {
            _jsRuntime     = jSRuntime;
            _logger        = logger;
            _lastProcessed = new ConcurrentDictionary <EventProcessorId, CommittedEventVersion>();

            var result = _jsRuntime.Invoke <IEnumerable <EventProcessorOffset> >($"{_globalObject}.load").Result;

            result.ForEach(_ => _lastProcessed.AddOrUpdate(_.EventProcessorId, _.Content, (id, v) => _.Content));
        }
Example #5
0
        public static IEnumerable <JsObjectRef> GetJsPropertyArray(this IJSRuntime jsRuntime,
                                                                   object parent, string property = null)
        {
            var jsObjectRefs = jsRuntime.Invoke <IEnumerable <JsObjectRef> >(
                "JsInterop.getPropertyArray",
                new object[]
            {
                parent,
                property,
            });

            return(jsObjectRefs);
        }
Example #6
0
        /// <inheritdoc/>
        public IMongoCollection <TDocument> GetCollection <TDocument>(string name, MongoCollectionSettings settings = null)
        {
            if (_collections.ContainsKey(name))
            {
                return((IMongoCollection <TDocument>)_collections[name]);
            }
            var collection = new MiniMongoCollection <TDocument>(name, _configuration, _jsRuntime, _serializer, _logger);

            _collections[name] = collection;

            _jsRuntime.Invoke($"{_globalObject}.database.addCollection", name);
            return(collection);
        }
Example #7
0
        public static JsObjectRef GetJsPropertyObjectRef(this IJSRuntime jsRuntime,
                                                         object parent, string property)
        {
            var jsObjectRef = jsRuntime.Invoke <JsObjectRef>(
                "JsInterop.getPropertyObjectRef",
                new object[]
            {
                parent,
                property    //,
                //null
            });

            return(jsObjectRef);
        }
Example #8
0
        public static T GetJsPropertyValue <T>(this IJSRuntime jsRuntime, object parent,
                                               string property, object valueSpec = null)
        {
            var content = jsRuntime.Invoke <T>(
                "JsInterop.getPropertyValue",
                new object[]
            {
                parent,
                property,
                valueSpec
            });

            return(content);
        }
Example #9
0
        /// <summary>
        /// Invoke 方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="el"></param>
        /// <param name="func"></param>
        /// <param name="method"></param>
        /// <param name="args"></param>
        public async Task Invoke(TValue value, object el, string func, string method, params object[] args)
        {
            _objRef = DotNetObjectReference.Create(value);
            var paras = new List <object>();

            if (!string.IsNullOrEmpty(method))
            {
                paras.Add(method);
            }
            if (args != null)
            {
                paras.AddRange(args);
            }
            await _jsRuntime.Invoke(el, func, _objRef, paras.ToArray());
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        public EventStreamCommitterAndFetcher(IJSRuntime jsRuntime, ISerializer serializer, ILogger logger, IInstancesOf <IWantToBeNotifiedWhenEventsAreCommited> commitListeners)
        {
            _jsRuntime       = jsRuntime;
            _serializer      = serializer;
            _commitListeners = commitListeners;
            var result = _jsRuntime.Invoke <IEnumerable <CommittedEventStream> >($"{_globalObject}.load").Result;

            logger.Information($"Loaded events {result}");

            _commits.AddRange(result);
            if (_commits.Count() > 0)
            {
                _sequenceNumber = _commits.Max(_ => (ulong)_.Sequence);
            }
            logger.Information($"Event Store contains {_commits.Count} events");
        }
Example #11
0
        //private static async void Sync<TValue>(IJSRuntime jsRuntime, string identifier, params object[] args)
        //{
        //    TValue value = default(TValue);
        //    value = await jsRuntime.InvokeAsync<TValue>(identifier, args).Wait();
        //}

        public static void InvokeVoid(this IJSRuntime jsRuntime, string identifier, params object[] args)
        {
            var isWasm = jsRuntime is IJSInProcessRuntime;

            if (isWasm)
            {
                _ = (IJSInProcessRuntime)jsRuntime.Invoke <object>(identifier, args);
            }
            else
            {
                // Sync call to JSInterop is not possible.
                // Blocking current thread with any kind of Wait throws:
                //   Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll
                // Async API is required.
                throw new NotImplementedException();
            }
        }
Example #12
0
        public static T CallJsMethod <T>(this IJSRuntime jsRuntime, object parent,
                                         string method, params object[] args)
        {
            var invokeParams = new object[]
            {
                parent,
                method
            };

            if (args != null)
            {
                invokeParams = invokeParams.Concat(args).ToArray();
            }
            var ret = jsRuntime.Invoke <T>("JsInterop.callMethod", invokeParams);

            return(ret);
        }
Example #13
0
        public static JsObjectRef CreateJsObject(this IJSRuntime jsRuntime, object parent,
                                                 string interface_, params object[] args)
        {
            var invokeParams = new object[]
            {
                parent,
                interface_
            };

            if (args != null)
            {
                ////args = args.Where(a => a is not null).ToArray();
                invokeParams = invokeParams.Concat(args).ToArray();
            }
            var jsObjectRef = jsRuntime.Invoke <JsObjectRef>("JsInterop.createObject", invokeParams);

            return(jsObjectRef);
        }
Example #14
0
        CommittedEventStream Commit(UncommittedEventStream uncommittedEvents, CommitSequenceNumber commitSequenceNumber)
        {
            lock (lockObject)
            {
                ThrowIfDuplicate(uncommittedEvents.Id);
                ThrowIfConcurrencyConflict(uncommittedEvents.Source);

                var commit = new CommittedEventStream(commitSequenceNumber, uncommittedEvents.Source, uncommittedEvents.Id, uncommittedEvents.CorrelationId, uncommittedEvents.Timestamp, uncommittedEvents.Events);
                _commits.Add(commit);
                _duplicates.Add(commit.Id);
                _versions.AddOrUpdate(commit.Source.Key, commit.Source, (id, ver) => commit.Source);

                var commitsAsJson = _serializer.ToJson(_commits, SerializationOptions.CamelCase);
                _jsRuntime.Invoke($"{_globalObject}.save", commitsAsJson);

                _commitListeners.ForEach(_ => _.Handle(commit));

                return(commit);
            }
        }
Example #15
0
        /// <inheritdoc/>
        public async Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <T> filter, FindOptions <T, TProjection> options = null, CancellationToken cancellationToken = default)
        {
            try
            {
                var filterAsJson = filter.ToJson();
                var deserialized = await _jsRuntime.Invoke <IEnumerable <TProjection> >($"{MiniMongoDatabase._globalObject}.database.{_collectionName}.find", filterAsJson).ConfigureAwait(false);

                return(new AsyncResult <TProjection>(deserialized));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error deserializing");
                throw;
            }
        }
Example #16
0
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     _lastProcessed.AddOrUpdate(eventProcessorId, committedEventVersion, (id, v) => committedEventVersion);
     _logger.Information($"Saving event processor offset");
     _jsRuntime.Invoke($"{_globalObject}.save", eventProcessorId, committedEventVersion);
 }
Example #17
0
 /// <inheritdoc/>
 public void Perform()
 {
     _jsRuntime.Invoke($"{MiniMongoDatabase._globalObject}.initialize", _configurationFor.Instance.Database);
 }
Example #18
0
 public static TReturn Get <TReturn>(this IJSRuntime js, ElementReference el, string property)
 => js.Invoke <TReturn>("Get", el, property);
 /// <summary>
 /// Invoke 方法
 /// </summary>
 /// <param name="value"></param>
 /// <param name="el"></param>
 /// <param name="func"></param>
 /// <param name="method"></param>
 /// <param name="args"></param>
 public void Invoke(TValue value, object el, string func, string method, params object[] args)
 {
     _objRef = DotNetObjectReference.Create(value);
     _jsRuntime.Invoke(el, func, _objRef, method, args);
 }
 /// <inheritdoc/>
 public Task InsertOneAsync(T document, CancellationToken _cancellationToken)
 {
     return(_jsRuntime.Invoke <object>($"{MiniMongoDatabase._globalObject}.database.{_collectionName}.upsert", document));
 }