Exemplo n.º 1
0
        public static RunTimeMetadata GetInitializedMetadata(BaseDomainService domainService,
                                                             IDataHelper dataHelper,
                                                             IValueConverter valueConverter)
        {
            RunTimeMetadata result = _metadataCache.GetOrAdd(domainService.GetType(), (svcType) =>
            {
                RunTimeMetadata runTimeMetadata = null;

                try
                {
                    DesignTimeMetadata designTimeMetadata      = ((IMetaDataProvider)domainService).GetDesignTimeMetadata(false);
                    IDataManagerContainer dataManagerContainer = domainService.ServiceContainer.DataManagerContainer;
                    runTimeMetadata = _InitMetadata(domainService, designTimeMetadata, dataHelper, valueConverter, dataManagerContainer);
                }
                catch (Exception ex)
                {
                    domainService._OnError(ex);
                    throw new DummyException(ex.Message, ex);
                }

                return(runTimeMetadata);
            });

            return(result);
        }
Exemplo n.º 2
0
 public RunTimeMetadataBuilder(Type domainServiceType,
                               DesignTimeMetadata designTimeMetadata,
                               IDataHelper dataHelper,
                               IValueConverter valueConverter,
                               IDataManagerContainer dataManagerContainer)
 {
     this.domainServiceType    = domainServiceType;
     this.designTimeMetadata   = designTimeMetadata;
     this.dataHelper           = dataHelper;
     this.valueConverter       = valueConverter;
     this.dataManagerContainer = dataManagerContainer;
 }
Exemplo n.º 3
0
        private static RunTimeMetadata _InitMetadata(BaseDomainService domainService,
                                                     DesignTimeMetadata designTimeMetadata,
                                                     IDataHelper dataHelper,
                                                     IValueConverter valueConverter,
                                                     IDataManagerContainer dataManagerContainer)
        {
            RunTimeMetadataBuilder runTimeMetadataBuilder = new RunTimeMetadataBuilder(domainService.GetType(), designTimeMetadata, dataHelper, valueConverter, dataManagerContainer);

            try
            {
                return(runTimeMetadataBuilder.Build());
            }
            catch (Exception ex)
            {
                domainService._OnError(ex);
                throw new DummyException(ex.Message, ex);
            }
        }
Exemplo n.º 4
0
        public static DesignTimeMetadata FromXML(string xml)
        {
            DesignTimeMetadata metadata  = new DesignTimeMetadata();
            XDocument          xdoc      = XDocument.Parse(xml);
            XElement           xmetadata = xdoc.Element(NS_DATA + "Metadata");
            XElement           xdbSets   = xmetadata.Element(NS_DATA + "Metadata.DbSets");
            IEnumerable <XProcessingInstruction> ximports = xmetadata.Nodes().Where(n => n is XProcessingInstruction && (n as XProcessingInstruction).Target == "import").Cast <XProcessingInstruction>();

            foreach (XProcessingInstruction xpc in ximports)
            {
                metadata.TypeScriptImports.Add(xpc.Data);
            }

            if (xdbSets != null)
            {
                foreach (XElement xdbSet in xdbSets.Elements(NS_DATA + "DbSetInfo"))
                {
                    string xType       = xdbSet.Attribute("EntityType").Value;
                    Type   _entityType = _GetTypeFromXType(xType, xdoc);

                    DbSetInfo dbSetInfo = new DbSetInfo
                    {
                        dbSetName = (string)xdbSet.Attribute("dbSetName")
                    };
                    dbSetInfo.SetEntityType(_entityType);

                    if (xdbSet.Attributes("enablePaging").Any())
                    {
                        dbSetInfo.enablePaging = (bool)xdbSet.Attribute("enablePaging");
                    }

                    if (xdbSet.Attributes("pageSize").Any())
                    {
                        dbSetInfo.pageSize = (int)xdbSet.Attribute("pageSize");
                    }

                    if (xdbSet.Attributes("isTrackChanges").Any())
                    {
                        dbSetInfo.SetIsTrackChanges((bool)xdbSet.Attribute("isTrackChanges"));
                    }

                    metadata.DbSets.Add(dbSetInfo);

                    XElement xFields = xdbSet.Element(NS_DATA + "DbSetInfo.fieldInfos");
                    IEnumerable <XElement> fields = xFields.Elements(NS_DATA + "Field");
                    dbSetInfo.fieldInfos.AddRange(_XElementsToFieldList(fields));
                }
            }

            XElement xAssocs = xmetadata.Element(NS_DATA + "Metadata.Associations");

            if (xAssocs != null)
            {
                foreach (XElement xAssoc in xAssocs.Elements(NS_DATA + "Association"))
                {
                    Association assoc = new Association
                    {
                        name = (string)xAssoc.Attribute("name")
                    };
                    if (xAssoc.Attributes("parentDbSetName").Any())
                    {
                        assoc.parentDbSetName = (string)xAssoc.Attribute("parentDbSetName");
                    }

                    if (xAssoc.Attributes("childDbSetName").Any())
                    {
                        assoc.childDbSetName = (string)xAssoc.Attribute("childDbSetName");
                    }

                    if (xAssoc.Attributes("childToParentName").Any())
                    {
                        assoc.childToParentName = (string)xAssoc.Attribute("childToParentName");
                    }

                    if (xAssoc.Attributes("parentToChildrenName").Any())
                    {
                        assoc.parentToChildrenName = (string)xAssoc.Attribute("parentToChildrenName");
                    }

                    if (xAssoc.Attributes("onDeleteAction").Any())
                    {
                        assoc.onDeleteAction =
                            (DeleteAction)Enum.Parse(typeof(DeleteAction), xAssoc.Attribute("onDeleteAction").Value);
                    }

                    XElement xFieldRels = xAssoc.Element(NS_DATA + "Association.fieldRels");
                    if (xFieldRels != null)
                    {
                        foreach (XElement xFieldRel in xFieldRels.Elements(NS_DATA + "FieldRel"))
                        {
                            FieldRel fldRel = new FieldRel
                            {
                                parentField = (string)xFieldRel.Attribute("parentField"),
                                childField  = (string)xFieldRel.Attribute("childField")
                            };
                            assoc.fieldRels.Add(fldRel);
                        }
                    }

                    metadata.Associations.Add(assoc);
                }
            }

            return(metadata);
        }