Exemplo n.º 1
0
        private void ProcessMethodDescriptions(Type fromType, MethodMap svcMethods, OperationalMethods operMethods, DbSetsDictionary dbSets, ILookup <Type, DbSetInfo> dbSetsByTypeLookUp)
        {
            IEnumerable <MethodInfoData> allList = _GetAllMethods(fromType);

            InitSvcMethods(allList.GetSvcMethods(valueConverter), svcMethods, dbSets, dbSetsByTypeLookUp);

            IEnumerable <MethodInfoData> otherMethods = allList.GetOthersOnly();

            InitOperMethods(otherMethods, operMethods, dbSetsByTypeLookUp);
        }
Exemplo n.º 2
0
 public RunTimeMetadata(DbSetsDictionary dbSets,
                        ILookup <Type, DbSetInfo> dbSetsByTypeLookUp,
                        AssociationsDictionary associations,
                        MethodMap svcMethods,
                        OperationalMethods operMethods,
                        string[] typeScriptImports)
 {
     DbSets = dbSets;
     this.dbSetsByTypeLookUp = dbSetsByTypeLookUp;
     Associations            = associations;
     _svcMethods             = svcMethods;
     _operMethods            = operMethods;
     TypeScriptImports       = typeScriptImports;
 }
Exemplo n.º 3
0
        private void InitSvcMethods(MethodsList methods, MethodMap svcMethods, DbSetsDictionary dbSets, ILookup <Type, DbSetInfo> dbSetsByTypeLookUp)
        {
            methods.ForEach(md =>
            {
                if (md.isQuery)
                {
                    //First check QueryAtrribute if it contains info for Entity Type or DbSet Name
                    QueryAttribute queryAttribute = (QueryAttribute)md.GetMethodData().MethodInfo.GetCustomAttributes(typeof(QueryAttribute), false).FirstOrDefault();

                    string dbSetName = queryAttribute.DbSetName;
                    if (!string.IsNullOrWhiteSpace(dbSetName))
                    {
                        if (!dbSets.ContainsKey(dbSetName))
                        {
                            throw new DomainServiceException(string.Format("Can not determine the DbSet for a query method: {0} by DbSetName {1}", md.methodName, dbSetName));
                        }

                        svcMethods.Add(dbSetName, md);
                    }
                    else
                    {
                        System.Type entityType = queryAttribute.EntityType ?? md.GetMethodData().EntityType;

                        IEnumerable <DbSetInfo> entityTypeDbSets = dbSetsByTypeLookUp[entityType];
                        if (!entityTypeDbSets.Any())
                        {
                            throw new DomainServiceException(string.Format("Can not determine the DbSet for a query method: {0}", md.methodName));
                        }

                        foreach (DbSetInfo dbSetInfo in entityTypeDbSets)
                        {
                            svcMethods.Add(dbSetInfo.dbSetName, md);
                        }
                    }
                }
                else
                {
                    svcMethods.Add("", md);
                }
            });
        }
Exemplo n.º 4
0
        public RunTimeMetadata Build()
        {
            DbSetsDictionary dbSets = new DbSetsDictionary();

            foreach (DbSetInfo dbSetInfo in designTimeMetadata.DbSets)
            {
                dbSets.Add(dbSetInfo.dbSetName, dbSetInfo);
            }

            foreach (DbSetInfo dbSetInfo in dbSets.Values)
            {
                dbSetInfo.Initialize(dataHelper);
            }

            ILookup <Type, DbSetInfo> dbSetsByTypeLookUp = dbSets.Values.ToLookup(v => v.GetEntityType());
            MethodMap          svcMethods  = new MethodMap();
            OperationalMethods operMethods = new OperationalMethods();

            foreach (Config.ServiceTypeDescriptor descriptor in dataManagerContainer.Descriptors)
            {
                ProcessMethodDescriptions(descriptor.ImplementationType, svcMethods, operMethods, dbSets, dbSetsByTypeLookUp);
            }

            ProcessMethodDescriptions(domainServiceType, svcMethods, operMethods, dbSets, dbSetsByTypeLookUp);

            operMethods.MakeReadOnly();
            svcMethods.MakeReadOnly();

            AssociationsDictionary associations = new AssociationsDictionary();

            foreach (Association assoc in designTimeMetadata.Associations)
            {
                ProcessAssociation(assoc, dbSets, associations);
            }

            return(new RunTimeMetadata(dbSets, dbSetsByTypeLookUp, associations, svcMethods, operMethods, designTimeMetadata.TypeScriptImports.ToArray()));
        }