private Maybe<Exception> Create(EntityDefinition definition, string templatePath, string @namespace, string filename)
 {
     var path = _projectPath.CombinePath(@namespace.Replace('.', Path.DirectorySeparatorChar)).CombinePath(filename).AppendExtension("cs");
     var table = _data.GetTableDefinition(definition.Server, definition.Database, definition.Table);
     var result = _templateService.Render(templatePath, path, definition.ToDictionary(_defaultNamespace).Concat(table.ToDictionary()));
     return result.Success ?
         Maybe.Nothing<Exception>() :
         Maybe.Just<Exception>(CompositeException.Create(result.Errors));
 }
 public Maybe<EntityDefinition> Display(string defaultEntityName, 
     Func<EntityDefinition, Maybe<Exception>> createEntity,
     Func<EntityDefinition, Maybe<Exception>> createMapping,
     Func<EntityDefinition, Tuple<Maybe<Exception>, string>> previewEntityOperation,
     Func<EntityDefinition, Tuple<Maybe<Exception>, string>> previewMappingOperation)
 {
     _createEntity = createEntity;
     _createMapping = createMapping;
     _previewEntityOperation = previewEntityOperation;
     _previewMappingOperation = previewMappingOperation;
     DataContext = new EntityDefinition { Server = "localhost", EntityName = defaultEntityName };
     return ShowDialog() == true
                ? Maybe.Just((EntityDefinition)DataContext)
                : Maybe.Nothing<EntityDefinition>();
 }
        public void Properly_Convert_To_Dictionary()
        {
            var entityDefinition = new EntityDefinition()
            {
                EntityName = "SomeEntity",
                Namespace = "Yada.Stuff",
            };

            var parameters = entityDefinition.ToDictionary("Default.Namespace");

            parameters.Count.ShouldEqual(4);

            parameters["entityName"].ShouldEqual("SomeEntity");
            parameters["mappingName"].ShouldEqual("SomeEntityMap");
            parameters["entityNamespace"].ShouldEqual("Default.Namespace.Domain.Yada.Stuff");
            parameters["mappingNamespace"].ShouldEqual("Default.Namespace.Infrastructure.Persistence.Mapping.Yada.Stuff");
        }
 public Maybe<EntityDefinition> Display(string defaultEntityName, 
     Func<EntityDefinition,Maybe<Exception>> createEntity,
     Func<EntityDefinition,Maybe<Exception>> createMapping,
     Func<EntityDefinition,Tuple<Maybe<Exception>,string>> previewEntityOperation,
     Func<EntityDefinition,Tuple<Maybe<Exception>,string>> previewMappingOperation)
 {
     var entityDefinition = new EntityDefinition { Database = string.Empty, Server = string.Empty, Table = string.Empty,
                                                   EntityName = string.Empty, Namespace = string.Empty};
     switch (_operation)
     {
         case Operation.Create: return createEntity(entityDefinition).Bind(x => createMapping(entityDefinition)).HasValue ?
                                             Maybe.Just(entityDefinition) : Maybe.Nothing<EntityDefinition>();
         case Operation.PreviewOperation: return previewEntityOperation(entityDefinition).ToMaybe().Bind(x => x.Item1).
                                                 Bind(x => previewMappingOperation(entityDefinition).ToMaybe()).Bind(x => x.Item1).HasValue ?
                                             Maybe.Just(entityDefinition) : Maybe.Nothing<EntityDefinition>();
     }
     return null;
 }
 private Tuple<Maybe<Exception>, string> Generate(EntityDefinition definition, string templatePath)
 {
     var table = _data.GetTableDefinition(definition.Server, definition.Database, definition.Table);
     var result = _templateService.Render(templatePath, definition.ToDictionary(_defaultNamespace).Concat(table.ToDictionary()));
     return Tuple.Create(result.Success ?
         Maybe.Nothing<Exception>() :
         Maybe.Just<Exception>(CompositeException.Create(result.Errors)), result.Output);
 }