Exemplo n.º 1
0
        public static async Task <TableEntity> ToDataAsync(dynamic documentObjectOrPath, CdmManifestDefinition manifest, CdmCorpusContext ctx,
                                                           ResolveOptions resOpt, CopyOptions options)
        {
            if (documentObjectOrPath is string)
            {
                dynamic obje = await ctx.Corpus.FetchObjectAsync <CdmEntityDefinition>(documentObjectOrPath, manifest);

                if (obje is CdmEntityDefinition cdmEntity)
                {
                    var             tableEntity  = EntityPersistence.ToData(cdmEntity, ctx, resOpt, options);
                    TableProperties teProperties = (TableProperties)tableEntity.Properties;
                    teProperties.NamespaceProperty = new TableNamespace
                    {
                        DatabaseName = manifest.ManifestName
                    };

                    if (cdmEntity.Owner != null && cdmEntity.Owner is CdmDocumentDefinition document)
                    {
                        if (document.Imports.Count > 0)
                        {
                            var Imports = Utils.ListCopyData <Import>(resOpt, document.Imports, options);
                            teProperties.Properties["cdm:imports"] = JToken.FromObject(Imports);
                        }
                    }
                    else
                    {
                        Logger.Warning(ctx, Tag, nameof(ToDataAsync), manifest.AtCorpusPath, CdmLogCode.WarnPersistSymsEntityMissing, cdmEntity.GetName());
                    }
                    return(tableEntity);
                }
                else
                {
                    Logger.Error(ctx, Tag, nameof(ToDataAsync), manifest.AtCorpusPath, CdmLogCode.ErrPersistSymsEntityFetchError, documentObjectOrPath);
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public static TableEntity ToData(CdmCorpusContext ctx, CdmDocumentDefinition doc, TableProperties currentTableProperties, ResolveOptions resOpt, CopyOptions options)
        {
            if (currentTableProperties == null)
            {
                return(null);
            }

            if (doc.Definitions.Count == 0 || doc.Definitions.Count > 1)
            {
                Logger.Error((ResolveContext)ctx, Tag, nameof(ToData), doc.AtCorpusPath, CdmLogCode.ErrPersistSymsMultipleOrZeroTableDefinition, doc.Name);
                return(null);
            }
            if (doc.Definitions[0] is CdmEntityDefinition cdmEntity)
            {
                var             tableEntity  = EntityPersistence.ToData(cdmEntity, ctx, resOpt, options);
                TableProperties teProperties = (TableProperties)tableEntity.Properties;

                if (cdmEntity.Owner != null && cdmEntity.Owner is CdmDocumentDefinition document)
                {
                    if (document.Imports.Count > 0)
                    {
                        var Imports = Utils.ListCopyData <Import>(resOpt, document.Imports, options);
                        teProperties.Properties["cdm:imports"] = JToken.FromObject(Imports);
                    }
                }

                teProperties.NamespaceProperty        = currentTableProperties.NamespaceProperty;
                teProperties.StorageDescriptor.Source = currentTableProperties.StorageDescriptor.Source;
                teProperties.StorageDescriptor.Format = currentTableProperties.StorageDescriptor.Format;
                teProperties.Partitioning             = currentTableProperties.Partitioning;

                tableEntity.Properties = teProperties;
                return(tableEntity);
            }
            return(null);
        }