Ejemplo n.º 1
0
        public void Serialize_Exception_PreservesValues()
        {
            // Arrange
            ArgumentException exception;

            try
            {
                ThrowArgumentNullException();
                throw new InvalidOperationException();
            }
            catch (ArgumentNullException ex)
            {
                exception = ex;
            }
            var exceptionObject = SerializedException.FromException(exception);
            var stateSerializer = new StateSerializer();

            stateSerializer.Serialize("Foo", exceptionObject);
            stateSerializer.Dispose();
            var stateDeserializer = new StateDeserializer(stateSerializer.GetState());

            // Act
            var result = stateDeserializer.Deserialize <SerializedException>("Foo");

            // Assert
            Assert.Equal(exception.Message, result.Message);
            Assert.Equal(exception.StackTrace, result.StackTrace);
            Assert.Equal(typeof(ArgumentNullException), result.ExceptionType);
            Assert.Equal(exception.ParamName, result.AdditionalProperties["ParamName"]);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialisiert und startet die Simulation.
        /// </summary>
        /// <param name="settings">Simulationseinstellungen</param>
        public void Start(Setup settings)
        {
            // Check for right State
            if (State != SimulationState.Stopped)
            {
                throw new NotSupportedException("Simulation is not stopped");
            }

            Type t = typeof(SecureHost);

            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            Evidence evidence = new Evidence();

            try
            {
                _appDomain = AppDomain.CreateDomain("AntMe! Jail", evidence, setup);
                _host      = _appDomain.CreateInstanceAndUnwrap(t.Assembly.FullName, t.FullName) as SecureHost;

                _host.Setup(extensionPaths, settings);

                State = SimulationState.Running;
            }
            catch
            {
                State = SimulationState.Failed;
                Stop();
                throw;
            }

            _deserializer = new StateDeserializer();
        }
Ejemplo n.º 3
0
        private void callback_OnSimulationChanged(SimulationState state, byte framerate)
        {
            // Server State changed from running to stopped
            if (_serverState != SimulationState.Stopped && state == SimulationState.Stopped)
            {
                // Trash Deserializer
                if (_deserializer != null)
                {
                    _deserializer.Dispose();
                    _deserializer = null;
                }

                // Remove last State
                _currentState = null;
            }

            //// Server State changed from stopped to running
            //if (_serverState == SimulationState.Stopped && state != SimulationState.Stopped)
            //{
            //    if (_deserializer == null)
            //    {
            //        _deserializer = new StateDeserializer();
            //    }
            //}

            // Set local Properties
            _serverState = state;
            _rate        = framerate;

            // Drop Event
            if (OnSimulationChanged != null)
            {
                OnSimulationChanged(this, state, framerate);
            }
        }
Ejemplo n.º 4
0
        public void Serialize_Value_Ok(object value)
        {
            // Arrange
            var stateSerializer = new StateSerializer();

            stateSerializer.Serialize("foo", value);
            stateSerializer.Dispose();
            var stateDeserializer = new StateDeserializer(stateSerializer.GetState());

            // Act
            var result = stateDeserializer.Deserialize("foo", value.GetType());

            // Assert
            Assert.Equal(value, result);
        }
Ejemplo n.º 5
0
        public void Stop()
        {
            if (_appDomain != null)
            {
                _host = null;
                AppDomain.Unload(_appDomain);
                _appDomain = null;

                if (_deserializer != null)
                {
                    _deserializer.Dispose();
                    _deserializer = null;
                }
            }
        }
Ejemplo n.º 6
0
        public void Serialize_Object_PreservesData()
        {
            // Arrange
            var stateSerializer  = new StateSerializer();
            var serializedObject = new SerializedObject(new CustomData("Foo"));

            stateSerializer.Serialize("Foo", serializedObject);
            stateSerializer.Dispose();
            var stateDeserializer = new StateDeserializer(stateSerializer.GetState());

            // Act
            var result = stateDeserializer.Deserialize <SerializedObject>("Foo");

            // Assert
            Assert.Equal("Foo", result.Values["Value"]);
        }
Ejemplo n.º 7
0
        private void callback_OnSimulationState(byte[] parameter)
        {
            // Skip, as long there is no Deserializer
            if (_deserializer == null)
            {
                _deserializer = new StateDeserializer();
            }

            // Set latest Main State
            _currentState = _deserializer.Deserialize(parameter);

            if (OnSimulationState != null)
            {
                OnSimulationState(this, _currentState);
            }
        }
Ejemplo n.º 8
0
        public void Compile_Greeting_Success()
        {
            // Arrange
            var muteCompiler = new Compiler();
            var result       = muteCompiler.Compile("module foo;\r\nlet s <- import 'greeting' as string;");

            var serializer         = new StateSerializer();
            var deserializer       = new StateDeserializer();
            var dependencyResolver = new DefaultDependencyResolver();

            dependencyResolver.Register <Transaction>(TransactionFactory.CreateNew(null), null);
            dependencyResolver.Register <ITimeService>(Substitute.For <ITimeService>(), null);
            dependencyResolver.Register("Hello World!", "greeting");

            // Act
            var state = result.Result(serializer, deserializer, dependencyResolver);

            // Assert
            Assert.True(result.Success);
        }
Ejemplo n.º 9
0
        private void callback_OnSimulationState(byte[] parameter)
        {
            // Skip, as long there is no Deserializer
            if (_deserializer == null)
                _deserializer = new StateDeserializer();

            // Set latest Main State
            _currentState = _deserializer.Deserialize(parameter);

            if (OnSimulationState != null)
                OnSimulationState(this, _currentState);
        }
Ejemplo n.º 10
0
        private void callback_OnSimulationChanged(SimulationState state, byte framerate)
        {
            // Server State changed from running to stopped
            if (_serverState != SimulationState.Stopped && state == SimulationState.Stopped)
            {
                // Trash Deserializer
                if (_deserializer != null)
                {
                    _deserializer.Dispose();
                    _deserializer = null;
                }

                // Remove last State
                _currentState = null;
            }

            //// Server State changed from stopped to running
            //if (_serverState == SimulationState.Stopped && state != SimulationState.Stopped)
            //{
            //    if (_deserializer == null)
            //    {
            //        _deserializer = new StateDeserializer();
            //    }
            //}

            // Set local Properties
            _serverState = state;
            _rate = framerate;

            // Drop Event
            if (OnSimulationChanged != null)
                OnSimulationChanged(this, state, framerate);
        }