コード例 #1
0
    protected override void Visit(VisitPath path, NotionPropertyValue propertyValue)
    {
        propertyValue.Configuration = Option.None;
        if (!path.Previous.HasValue || !propertyValue.Id.HasValue)
        {
            return;
        }

        var optionalPageObject = path.FindPrevious <PageObject>();

        if (!optionalPageObject.HasValue)
        {
            _logger.LogWarning(
                "Parent for property value with id: {PropertyId} is not a page, this is not expected. Path: {Path}",
                propertyValue.Id.Value, path.ToString());
            return;
        }

        var pageObject = optionalPageObject.Value;

        propertyValue.Container = pageObject;

        if (!pageObject.Container.HasValue)
        {
            _logger.LogWarning("Container for page: {PageId} is not set", pageObject.Id);
            return;
        }

        if (!(pageObject.Container.Value is DatabaseObject parentDatabase))
        {
            _logger.LogWarning(
                "Container for page: {PageId} is not a database, yet it has properties. This is not expected",
                pageObject.Id);
            return;
        }

        var propertyConfigurationId = propertyValue.Id.Value;
        var propertyConfiguration   = _notionCache.GetPropertyConfiguration(parentDatabase.Id, propertyConfigurationId);

        if (!propertyConfiguration.HasValue)
        {
            _logger.LogTrace(
                "Could not find property configuration for id: {PropertyConfigurationId}, in database: {DatabaseId} for page: {PageId}",
                propertyConfigurationId, parentDatabase.Id, pageObject.Id);
            return;
        }

        propertyValue.Configuration = propertyConfiguration.Value;
    }