Exemple #1
0
        public bool TryTranslateMessage(Exception ex, out RESTError webServiceError)
        {
            Preconditions.ThrowIfNull(ex, nameof(ex));

            webServiceError = null;

            // Unwrap the NHibernate generic exception if it is present
            var exception = ex is GenericADOException
                ? ex.InnerException
                : ex;

            if (exception is DatabaseConnectionException &&
                _snapshotContextProvider.GetSnapshotContext() != null)
            {
                webServiceError = new RESTError
                {
                    Code    = (int)HttpStatusCode.Gone,
                    Type    = HttpStatusCode.Gone.ToString().NormalizeCompositeTermForDisplay(),
                    Message = "Snapshot not available."
                };

                return(true);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Gets the replacement token with a snapshot-specific suffix appended.
        /// </summary>
        /// <returns>The configured token replacement with a snapshot database suffix appended.</returns>
        /// <exception cref="FormatException">Occurs if the snapshot identifier in context
        /// is not an alphanumeric value.</exception>
        public string GetReplacementToken()
        {
            var snapshotContext = _snapshotContextProvider.GetSnapshotContext();

            if (snapshotContext == null || string.IsNullOrEmpty(snapshotContext.SnapshotIdentifier))
            {
                return(_next.GetReplacementToken());
            }

            // To prevent possible tampering, snapshot identifier must only contain letters or numbers.
            if (snapshotContext.SnapshotIdentifier.Any(c => !(char.IsLetter(c) || char.IsDigit(c))))
            {
                throw new FormatException("Invalid value for snapshot identifier.");
            }

            return(_next.GetReplacementToken() + $"_SS{snapshotContext.SnapshotIdentifier}");
        }