private RhspCommandResponse executeCommand(string method, object anonymousParams)
        {
            try
            {
                enforceInitialized();
                RhspConnection            connection = manager.CreateConnection();
                RhspAdapterUsageAttribute attribute  = getUsageAttribute();
                string      commandText = string.Format("{0}.{1}", attribute.ModuleName, method);
                RhspCommand command     = new RhspCommand(connection, commandText);
                addAnonymousParamsToCommand(anonymousParams, command);
                return(command.Execute());
            }
            catch (Exception ex)
            {
                RhspAdapterErrorEventArgs errorArgs = new RhspAdapterErrorEventArgs();
                errorArgs.ThrowException = true;
                errorArgs.Error          = ex;

                if (ErrorOccured != null)
                {
                    ErrorOccured(this, errorArgs);
                }

                if (errorArgs.ThrowException)
                {
                    // When throwing has not ben disabled, throw error.
                    throw new Exception("Error occured while executing command.", ex);
                }
                else
                {
                    // Something must be returned, and null would be bad.
                    return(RhspCommandResponse.Error);
                }
            }
        }
Example #2
0
        public ServerStatusActionResult RunActionCommand(string actionCommand)
        {
            RhspConnection      connection = CreateConnection();
            RhspCommand         command    = new RhspCommand(connection, "ServerStatus." + actionCommand);
            RhspCommandResponse response   = command.Execute();

            return(response.GetResult <ServerStatusActionResult>());
        }
Example #3
0
        public ServerStatusElement[] GetElementArray()
        {
            RhspConnection      connection = CreateConnection();
            RhspCommand         command    = new RhspCommand(connection, "ServerStatus.GetElementArray");
            RhspCommandResponse response   = command.Execute();

            return(response.GetResult <ServerStatusElement[]>());
        }
Example #4
0
        public string[] TestArray()
        {
            RhspConnection      connecton = CreateConnection();
            RhspCommand         command   = new RhspCommand(connecton, "Diagnostic.TestArray");
            RhspCommandResponse response  = command.Execute();

            return(response.GetResult <string[]>());
        }
        protected void Set(string settingName, object value)
        {
            RhspConnection connecton = CreateConnection();
            RhspCommand    command   = new RhspCommand(connecton, "ServerConfig.Set");

            command.Parameters.Add("settingName", settingName);
            command.Parameters.Add("value", value);
            RhspCommandResponse response = command.Execute();
        }
Example #6
0
        public string Test(string[] testArray)
        {
            RhspConnection connecton = CreateConnection();
            RhspCommand    command   = new RhspCommand(connecton, "Diagnostic.Test");

            command.Parameters.Add("testArray", testArray);
            RhspCommandResponse response = command.Execute();

            return(response.GetResult <string>());
        }
 private static void addAnonymousParamsToCommand(object anonymousParams, RhspCommand command)
 {
     if (anonymousParams != null)
     {
         foreach (PropertyInfo p in anonymousParams.GetType().GetProperties())
         {
             command.Parameters.Add(p.Name, p.GetValue(anonymousParams, null));
         }
     }
 }
        protected TValue Get <TValue>(string settingName)
        {
            RhspConnection connecton = CreateConnection();
            RhspCommand    command   = new RhspCommand(connecton, "ServerConfig.Get");

            command.Parameters.Add("settingName", settingName);
            command.Parameters.Add("typeName", typeof(TValue).FullName);
            RhspCommandResponse response = command.Execute();

            return(response.GetResult <TValue>());
        }
 public void InvalidListTest()
 {
     try
     {
         RhspConnection      connecton = LocalContext.Default.CreateConnection();
         RhspCommand         command   = new RhspCommand(connecton, "Diagnostic.TestInvalidList");
         RhspCommandResponse response  = command.Execute();
         Assert.Fail("Exception should have been thrown due invalid return type of list.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "Lists are not supported. Consider converting the list to an array.");
     }
 }
 public void NonExistantMethodTest()
 {
     try
     {
         RhspConnection      connecton = LocalContext.Default.CreateConnection();
         RhspCommand         command   = new RhspCommand(connecton, "Diagnostic.DoesNotExist");
         RhspCommandResponse response  = command.Execute();
         Assert.Fail("Exception should have been thrown due to non existant method.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "No methods exist with the name 'DoesNotExist'.");
     }
 }
 public void InvalidParamTypeTest()
 {
     try
     {
         RhspConnection connecton = LocalContext.Default.CreateConnection();
         RhspCommand    command   = new RhspCommand(connecton, "Diagnostic.Test");
         command.Parameters.Add("test", true);
         RhspCommandResponse response = command.Execute();
         Assert.Fail("Exception should have been thrown due to param type.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "The data type 'String' of system parameter with name 'test' is not compatible with the equivilent command parameter of type 'Boolean'.");
     }
 }
 public void InvalidNonSystemArrayTest()
 {
     try
     {
         RhspConnection connecton = LocalContext.Default.CreateConnection();
         RhspCommand    command   = new RhspCommand(connecton, "Diagnostic.TestInvalidArray");
         command.Parameters.Add("array", new RhspData[0]);
         RhspCommandResponse response = command.Execute();
         Assert.Fail("Exception should have been thrown due invalid param array type.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "Cannot handle arrays of non-system type. Consider wrapping non-system elements in a system type array such as object[].");
     }
 }
 public void InvalidNonArrayTest()
 {
     try
     {
         RhspConnection connecton = LocalContext.Default.CreateConnection();
         RhspCommand    command   = new RhspCommand(connecton, "Diagnostic.TestInvalidArray");
         RhspParameter  param     = command.Parameters.Add("array", new RhspData[0]);
         param.DataTypeName = "System.String"; // Purposely set non-array type.
         RhspCommandResponse response = command.Execute();
         Assert.Fail("Exception should have been thrown due invalid param array type.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "A non-array type was specified, which is not allowed for array values.");
     }
 }
 public void InvalidParamCountTest()
 {
     try
     {
         RhspConnection connecton = LocalContext.Default.CreateConnection();
         RhspCommand    command   = new RhspCommand(connecton, "Diagnostic.Test");
         command.Parameters.Add("1", null);
         command.Parameters.Add("2", null);
         command.Parameters.Add("3", null);
         command.Parameters.Add("4", null);
         RhspCommandResponse response = command.Execute();
         Assert.Fail("Exception should have been thrown due to invalid param count.");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.Message == "None of the methods named 'Test' have the same number of prameters as specified in the command.");
     }
 }
Example #15
0
        public ConnectionTestResult TestConnection()
        {
            // Consider making this test a bit more elegant.
            try
            {
                RhspConnection      connecton = CreateConnection();
                RhspCommand         command   = new RhspCommand(connecton, "Diagnostic.Test");
                RhspCommandResponse response  = command.Execute();

                return(new ConnectionTestResult()
                {
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new ConnectionTestResult()
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }