Exemple #1
0
        protected virtual void OnSessionDisposed(EventArgs e)
        {
            _errors.Clear();
            _errors = null;
            _serializersCache.Clear();
            _serializersCache = null;
            _instancesByNameCache.Clear();
            _instancesByNameCache = null;
            _instancesByValueCache.Clear();
            _instancesByValueCache = null;
            _session                      = null;
            _contextStack                 = null;
            _resolveNameHandler           = null;
            _serializationCompleteHandler = null;

            if (SessionDisposed != null)
            {
                SessionDisposed(this, e);
            }

            if (_serializationCompleteHandler != null)
            {
                _serializationCompleteHandler(this, EventArgs.Empty);
            }
        }
Exemple #2
0
		public void IntegrityTest ()
		{
			ContextStack stack = new ContextStack ();

			string one = "one";
			string two = "two";
			stack.Push (two);
			stack.Push (one);
			Assert.AreSame (one, stack [typeof (string)], "#1");
			Assert.AreSame (one, stack [0], "#2");
			Assert.AreSame (one, stack.Current, "#3");

			Assert.AreSame (one, stack.Pop (), "#4");

			Assert.AreSame (two, stack [typeof (string)], "#5");
			Assert.AreSame (two, stack [0], "#6");
			Assert.AreSame (two, stack.Current, "#7");

			string three = "three";
			stack.Append (three);

			Assert.AreSame (two, stack[typeof (string)], "#8");
			Assert.AreSame (two, stack[0], "#9");
			Assert.AreSame (two, stack.Current, "#10");

			Assert.AreSame (two, stack.Pop (), "#11");

			Assert.AreSame (three, stack[typeof (string)], "#12");
			Assert.AreSame (three, stack[0], "#13");
			Assert.AreSame (three, stack.Current, "#14");
			Assert.AreSame (three, stack.Pop (), "#15");

			Assert.IsNull (stack.Pop (), "#16");
			Assert.IsNull (stack.Current, "#17");
		}
Exemple #3
0
 protected virtual void OnSessionDisposed(EventArgs e)
 {
     try
     {
         try
         {
             if (this.sessionDisposedEventHandler != null)
             {
                 this.sessionDisposedEventHandler(this, e);
             }
         }
         finally
         {
             if (this.serializationCompleteEventHandler != null)
             {
                 this.serializationCompleteEventHandler(this, EventArgs.Empty);
             }
         }
     }
     finally
     {
         this.resolveNameEventHandler           = null;
         this.serializationCompleteEventHandler = null;
         this.instancesByName = null;
         this.namesByInstance = null;
         this.serializers     = null;
         this.contextStack    = null;
         this.errorList       = null;
         this.session         = null;
     }
 }
        public void IntegrityTest()
        {
            ContextStack stack = new ContextStack();

            string one = "one";
            string two = "two";
            stack.Push(two);
            stack.Push(one);
            Assert.Same(one, stack[typeof(string)]);
            Assert.Same(one, stack[0]);
            Assert.Same(one, stack.Current);

            Assert.Same(one, stack.Pop());

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            string three = "three";
            stack.Append(three);

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            Assert.Same(two, stack.Pop());

            Assert.Same(three, stack[typeof(string)]);
            Assert.Same(three, stack[0]);
            Assert.Same(three, stack.Current);
            Assert.Same(three, stack.Pop());

            Assert.Null(stack.Pop());
            Assert.Null(stack.Current);
        }
 public void Append_Context_Null()
 {
     ContextStack stack = new ContextStack();
     ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() => stack.Append(null));
     Assert.Equal(typeof(ArgumentNullException), ex.GetType());
     Assert.Null(ex.InnerException);
     Assert.NotNull(ex.Message);
     Assert.Equal("context", ex.ParamName);
 }
		public void Append_Context_Null ()
		{
			ContextStack stack = new ContextStack ();
			try {
				stack.Append (null);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("context", ex.ParamName, "#5");
			}
		}
Exemple #7
0
        public IDisposable CreateSession()
        {
            VerifyNotInSession();
            _errors                = new ArrayList();
            _session               = new Session(this);
            _serializersCache      = new Dictionary <System.Type, object> ();
            _instancesByNameCache  = new Dictionary <string, object> ();
            _instancesByValueCache = new Dictionary <object, string> ();
            _contextStack          = new ContextStack();

            this.OnSessionCreated(EventArgs.Empty);

            return(_session);
        }
		protected virtual void OnSessionDisposed (EventArgs e)
		{
			_errors.Clear ();
			_errors = null;
			_serializersCache.Clear ();
			_serializersCache = null;
			_instancesByNameCache.Clear ();
			_instancesByNameCache = null;
			_instancesByValueCache.Clear ();
			_instancesByValueCache = null;
			_session = null;
			_contextStack = null;
			_resolveNameHandler = null;
			_serializationCompleteHandler = null;
			
			if (SessionDisposed != null) {
				SessionDisposed (this, e);
			}
		}
		public IDisposable CreateSession ()
		{
			_errors = new ArrayList ();
			_session = new Session (this);
			_serializersCache = new Dictionary<System.Type,object> ();
			_instancesByNameCache = new Dictionary<string,object> ();
			_instancesByValueCache = new Dictionary<object, string> ();
			_contextStack = new ContextStack ();
			
			this.OnSessionCreated (EventArgs.Empty);
			if (_serializationCompleteHandler != null)
				_serializationCompleteHandler (this, EventArgs.Empty);

			return _session;
		}
		///     This ends the loading process.  This resets the state
		///     of the serialization manager and merges the provided
		///     error collection into the manager's own error list and
		///     returns the merged list.
		internal ICollection Terminate(ICollection errors) 
		{

			// Let interested parties know that we're finished.
			//
			try 
			{
				if (_serializationCompleteEventHandler != null) 
				{
					_serializationCompleteEventHandler(this, EventArgs.Empty);
				}
			}
			catch {}

			// Merge the error list
			//
			if (_errorList != null && _errorList.Count > 0) 
			{
				if (errors != null && errors.Count > 0) 
				{
					_errorList.AddRange(errors);
				}
				errors = _errorList;
			}

			// Now disolve our state.  The serialization manager
			// should remain stateless.
			//
			_resolveNameEventHandler = null;
			_serializationCompleteEventHandler = null;
			_instancesByName = null;
			_namesByInstance = null;
			_serializers = null;
			_errorList = null;
			_contextStack = null;

			return errors;
		}
Exemple #11
0
		[Test] // Item (Type)
		public void Indexer2_Type_Null ()
		{
			ContextStack stack = new ContextStack ();
			stack.Push (new Foo ());
			try {
				object context = stack [(Type) null];
				Assert.Fail ("#1:" + context);
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("type", ex.ParamName, "#5");
			}
		}
Exemple #12
0
		[Test] // Item (Type)
		public void Indexer2 ()
		{
			ContextStack stack = new ContextStack ();

			Foo foo = new Foo ();
			FooBar foobar = new FooBar ();

			stack.Push (foobar);
			stack.Push (foo);
			Assert.AreSame (foo, stack [typeof (Foo)], "#1");
			Assert.AreSame (foo, stack [typeof (IFoo)], "#2");
			Assert.AreSame (foo, stack.Pop (), "#3");
			Assert.AreSame (foobar, stack [typeof (Foo)], "#4");
			Assert.AreSame (foobar, stack [typeof (FooBar)], "#5");
			Assert.AreSame (foobar, stack [typeof (IFoo)], "#6");
			Assert.IsNull (stack [typeof (string)], "#7");
		}
Exemple #13
0
        [Fact] // Item (Int32)
        public void Indexer1_Level_Negative()
        {
            ContextStack stack = new ContextStack();
            stack.Push(new Foo());
            ArgumentOutOfRangeException ex;

            ex = Assert.Throws<ArgumentOutOfRangeException>(() => stack[-1]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);


            ex = Assert.Throws<ArgumentOutOfRangeException>(() => stack[-5]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);
        }
 protected virtual void OnSessionDisposed(EventArgs e)
 {
     try
     {
         try
         {
             if (this.sessionDisposedEventHandler != null)
             {
                 this.sessionDisposedEventHandler(this, e);
             }
         }
         finally
         {
             if (this.serializationCompleteEventHandler != null)
             {
                 this.serializationCompleteEventHandler(this, EventArgs.Empty);
             }
         }
     }
     finally
     {
         this.resolveNameEventHandler = null;
         this.serializationCompleteEventHandler = null;
         this.instancesByName = null;
         this.namesByInstance = null;
         this.serializers = null;
         this.contextStack = null;
         this.errorList = null;
         this.session = null;
     }
 }
Exemple #15
0
        [Fact] // Item (Int32)
        public void Indexer1()
        {
            ContextStack stack = new ContextStack();
            string one = "one";
            string two = "two";

            stack.Push(one);
            stack.Push(two);

            Assert.Same(two, stack[0]);
            Assert.Same(one, stack[1]);
            Assert.Null(stack[2]);
            Assert.Same(two, stack.Pop());
            Assert.Same(one, stack[0]);
            Assert.Null(stack[1]);
            Assert.Same(one, stack.Pop());
            Assert.Null(stack[0]);
            Assert.Null(stack[1]);
        }
Exemple #16
0
 [Fact] // Item (Type)
 public void Indexer2_Type_Null()
 {
     ContextStack stack = new ContextStack();
     stack.Push(new Foo());
     ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() => stack[(Type)null]);
     Assert.Equal(typeof(ArgumentNullException), ex.GetType());
     Assert.Null(ex.InnerException);
     Assert.NotNull(ex.Message);
     Assert.Equal("type", ex.ParamName);
 }
Exemple #17
0
        [Fact] // Item (Type)
        public void Indexer2()
        {
            ContextStack stack = new ContextStack();

            Foo foo = new Foo();
            FooBar foobar = new FooBar();

            stack.Push(foobar);
            stack.Push(foo);
            Assert.Same(foo, stack[typeof(Foo)]);
            Assert.Same(foo, stack[typeof(IFoo)]);
            Assert.Same(foo, stack.Pop());
            Assert.Same(foobar, stack[typeof(Foo)]);
            Assert.Same(foobar, stack[typeof(FooBar)]);
            Assert.Same(foobar, stack[typeof(IFoo)]);
            Assert.Null(stack[typeof(string)]);
        }
Exemple #18
0
		[Test] // Item (Int32)
		public void Indexer1_Level_Negative ()
		{
			ContextStack stack = new ContextStack ();
			stack.Push (new Foo ());

			try {
				object context = stack [-1];
				Assert.Fail ("#A1:" + context);
			} catch (ArgumentOutOfRangeException ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#A4");
				Assert.AreEqual ("level", ex.ParamName, "#A5");
			}

			try {
				object context = stack [-5];
				Assert.Fail ("#B1:" + context);
			} catch (ArgumentOutOfRangeException ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#B4");
				Assert.AreEqual ("level", ex.ParamName, "#B5");
			}
		}
Exemple #19
0
		[Test] // Item (Int32)
		public void Indexer1 ()
		{
			ContextStack stack = new ContextStack ();
			string one = "one";
			string two = "two";

			stack.Push (one);
			stack.Push (two);

			Assert.AreSame (two, stack [0], "#1");
			Assert.AreSame (one, stack [1], "#2");
			Assert.IsNull (stack [2], "#3");
			Assert.AreSame (two, stack.Pop (), "#4");
			Assert.AreSame (one, stack [0], "#5");
			Assert.IsNull (stack [1], "#6");
			Assert.AreSame (one, stack.Pop (), "#7");
			Assert.IsNull (stack [0], "#8");
			Assert.IsNull (stack [1], "#9");
		}
 internal ICollection Terminate(ICollection errors)
 {
     try
     {
         if (this.SerializationComplete != null)
         {
             this.SerializationComplete(this, EventArgs.Empty);
         }
     }
     catch
     {
     }
     if ((this._errorList != null) && (this._errorList.Count > 0))
     {
         if ((errors != null) && (errors.Count > 0))
         {
             this._errorList.AddRange(errors);
         }
         errors = this._errorList;
     }
     this.ResolveName = null;
     this.SerializationComplete = null;
     this._instancesByName = null;
     this._namesByInstance = null;
     this._serializers = null;
     this._errorList = null;
     this._contextStack = null;
     return errors;
 }