示例#1
0
        public WorkerInitOptions MergeWith(WorkerInitOptions initOptions)
        {
            var redirects = new Dictionary <string, string>(this.FetchUrlOverride);

            foreach (var item in initOptions.FetchUrlOverride)
            {
                redirects[item.Key] = item.Value;
            }

            var fethOverride = new Dictionary <string, FetchResponse>(this.FetchOverride);

            foreach (var item in initOptions.FetchOverride)
            {
                fethOverride[item.Key] = item.Value;
            }

            return(new WorkerInitOptions
            {
                DependentAssemblyFilenames = this.DependentAssemblyFilenames
                                             .Concat(initOptions.DependentAssemblyFilenames)
                                             .Distinct()
                                             .ToArray(),
                FetchUrlOverride = redirects,
                CallbackMethod = initOptions.CallbackMethod ?? this.CallbackMethod,
                MessageEndPoint = initOptions.MessageEndPoint ?? this.MessageEndPoint,
                InitEndPoint = initOptions.InitEndPoint ?? this.InitEndPoint,
                FetchOverride = fethOverride
            });
        }
示例#2
0
 public WorkerInitOptions MergeWith(WorkerInitOptions initOptions)
 {
     return(new WorkerInitOptions
     {
         CallbackMethod = initOptions.CallbackMethod ?? this.CallbackMethod,
         DependentAssemblyFilenames = this.DependentAssemblyFilenames
                                      .Concat(initOptions.DependentAssemblyFilenames)
                                      .Distinct()
                                      .ToArray(),
         UseConventionalServiceAssembly = initOptions.UseConventionalServiceAssembly,
         MessageEndPoint = initOptions.MessageEndPoint ?? this.MessageEndPoint,
         InitEndPoint = initOptions.InitEndPoint ?? this.InitEndPoint,
     });
 }
示例#3
0
        public async Task InitAsync(WorkerInitOptions initOptions)
        {
            await this.scriptLoader.InitScript();

            await this.jsRuntime.InvokeVoidAsync(
                "BlazorWorker.initWorker",
                this.Identifier,
                thisReference,
                new WorkerInitOptions {
                DependentAssemblyFilenames =
                    WorkerProxyDependencies.DependentAssemblyFilenames,
                CallbackMethod  = nameof(OnMessage),
                MessageEndPoint = messageMethod
            }.MergeWith(initOptions));
        }
示例#4
0
        /// <summary>
        /// Registers the neccessary dependencies for injecting or instanciating <see cref="System.Net.Http.HttpClient"/> in the background service.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        /// <remarks>When this method has been called, <see cref="System.Net.Http.HttpClient"/> can be used inside the service either by instanciating it or by injection into the constructor.</remarks>
        public static WorkerInitOptions AddHttpClient(this WorkerInitOptions source)
        {
#if NETSTANDARD21
            source.AddAssemblies("System.Net.Http.dll", "System.Net.Http.WebAssemblyHttpHandler.dll");
#endif

#if NET5
            source.AddAssemblies(
                "System.Net.Http.dll",
                "System.Security.Cryptography.X509Certificates.dll",
                "System.Net.Primitives.dll",
                "System.Net.Requests.dll",
                "System.Net.Security.dll",
                "System.Net.dll",
                "System.Diagnostics.Tracing.dll");
#endif

            return(source);
        }
示例#5
0
        public async Task InitAsync(WorkerInitOptions initOptions)
        {
            await this.scriptLoader.InitScript();

            await this.jsRuntime.InvokeVoidAsync(
                "BlazorWorker.initWorker",
                this.Identifier,
                DotNetObjectReference.Create(this),
                new WorkerInitOptions {
                DependentAssemblyFilenames =
                    new[] {
                    "BlazorWorker.WorkerCore.dll",
                    "netstandard.dll",
                    "mscorlib.dll",
                    "WebAssembly.Bindings.dll",
                    "System.dll",
                    "System.Core.dll"
                },
                CallbackMethod  = nameof(OnMessage),
                MessageEndPoint = messageMethod
            }.MergeWith(initOptions));
        }
示例#6
0
 /// <summary>
 /// Deducts the name of the assembly containing the specified <paramref name="type"/> using the assembly name with dll extension as file name, and adds it as a dependency.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static WorkerInitOptions AddAssemblyOfType(this WorkerInitOptions source, Type type)
 {
     source.AddAssemblies($"{type.Assembly.GetName().Name}.dll");
     return(source);
 }
示例#7
0
 /// <summary>
 /// Deducts the name of the assembly containing the specified <typeparamref name="T"/> using the assembly name with dll extension as file name, and adds it as a dependency.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static WorkerInitOptions AddAssemblyOf <T>(this WorkerInitOptions source)
 {
     return(source.AddAssemblyOfType(typeof(T)));
 }
示例#8
0
 /// <summary>
 /// Deducts the name of the assembly containing the service using the the service type assembly name with dll extension as file name, and adds it as a dependency.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static WorkerInitOptions AddConventionalAssemblyOfService(this WorkerInitOptions source)
 {
     source.UseConventionalServiceAssembly = true;
     return(source);
 }
示例#9
0
 /// <summary>
 /// Adds the specified assembly filesnames as dependencies
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dependentAssemblyFilenames"></param>
 /// <returns></returns>
 public static WorkerInitOptions AddAssemblies(this WorkerInitOptions source, params string[] dependentAssemblyFilenames)
 {
     source.DependentAssemblyFilenames =
         source.DependentAssemblyFilenames.Concat(dependentAssemblyFilenames).ToArray();
     return(source);
 }
示例#10
0
 /// <summary>
 /// Registers the neccessary dependencies for injecting or instanciating <see cref="System.Net.Http.HttpClient"/> in the background service.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 /// <remarks>When this method has been called, <see cref="System.Net.Http.HttpClient"/> can be used inside the service either by instanciating it or by injection into the constructor.</remarks>
 public static WorkerInitOptions AddHttpClient(this WorkerInitOptions source)
 {
     source.AddAssemblies("System.Net.Http.dll", "System.Net.Http.WebAssemblyHttpHandler.dll");
     return(source);
 }