Example #1
0
 /// <summary>
 /// Invokes an action on the specified urn.
 /// </summary>
 /// <param name="urn">The URN to invoke the action.</param>
 /// <param name="arguments">The arguments for the action.</param>
 /// <returns>
 /// The results of the action.
 /// </returns>
 public InvokeResult Invoke(string urn, InvokeArguments arguments)
 {
     var logId = Guid.NewGuid();
     logger.Debug(
         "Invoking '{2}' on '{0}' - {1}", 
         urn, 
         logId, 
         (arguments == null ? string.Empty : arguments.Action ?? string.Empty));
     try
     {
         var result = this.Invoker.Invoke(urn, arguments);
         result.LogId = logId;
         logger.Debug("Invoke completed for '{0}' - {1}", urn, logId);
         return result;
     }
     catch (Exception error)
     {
         logger.ErrorException(
             "Error happened on invoke for '" + urn +
             "' - " + logId + ": " + error.Message,
             error);
         return new InvokeResult
                    {
                        LogId = logId,
                        ResultCode = RemoteResultCode.FatalError
                    };
     }
 }
        public void InvokePassesOnCall()
        {
            var urn = string.Empty;
            var args = new InvokeArguments();
            var result = new InvokeResult();
            var invokerMock = new Mock<IActionInvoker>(MockBehavior.Strict);
            invokerMock.Setup(i => i.Invoke(urn, args)).Returns(result).Verifiable();

            var channel = new WcfChannel(invokerMock.Object);
            var actual = channel.Invoke(urn, args);
            Assert.AreSame(result, actual);
            invokerMock.Verify();
        }
 public void InvokeFailsIfInputIsMissing()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "TestAction",
                             Data = string.Empty
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.InvalidInput, result.ResultCode);
 }
 public void InvokeFailsIfInputIsIncorrectType()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "TestAction",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.InvalidInput, result.ResultCode);
 }
Example #5
0
        /// <summary>
        /// Invokes an action using raw messages.
        /// </summary>
        /// <param name="urn">The URN to invoke the action on.</param>
        /// <param name="action">The action.</param>
        /// <param name="args">The arguments for the action in XAML.</param>
        /// <returns>
        /// The result of the action in XAML.
        /// </returns>
        public virtual string Invoke(string urn, string action, string args)
        {
            var request = new InvokeArguments
            {
                Action = action,
                Data   = args
            };
            var result = this.PerformChannelOperation(c => c.Invoke(urn, request));

            if (result.ResultCode == RemoteResultCode.Success)
            {
                return(result.Data);
            }

            throw new RemoteServerException(result.ResultCode, result.LogId);
        }
 public void InvokeHandlesMethodsWithTheSameName()
 {
     var called = false;
     var item = new TroublesomeItem
                    {
                        Name = "ghost",
                        DoSomethingAction = () => called = true
                    };
     var server = new Server("Test", item);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "DoSomething",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:ghost", arguments);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     Assert.IsTrue(called);
 }
Example #7
0
        /// <summary>
        /// Invokes an action on an item.
        /// </summary>
        /// <param name="urn">The URN to invoke the action.</param>
        /// <param name="arguments">The arguments for the action.</param>
        /// <returns>
        /// The return message from the action.
        /// </returns>
        public InvokeResult Invoke(string urn, InvokeArguments arguments)
        {
            var result = new InvokeResult();
            var item = this.LocateItem(urn);
            if (item == null)
            {
                logger.Warn("Request made to unknown URN '{0}'", urn);
                result.ResultCode = RemoteResultCode.UnknownUrn;
                return result;
            }

            if (arguments == null)
            {
                result.ResultCode = RemoteResultCode.MissingArguments;
                return result;
            }

            var method = FindAction(item.GetType(), arguments.Action);
            if (method == null)
            {
                logger.Warn("Request made for unknown action '{0}' on '{1}", arguments.Action, urn);
                result.ResultCode = RemoteResultCode.UnknownAction;
                return result;
            }

            // TODO: Validate security

            if (string.IsNullOrEmpty(arguments.Data))
            {
                result.ResultCode = RemoteResultCode.InvalidInput;
                return result;
            }

            var parameters = method.GetParameters();
            var input = MessageSerialiser.Deserialise(arguments.Data);
            if (parameters[0].ParameterType.IsAssignableFrom(input.GetType()))
            {
                var output = method.Invoke(item, new[] { input });
                result.Data = MessageSerialiser.Serialise(output);
            }
            else
            {
                result.ResultCode = RemoteResultCode.InvalidInput;
            }

            return result;
        }
Example #8
0
        /// <summary>
        /// Sends the request to the local server.
        /// </summary>
        /// <param name="context">The context.</param>
        private void SendLocalRequest(TaskExecutionContext context)
        {
            // Resolve the URN
            var urn = this.ProjectName;
            if (!UrnHelpers.IsCCNetUrn(urn))
            {
                urn = UrnHelpers.GenerateProjectUrn(this.Project.Server, this.ProjectName);
            }

            // Send the actual request
            logger.Debug("Performing local force build on '{0}'", urn);
            var arguments = new InvokeArguments
                                {
                                    Action = "ForceBuild"
                                };
            var result = this.Project.Server.ActionInvoker.Invoke(urn, arguments);

            // Check the result
            if (result.ResultCode == RemoteResultCode.Success)
            {
                var message = "Force build successfully sent to '" + ProjectName + "'";
                logger.Info(message);
                context.AddEntryToBuildLog(message);
            }
            else
            {
                var message = "Force build failed for '" + ProjectName + "' - result code " + result.ResultCode;
                logger.Info(message);
                context.AddEntryToBuildLog(message);
                context.CurrentStatus = IntegrationStatus.Failure;
            }
        }
 public void InvokeInvokesMethod()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "DoSomething",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     Assert.IsNotNull(result);
     Assert.IsNotNull(result.Data);
     var message = MessageSerialiser.Deserialise(result.Data);
     Assert.IsInstanceOf<Messages.Blank>(message);
     Assert.IsTrue(testItem.WasInvoked);
 }