/// <summary>
        /// Gets the modeler specified in the provided Settings.
        /// </summary>
        /// <param name="settings">The code generation settings</param>
        /// <returns>Modeler specified in Settings.Modeler</returns>
        public static Modeler GetModeler(Settings settings)
        {
            Logger.LogInfo(Resources.ModelerInitialized);
            if (settings == null || string.IsNullOrEmpty(settings.Modeler))
            {
                throw new ArgumentNullException("settings", "settings or settings.Modeler cannot be null.");
            }

            Modeler modeler = null;

            string configurationFile = GetConfigurationFileContent(settings);

            if (configurationFile != null)
            {
                try
                {
                    var config = JsonConvert.DeserializeObject <AutoRestConfiguration>(configurationFile);
                    modeler = LoadTypeFromAssembly <Modeler>(config.Modelers, settings.Modeler, settings);
                }
                catch (Exception ex)
                {
                    throw ErrorManager.CreateError(ex, Resources.ErrorParsingConfig);
                }
            }
            else
            {
                throw ErrorManager.CreateError(Resources.ConfigurationFileNotFound);
            }

            Logger.LogInfo(Resources.ModelerInitialized,
                           settings.Modeler,
                           modeler.GetType().Assembly.GetName().Version);
            return(modeler);
        }
Example #2
0
        /// <summary>
        /// Gets the modeler specified in the provided Settings.
        /// </summary>
        /// <param name="settings">The code generation settings</param>
        /// <returns>Modeler specified in Settings.Modeler</returns>
        public static Modeler GetModeler()
        {
            Logger.Instance.Log(Category.Info, Resources.InitializingModeler);
            if (Settings.Instance == null)
            {
                throw new ArgumentNullException("settings", "settings or settings.Modeler cannot be null.");
            }

            if (string.IsNullOrEmpty(Settings.Instance.Modeler))
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture,
                                        Resources.ParameterValueIsMissing, "Modeler"));
            }

            Modeler modeler = null;

            var config = AutoRestConfiguration.Get();

            modeler = LoadTypeFromAssembly <Modeler>(config.Modelers, Settings.Instance.Modeler);
            Settings.PopulateSettings(modeler, Settings.Instance.CustomSettings);

            Logger.Instance.Log(Category.Info, Resources.ModelerInitialized,
                                Settings.Instance.Modeler,
                                modeler.GetType().GetAssembly().GetName().Version);
            return(modeler);
        }
Example #3
0
        /// <summary>
        /// Gets the modeler specified in the provided Settings.
        /// </summary>
        /// <param name="settings">The code generation settings</param>
        /// <returns>Modeler specified in Settings.Modeler</returns>
        public static Modeler GetModeler(Settings settings)
        {
            Logger.LogInfo(Resources.ModelerInitialized);
            if (settings == null)
            {
                throw new ArgumentNullException("settings", "settings or settings.Modeler cannot be null.");
            }

            if (string.IsNullOrEmpty(settings.Modeler))
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture,
                                        Resources.ParameterValueIsMissing, "Modeler"));
            }

            Modeler modeler = null;

            string configurationFile = GetConfigurationFileContent(settings);

            if (configurationFile != null)
            {
                try
                {
                    var config = JsonConvert.DeserializeObject <AutoRestConfiguration>(configurationFile);
                    modeler = LoadTypeFromAssembly <Modeler>(config.Modelers, settings.Modeler, settings);
                    Settings.PopulateSettings(modeler, settings.CustomSettings).ForEach(kv => settings.CustomSettings[kv.Key] = kv.Value);
                }
                catch (Exception ex)
                {
                    throw ErrorManager.CreateError(ex, Resources.ErrorParsingConfig);
                }
            }
            else
            {
                throw ErrorManager.CreateError(Resources.ConfigurationFileNotFound);
            }

            Logger.LogInfo(Resources.ModelerInitialized,
                           settings.Modeler,
                           modeler.GetType().Assembly.GetName().Version);
            return(modeler);
        }