/// <summary>
        /// Returns the desired command based on the provided <see cref="OptionObject2015"/> and parameter.
        /// </summary>
        /// <param name="optionObject"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static IRunScriptCommand GetCommand(IOptionObject2015 optionObject, IParameter parameter)
        {
            if (optionObject == null)
            {
                logger.Error("The provided OptionObject2015 is null");
            }

            IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject);

            logger.Debug("Script '" + parameter.ScriptName + "' requested.");

            // Get Dependencies
            ConnectionStringCollection odbcConnectionStrings = ConnectionStringSelector.GetConnectionStringCollection();
            var repository  = new GetOdbcDataRepository(odbcConnectionStrings);
            var smtpService = new SmtpService();

            switch (parameter.ScriptName.ToUpperInvariant().Trim())
            {
                #region General Purpose Commands

                #endregion

                #region PM/Cal-PM Commands

                #endregion

                #region CWS Commands

                #endregion

                #region MSO Commands

                #endregion

                #region Utility and Testing Commands

            case "GETODBCDATA":
                logger.Debug("{command} selected.", nameof(GetOdbcDataCommand));
                return(new GetOdbcDataCommand(optionObjectDecorator, repository));

            case "HELLOWORLD":
                logger.Debug(nameof(HelloWorldCommand) + " selected.");
                return(new HelloWorldCommand(optionObjectDecorator));

            case "SENDEMAIL":
                logger.Debug("{command} selected.", nameof(SendEmailCommand));
                return(new SendEmailCommand(optionObjectDecorator, smtpService));

            case "SETFIELDVALUE":
                logger.Debug("{command} selected.", nameof(SetFieldValueCommand));
                return(new SetFieldValueCommand(optionObjectDecorator, parameter));

                #endregion

            default:
                logger.Warn(nameof(DefaultCommand) + " selected because ScriptName '" + parameter.ScriptName + "' does not match an existing command option.");
                return(new DefaultCommand(optionObjectDecorator, parameter));
            }
        }
        public void GetCommand_GetOdbcData_ReturnsGetOdbcDataCommand()
        {
            // Arrange
            OptionObject2015           optionObject2015           = new OptionObject2015();
            IOptionObjectDecorator     optionObjectDecorator      = new OptionObjectDecorator(optionObject2015);
            IParameter                 parameter                  = new Parameter("GetOdbcData");
            ConnectionStringCollection connectionStringCollection = new ConnectionStringCollection("", "", "");
            var repository = new GetOdbcDataRepository(connectionStringCollection);
            GetOdbcDataCommand expected = new GetOdbcDataCommand(optionObjectDecorator, repository);

            // Act
            IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter);

            // Assert
            Assert.AreEqual(expected.GetType(), actual.GetType());
        }
Example #3
0
        /// <summary>
        /// Returns the desired command based on the provided <see cref="OptionObject2015"/> and parameter.
        /// </summary>
        /// <param name="optionObject"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static IRunScriptCommand GetCommand(OptionObject2015 optionObject, string parameter)
        {
            if (optionObject == null)
            {
                logger.Error("The provided {object} is null", nameof(OptionObject2015));
                return(new DefaultCommand(optionObject, parameter));
            }

            // Determine ScriptName
            logger.Debug("Parameter for scriptName is:  " + parameter);
            string scriptName = parameter != null?parameter.Split(',')[0] : "";

            logger.Debug("Script '" + scriptName + "' requested.");

            // Get Dependencies
            // Replace with this line when ready to do ODBC from SBOX and BLD
            //ConnectionStringCollection odbcConnectionStrings = ConnectionStringSelector.GetConnectionStringCollection(optionObject.Facility, optionObject.NamespaceName);
            ConnectionStringCollection odbcConnectionStrings = ConnectionStringSelector.GetConnectionStringCollection(optionObject.Facility);

            logger.Debug("Facility is: " + optionObject.Facility);
            var repository = new GetOdbcDataRepository(odbcConnectionStrings);

            logger.Debug("Repository is: " + repository.ToString());
            var smtpService = new SmtpService();

            logger.Debug("SMTP is: " + smtpService.ToString());

            // Select Command, Not Case Sensitive
            switch (scriptName.ToUpperInvariant().Trim())
            {
            // General Commands
            case "ADDDURATIONANDTIME":
                logger.Debug(nameof(AddDurationAndTimeCommand) + " selected.");
                return(new AddDurationAndTimeCommand(optionObject, parameter));

            case "CHKCHRS":
                logger.Debug(nameof(ChkChrsCommand) + " selected.");
                return(new ChkChrsCommand(optionObject, parameter));

            // PM Commands
            case "DIAGNOSISFORMLOAD":
                logger.Debug(nameof(DiagnosisFormLoadCommand) + " selected.");
                return(new DiagnosisFormLoadCommand(optionObject, repository));

            // CWS Commands

            // Testing and Sample ("Utility") Commands
            case "GETODBCDATA":
                logger.Debug(nameof(GetOdbcDataCommand) + " selected.");
                return(new GetOdbcDataCommand(optionObject, repository));

            case "HELLOWORLD":
                logger.Debug(nameof(HelloWorldCommand) + " selected.");
                return(new HelloWorldCommand(optionObject));

            case "SENDTESTEMAIL":
                logger.Debug(nameof(SendTestEmailCommand) + " selected.");
                return(new SendTestEmailCommand(optionObject, parameter, smtpService));

            // If nothing matches
            default:
                logger.Warn(nameof(DefaultCommand) + " selected because ScriptName '" + scriptName + "' does not match an existing command.");
                return(new DefaultCommand(optionObject, parameter));
            }
        }