Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Asynchronously updates an existing log record using data from the specified <see cref="ActivityDataLog" />.
        /// </summary>
        /// <param name="dataLog">The <see cref="ActivityDataLog" />.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public void UpdateAsync(ActivityDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition table  = DataLogTranslator.BuildTableDefinition(dataLog);
            LogTableRecord     record = DataLogTranslator.BuildUpdateRecord(dataLog);

            Task.Factory.StartNew(() => Update(table, record));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates an existing log record using data from the specified <see cref="ActivityDataLog" />.
        /// </summary>
        /// <param name="dataLog">The <see cref="ActivityDataLog" />.</param>
        /// <returns><c>true</c> if update was successful, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public bool Update(ActivityDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition table  = DataLogTranslator.BuildTableDefinition(dataLog);
            LogTableRecord     record = DataLogTranslator.BuildUpdateRecord(dataLog);

            return(Update(table, record));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Asynchronously submits the specified <see cref="FrameworkDataLog" /> as a new log record.
        /// </summary>
        /// <param name="dataLog">The <see cref="FrameworkDataLog" />.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public void SubmitAsync(FrameworkDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition table  = DataLogTranslator.BuildTableDefinition(dataLog);
            LogTableRecord     record = DataLogTranslator.BuildInsertRecord(dataLog);

            Task.Factory.StartNew(() => Submit(table, record));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Submits the specified <see cref="FrameworkDataLog" /> as a new log record.
        /// </summary>
        /// <param name="dataLog">The <see cref="FrameworkDataLog" />.</param>
        /// <returns><c>true</c> if submission was successful, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="dataLog" /> is null.</exception>
        public bool Submit(FrameworkDataLog dataLog)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            LogTableDefinition table  = DataLogTranslator.BuildTableDefinition(dataLog);
            LogTableRecord     record = DataLogTranslator.BuildInsertRecord(dataLog);

            return(Submit(table, record));
        }
Exemplo n.º 7
0
        private bool Update(LogTableDefinition table, LogTableRecord record)
        {
            LogTrace($"Submitting UPDATE to table {table.Name} (primary key = {record[table.PrimaryKey]})");

            bool success = false;

            using (DataLogServiceClient client = new DataLogServiceClient(_dataLogServiceAddress))
            {
                void update() => success = client.Update(table, record);

                Retry.WhileThrowing <CommunicationException>(update, 10, TimeSpan.FromSeconds(1));
            }

            if (!success)
            {
                LogWarn($"Data Log update for {table.Name} failed.");
            }

            return(success);
        }
Exemplo n.º 8
0
        private static LogTableRecord BuildRecord(ActivityDataLog dataLog, bool insert)
        {
            if (dataLog == null)
            {
                throw new ArgumentNullException(nameof(dataLog));
            }

            // Build the table definition so that we can use the primary key
            LogTableDefinition tableDefinition = new LogTableDefinition(dataLog.TableName);

            LogTableRecord record = new LogTableRecord();

            foreach (DataLogPropertyInfo dataLogProperty in GetDataLogProperties(dataLog))
            {
                bool isPrimaryKey = dataLogProperty.Name.Equals(nameof(ActivityDataLog.RecordId));
                if (insert || dataLogProperty.IncludeInUpdates || isPrimaryKey)
                {
                    // Special case: change "RecordId" to the primary key name
                    string columnName = isPrimaryKey ? tableDefinition.PrimaryKey : dataLogProperty.Name;
                    record.Add(columnName, GetPropertyValue(dataLogProperty, dataLog));
                }
            }
            return(record);
        }