Exemplo n.º 1
0
        public override void Awake()
        {
            _logger.Log("Begin");

            _tstRayScaner = new TstRayScaner();

            var platformListener = new TstPlatformHostListener();

            _id = "#`Test 1`";

            var npcSettings = new HumanoidNPCSettings();

            npcSettings.Id         = _id;
            npcSettings.InstanceId = 1;
            //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host");
            npcSettings.LogicFile       = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Npcs\PeaceKeeper\PeaceKeeper.sobj");
            npcSettings.HostListener    = platformListener;
            npcSettings.VisionProvider  = _tstRayScaner;
            npcSettings.PlatformSupport = new PlatformSupportCLIStub();

            _logger.Log($"npcSettings = {npcSettings}");

            _npc = WorldFactory.WorldInstance.GetHumanoidNPC(npcSettings);

            _logger.Log($"_npc == null = {_npc == null}");

            _tstRayScaner.SetNPC(_npc);

            _logger.Log("End");
        }
        public HumanoidNPCGameComponent(HumanoidNPCSettings settings, IWorldCoreGameComponentContext worldContext)
            : base(settings, worldContext)
        {
            try
            {
#if DEBUG
                //Log($"settings = {settings}");
                //Log($"worldContext.TmpDir = {worldContext.TmpDir}");
                //Log($"worldContext.LogicQueryParseAndCache == null = {worldContext.LogicQueryParseAndCache == null}");
#endif

                var internalContext = new HumanoidNPCGameComponentContext();

                _idForFacts = settings.IdForFacts;

                internalContext.IdForFacts     = _idForFacts;
                internalContext.SelfInstanceId = settings.InstanceId;

                var tmpDir = Path.Combine(worldContext.TmpDir, settings.Id);

                Directory.CreateDirectory(worldContext.TmpDir);

                if (settings.VisionProvider != null)
                {
                    _visionComponent = new VisionComponent(Logger, settings.VisionProvider, internalContext, worldContext);
                    internalContext.VisionComponent = _visionComponent;
                }

                _hostSupport = new HostSupportComponent(Logger, settings.PlatformSupport, internalContext, worldContext);
                internalContext.HostSupportComponent = _hostSupport;

                var coreEngineSettings = new EngineSettings();
                coreEngineSettings.Id          = settings.Id;
                coreEngineSettings.AppFile     = settings.LogicFile;
                coreEngineSettings.Logger      = Logger;
                coreEngineSettings.SyncContext = worldContext.SyncContext;

                coreEngineSettings.ModulesStorage          = worldContext.ModulesStorage;
                coreEngineSettings.LogicQueryParseAndCache = worldContext.LogicQueryParseAndCache;
                coreEngineSettings.TmpDir           = tmpDir;
                coreEngineSettings.HostListener     = this;
                coreEngineSettings.DateTimeProvider = worldContext.DateTimeProvider;
                coreEngineSettings.HostSupport      = _hostSupport;

#if DEBUG
                //Log($"coreEngineSettings = {coreEngineSettings}");
#endif
                _coreEngine = new Engine(coreEngineSettings);
                internalContext.CoreEngine = _coreEngine;
            }
            catch (Exception e)
            {
                Log(e.ToString());

                throw e;
            }
        }
Exemplo n.º 3
0
        private static void TstCLIRunHandler()
        {
            _logger.Log("Begin");

            var args = new List <string>()
            {
                "run" //,
                //"%USERPROFILE%/source/repos/SymOntoClay/TestSandbox/Source/Npcs/PeaceKeeper/PeaceKeeper.sobj"
                //"%USERPROFILE%/source/repos/SymOntoClay/TestSandbox/Source"
            }.ToArray();

            var targetDirectory = EVPath.Normalize("%USERPROFILE%/source/repos/SymOntoClay/TestSandbox/Source");

            _logger.Log($"targetDirectory = {targetDirectory}");

            Directory.SetCurrentDirectory(targetDirectory);

            var command = CLICommandParser.Parse(args);

            _logger.Log($"command = {command}");

            var targetFiles = RunCommandFilesSearcher.Run(command);

            _logger.Log($"targetFiles = {targetFiles}");

            //var logDir = Path.Combine(Directory.GetCurrentDirectory(), "NpcLogs");

            var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create();

            var instance = WorldFactory.WorldInstance;

            var settings = new WorldSettings();

            settings.SharedModulesDirs = new List <string>()
            {
                targetFiles.SharedModulesDir
            };

            settings.ImagesRootDir = targetFiles.ImagesRootDir;

            settings.TmpDir = targetFiles.TmpDir;

            settings.HostFile = targetFiles.WorldFile;

            settings.InvokerInMainThread = invokingInMainThread;

            settings.Logging = new LoggingSettings()
            {
                //LogDir = logDir,
                RootContractName = "Hi1",
                PlatformLoggers  = new List <IPlatformLogger>()
                {
                    new CLIPlatformLogger()
                },
                Enable = true,
                EnableRemoteConnection = true
            };

            _logger.Log($"settings = {settings}");

            instance.SetSettings(settings);

            var platformListener = new TstPlatformHostListener();

            var npcSettings = new HumanoidNPCSettings();

            npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5";
            //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host");
            npcSettings.LogicFile       = targetFiles.LogicFile;
            npcSettings.HostListener    = platformListener;
            npcSettings.PlatformSupport = new PlatformSupportCLIStub();

            _logger.Log($"npcSettings = {npcSettings}");

            var npc = instance.GetHumanoidNPC(npcSettings);

            instance.Start();

            Thread.Sleep(50000);

            _logger.Log("End");
        }
Exemplo n.º 4
0
        private static void TstManageTempProject()
        {
            _logger.Log("Begin");

            var initialDir = Directory.GetCurrentDirectory();

            _logger.Log($"initialDir = {initialDir}");

            initialDir = Path.Combine(initialDir, "TempProjects");

            _logger.Log($"initialDir (2) = {initialDir}");

            if (!Directory.Exists(initialDir))
            {
                Directory.CreateDirectory(initialDir);
            }

            var testDir = Path.Combine(initialDir, $"TstDir{Guid.NewGuid().ToString("D").Replace("-", string.Empty)}");

            _logger.Log($"testDir = {testDir}");

            if (!Directory.Exists(testDir))
            {
                Directory.CreateDirectory(testDir);
            }

            var projectName = "Example";

            var worldSpaceCreationSettings = new WorldSpaceCreationSettings()
            {
                ProjectName = projectName
            };

            _logger.Log($"worldSpaceCreationSettings = {worldSpaceCreationSettings}");

            var wSpaceFile = WorldSpaceCreator.CreateWithOutWSpaceFile(worldSpaceCreationSettings, testDir
                                                                       , errorMsg => _logger.Error(errorMsg)
                                                                       );

            _logger.Log($"wSpaceFile = {wSpaceFile}");

            var wSpaceDir = wSpaceFile.DirectoryName;

            _logger.Log($"wSpaceDir = {wSpaceDir}");

            var targetRelativeFileName = @"/Npcs/Example/Example.soc";

            _logger.Log($"targetRelativeFileName = {targetRelativeFileName}");

            if (targetRelativeFileName.StartsWith("/") || targetRelativeFileName.StartsWith("\\"))
            {
                targetRelativeFileName = targetRelativeFileName.Substring(1);
            }

            _logger.Log($"targetRelativeFileName (after) = {targetRelativeFileName}");

            var targetFileName = Path.Combine(wSpaceDir, targetRelativeFileName);

            _logger.Log($"targetFileName = {targetFileName}");

            var text = @"linvar logic for range [0, 1]
{
    constraints:
	    for inheritance;

	terms:
		minimal = L(0, 0.1);
		low = Trapezoid(0, 0.05, 0.3, 0.45);
		middle = Trapezoid(0.3, 0.4, 0.6, 0.7);
		high = Trapezoid(0.55, 0.7, 0.95, 1);
		maximal = S(0.9, 1);
}

linvar age for range (0, 150]
{
	constraints:
		for relation age;

	terms:
        `teenager` = Trapezoid(10, 12, 17, 20);
	    //`teenager` = L(5, 10);
	    //`teenager` = S(12, 22);
	    //`teenager` = S(12, 17, 22);
}

app PeaceKeeper is [very middle] exampleClass
{
    {: >: {distance($x, $y)} -> { distance(I, $x, $y) } :}
    {: barrel(#a) :}
	{: see(I, #a) :}
	{: dog(#b) & bird(#f) :}
	{: cat(#с) :}
	{: animal(cat) :}
	//{: focus(I, friend) :}
	{: age(#Tom, 50) :}
	//{: value(distance(I, #Tom), 1) :}
	{: distance(I, #Tom, 12) :}

    on Init => {
	     'Begin from test!!!' >> @>log;
		 //NULL >> @>log;

		 //use @@self is [very middle] linux;

		 //select {: { cat is animal } :} >> @>log;
		 //select {: see(I, barrel) :} >> @>log;
		 select {: son($x, $y) :} >> @>log;
		 //select {: $z($x, $y) :} >> @>log;
		 //select {: age(#Tom, `teenager`) :} >> @>log;
		 select {: age(#Tom, $x) & distance(#Tom, $y) & $x is not $y :} >> @>log;
		 //select {: value(distance(I, $x), $y) :} >> @>log;
		 //select {: distance(I, #Tom, $x) :} >> @>log;
		 //select {: distance(#Tom, $x) & $x is 12 :} >> @>log;
		 //select {: distance(#Tom, $x) & $x > 5 :} >> @>log;

		 //insert {: >: { bird (#1234) } :};
		 //insert {: see(I, #a) :};

		 //exampleClass is not human >> @>log;
		 //exampleClass is human >> @>log;

		 //@@host.`go`(to: #@[10]);

		 'End' >> @>log;

    }

        //on {: see(I, $x) & barrel($x) & !focus(I, friend) :} ($x >> @x) => {
        //     @x >> @>log;
        //}

        //on {: see(I, #`gun 1`) :} => {
        //     'D' >> @>log;
        //}
    }
";

            File.WriteAllText(targetFileName, text);

            var supportBasePath = Path.Combine(testDir, "SysDirs");

            _logger.Log($"supportBasePath = {supportBasePath}");

            var logDir = Path.Combine(supportBasePath, "NpcLogs");

            _logger.Log($"logDir = {logDir}");

            var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create();

            var instance = WorldFactory.WorldInstance;

            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 => { _logger.Log($"message = {message}"); },
                error => { _logger.Log($"error = {error}"); }
                );

            settings.Logging = new LoggingSettings()
            {
                LogDir           = logDir,
                RootContractName = "Hi1",
                PlatformLoggers  = new List <IPlatformLogger>()
                {
                    callBackLogger
                },
                Enable = true,
                EnableRemoteConnection = true
            };

            _logger.Log($"settings = {settings}");

            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();

            _logger.Log($"npcSettings = {npcSettings}");

            var npc = instance.GetHumanoidNPC(npcSettings);

            instance.Start();

            Thread.Sleep(5000);

            Directory.Delete(testDir, true);

            _logger.Log("End");
        }
        public void Run()
        {
            _logger.Log("Begin");

            var complexContext = TstEngineContextHelper.CreateAndInitContext();

            var context      = complexContext.EngineContext;
            var worldContext = complexContext.WorldContext;

            //var dictionary = context.Dictionary;

            var platformListener = new TstPlatformHostListener();

            var npcSettings = new HumanoidNPCSettings();

            npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5";
            //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host");
            npcSettings.LogicFile       = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Apps\PeaceKeeper\PeaceKeeper.sobj");
            npcSettings.HostListener    = platformListener;
            npcSettings.PlatformSupport = new PlatformSupportCLIStub();

            _logger.Log($"npcSettings = {npcSettings}");

            var tstBaseManualControllingGameComponent = new TstBaseManualControllingGameComponent(npcSettings, worldContext);

            var methodName = NameHelper.CreateName("go");

            var command = new Command();

            command.Name       = methodName;
            command.ParamsDict = new Dictionary <StrongIdentifierValue, Value>();

            var param1Value = new WaypointValue(25, 36, context);
            var param1Name  = NameHelper.CreateName("to");

            command.ParamsDict[param1Name] = param1Value;

            var param2Value = new NumberValue(12.4);
            var param2Name  = NameHelper.CreateName("speed");

            command.ParamsDict[param2Name] = param2Value;

            _logger.Log($"command = {command}");

            //ExecuteCommand(tstBaseManualControllingGameComponent, command);

            methodName = NameHelper.CreateName("shoot");

            command      = new Command();
            command.Name = methodName;

            ExecuteCommand(tstBaseManualControllingGameComponent, command);

            var gameObjectSettings = new GameObjectSettings();

            gameObjectSettings.Id = "#120ED339-6313-459A-900D-92F809CEBDC5";

            var gunPlatformHostListener = new TstGunPlatformHostListener();

            gameObjectSettings.HostListener = gunPlatformHostListener;

            _logger.Log($"gameObjectSettings = {gameObjectSettings}");

            var gameObject = new GameObjectImplementation(gameObjectSettings, worldContext);

            tstBaseManualControllingGameComponent.AddToManualControl(gameObject, 12);

            methodName = NameHelper.CreateName("shoot");

            command      = new Command();
            command.Name = methodName;

            ExecuteCommand(tstBaseManualControllingGameComponent, command);

            var manualControlledObjectsList = tstBaseManualControllingGameComponent.GetManualControlledObjects();

            //_logger.Log($"manualControlledObjectsList = {manualControlledObjectsList.WriteListToString()}");
            _logger.Log($"manualControlledObjectsList.Count = {manualControlledObjectsList.Count}");

            tstBaseManualControllingGameComponent.RemoveFromManualControl(gameObject);

            manualControlledObjectsList = tstBaseManualControllingGameComponent.GetManualControlledObjects();

            _logger.Log($"manualControlledObjectsList.Count = {manualControlledObjectsList.Count}");

            _logger.Log("End");
        }
Exemplo n.º 6
0
        public void Run(CLICommand command)
        {
            ConsoleWrapper.WriteText($"Loading {command.InputFile}...");

#if DEBUG
            //_logger.Info($"command = {command}");
#endif

            var targetFiles = RunCommandFilesSearcher.Run(command);

#if DEBUG
            //_logger.Info($"targetFiles = {targetFiles}");
#endif

            var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create();

            var instance = WorldFactory.WorldInstance;
            world = instance;

            var settings = new WorldSettings();
            settings.EnableAutoloadingConvertors = true;

            settings.SharedModulesDirs = new List <string>()
            {
                targetFiles.SharedModulesDir
            };

            settings.ImagesRootDir = targetFiles.ImagesRootDir;

            settings.TmpDir = targetFiles.TmpDir;

            settings.HostFile = targetFiles.WorldFile;

            settings.InvokerInMainThread = invokingInMainThread;

            var logDir = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "SymOntoClay", "CLI", "NpcLogs");

            settings.Logging = new LoggingSettings()
            {
                LogDir           = logDir,
                RootContractName = "Hi1",
                PlatformLoggers  = new List <IPlatformLogger>()
                {
                    new CLIPlatformLogger()
                },
                Enable = true,
                EnableRemoteConnection = true
            };

#if DEBUG
            //_logger.Info($"settings = {settings}");
#endif
            instance.SetSettings(settings);

            var platformListener = this;

            var npcSettings = new HumanoidNPCSettings();
            npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5";
            //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host");
            npcSettings.LogicFile       = targetFiles.LogicFile;
            npcSettings.HostListener    = platformListener;
            npcSettings.PlatformSupport = new PlatformSupportCLIStub();

#if DEBUG
            //_logger.Info($"npcSettings = {npcSettings}");
#endif
            var npc = instance.GetHumanoidNPC(npcSettings);

            instance.Start();

            ConsoleWrapper.WriteText("Press 'exit' and Enter for exit.");

            while (true)
            {
                var inputStr = Console.ReadLine();

                ConsoleWrapper.WriteText(inputStr);

                if (inputStr == "exit")
                {
                    ConsoleWrapper.WriteText("Are you sure? Type y/n and press Enter.");

                    inputStr = Console.ReadLine();

                    if (inputStr == "y")
                    {
                        break;
                    }
                }
                else
                {
                    ConsoleWrapper.WriteError("Unknown command! Press 'exit' and Enter for exit.");
                }
            }
        }
        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 HumanoidNPCImplementation(HumanoidNPCSettings settings)
 {
     _settings = settings;
 }
 public HumanoidNPCImplementation(HumanoidNPCSettings settings, IWorldCoreGameComponentContext worldContext)
 {
     _gameComponent = new HumanoidNPCGameComponent(settings, worldContext);
 }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public static TstComplexContext CreateAndInitContext()
        {
            var invokingInMainThread = DefaultInvokerInMainThreadFactory.Create();

            var appName = AppDomain.CurrentDomain.FriendlyName;

            _logger.Log($"appName = {appName}");

            var supportBasePath = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "SymOntoClay", appName);

            _logger.Log($"supportBasePath = {supportBasePath}");

            var result = new TstComplexContext();

            var logDir = Path.Combine(Directory.GetCurrentDirectory(), "NpcLogs");

            var worldSettings = new WorldSettings();

            worldSettings.EnableAutoloadingConvertors = true;

            worldSettings.SharedModulesDirs = new List <string>()
            {
                Path.Combine(Directory.GetCurrentDirectory(), "Source", "Modules")
            };

            worldSettings.ImagesRootDir = Path.Combine(Directory.GetCurrentDirectory(), "Images");

            worldSettings.TmpDir = Path.Combine(Environment.GetEnvironmentVariable("TMP"), "SymOntoClay", appName);

            worldSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\World\HelloWorld.world");

            worldSettings.Logging = new LoggingSettings()
            {
                LogDir           = logDir,
                RootContractName = "Hi1",
                PlatformLoggers  = new List <IPlatformLogger>()
                {
                    ConsoleLogger.Instance                                            /*, CommonNLogLogger.Instance */
                },
                Enable = true,
                EnableRemoteConnection = true
            };

            worldSettings.InvokerInMainThread = invokingInMainThread;

            _logger.Log($"worldSettings = {worldSettings}");

            var worldContext = new WorldContext();

            worldContext.SetSettings(worldSettings);

            var npcSettings = new HumanoidNPCSettings();

            npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5";
            //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host");
            npcSettings.LogicFile       = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Apps\PeaceKeeper\PeaceKeeper.sobj");
            npcSettings.PlatformSupport = new PlatformSupportCLIStub();

            _logger.Log($"npcSettings = {npcSettings}");

            var entityLogger = new LoggerImpementation();

            var tmpDir = Path.Combine(worldSettings.TmpDir, npcSettings.Id);

            Directory.CreateDirectory(worldSettings.TmpDir);

            //var standaloneStorageSettings = new StandaloneStorageSettings();
            //standaloneStorageSettings.Id = npcSettings.Id;
            //standaloneStorageSettings.IsWorld = false;
            //standaloneStorageSettings.AppFile = npcSettings.HostFile;
            //standaloneStorageSettings.Logger = entityLogger;
            //standaloneStorageSettings.Dictionary = worldContext.SharedDictionary.Dictionary;
            //standaloneStorageSettings.ModulesStorage = worldContext.ModulesStorage.ModulesStorage;
            //standaloneStorageSettings.ParentStorage = worldContext.StandaloneStorage.StandaloneStorage;

#if DEBUG
            //_logger.Log($"standaloneStorageSettings = {standaloneStorageSettings}");
#endif
            //var _hostStorage = new StandaloneStorage(standaloneStorageSettings);

            var coreEngineSettings = new EngineSettings();
            coreEngineSettings.Id          = npcSettings.Id;
            coreEngineSettings.AppFile     = npcSettings.LogicFile;
            coreEngineSettings.Logger      = entityLogger;
            coreEngineSettings.SyncContext = worldContext.ThreadsComponent;

            coreEngineSettings.ModulesStorage = worldContext.ModulesStorage.ModulesStorage;
            //coreEngineSettings.ParentStorage = _hostStorage;
            coreEngineSettings.TmpDir      = tmpDir;
            coreEngineSettings.HostSupport = new TstHostSupportComponent(npcSettings.PlatformSupport);

#if DEBUG
            _logger.Log($"coreEngineSettings = {coreEngineSettings}");
#endif

#if DEBUG
            //_logger.Log($"Begin worldContext.Start()");
#endif

            worldContext.Start();

            result.WorldContext = worldContext;

#if DEBUG
            //_logger.Log($"After worldContext.Start()");
#endif

            var context = EngineContextHelper.CreateAndInitContext(coreEngineSettings);

#if DEBUG
            //_logger.Log($"After var context = EngineContextHelper.CreateAndInitContext(coreEngineSettings);");
#endif

            context.CommonNamesStorage.LoadFromSourceCode();

#if DEBUG
            //_logger.Log($"After context.CommonNamesStorage.LoadFromSourceCode();");
#endif

            context.Storage.LoadFromSourceCode();

#if DEBUG
            //_logger.Log($"After context.Storage.LoadFromSourceCode();");
#endif

            context.StandardLibraryLoader.LoadFromSourceCode();

#if DEBUG
            //_logger.Log($"After context.StandardLibraryLoader.LoadFromSourceCode();");
#endif

            context.StatesStorage.LoadFromSourceCode();

#if DEBUG
            //_logger.Log($"After context.StatesStorage.LoadFromSourceCode();");
#endif

            context.InstancesStorage.LoadFromSourceFiles();

            result.EngineContext = context;

            return(result);
        }