protected void Example(string fileName, string fileContent) { if (string.IsNullOrWhiteSpace(fileContent)) { throw new ArgumentNullException(nameof(fileContent)); } _logger.Log($"fileContent = {fileContent}"); _logger.Log($"fileName = {fileName}"); var targetDirectoryName = string.Empty; if (fileName.EndsWith(".zip")) { targetDirectoryName = fileName.Replace(".zip", string.Empty); } else { targetDirectoryName = fileName; fileName = $"{fileName}.zip"; } WriteLineToReport("---------------------------------------------------------------------------------"); WriteLineToReport(targetDirectoryName); WriteLineToReport(" "); _logger.Log($"fileName (after) = {fileName}"); _logger.Log($"targetDirectoryName = {targetDirectoryName}"); var fullDestDirName = Path.Combine(_destDir, targetDirectoryName); var fullFileName = Path.Combine(_destDir, fileName); _logger.Log($"fullDestDirName = {fullDestDirName}"); _logger.Log($"fullFileName = {fullFileName}"); var relativeExampleHref = $"{_baseRelativeExampleHref}{fileName}"; _logger.Log($"relativeExampleHref = {relativeExampleHref}"); WriteLineToReport($"<code data-lng='soc' example-href='{relativeExampleHref}'>"); WriteLineToReport(fileContent); WriteLineToReport("</code>"); WriteLineToReport(" "); var testDir = Path.Combine(_rootDir, $"TstDir{Guid.NewGuid().ToString("D").Replace("-", string.Empty)}"); if (!Directory.Exists(testDir)) { Directory.CreateDirectory(testDir); } var worldSpaceCreationSettings = new WorldSpaceCreationSettings() { ProjectName = _projectName }; var wSpaceFile = WorldSpaceCreator.CreateWithOutWSpaceFile(worldSpaceCreationSettings, testDir , errorMsg => throw new Exception(errorMsg) ); var wSpaceDir = wSpaceFile.DirectoryName; _logger.Log($"testDir = {testDir}"); _logger.Log($"wSpaceDir = {wSpaceDir}"); var relativeFileName = _defaultRelativeFileName; if (relativeFileName.StartsWith("/") || relativeFileName.StartsWith("\\")) { relativeFileName = relativeFileName.Substring(1); } var targetFileName = Path.Combine(wSpaceDir, relativeFileName); File.WriteAllText(targetFileName, fileContent); var supportBasePath = Path.Combine(testDir, "SysDirs"); var logDir = Path.Combine(supportBasePath, "NpcLogs"); var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create(); var instance = new WorldCore(); var settings = new WorldSettings(); settings.EnableAutoloadingConvertors = true; settings.SharedModulesDirs = new List <string>() { Path.Combine(wSpaceDir, "Modules") }; settings.ImagesRootDir = Path.Combine(supportBasePath, "Images"); settings.TmpDir = Path.Combine(supportBasePath, "TMP"); settings.HostFile = Path.Combine(wSpaceDir, "World/World.world"); settings.InvokerInMainThread = invokingInMainThread; var callBackLogger = new CallBackLogger( message => { WriteLineToReport(NormalizeTextForConsole(message)); _logger.Log(message); }, errorMsg => { _logger.Error(errorMsg); } ); settings.Logging = new LoggingSettings() { LogDir = logDir, RootContractName = "Hi1", PlatformLoggers = new List <IPlatformLogger>() { callBackLogger }, Enable = true, EnableRemoteConnection = true }; instance.SetSettings(settings); var platformListener = new object(); var npcSettings = new HumanoidNPCSettings(); npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5"; npcSettings.LogicFile = Path.Combine(wSpaceDir, $"Npcs/{_projectName}/{_projectName}.sobj"); npcSettings.HostListener = platformListener; npcSettings.PlatformSupport = new PlatformSupportCLIStub(); var npc = instance.GetHumanoidNPC(npcSettings); WriteLineToReport("<console>"); instance.Start(); Thread.Sleep(_timeoutToEnd); WriteLineToReport("</console>"); Directory.Move(wSpaceDir, fullDestDirName); ZipFile.CreateFromDirectory(fullDestDirName, fullFileName); Directory.Delete(testDir, true); Directory.Delete(fullDestDirName, true); }
public bool Run(int timeoutToEnd, Action <string> logChannel, Action <string> error) { var result = true; var supportBasePath = Path.Combine(_testDir, "SysDirs"); var logDir = Path.Combine(supportBasePath, "NpcLogs"); var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create(); var instance = new WorldCore(); var settings = new WorldSettings(); settings.EnableAutoloadingConvertors = true; settings.SharedModulesDirs = new List <string>() { Path.Combine(_wSpaceDir, "Modules") }; settings.ImagesRootDir = Path.Combine(supportBasePath, "Images"); settings.TmpDir = Path.Combine(supportBasePath, "TMP"); settings.HostFile = Path.Combine(_wSpaceDir, "World/World.world"); settings.InvokerInMainThread = invokingInMainThread; var callBackLogger = new CallBackLogger( message => { logChannel(message); }, errorMsg => { result = false; error(errorMsg); } ); settings.Logging = new LoggingSettings() { LogDir = logDir, RootContractName = "Hi1", PlatformLoggers = new List <IPlatformLogger>() { callBackLogger }, Enable = true, EnableRemoteConnection = true }; instance.SetSettings(settings); var platformListener = new object(); var npcSettings = new HumanoidNPCSettings(); npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5"; npcSettings.LogicFile = Path.Combine(_wSpaceDir, $"Npcs/{_projectName}/{_projectName}.sobj"); npcSettings.HostListener = platformListener; npcSettings.PlatformSupport = new PlatformSupportCLIStub(); var npc = instance.GetHumanoidNPC(npcSettings); instance.Start(); Thread.Sleep(timeoutToEnd); return(result); }