Click here to Skip to main content
15,897,518 members
Articles / Programming Languages / C#

ObjectLounge - An Object-Oriented Database Framework

Rate me:
Please Sign up or sign in to vote.
4.07/5 (8 votes)
30 Jul 2009LGPL310 min read 44K   425   45  
Host your Domain Models "Out Of The Box" + No storage or schema needed + Transactions on Domain Models + Validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom.Compiler;
using System.Reflection;
using Technewlogic.ObjectLounge.Framework.Transactions;

namespace Technewlogic.ObjectLounge.Framework.BaseConcerns
{
	// TODO: Aus den returns returns machen
	internal static class Error
	{
		#region Helper

		private static string GetObjectDescription(object entity)
		{
			string name = entity != null ? entity.ToString() : "UNDEFINED";
			string type = entity != null ? entity.GetType().Name : "UNDEFINED";

			return name + "(" + type + ")";
		}

		#endregion

		public static StateException AggregationSlaveNotInDB(
			object master,
			object child)
		{
			return new StateException(
				"Cannot create link between '" +
				GetObjectDescription(master) + "' and '" +
				GetObjectDescription(child) + "'.");
		}

		public enum EntityStateOperation
		{
			Update,
			Insert,
			Delete
		}

		public static InvalidOperationException InvalidEntityStateOperation(
			object entity,
			EntityStateOperation operation,
			SynchronizationOperation currentState)
		{
			return new InvalidOperationException(
				"Cannot perform the operation '" + operation.ToString() + "' of the entity '" +
				GetObjectDescription(entity) + "' because it is currently in state '" + currentState.ToString() + "'.");
		}

		public static NotImplementedException EntityStateUnknown(
			object entity,
			EntityStateOperation operation,
			SynchronizationOperation currentState)
		{
			return new NotImplementedException(
				"Cannot perform the operation '" + operation.ToString() + "' of the entity '" +
				GetObjectDescription(entity) + "' because the currently state '" + currentState.ToString() + "' is unknown.");
		}

		public static InvalidOperationException EntityTypeNotRegistered(Type type)
		{
			return new InvalidOperationException(
				"There was an attempt to access an entity of type '" + type.Name + "', " +
				"but it is not registered as an entity type. To register it, create a list in " +
				"your application context and mark it with " + typeof(EntityCollectionAttribute).Name + ".");
		}

		public static InvalidOperationException CollectionElementInconsistent(
			object master,
			object child,
			bool isAdding)
		{
			return new InvalidOperationException(
				(isAdding ? "Adding" : "Removing") +
				" the elemenmt '" +
				GetObjectDescription(child) + "' to the collection of the master '" +
				GetObjectDescription(master) + "' failed because the collection " +
				(isAdding ? "already contains" : "does not contain") + 
				" the child.");
		}

		public static ModelConfigurationException ProxyCompilation(CompilerResults results)
		{
			string errorMessage = "Error in generating an entity proxy: ";
			foreach (CompilerError it in results.Errors)
				errorMessage += "\r\n" + it.ToString();

			return new ModelConfigurationException(errorMessage);
		}

		public static InvalidOperationException ListLoadTypeMismatch(
			string typeNameInList,
			Type typeToLoad)
		{
			return new InvalidOperationException(
				"Could not load the type '" + typeToLoad.Name + "' from the filesystem because " +
				"the stored type does not match ('" + typeNameInList + "').");
		}

		public static InvalidOperationException ListLoadFieldMismatch(
			string fieldNameInList,
			Type typeToLoad)
		{
			return new InvalidOperationException(
				"Could not load the type '" + typeToLoad.Name + "' from the filesystem because " +
				"the stored field '" + fieldNameInList + "' is not a member of that type.");
		}

		public static ModelConfigurationException EntitySyncNull(PropertyInfo entitySyncProperty)
		{
			return new ModelConfigurationException(
				"The property '" + entitySyncProperty.Name +
				"' of the type '" + entitySyncProperty.DeclaringType.Name +
				"' is null. Try to instanciate it in the entity class constructor.");
		}

		public static StateException ProxyExpected(object entity)
		{
			return new StateException(
				"There was an attempt to perform an operation with the object '" + 
				GetObjectDescription(entity) + "' which does not implement the IProxy interface. " +
				"Try using the proxy generator or the CreateInstance factory method of the context " +
				"to create new entities.");
		}

		public static InvalidOperationException ContextAlreadyStarted()
		{
			return new InvalidOperationException(
				"This context is already started.");
		}

		public static InvalidOperationException ContextNotStarted()
		{
			return new InvalidOperationException(
				"This context is not started yet. Use the 'Start' method of the entity context.");
		}

		// TODO: mehr Aussagen
		public static InvalidOperationException TransactionRunning()
		{
			return new InvalidOperationException(
				"Cannot perform the operation because there is a transaction running for the current thread.");
		}

		public static InvalidOperationException TransactionNotRunning()
		{
			return new InvalidOperationException(
				"Cannot perform the operation because there is no transaction running for the current thread.");
		}

		public static InvalidOperationException NoTransactionRunning()
		{
			return new InvalidOperationException(
				"Cannot perform the operation because there is no transaction running for the current thread.");
		}

		public static InvalidOperationException TransactionCommitted()
		{
			return new InvalidOperationException(
				"Cannot perform the operation because the transaction because it is committed.");
		}

		public static InvalidOperationException TransactionRolledBack()
		{
			return new InvalidOperationException(
				"Cannot perform the operation because the transaction because it is rolled back.");
		}

		//public static void EntityInTransaction(object entity, Transaction blockingTransaction)
		//{
		//    return new ConcurrencyException(
		//        "Cannot modify the entity '" + GetObjectDescription(entity) + "' " +
		//        "because the entity is currently write locked by another transaction.",
		//        blockingTransaction);
		//}

		// der TransactionDispatcher hat keinen Parent mehr
		//public static void ParentAlreadySet()
		//{
		//    return new InvalidOperationException(
		//        "The parent of a proxy communication object can only been set once.");
		//}

		public static InvalidOperationException EntityAlreadyInserted(
			object entity)
		{
			return new InvalidOperationException(
				"Cannot insert the entity '" + GetObjectDescription(entity) + "' " +
				"because it is already inserted.");
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) www.technewlogic.de
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions