public void Create_With_Indexed_And_Dynamic_Syntaxes()
		{
			DeepObject obj = new DeepObject();
			obj["FirstName"] = "James";
			obj["LastName"] = "Bond";
			ConsoleEx.WriteLine("\n> {0}", obj);
			Assert.AreEqual(
				"{[{FirstName='James'}, {LastName='Bond'}]}"
				, obj.ToString());

			dynamic d = obj;
			d.Age = 50;
			d.Roles[0] = "Spy";
			d.Roles[1] = "Lover";
			d.Books["1965", 5] = "Thunderball";
			d.Gear.Gun = true;
			d.Gear.Knife = false;
			ConsoleEx.WriteLine("\n> {0}", obj);
			Assert.AreEqual(
				"{[" + "{FirstName='James'}, {LastName='Bond'}, {Age='50'}, " +
				"{Roles [{[0]='Spy'}, {[1]='Lover'}]}, " +
				"{Books [{[1965, 5]='Thunderball'}]}, " +
				"{Gear [{Gun='True'}, {Knife='False'}]}" + "]}"
				, obj.ToString());
		}
		public void Dynamic_Adding()
		{
			var obj = new DeepObject();
			dynamic d = obj;

			d.DeepAdd("James"); Assert.AreEqual("{[{James}]}", obj.ToString());

			obj.DeepClear();
			d["Bond"] = "Spy"; Assert.AreEqual("{[{Bond='Spy'}]}", obj.ToString());
		}
		public void Null_Indexes()
		{
			var obj = new DeepObject();
			obj[null] = "Hello";
			Assert.AreEqual("{[{[]='Hello'}]}", obj.ToString());

			obj = new DeepObject();
			obj[null, null] = "Hello";
			Assert.AreEqual("{[{[, ]='Hello'}]}", obj.ToString());
		}
Esempio n. 4
0
		/// <summary>
		/// Creates a new	<see cref="KLinkWCF"/> for the personality of the database defined by the factory argument, and
		/// connects to the service located by the endpoint argument using the connection package given.
		/// </summary>
		/// <param name="factory">The factory defining the personality of the database.</param>
		/// <param name="endpoint">The endpoint to use to locate the WCF service.</param>
		/// <param name="package">The connection package to use by the service to modulate how it will connect with the real
		/// underlying database, if needed, or null if it is not needed.</param>
		public KLinkWCF( IKFactory factory, string endpoint, DeepObject package = null ) : base( factory )
		{
			DEBUG.IndentLine( "\n-- KLinkWCF( Factory, EndPoint={0}, Package={1} )", endpoint ?? "<null>", package == null ? "<null>" : package.ToString() );
			ProxyConnect( endpoint, package );
			DEBUG.Unindent();
		}
Esempio n. 5
0
		/// <summary>
		/// Connects this link object with the WCF service. If it has been already connected, an exceptio will be thrown.
		/// </summary>
		/// <param name="endpoint">The endpoint to use to locate the WCF service.</param>
		/// <param name="package">The connection package to use by the service to modulate how it will connect with the real
		/// underlying database, if needed, or null if it is not needed.</param>
		public virtual void ProxyConnect( string endpoint, DeepObject package )
		{
			DEBUG.IndentLine( "\n-- KLinkWCF.ProxyConnect( EndPoint={0}, Package={1}", endpoint ?? "<null>", package == null ? "<null>" : package.ToString() );

			if( _Proxy != null ) throw new InvalidOperationException( "This link is already connected." );
			_EndPoint = endpoint.Validated( "EndPoint" );
			_Package = package;

			var channelFactory = new ChannelFactory<IKProxyWCF>( _EndPoint );
			_Proxy = channelFactory.CreateChannel();
			_ProxyId = _Proxy.ProxyConnect( _Package );

			DEBUG.WriteLine( "\n-- Connected with UID = {0}", _ProxyId.TagString() );
			DEBUG.Unindent();
		}
Esempio n. 6
0
		/// <summary>
		/// Connects to the underlying database, creating the actual link object, using the optional connection package that
		/// might have been provided. This connection package is a dynamic object, an instance of <see cref="DeepObject"/>,
		/// able to carry an arbitrary number of properties and values as needed.
		/// <para>If this proxy is already connected with an underlying database, an exception will be thrown.</para>
		/// </summary>
		/// <param name="package">The connection package to use, or null.</param>
		/// <returns>The Guid of this proxy.</returns>
		public virtual Guid ProxyConnect( DeepObject package )
		{
			DEBUG.IndentLine( "\n-- [{0}] KServerWCF.ProxyConnect( Package={1} )", _ProxyId.TagString(), package == null ? "<null>" : package.ToString() );
			try {
				if( _Link != null ) throw new InvalidOperationException( "WCF Server is already connected." );

				_Package = package;
				_Link = CreateLink();
				if( _Link == null ) throw new InvalidOperationException( "Cannot create WCF Server's surrogate Link instance." );

				_Link.TransactionMode = GetDefaultTransactionMode();
				return _ProxyId;
			}
			catch( Exception e ) { DEBUG.PrintException( e ); throw; }
			finally { DEBUG.Unindent(); }
		}