public void BuildAggregateRoot(BoundedContext context)
        {
            this.WriteLine("public partial class "+context.Element.Name +" : IAggregateRoot,");
            this.PushIndent("\t");
            this.WriteLine("IMemento<IAggregateState>,");
            BuildCommandHandlerInterfaces(context);
            this.WriteLine("{");
            this.PushIndent("\t");
            this.WriteLine("internal AccountState _state = null;");
            this.WriteLine("internal IRepository _repository = null;");
            this.WriteLine("private readonly Func<MyMessageContext> _contextFactory;");
            //public Account()
            //{
            //    _state = new AccountState();
            //}

            //public Account(IRepository repository, Func<MyMessageContext> contextFactory)
            //{
            //    _state = new AccountState();
            //    _repository = repository;
            //    _contextFactory = contextFactory;
            //}

            //public Account(IRepository repository, AccountState state)
            //{
            //    _state = state;
            //    _repository = repository;
            //}

            //public Account(IRepository repository, Guid accountNumber)
            //{
            //    _repository = repository;
            //    _state = _repository.GetStateById<AccountState>(accountNumber);
            //}
        }
 public void BuildEventInterfaceMethodsWithContext(BoundedContext context)
 {
     this.PushIndent("\t\t");
     foreach (DomainEvent evt in context.Element.AggregateState.DomainEvents)
     {
         this.WriteLine("void When(" + evt.Name + " e, MessageContext context);");
     }
     this.PopIndent();
 }
 public void BuildCommandInterfaceMethods(BoundedContext context)
 {
     this.PushIndent("\t\t");
     foreach(DomainCommand command in context.Element.DomainCommands)
     {
         this.WriteLine("void When(" + command.Name + " c);");
     }
     this.PopIndent();
 }
 public void BuildCommandInterfaceMethodsWithContext(BoundedContext context)
 {
     this.PushIndent("\t\t");
     foreach (DomainCommand command in context.Element.DomainCommands)
     {
         if(!string.IsNullOrEmpty(command.RequiredPrivilege))
         {
             this.WriteLine("[RequiresPrivilege(\"" + command.RequiredPrivilege + "\")]");
         }
         this.WriteLine("void When(" + command.Name + " c, MessageContext context);");
     }
     this.PopIndent();
 }
 public void BuildCommandHandlerInterfaces(BoundedContext context)
 {
     int count = 0;
     foreach (DomainCommand cmd in context.DomainCommands)
     {
         if (count == 0)
         {
             this.WriteLine("Define.Handle<" + cmd.Name + ">");
             this.PushIndent("\t");
         }
         else
         {
             this.WriteLine(this.CurrentIndent + ", Define.Handle<" + cmd.Name + ">");
         }
         count++;
     }
     this.PopIndent();
 }
 public void BuildEventInterfaceMethods(BoundedContext context)
 {
     //void When(UserCreated c);
     this.PushIndent("\t\t");
     foreach (DomainEvent evt in context.Element.AggregateState.DomainEvents)
     {
         this.WriteLine("void When(" + evt.Name + " e);");
     }
     this.PopIndent();
 }
Example #7
0
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string modelFileName, DizzleDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (string.IsNullOrEmpty(modelFileName))
				throw new global::System.ArgumentNullException("modelFileName");
			if (diagram == null)
				throw new global::System.ArgumentNullException("diagram");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			if (serializationResult.Failed)
				return;
	
			// Save the model file first
			using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue))
			{
				if (serializationResult.Failed)
					return;
	
				using (global::System.IO.MemoryStream diagramFileContent = this.InternalSaveDiagram(serializationResult, diagram, diagramFileName, encoding, writeOptionalPropertiesWithDefaultValue))
				{
					if (!serializationResult.Failed)
					{
						// Only write the contents if there's no error encountered during serialization.
						if (modelFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(modelFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(modelFileContent.ToArray());
								}
							}
						}
						if (diagramFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(diagramFileContent.ToArray());
								}
							}
						}
					}
				}
			}
		}
Example #8
0
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8).
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">BoundedContext instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">DizzleDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string modelFileName, DizzleDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
Example #9
0
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">BoundedContext instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">DizzleDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string modelFileName, DizzleDiagram diagram, string diagramFileName)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false);
		}
 public string GetAggregateRootName(BoundedContext context)
 {
     if (context != null && context.Element != null)
         return context.Element.Name;
     else return "Aggregate Root name cannot be obtained. Make sure your model contains an aggregate root with a name";
 }
 public string GetAggregateStateName(BoundedContext context)
 {
     return context.Element.AggregateState.Name;
 }
 public string GetAggregateStateDescription(BoundedContext context)
 {
     return context.Element.AggregateState.Description;
 }
Example #13
0
		/// <summary>
		/// Saves the given model root to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">BoundedContext instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the BoundedContext instance will be saved.</param>
		public virtual void SaveModel(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string fileName)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, false);
		}
 public string GetAggregateStateName(BoundedContext context)
 {
     if (context != null && context.Element != null && context.Element.AggregateState != null)
         return context.Element.AggregateState.Name;
     else return "Aggregate State has not been defined for the Aggregate Root.  Please make sure you define the State object and link it to the root";
 }
 public string GetAggregateStateIdType(BoundedContext context)
 {
     if (context != null && context.Element != null && context.Element.AggregateState != null)
         return context.Element.AggregateState.Properties.OrderBy(prop=>prop.Order).First().Type;
     return "object";
 }
 public string GetAggregateRootName(BoundedContext context)
 {
     return context.Element.Name;
 }
Example #17
0
		/// <summary>
		/// Saves the given model to the given file, with default encoding (UTF-8).
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">BoundedContext instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the BoundedContext instance will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		public virtual void SaveModel(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string fileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
 public string GetAggregateStateIdType(BoundedContext context)
 {
     return context.Element.AggregateState.Properties.OrderBy(prop=>prop.Order).First().Type;
 }
Example #19
0
		private global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, BoundedContext modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(modelRoot != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
	
			serializationResult.Encoding = encoding;
	
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);
	
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
			this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
			// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
			serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
			global::System.Xml.XmlWriterSettings settings = DizzleSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
			using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
			{
				this.WriteRootElement(serializationContext, modelRoot, writer);
			}
				
			return newFileContent;
		}
Example #20
0
		/// <summary>
		/// Helper method to create and initialize a new BoundedContext.
		/// </summary>
		internal protected virtual BoundedContext CreateModelHelper(DslModeling::Partition modelPartition)
		{
			BoundedContext model = new BoundedContext(modelPartition);
			return model;
		}
 public string GetAggregateRootDescription(BoundedContext context)
 {
     if (context != null && context.Element != null)
         return context.Element.Description;
     else return "Aggregate Root description cannot be obtained. Make sure your model contains an aggregate root with a description";
 }