/// <inheritdoc /> public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var dt = Scheduler.Normalize(dueTime); if (dt.Ticks == 0) { return(Schedule(state, action)); } var d = new SingleAssignmentDisposable(); WasmRuntime.ScheduleTimeout( (int)dt.TotalMilliseconds, () => { if (!d.IsDisposed) { d.Disposable = action(this, state); } }); return(d); }
protected void GenerateProjectAot(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) { BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase; var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger); WasmRuntime runtime = (WasmRuntime)buildPartition.Runtime; using (var file = new StreamReader(File.OpenRead(projectFile.FullName))) { var(customProperties, sdkName) = GetSettingsThatNeedsToBeCopied(file, projectFile); string content = new StringBuilder(ResourceHelper.LoadTemplate("WasmAotCsProj.txt")) .Replace("$PLATFORM$", buildPartition.Platform.ToConfig()) .Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath)) .Replace("$CSPROJPATH$", projectFile.FullName) .Replace("$TFM$", TargetFrameworkMoniker) .Replace("$PROGRAMNAME$", artifactsPaths.ProgramName) .Replace("$RUNTIMESRCDIR$", runtime.RuntimeSrcDir.ToString()) .Replace("$COPIEDSETTINGS$", customProperties) .Replace("$CONFIGURATIONNAME$", buildPartition.BuildConfiguration) .Replace("$SDKNAME$", sdkName) .ToString(); File.WriteAllText(artifactsPaths.ProjectFilePath, content); } }
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger) { BuildResult buildResult = dotNetCliBuilder.Build(generateResult, buildPartition, logger); WasmRuntime runtime = (WasmRuntime)buildPartition.Runtime; return(buildResult); }
private void BuildApp(string programName, string projectRoot, WasmRuntime runtime) { string appDir = Path.Combine(projectRoot, $"bin", targetFrameworkMoniker, "browser-wasm", "publish"); string outputDir = Path.Combine(appDir, "output"); string mainAssemblyPath = Path.Combine(appDir, $"{programName}.dll"); if (!File.Exists(mainAssemblyPath)) { throw new ArgumentException($"File MainAssembly='{mainAssemblyPath}' doesn't exist."); } var assemblies = Directory.GetFiles(appDir, "*.dll"); // Create app Directory.CreateDirectory(outputDir); Directory.CreateDirectory(Path.Combine(outputDir, "managed")); foreach (var assembly in assemblies) { File.Copy(assembly, Path.Combine(outputDir, "managed", Path.GetFileName(assembly)), true); } string timeZoneDat = "dotnet.timezones.blat"; string icutDat = "icudt.dat"; foreach (var f in new string[] { "dotnet.wasm", "dotnet.js", timeZoneDat, icutDat }) { File.Copy(Path.Combine(appDir, f), Path.Combine(outputDir, f), true); } File.Copy(runtime.MainJs.FullName, Path.Combine(outputDir, "runtime.js"), true); using (var sw = File.CreateText(Path.Combine(outputDir, "mono-config.js"))) { sw.WriteLine("config = {"); sw.WriteLine("\t\"assembly_root\": \"managed\","); sw.WriteLine("\t\"enable_debugging\": 0,"); sw.WriteLine("\t\"assets\": ["); foreach (var assembly in assemblies) { sw.Write($"\t\t{{ \"behavior\": \"assembly\", \"name\": \"{ Path.GetFileName(assembly)}\" }}"); sw.WriteLine(","); } sw.WriteLine($"\t\t{{ \"behavior\": \"icu\", \"name\": \"icudt.dat\", \"load_remote\": false}},"); sw.WriteLine($"\t\t{{ \"behavior\": \"vfs\", \"name\": \"{timeZoneDat}\", \"virtual_path\": \"/usr/share/zoneinfo/\" }}"); sw.WriteLine("\t],"); sw.WriteLine("\t\"files_to_map\": []"); sw.WriteLine("};"); } }
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger) { BuildResult buildResult = dotNetCliBuilder.Build(generateResult, buildPartition, logger); WasmRuntime runtime = (WasmRuntime)buildPartition.Runtime; if (buildResult.IsBuildSuccess && !runtime.Aot) { BuildApp(buildPartition.ProgramName, generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, runtime); } return(buildResult); }
public static void Run() { // the Wasm Toolchain requires two mandatory arguments: const string cliPath = @"/home/adam/projects/runtime/dotnet.sh"; WasmRuntime runtime = new WasmRuntime(msBuildMoniker: "net5.0"); NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings( targetFrameworkMoniker: "net5.0", runtimeFrameworkVersion: null, name: "Wasm", customDotNetCliPath: cliPath); IToolchain toolChain = WasmToolChain.From(netCoreAppSettings); BenchmarkRunner.Run <IntroCustomMonoFluentConfig>(DefaultConfig.Instance .AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain))); }
private void BuildApp(string programName, string projectRoot, WasmRuntime runtime) { string appDir = Path.Combine(projectRoot, $"bin", targetFrameworkMoniker, "browser-wasm", "publish"); string outputDir = Path.Combine(appDir, "output"); string mainAssemblyPath = Path.Combine(appDir, $"{programName}.dll"); if (!File.Exists(mainAssemblyPath)) { throw new ArgumentException($"File MainAssembly='{mainAssemblyPath}' doesn't exist."); } var assemblies = Directory.GetFiles(appDir, "*.dll"); // Create app Directory.CreateDirectory(outputDir); Directory.CreateDirectory(Path.Combine(outputDir, "managed")); foreach (var assembly in assemblies) { File.Copy(assembly, Path.Combine(outputDir, "managed", Path.GetFileName(assembly)), true); } foreach (var f in new string[] { "dotnet.wasm", "dotnet.js" }) { File.Copy(Path.Combine(appDir, f), Path.Combine(outputDir, f), true); } File.Copy(runtime.MainJs.FullName, Path.Combine(outputDir, "runtime.js"), true); using (var sw = File.CreateText(Path.Combine(outputDir, "mono-config.js"))) { sw.WriteLine("config = {"); sw.WriteLine("\tvfs_prefix: \"managed\","); sw.WriteLine("\tdeploy_prefix: \"managed\","); sw.WriteLine("\tenable_debugging: 0,"); sw.WriteLine("\tassembly_list: ["); foreach (var assembly in assemblies) { sw.Write("\t\t\"" + Path.GetFileName(assembly) + "\""); sw.WriteLine(","); } sw.WriteLine("\t],"); sw.WriteLine("\tfiles_to_map: [],"); sw.WriteLine("}"); } }
/// <summary> /// Schedules a periodic piece of work, using a Windows.System.Threading.ThreadPoolTimer object. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">Initial state passed to the action upon the first iteration.</param> /// <param name="period">Period for running the work periodically.</param> /// <param name="action">Action to be executed, potentially updating the state.</param> /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than one millisecond.</exception> public IDisposable SchedulePeriodic <TState>(TState state, TimeSpan period, Func <TState, TState> action) { // The WinRT thread pool is based on the Win32 thread pool and cannot handle // sub-1ms resolution. When passing a lower period, we get single-shot // timer behavior instead. See MSDN documentation for CreatePeriodicTimer // for more information. if (period < TimeSpan.FromMilliseconds(1)) { throw new ArgumentOutOfRangeException(nameof(period), "The WinRT thread pool doesn't support creating periodic timers with a period below 1 millisecond."); } if (action == null) { throw new ArgumentNullException(nameof(action)); } var state1 = state; var gate = new AsyncLock(); WasmRuntime.ScheduleTimeout( (int)period.TotalMilliseconds, () => { Action run = null; run = () => { gate.Wait(() => { state1 = action(state1); WasmRuntime.ScheduleTimeout( (int)period.TotalMilliseconds, run); }); }; }); return(Disposable.Create(() => { gate.Dispose(); action = Stubs <TState> .I; })); }
/// <inheritdoc /> public override IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var d = new SingleAssignmentDisposable(); WasmRuntime.ScheduleTimeout(0, () => { if (!d.IsDisposed) { d.Disposable = action(this, state); } }); return(d); }