internal async Task EnsureInitialized() { if (_initialized) { return; } await _initLocker.WaitAsync(); if (_initialized) { return; } try { CleanEmptyDataFolders(); var jsreportBinaryDirectory = Path.Combine(Configuration.TempDirectory ?? Path.Combine(Path.GetTempPath(), "jsreport"), "dotnet", "binary-" + _binary.UniqueId); Directory.CreateDirectory(jsreportBinaryDirectory); _exePath = Path.Combine(jsreportBinaryDirectory, "jsreport.exe"); if (File.Exists(_exePath)) { return; } for (var i = 0; i < 10; i++) { try { using (var f = File.Create(_exePath)) { _binary.ReadContent().CopyTo(f); } if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { AddExecutePermissions(_exePath); } break; } catch (Exception e) { Console.WriteLine(e.ToString()); Thread.Sleep(50); } } } finally { _initialized = true; _initLocker.Release(); } }
internal async Task EnsureInitialized() { if (_initialized) { return; } await _initLocker.WaitAsync().ConfigureAwait(false); try { if (_initialized) { return; } CleanEmptyDataFolders(); var jsreportBinaryDirectory = Path.Combine(Configuration.TempDirectory, "dotnet", "binary-" + _binary.UniqueId); Directory.CreateDirectory(jsreportBinaryDirectory); _exePath = Path.Combine(jsreportBinaryDirectory, "jsreport.exe"); if (File.Exists(_exePath) && new FileInfo(_exePath).Length > 0) { return; } var tmpExePath = Path.Combine(jsreportBinaryDirectory, Shortid() + "jsreport.exe"); using (var f = File.Create(tmpExePath)) { _binary.ReadContent().CopyTo(f); } if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { AddExecutePermissions(tmpExePath); } for (var i = 0; i < 10; i++) { try { File.Move(tmpExePath, _exePath); break; } catch (Exception e) { if (i == 9) { throw; } Thread.Sleep(50); } } } finally { _initialized = true; _initLocker.Release(); } }