Exemple #1
0
        /// <summary>
        /// Returns an error message.
        /// </summary>
        /// <param name="structureReference">
        /// The structure reference.
        /// </param>
        /// <param name="ex">
        /// The ex.
        /// </param>
        /// <returns>
        /// The <see cref="ImportMessage"/>.
        /// </returns>
        public static ImportMessage GetErrorMessage(this IStructureReference structureReference, Exception ex)
        {
            var errorMessage = string.Format(
                CultureInfo.InvariantCulture,
                "Failure: {0} cannot be inserted. REASON: {1}{2}",
                structureReference.GetAsHumanReadableString(),
                ex.Message,
                Environment.NewLine);

            _log.Error(errorMessage, ex);
            return(new ImportMessage(ImportMessageStatus.Error, structureReference, errorMessage));
        }
Exemple #2
0
        /// <summary>
        /// Delete the specified <paramref name="objects"/> from Mapping Store if they exist.
        /// </summary>
        /// <param name="objects">
        /// The objects.
        /// </param>
        /// <typeparam name="T"> The type of maintainable object</typeparam>
        protected void DeleteObjects <T>(IEnumerable <T> objects) where T : IMaintainableObject
        {
            foreach (var maintainableObject in objects)
            {
                using (DbTransactionState state = DbTransactionState.Create(this._database))
                {
                    try
                    {
                        IStructureReference structureReference = maintainableObject.AsReference;
                        var status = GetFinalStatus(state, structureReference);
                        if (status != null && status.PrimaryKey > 0)
                        {
                            _log.DebugFormat(CultureInfo.InvariantCulture, "Deleting artefact record {0}.", structureReference.GetAsHumanReadableString());
                            this.Delete(state, status.PrimaryKey);
                        }
                        else
                        {
                            _log.WarnFormat(CultureInfo.InvariantCulture, "Failed to delete artefact record {0}.", structureReference.GetAsHumanReadableString());
                        }

                        state.Commit();
                    }
                    catch (Exception e)
                    {
                        state.RollBack();
                        _log.Error(maintainableObject.Urn, e);
                        throw;
                    }
                }
            }
        }