protected void Error(string message)
 {
     _logger.Error(message);
 }
Esempio n. 2
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");
        }
        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);
        }