Example #1
0
        /// <summary>
        /// Get the reason that a property is not available from an engine.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to look for
        /// </param>
        /// <param name="engines">
        /// The engines that are expected to supply the property value.
        /// </param>
        /// <returns>
        /// A <see cref="MissingPropertyResult"/> instance that includes an
        /// enum giving the reason and a developer-facing description of
        /// the reason.
        /// </returns>
        public MissingPropertyResult GetMissingPropertyReason(string propertyName, IReadOnlyList <IAspectEngine> engines)
        {
            MissingPropertyResult result = null;

            foreach (var engine in engines.Where(e => e != null))
            {
                result = GetMissingPropertyReason(propertyName, engine);
                if (result.Reason != MissingPropertyReason.Unknown)
                {
                    return(result);
                }
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Get the reason that a property is not available from an engine.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to look for
        /// </param>
        /// <param name="engine">
        /// The engine that is expected to supply the property value.
        /// </param>
        /// <returns>
        /// A <see cref="MissingPropertyResult"/> instance that includes an
        /// enum giving the reason and a developer-facing description of
        /// the reason.
        /// </returns>
        public MissingPropertyResult GetMissingPropertyReason(string propertyName, IAspectEngine engine)
        {
            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }

            MissingPropertyResult result = new MissingPropertyResult();
            MissingPropertyReason reason = MissingPropertyReason.Unknown;

            IAspectPropertyMetaData property = null;

            property = engine.Properties.FirstOrDefault(p => p.Name == propertyName);

            if (property != null)
            {
                // Check if the property is available in the data file that is
                // being used by the engine.
                if (property.DataTiersWherePresent.Any(t => t == engine.DataSourceTier) == false)
                {
                    reason = MissingPropertyReason.DataFileUpgradeRequired;
                }
                // Check if the property is excluded from the results.
                else if (property.Available == false)
                {
                    reason = MissingPropertyReason.PropertyExculdedFromEngineConfiguration;
                }
            }

            if (reason == MissingPropertyReason.Unknown &&
                typeof(ICloudAspectEngine).IsAssignableFrom(engine.GetType()))
            {
                reason = MissingPropertyReason.CloudEngine;
            }

            // Build the message string to return to the caller.
            StringBuilder message = new StringBuilder();

            message.AppendLine($"Property '{propertyName}' is not present in the results.");
            switch (reason)
            {
            case MissingPropertyReason.DataFileUpgradeRequired:
                message.Append("This is because your license and/or data file " +
                               "does not include this property. The property is available ");
                message.Append("with the ");
                message.Append(string.Join(",", property.DataTiersWherePresent));
                message.Append($" license/data for the {engine.GetType().Name}");
                break;

            case MissingPropertyReason.PropertyExculdedFromEngineConfiguration:
                message.Append("This is because the property has been " +
                               "excluded when configuring the engine.");
                break;

            case MissingPropertyReason.CloudEngine:
                message.Append("This may be because your resource key " +
                               "does not include this property. " +
                               "Check the property name is correct. Compare this " +
                               "to the properties available using the supplied " +
                               "resource key: ");
                message.Append(string.Join(",", engine.Properties.Select(p => p.Name)));
                break;

            case MissingPropertyReason.Unknown:
                message.Append("The reason for this is unknown. Please " +
                               "check that the aspect and property name are correct.");
                break;

            default:
                break;
            }

            result.Description = message.ToString();
            result.Reason      = reason;
            return(result);
        }
        /// <summary>
        /// Get the reason that a property is not available from an engine.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to look for
        /// </param>
        /// <param name="engine">
        /// The engine that is expected to supply the property value.
        /// </param>
        /// <returns>
        /// A <see cref="MissingPropertyResult"/> instance that includes an
        /// enum giving the reason and a developer-facing description of
        /// the reason.
        /// </returns>
        public MissingPropertyResult GetMissingPropertyReason(string propertyName, IAspectEngine engine)
        {
            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }

            MissingPropertyResult result = new MissingPropertyResult();
            MissingPropertyReason reason = MissingPropertyReason.Unknown;

            IAspectPropertyMetaData property = null;

            property = engine.Properties.FirstOrDefault(p => p.Name == propertyName);

            if (property != null)
            {
                // Check if the property is available in the data file that is
                // being used by the engine.
                if (property.DataTiersWherePresent.Any(t => t == engine.DataSourceTier) == false)
                {
                    reason = MissingPropertyReason.DataFileUpgradeRequired;
                }
                // Check if the property is excluded from the results.
                else if (property.Available == false)
                {
                    reason = MissingPropertyReason.PropertyExcludedFromEngineConfiguration;
                }
            }

            if (reason == MissingPropertyReason.Unknown &&
                typeof(ICloudAspectEngine).IsAssignableFrom(engine.GetType()))
            {
                if (engine.Properties.Count == 0)
                {
                    reason = MissingPropertyReason.ProductNotAccessibleWithResourceKey;
                }
                else
                {
                    reason = MissingPropertyReason.PropertyNotAccessibleWithResourceKey;
                }
            }

            // Build the message string to return to the caller.
            StringBuilder message = new StringBuilder();

            message.Append(
                string.Format(CultureInfo.InvariantCulture,
                              Messages.MissingPropertyMessagePrefix,
                              propertyName,
                              engine.ElementDataKey));
            switch (reason)
            {
            case MissingPropertyReason.DataFileUpgradeRequired:
                message.Append(
                    string.Format(CultureInfo.InvariantCulture,
                                  Messages.MissingPropertyMessageDataUpgradeRequired,
                                  string.Join(",", property.DataTiersWherePresent),
                                  engine.GetType().Name));
                break;

            case MissingPropertyReason.PropertyExcludedFromEngineConfiguration:
                message.Append(Messages.MissingPropertyMessagePropertyExcluded);
                break;

            case MissingPropertyReason.ProductNotAccessibleWithResourceKey:
                message.Append(
                    string.Format(CultureInfo.InvariantCulture,
                                  Messages.MissingPropertyMessageProductNotInCloudResource,
                                  engine.ElementDataKey));
                break;

            case MissingPropertyReason.PropertyNotAccessibleWithResourceKey:
                message.Append(
                    string.Format(CultureInfo.InvariantCulture,
                                  Messages.MissingPropertyMessagePropertyNotInCloudResource,
                                  engine.ElementDataKey,
                                  string.Join(",", engine.Properties.Select(p => p.Name))));
                break;

            case MissingPropertyReason.Unknown:
                message.Append(Messages.MissingPropertyMessageUnknown);
                break;

            default:
                break;
            }

            result.Description = message.ToString();
            result.Reason      = reason;
            return(result);
        }