Пример #1
0
        private static string ExtractTypeScriptName(ITypeMetadata metadata)
        {
            var fullName = metadata.IsNullable ? metadata.FullName.TrimEnd('?') : metadata.FullName;

            switch (fullName)
            {
                case "System.Boolean":
                    return "boolean";
                case "System.String":
                case "System.Char":
                case "System.Guid":
                case "System.TimeSpan":
                    return "string";
                case "System.Byte":
                case "System.SByte":
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                case "System.UInt16":
                case "System.UInt32":
                case "System.UInt64":
                case "System.Single":
                case "System.Double":
                case "System.Decimal":
                    return "number";
                case "System.DateTime":
                case "System.DateTimeOffset":
                    return "Date";
                case "System.Void":
                    return "void";
            }

            return metadata.IsNullable ? metadata.Name.TrimEnd('?') : metadata.Name;
        }
Пример #2
0
 private TypeImpl(ITypeMetadata metadata, Item parent)
 {
     _metadata = metadata;
     Parent = parent;
     _lazyName = new Lazy<string>(() => GetTypeScriptName(metadata));
     _lazyOriginalName = new Lazy<string>(() => GetOriginalName(metadata));
 }
Пример #3
0
        public static string GetTypeScriptName(ITypeMetadata metadata)
        {
            if (metadata == null)
                return "any";

            if (metadata.IsEnumerable)
            {
                var genericTypeArguments = metadata.GenericTypeArguments.ToList();

                if (genericTypeArguments.Count == 1)
                    return GetTypeScriptName(genericTypeArguments.FirstOrDefault()) + "[]";

                if (genericTypeArguments.Count == 2)
                {
                    var key = GetTypeScriptName(genericTypeArguments[0]);
                    var value = GetTypeScriptName(genericTypeArguments[1]);

                    return string.Concat("{ [key: ", key, "]: ", value, "; }");
                }

                return "any";
            }

            if (metadata.IsGeneric)
                return metadata.Name + string.Concat("<", string.Join(", ", metadata.GenericTypeArguments.Select(GetTypeScriptName)), ">");

            return ExtractTypeScriptName(metadata);
        }
Пример #4
0
		public InputModelFormatter(ITypeMetadata metadata)
		{
			var model = (IInputModel)Activator.CreateInstance(metadata.Type);

			if (model == null)
			{
				throw new InvalidTypeSettingException(metadata.Name, typeof(IInputModel), metadata.Type);
			}

			if (model.CommandType == null || string.IsNullOrEmpty(model.CommandType.Name))
			{
				throw new CommandTypeNotSpecifiedException(string.Format(
					"The input model {0} has not set it's CommandType property", metadata.Name));
			}

			_commandName = model.CommandType.Name;
			_modelName = metadata.Type.Name;
			_properties = metadata.Properties.Select(pi => new Property
			                                               	{
			                                               		Name = pi.Name,
			                                               		Type = pi.PropertyType.Name,
																Value = pi.PropertyType.GetDefaultValue(),
																Choices = pi.PropertyType.IsEnum ? Enum.GetNames(pi.PropertyType) : null,
																MultiChoice = pi.PropertyType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0
			                                               	}).ToList();
		}
Пример #5
0
        public static string GetOriginalName(ITypeMetadata metadata)
        {
            var name = metadata.Name;
            var fullName = metadata.IsNullable ? metadata.FullName.TrimEnd('?') : metadata.FullName;

            if (primitiveTypes.ContainsKey(fullName))
                name = primitiveTypes[fullName] + (metadata.IsNullable ? "?" : string.Empty);

            return name;
        }
Пример #6
0
		public ActionResult ViewPart(ITypeMetadata typeMetadata, IPartCollection containingCollection, string format)
		{
			ViewBag.Title = typeMetadata.Name;

            return View(new PartModel
			            	{
			            		TypeMetadata = typeMetadata,
			            		NextActionName = (containingCollection.DescriptiveName == "Commands") ? "ViewCommand" : "ViewPart",
                                AgentSytemName = containingCollection.AgentSystemName,
                                PartDescriptiveName = containingCollection.DescriptiveName,
                                PartType = typeMetadata.Type.Name
			            	});
		}
Пример #7
0
		public static IMetadataFormatter GetFormatter(ITypeMetadata metadata)
		{
			if (typeof(ICommand).IsAssignableFrom(metadata.Type))
			{
				return new CommandMetadataFormatter(metadata);
			}
			else if (typeof(IReadModel).IsAssignableFrom(metadata.Type))
			{
				return new ReadModelFormatter(metadata);
			}
			else if (typeof(IQuery).IsAssignableFrom(metadata.Type))
			{
				return new QueryFormatter(metadata);
			}
			else if (typeof(IInputModel).IsAssignableFrom(metadata.Type))
			{
				return new InputModelFormatter(metadata);
			}

			return new DefaultFormatter(metadata);
		}
 void IRelationalMappingConvention.ApplyToType(ITypeMetadata type)
 {
     ApplyToType((TypeMetadataBuilder)type);
 }
Пример #9
0
 //-----------------------------------------------------------------------------------------------------------------------------------------------------
 public void EnsureRelationalMapping(ITypeMetadata type)
 {
     var metadata = (TypeMetadataBuilder)type;
     metadata.EnsureRelationalMapping(_relationalMappingConvention);
 }
 //-----------------------------------------------------------------------------------------------------------------------------------------------------
 public EfEntityConfigurationWriter(ITypeMetadata metadata, MethodWriterBase method, Operand<DbModelBuilder> model)
 {
     _model = model;
     _method = method;
     _metadata = metadata;
 }
Пример #11
0
		public DefaultFormatter(ITypeMetadata metadata)
		{
			_metadata = metadata;
		}
Пример #12
0
        public static bool IsPrimitive(ITypeMetadata metadata)
        {
            var fullName = metadata.FullName;

            if (metadata.IsNullable)
            {
                fullName = fullName.TrimEnd('?');
            }
            else if (metadata.IsEnumerable)
            {
                var innerType = metadata.TypeArguments.FirstOrDefault();
                if (innerType != null)
                {
                    fullName = innerType.IsNullable ? innerType.FullName.TrimEnd('?') : innerType.FullName;
                }
                else
                {
                    return false;
                }
            }

            return metadata.IsEnum || primitiveTypes.ContainsKey(fullName);
        }
Пример #13
0
        public ActionResult ViewCommand(IInputModel inputModel, ITypeMetadata typeMetadata, string format)
        {
            var partCollection = typeMetadata.GetContainingPartCollection();

            ViewBag.Title = typeMetadata.Type.Name;

            ViewBag.Navigation = new FooterLinkModel
                                     {
                                         AgentSytemName = partCollection.AgentSystemName,
                                         PartDescriptiveName = partCollection.DescriptiveName,
                                         PartType = typeMetadata.Type.Name
                                     };

            ActionResult result = View("ViewCommand", inputModel);

            return result;
        }
Пример #14
0
 public static Type FromMetadata(ITypeMetadata metadata, Item parent)
 {
     return metadata == null ? null : new TypeImpl(metadata, parent);
 }
Пример #15
0
		public QueryFormatter(ITypeMetadata partMetadata)
		{
			_partMetadata = partMetadata;
			_agentMetadata = partMetadata.Type.Assembly.GetAgentMetadata();
		}
Пример #16
0
		public ReadModelFormatter(ITypeMetadata partMetadata)
		{
			_partMetadata = partMetadata;
		}
Пример #17
0
		public CommandMetadataFormatter(ITypeMetadata typeMetadata)
		{
			_typeMetadata = typeMetadata;
		}