예제 #1
0
 /// <summary>
 /// initialize setting container with specified <paramref name="outputReportingProfile"/>.
 /// if <paramref name="outputReportingProfile"/> is null, a default
 /// <see cref="OutputReportingProfile"/> is used.
 /// </summary>
 /// <param name="outputReportingProfile"></param>
 internal SettingsContainer(OutputReportingProfile outputReportingProfile = null)
 {
     if (outputReportingProfile != null)
     {
         this.outputReportingProfile = outputReportingProfile;
     }
 }
예제 #2
0
            /// <summary>
            /// prompts user to select one of the pre-defined <see cref="OutputReportingProfile"/>s.
            /// </summary>
            /// <param name="commandArguments"></param>
            /// <returns>
            /// <seealso cref="Command.Execute(string[])"/>
            /// </returns>
            protected override bool Execute(string[] commandArguments)
            {
                bool commandExecutedSuccessfuly;

                // display menu allowing user to select desired reporting profile
                int userSelectedReportingProfileIndex = ConsoleIOManager.Instance.ShowMenuDialog(
                    outputReportingProfileMenuDialog,
                    ConsoleIOManager.eOutputReportType.CommandExecution);

                // menu indexing starts at 1, while profile indexing starts at 0
                userSelectedReportingProfileIndex--;

                // get OutputReportingProfile user selected by index
                OutputReportingProfile userSelectedOutputReportingProfile =
                    OutputReportingProfile.GetOutputReportingProfile(userSelectedReportingProfileIndex);

                try
                {
                    // set user selected OutputReportingProfile in SettingManager
                    ConfigurationManager.Instance.OutputReportingProfile =
                        userSelectedOutputReportingProfile;

                    // log success notice
                    ConsoleIOManager.Instance.LogNoticeFormat(
                        false,
                        eOutputReportType.CommandExecution,
                        "Reporting Profile '{0}' set successfully.",
                        userSelectedOutputReportingProfile.Title);

                    commandExecutedSuccessfuly = true;
                }
                catch (SettingsUpdateException settingsUpdateException)
                {
                    // log failure notice
                    ConsoleIOManager.Instance.LogError(
                        "An exception occurred while trying to update Reporting Profile setting",
                        eOutputReportType.CommandExecution);
                    ExceptionManager.Instance.ConsoleLogReferToErrorLogFileMessage(
                        eOutputReportType.CommandExecution);

                    // log exception in error log file
                    ExceptionManager.Instance.LogException(settingsUpdateException);

                    commandExecutedSuccessfuly = false;
                }

                return(commandExecutedSuccessfuly);
            }
            /// <summary>
            /// logs to console details about
            /// the currently set <see cref="OutputReportingProfile"/>.
            /// </summary>
            /// <param name="commandArguments"></param>
            /// <returns>
            /// <seealso cref="Command.Execute(string[])"/>
            /// </returns>
            protected override bool Execute(string[] commandArguments)
            {
                bool commandExecutedSuccessfuly;

                // get current OutputReportingProfile
                OutputReportingProfile outputReportingProfile =
                    ConfigurationManager.Instance.OutputReportingProfile;

                // log OutputReportingProfile title to console
                string notice = string.Format("" +
                                              "Current Reporting Profile: '{0}'.",
                                              outputReportingProfile.Title);

                ConsoleIOManager.Instance.LogNotice(notice, eOutputReportType.CommandExecution);

                commandExecutedSuccessfuly = true;

                return(commandExecutedSuccessfuly);
            }
예제 #4
0
            /// <summary>
            /// parses <see cref="SettingsContainer"/> from <paramref name="settingsContainerJsonObject"/>,
            /// which is expected to be a <see cref="JObject"/>.
            /// </summary>
            /// <param name="settingsContainerJsonObject"></param>
            /// <returns>
            /// <see cref="SettingsContainer"/> parsed from <paramref name="settingsContainerJsonObject"/>
            /// </returns>
            /// <exception cref="SettingsContainerJsonObjectParseException">
            /// thrown if <see cref="SettingsContainer"/> parse failed
            /// </exception>
            internal static SettingsContainer Parse(dynamic settingsContainerJsonObject)
            {
                try
                {
                    // get index of OutputReportingProfile
                    int outputReportingProfileIndex =
                        settingsContainerJsonObject.OutputReportingProfile.Index;

                    // get OutputReportingProfile corresponding to index
                    OutputReportingProfile outputReportingProfile =
                        OutputReportingProfile.GetOutputReportingProfile(outputReportingProfileIndex);

                    // init a new SettingsContainer
                    return(new SettingsContainer(outputReportingProfile));
                }
                catch (RuntimeBinderException runtimeBinderException)
                {
                    throw new SettingsContainerJsonObjectParseException(
                              settingsContainerJsonObject,
                              runtimeBinderException);
                }
            }