コード例 #1
0
        public static void Map(ClientModel model, IMapperContext context)
        {
            var entities = new List <EntityIdDescriptor>();

            foreach (var entity in model.Entities)
            {
                var fields = new List <ScalarEntityIdDescriptor>();

                foreach (var field in entity.Fields)
                {
                    if (field.Type.NamedType() is ILeafType leafType)
                    {
                        fields.Add(
                            new ScalarEntityIdDescriptor(
                                field.Name,
                                leafType.Name,
                                model.Schema.GetOrCreateTypeInfo(leafType.GetSerializationType())));
                    }
                }

                entities.Add(
                    new EntityIdDescriptor(entity.Name, entity.Name, fields));
            }

            context.Register(
                new EntityIdFactoryDescriptor(
                    context.ClientName + "EntityIdFactory",
                    entities,
                    NamingConventions.CreateStateNamespace(context.Namespace)));
        }
コード例 #2
0
 public static void Map(
     ClientModel model,
     IMapperContext context)
 {
     context.Register(
         new StoreAccessorDescriptor(
             NamingConventions.CreateStoreAccessor(context.ClientName),
             NamingConventions.CreateStateNamespace(context.Namespace)));
 }
コード例 #3
0
        private static IEnumerable <DataTypeDescriptor> CollectDataTypes(
            ClientModel model,
            IMapperContext context)
        {
            var dataTypes = context.Types
                            .OfType <ObjectTypeDescriptor>()
                            .Where(x => x.IsData())
                            .ToList();

            var unionTypes = model.Schema.Types
                             .OfType <UnionType>()
                             .ToList();

            var dataTypeInfos = new Dictionary <NameString, DataTypeInfo>();

            foreach (ObjectTypeDescriptor dataType in dataTypes)
            {
                ObjectType objectType = model.Schema.GetType <ObjectType>(dataType.Name);

                var abstractTypes = new List <INamedType>();
                abstractTypes.AddRange(unionTypes.Where(t => t.ContainsType(dataType.Name)));
                abstractTypes.AddRange(objectType.Implements);

                if (!dataTypeInfos.TryGetValue(dataType.Name, out var dataTypeInfo))
                {
                    dataTypeInfo = new DataTypeInfo(dataType.Name, dataType.Description);
                    dataTypeInfo.AbstractTypeParentName.AddRange(
                        abstractTypes.Select(abstractType => abstractType.Name.Value));
                    dataTypeInfos.Add(dataType.Name, dataTypeInfo);
                }

                dataTypeInfo.Components.Add(dataType.RuntimeType.Name);
            }

            var handledAbstractTypes = new HashSet <string>();

            foreach (DataTypeInfo dataTypeInfo in dataTypeInfos.Values)
            {
                var implements = new List <string>();

                foreach (var abstractTypeName in dataTypeInfo.AbstractTypeParentName)
                {
                    var dataTypeInterfaceName = GetInterfaceName(abstractTypeName);
                    implements.Add(dataTypeInterfaceName);
                    if (handledAbstractTypes.Add(dataTypeInterfaceName))
                    {
                        yield return(new DataTypeDescriptor(
                                         dataTypeInterfaceName,
                                         NamingConventions.CreateStateNamespace(context.Namespace),
                                         Array.Empty <ComplexTypeDescriptor>(),
                                         Array.Empty <string>(),
                                         dataTypeInfo.Description,
                                         true));
                    }
                }

                yield return(new DataTypeDescriptor(
                                 dataTypeInfo.Name,
                                 NamingConventions.CreateStateNamespace(context.Namespace),
                                 dataTypeInfo.Components
                                 .Select(name => context.Types.Single(t => t.RuntimeType.Name.Equals(name)))
                                 .OfType <ComplexTypeDescriptor>()
                                 .ToList(),
                                 implements,
                                 dataTypeInfo.Description));
            }
        }