Пример #1
0
        /// <summary>
        /// Creates a <see cref="LogTableDefinition" /> for the specified <see cref="FrameworkDataLog" /> object.
        /// </summary>
        /// <param name="dataLog">The <see cref="FrameworkDataLog" /> object.</param>
        /// <returns>A <see cref="LogTableDefinition" /> for the specified <see cref="FrameworkDataLog" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public static LogTableDefinition BuildTableDefinition(FrameworkDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition definition = new LogTableDefinition(dataLog.TableName, dataLog.PrimaryKeyColumn);

            foreach (DataLogPropertyInfo dataLogProperty in GetDataLogProperties(dataLog))
            {
                // Special case for session ID
                if (dataLogProperty.Name == "SessionId" && dataLogProperty.PropertyType == typeof(string))
                {
                    definition.Add(new LogTableColumn(dataLogProperty.Name, "varchar(50)", false));
                }
                else
                {
                    // Primary key should be non-null; everything else is nullable
                    bool nullable = (dataLogProperty.Name != dataLog.PrimaryKeyColumn);
                    definition.Add(new LogTableColumn(dataLogProperty.PropertyInfo, dataLogProperty.MaxLength, nullable));
                }
            }
            return(definition);
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="LogTableDefinition" /> for the specified <see cref="ActivityDataLog" /> object.
        /// </summary>
        /// <param name="dataLog">The <see cref="ActivityDataLog" /> object.</param>
        /// <returns>A <see cref="LogTableDefinition" /> for the specified <see cref="ActivityDataLog" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public static LogTableDefinition BuildTableDefinition(ActivityDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition definition = new LogTableDefinition(dataLog.TableName);

            foreach (DataLogPropertyInfo dataLogProperty in GetDataLogProperties(dataLog))
            {
                switch (dataLogProperty.Name)
                {
                // Special cases for base class properties
                case nameof(ActivityDataLog.RecordId):
                    definition.Add(new LogTableColumn(definition.PrimaryKey, "uniqueidentifier", false));
                    break;

                case nameof(ActivityDataLog.SessionId):
                    definition.Add(new LogTableColumn(dataLogProperty.Name, "varchar(50)", false));
                    break;

                case nameof(ActivityDataLog.ActivityExecutionId):
                    definition.Add(new LogTableColumn(dataLogProperty.Name, "uniqueidentifier", false));
                    break;

                default:
                    definition.Add(new LogTableColumn(dataLogProperty.PropertyInfo, dataLogProperty.MaxLength, true));
                    break;
                }
            }
            return(definition);
        }