private static CachedMetadata InitMetadata(BaseDomainService domainService) { EventHandler <RegisteredDMEventArgs> fn_regDM = (sender, e) => { ProcessMethodDescriptions(domainService.ServiceContainer, e.DataManagerType, (CachedMetadata)sender); }; CachedMetadata cachedMetadata = new CachedMetadata(); //called on every data manager registered while bootstrapping cachedMetadata.RegisteredDM += fn_regDM; try { InitCachedMetadata(domainService, cachedMetadata); } catch (Exception ex) { domainService._OnError(ex); throw new DummyException(ex.Message, ex); } finally { cachedMetadata.RegisteredDM -= fn_regDM; cachedMetadata.InitCompleted(); } return(cachedMetadata); }
private static void InitCachedMetadata(BaseDomainService domainService, CachedMetadata cachedMetadata) { var metadata = domainService.GetMetadata(false); foreach (var dbSetInfo in metadata.DbSets) { dbSetInfo.Initialize(domainService.ServiceContainer); //indexed by dbSetName cachedMetadata.dbSets.Add(dbSetInfo.dbSetName, dbSetInfo); } //bootstrapping domainService.Bootstrap(new ServiceConfig(cachedMetadata)); ProcessMethodDescriptions(domainService.ServiceContainer, domainService.GetType(), cachedMetadata); foreach (var assoc in metadata.Associations) { if (string.IsNullOrWhiteSpace(assoc.name)) { throw new DomainServiceException(ErrorStrings.ERR_ASSOC_EMPTY_NAME); } if (!cachedMetadata.dbSets.ContainsKey(assoc.parentDbSetName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_PARENT, assoc.name, assoc.parentDbSetName)); } if (!cachedMetadata.dbSets.ContainsKey(assoc.childDbSetName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_CHILD, assoc.name, assoc.childDbSetName)); } var childDb = cachedMetadata.dbSets[assoc.childDbSetName]; var parentDb = cachedMetadata.dbSets[assoc.parentDbSetName]; var parentDbFields = parentDb.GetFieldByNames(); var childDbFields = childDb.GetFieldByNames(); //check navigation field //dont allow to define it explicitly, the association adds the field by itself (implicitly) if (!string.IsNullOrEmpty(assoc.childToParentName) && childDbFields.ContainsKey(assoc.childToParentName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.childToParentName)); } //check navigation field //dont allow to define it explicitly, the association adds the field by itself (implicitly) if (!string.IsNullOrEmpty(assoc.parentToChildrenName) && parentDbFields.ContainsKey(assoc.parentToChildrenName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.parentToChildrenName)); } if (!string.IsNullOrEmpty(assoc.parentToChildrenName) && !string.IsNullOrEmpty(assoc.childToParentName) && assoc.childToParentName == assoc.parentToChildrenName) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.parentToChildrenName)); } foreach (var frel in assoc.fieldRels) { if (!parentDbFields.ContainsKey(frel.parentField)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_PARENT_FIELD, assoc.name, frel.parentField)); } if (!childDbFields.ContainsKey(frel.childField)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_CHILD_FIELD, assoc.name, frel.childField)); } } //indexed by Name cachedMetadata.associations.Add(assoc.name, assoc); if (!string.IsNullOrEmpty(assoc.childToParentName)) { var sb = new StringBuilder(120); var dependentOn = assoc.fieldRels.Aggregate(sb, (a, b) => a.Append((a.Length == 0 ? "" : ",") + b.childField), a => a).ToString(); //add navigation field to dbSet's field collection childDb.fieldInfos.Add(new Field { fieldName = assoc.childToParentName, fieldType = FieldType.Navigation, dataType = DataType.None, dependentOn = dependentOn, _TypeScriptDataType = TypeScriptHelper.GetEntityInterfaceName(parentDb.dbSetName) }); } if (!string.IsNullOrEmpty(assoc.parentToChildrenName)) { var sb = new StringBuilder(120); //add navigation field to dbSet's field collection parentDb.fieldInfos.Add(new Field { fieldName = assoc.parentToChildrenName, fieldType = FieldType.Navigation, dataType = DataType.None, _TypeScriptDataType = string.Format("{0}[]", TypeScriptHelper.GetEntityInterfaceName(childDb.dbSetName)) }); } } //foreach (var assoc in metadata.Associations) }
/// <summary> /// Test if public methods on the service has Invoke or Query Attribute /// and generates from this methods their invocation method descriptions /// </summary> /// <returns></returns> private static void ProcessMethodDescriptions(IServiceContainer services, Type fromType, CachedMetadata metadata) { var allList = GetAllMethods(fromType); var svcMethods = GetSvcMethods(allList, services); metadata.InitSvcMethods(svcMethods); var otherMethods = allList.GetOthersOnly(); metadata.InitOperMethods(otherMethods); }