Exemple #1
0
        public static void MeasureEnqueue()
        {
            var engine = new XEngine();

            engine.Start();

            var stopwatch = new Stopwatch();

            for (int i = 0; i < 2; i++)
            {
                stopwatch.Restart();
                PublishTradingSignalV1(engine);
                stopwatch.Stop();
                var v1 = stopwatch.Elapsed;
                Console.WriteLine($"V1: {v1}");
                Thread.Sleep(200);

                stopwatch.Restart();
                PublishTradingSignalV2(engine);
                stopwatch.Stop();
                var v2 = stopwatch.Elapsed;
                Console.WriteLine($"V2: {v2}");
                Console.WriteLine($"Delta: {(v2.Ticks - v1.Ticks) / (double)v1.Ticks:P2}");
                Thread.Sleep(200);
            }

            engine.Stop();
        }
Exemple #2
0
        public void Init()
        {
            //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
//            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            m_xEngine = new XEngine();

            // Necessary to stop serialization complaining
            WorldCommModule wcModule = new WorldCommModule();

            IniConfigSource configSource = new IniConfigSource();
            
            IConfig startupConfig = configSource.AddConfig("Startup");
            startupConfig.Set("DefaultScriptEngine", "XEngine");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");
            xEngineConfig.Set("Enabled", "true");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource);
            SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
            m_scene.StartScripts();
        }
Exemple #3
0
        public void Init()
        {
            //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
//            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            m_xEngine = new XEngine();

            // Necessary to stop serialization complaining
            WorldCommModule wcModule = new WorldCommModule();

            IniConfigSource configSource = new IniConfigSource();

            IConfig startupConfig = configSource.AddConfig("Startup");

            startupConfig.Set("DefaultScriptEngine", "XEngine");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");

            xEngineConfig.Set("Enabled", "true");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
            SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);

            m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
            m_scene.StartScripts();
        }
        public static void PublisherMarketDataUpdates()
        {
            var engine = new XEngine();

            engine.Start();

            var publisher = new MarketDataPublisher2(engine, securityCount: 50);

            publisher.Run(1_000_000);
            Console.WriteLine($"Generated UpdateCount: {publisher.UpdateCount}");

            engine.Stop();
        }
Exemple #5
0
        public void initialize(Scene scene)
        {
            /* Actor Events */
            scene.EventManager.OnNewPresence            += onAddAvatar;
            scene.EventManager.OnRemovePresence         += onRemoveAvatar;
            scene.EventManager.OnAvatarAppearanceChange += onAvatarAppearanceChanged;
            scene.EventManager.OnScenePresenceUpdated   += onAvatarPresenceChanged;
            scene.EventManager.OnMakeChildAgent         += onRemoveAvatar;
            scene.EventManager.OnMakeRootAgent          += onAddAvatar;

            /* Object Events */
            scene.EventManager.OnObjectAddedToScene          += onAddObject;
            scene.EventManager.OnSceneObjectLoaded           += onAddObject;
            scene.EventManager.OnObjectBeingRemovedFromScene += onRemoveObject;
            scene.EventManager.OnSceneObjectPartUpdated      += onUpdateObject;

            /* Chat Events */
            scene.EventManager.OnChatFromClient += onChatBroadcast;

            /* lookup xEngine */
            IScriptModule scriptModule = null;

            foreach (IScriptModule sm in scene.RequestModuleInterfaces <IScriptModule>())
            {
                if (sm.ScriptEngineName == scene.DefaultScriptEngine)
                {
                    scriptModule = sm;
                }
                else if (scriptModule == null)
                {
                    scriptModule = sm;
                }
            }
            xEngine = (XEngine)scriptModule;
            m_scene = scene;
        }
 public MarketDataPublisher2(XEngine targetEngine, int securityCount)
 {
     _targetEngine = targetEngine;
     _prices       = Enumerable.Repeat(500L, securityCount).ToArray();
 }
        public void TestScriptCrossOnSameSimulator()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            UUID userId            = TestHelpers.ParseTail(0x1);
            int  sceneObjectIdTail = 0x2;

            EntityTransferModule           etmA = new EntityTransferModule();
            EntityTransferModule           etmB = new EntityTransferModule();
            LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
            XEngine xEngineA = new XEngine();
            XEngine xEngineB = new XEngine();

            xEngineA.DebugLevel = 1;
            xEngineB.DebugLevel = 1;

            IConfigSource configSource = new IniConfigSource();

            IConfig startupConfig = configSource.AddConfig("Startup");

            startupConfig.Set("DefaultScriptEngine", "XEngine");
            startupConfig.Set("TrustBinaries", "true");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");

            xEngineConfig.Set("Enabled", "true");
            xEngineConfig.Set("StartDelay", "0");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            IConfig modulesConfig = configSource.AddConfig("Modules");

            modulesConfig.Set("EntityTransferModule", etmA.Name);
            modulesConfig.Set("SimulationServices", lscm.Name);

            SceneHelpers sh     = new SceneHelpers();
            TestScene    sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
            TestScene    sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);

            SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
            SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
            SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
            sceneA.StartScripts();
            sceneB.StartScripts();

            SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);

            soSceneA.AbsolutePosition = new Vector3(128, 10, 20);

            string soSceneAName         = soSceneA.Name;
            string scriptItemSceneAName = "script1";

            // CREATE SCRIPT TODO
            InventoryItemBase scriptItemSceneA = new InventoryItemBase();

            //            itemTemplate.ID = itemId;
            scriptItemSceneA.Name    = scriptItemSceneAName;
            scriptItemSceneA.Folder  = soSceneA.UUID;
            scriptItemSceneA.InvType = (int)InventoryType.LSL;

            AutoResetEvent chatEvent       = new AutoResetEvent(false);
            OSChatMessage  messageReceived = null;

            sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };

            sceneA.RezNewScript(userId, scriptItemSceneA,
                                @"integer c = 0;

default
{    
    state_entry()
    {
        llSay(0, ""Script running"");
    }

    changed(integer change)
    {
        llSay(0, ""Changed"");
    }

    touch_start(integer n)
    {
        c = c + 1; 
        llSay(0, (string)c);
    }
}");

            chatEvent.WaitOne(60000);

            Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
            Assert.That(messageReceived.Message, Is.EqualTo("Script running"));

            {
                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0]     = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneA);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                messageReceived = null;
                chatEvent.Reset();
                xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
                chatEvent.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("1"));
            }

            AutoResetEvent chatEventB = new AutoResetEvent(false);

            sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEventB.Set(); };

            messageReceived = null;
            chatEventB.Reset();
            // Cross with a negative value
            soSceneA.AbsolutePosition = new Vector3(128, -10, 20);

            chatEventB.WaitOne(60000);
            Assert.That(messageReceived, Is.Not.Null, "No Changed message received.");
            Assert.That(messageReceived.Message, Is.Not.Null, "Changed message without content");
            Assert.That(messageReceived.Message, Is.EqualTo("Changed"));

            // TEST sending event to moved prim and output
            {
                SceneObjectGroup  soSceneB         = sceneB.GetSceneObjectGroup(soSceneAName);
                TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneAName);

                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0]     = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneB);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                messageReceived = null;
                chatEventB.Reset();
                xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
                chatEventB.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("2"));
            }
        }
        public void TestScriptCrossOnSameSimulator()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            UUID userId = TestHelpers.ParseTail(0x1);
            int sceneObjectIdTail = 0x2;

            EntityTransferModule etmA = new EntityTransferModule();
            EntityTransferModule etmB = new EntityTransferModule();
            LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
            XEngine xEngineA = new XEngine();
            XEngine xEngineB = new XEngine();
            xEngineA.DebugLevel = 1;
            xEngineB.DebugLevel = 1;

            IConfigSource configSource = new IniConfigSource();

            IConfig startupConfig = configSource.AddConfig("Startup");
            startupConfig.Set("DefaultScriptEngine", "XEngine");
            startupConfig.Set("TrustBinaries", "true");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");
            xEngineConfig.Set("Enabled", "true");
            xEngineConfig.Set("StartDelay", "0");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            IConfig modulesConfig = configSource.AddConfig("Modules");
            modulesConfig.Set("EntityTransferModule", etmA.Name);
            modulesConfig.Set("SimulationServices", lscm.Name);

            SceneHelpers sh = new SceneHelpers();
            TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
            TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);

            SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
            SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
            SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
            sceneA.StartScripts();
            sceneB.StartScripts();

            SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
            soSceneA.AbsolutePosition = new Vector3(128, 10, 20);

            string soSceneAName = soSceneA.Name;
            string scriptItemSceneAName = "script1";

            // CREATE SCRIPT TODO
            InventoryItemBase scriptItemSceneA = new InventoryItemBase();
            //            itemTemplate.ID = itemId;
            scriptItemSceneA.Name = scriptItemSceneAName;
            scriptItemSceneA.Folder = soSceneA.UUID;
            scriptItemSceneA.InvType = (int)InventoryType.LSL;

            AutoResetEvent chatEvent = new AutoResetEvent(false);
            OSChatMessage messageReceived = null;
            sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };

            sceneA.RezNewScript(userId, scriptItemSceneA, 
@"integer c = 0;

default
{    
    state_entry()
    {
        llSay(0, ""Script running"");
    }

    changed(integer change)
    {
        llSay(0, ""Changed"");
    }

    touch_start(integer n)
    {
        c = c + 1; 
        llSay(0, (string)c);
    }
}");

            chatEvent.WaitOne(60000);

            Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
            Assert.That(messageReceived.Message, Is.EqualTo("Script running"));           

            {
                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0] = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneA);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                messageReceived = null;
                chatEvent.Reset();
                xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
                chatEvent.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("1")); 
            }

            AutoResetEvent chatEventB = new AutoResetEvent(false);
            sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEventB.Set(); };

            messageReceived = null;
            chatEventB.Reset();
            // Cross with a negative value
            soSceneA.AbsolutePosition = new Vector3(128, -10, 20);

            chatEventB.WaitOne(60000);
            Assert.That(messageReceived, Is.Not.Null, "No Changed message received.");
            Assert.That(messageReceived.Message, Is.Not.Null, "Changed message without content");
            Assert.That(messageReceived.Message, Is.EqualTo("Changed")); 

            // TEST sending event to moved prim and output
            {
                SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneAName);
                TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneAName);

                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0] = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneB);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                Thread.Sleep(250); // wait for other change messages to pass
                messageReceived = null;
                chatEventB.Reset();
                xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
                chatEventB.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("2")); 
            }
        }
        public void TestPostAssetRewrite()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            XEngine xengine = new XEngine();

            xengine.DebugLevel = 1;

            IniConfigSource configSource = new IniConfigSource();

            IConfig startupConfig = configSource.AddConfig("Startup");

            startupConfig.Set("DefaultScriptEngine", "XEngine");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");

            xEngineConfig.Set("Enabled", "true");
            xEngineConfig.Set("StartDelay", "0");
            xEngineConfig.Set("AppDomainLoading", "false");

            string homeUrl       = "http://hg.HomeTestPostAssetRewriteGrid.com";
            string foreignUrl    = "http://hg.ForeignTestPostAssetRewriteGrid.com";
            int    soIdTail      = 0x1;
            UUID   assetId       = TestHelpers.ParseTail(0x10);
            UUID   userId        = TestHelpers.ParseTail(0x100);
            UUID   sceneId       = TestHelpers.ParseTail(0x1000);
            string userFirstName = "TestPostAsset";
            string userLastName  = "Rewrite";
            int    soPartsCount  = 3;

            Scene scene = new SceneHelpers().SetupScene("TestPostAssetRewriteScene", sceneId, 1000, 1000, configSource);

            SceneHelpers.SetupSceneModules(scene, configSource, xengine);
            scene.StartScripts();

            HGAssetMapper hgam = new HGAssetMapper(scene, homeUrl);
            UserAccount   ua
                = UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "password");

            SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, soPartsCount, ua.PrincipalID, "part", soIdTail);

            RezScript(
                scene, so.UUID, "default { state_entry() { llSay(0, \"Hello World\"); } }", "item1", ua.PrincipalID);

            AssetBase asset = AssetHelpers.CreateAsset(assetId, so);

            asset.CreatorID = foreignUrl;
            hgam.PostAsset(foreignUrl, asset);

            // Check transformed asset.
            AssetBase ncAssetGet = scene.AssetService.Get(assetId.ToString());

            Assert.AreEqual(foreignUrl, ncAssetGet.CreatorID);
            string      xmlData          = Utils.BytesToString(ncAssetGet.Data);
            XmlDocument ncAssetGetXmlDoc = new XmlDocument();

            ncAssetGetXmlDoc.LoadXml(xmlData);

//            Console.WriteLine(ncAssetGetXmlDoc.OuterXml);

            XmlNodeList creatorDataNodes = ncAssetGetXmlDoc.GetElementsByTagName("CreatorData");

            Assert.AreEqual(soPartsCount, creatorDataNodes.Count);
            //Console.WriteLine("creatorDataNodes {0}", creatorDataNodes.Count);

            foreach (XmlNode creatorDataNode in creatorDataNodes)
            {
                Assert.AreEqual(
                    string.Format("{0};{1} {2}", homeUrl, ua.FirstName, ua.LastName), creatorDataNode.InnerText);
            }

            // Check that saved script nodes have attributes
            XmlNodeList savedScriptStateNodes = ncAssetGetXmlDoc.GetElementsByTagName("SavedScriptState");

            Assert.AreEqual(1, savedScriptStateNodes.Count);
            Assert.AreEqual(1, savedScriptStateNodes[0].Attributes.Count);
            XmlNode uuidAttribute = savedScriptStateNodes[0].Attributes.GetNamedItem("UUID");

            Assert.NotNull(uuidAttribute);
            // XXX: To check the actual UUID attribute we would have to do some work to retreive the UUID of the task
            // item created earlier.
        }
Exemple #10
0
 public void T001_XStart()
 {
     INonSharedRegionModule xengine = new XEngine();
     SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), xengine);
     xengine.RegionLoaded(scene);
 }
Exemple #11
0
 public MarketDataPublisher1(XEngine targetEngine, int securityCount)
 {
     _conflacters = Enumerable.Range(0, securityCount).ToDictionary(x => x, x => new MarketDataConflater(targetEngine, x));
     _prices      = Enumerable.Repeat(500L, securityCount).ToArray();
 }