public void ConvertToDictionaryParametersAndBackSucceeds()
        {
            // Arrange
            var stringProperty            = "arbitrary-string";
            var intProperty               = 42;
            var networkCredentialProperty = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain");

            var arbitraryObject = new ArbitraryObject
            {
                StringProperty            = stringProperty,
                IntProperty               = intProperty,
                NetworkCredentialProperty = networkCredentialProperty
            };

            var sut = new DictionaryParameters();

            // Act
            var resultDictionaryParameters = sut.Convert(arbitraryObject);
            var result = resultDictionaryParameters.Convert <ArbitraryObject>();

            // Assert
            Assert.AreEqual(arbitraryObject.StringProperty, result.StringProperty);
            Assert.AreEqual(arbitraryObject.IntProperty, result.IntProperty);
            Assert.AreEqual(arbitraryObject.NetworkCredentialProperty, result.NetworkCredentialProperty);
        }
        public void ConvertToDictionaryParametersThrowsContractException()
        {
            // Arrange
            var arbitraryObject = default(ArbitraryObject);

            var sut = new DictionaryParameters();

            // Act
            var result = sut.Convert(arbitraryObject);

            // Assert
            // N/A
        }
        public void ConvertToDictionaryParametersSucceeds()
        {
            // Arrange
            var stringProperty            = "arbitrary-string";
            var intProperty               = 42;
            var networkCredentialProperty = new NetworkCredential("arbitrary-user", "arbitrary-password", "arbitrary-domain");

            var arbitraryObject = new ArbitraryObject();

            arbitraryObject.StringProperty            = stringProperty;
            arbitraryObject.IntProperty               = intProperty;
            arbitraryObject.NetworkCredentialProperty = networkCredentialProperty;

            var sut = new DictionaryParameters();

            // Act
            var result = sut.Convert(arbitraryObject);

            // Assert
            Assert.AreEqual(arbitraryObject.StringProperty, result["StringProperty"]);
            Assert.AreEqual(arbitraryObject.IntProperty, result["IntProperty"]);
            Assert.AreEqual(arbitraryObject.NetworkCredentialProperty, result["NetworkCredentialProperty"]);
        }
        public override bool Invoke(DictionaryParameters parameters, IInvocationResult jobResult)
        {
            var fReturn = false;

            if(!IsActive)
            {
                jobResult.Succeeded = fReturn;
                jobResult.Code = 1;
                jobResult.Message = "Plugin inactive";
            }
            
            var invocationParameters = parameters.Convert<ProgrammePluginInvokeParameters>();

            try
            {
                var result = biz.dfch.CS.Utilities.Process.StartProcess(
                    invocationParameters.CommandLine, 
                    invocationParameters.WorkingDirectory, 
                    invocationParameters.Credential);

                fReturn = true;

                jobResult.Succeeded = fReturn;
                jobResult.Code = 0;
                jobResult.Message = invocationParameters.CommandLine;
            }
            catch(Exception ex)
            {
                jobResult.Succeeded = fReturn;
                jobResult.Code = ex.HResult;
                jobResult.Message = ex.Message;
                jobResult.Description = ex.StackTrace;
            }

            return jobResult.Succeeded;
        }
        public override bool Invoke(DictionaryParameters parameters, IInvocationResult jobResult)
        {
            var activityId = Trace.CorrelationManager.ActivityId;
            
            var result = base.Invoke(parameters, jobResult);
            if(!result)
            {
                return result;
            }

            try
            {
                var invocationParameters = parameters.Convert<ActivitiPluginInvokeParameters>();
                var workflowInputParameters = new DictionaryParameters(invocationParameters.Parameters);

                Logger.Info("JobId: '{0}'. ActivityId '{1}'. {2}({3}).", invocationParameters.JobId, activityId, invocationParameters.Id, string.Join(", ", workflowInputParameters.Keys));

                var message = string.Format("JobId: '{0}'", invocationParameters.JobId);
                var description = string.Format("ExternalWorkflow: ActivityId '{0}'.", activityId);

                var definitionId = client.GetDefinitionId(invocationParameters.Id);
                var responseData = client.InvokeWorkflowInstance(definitionId, new Hashtable(workflowInputParameters));
                var responseDataMessage = string.Format
                    (
                    "id '{0}'. processDefinitionId '{1}'. Suspended '{2}'. Completed '{3}'. Ended '{4}'. [JobId '{5}'. ActivityId '{6}]",
                    responseData.id, responseData.processDefinitionId, responseData.suspended, responseData.completed, responseData.ended,
                    invocationParameters.JobId, activityId
                    );
                Logger.Info(responseDataMessage);

                result = true;
                if (result)
                {
                    jobResult.Code = biz.dfch.CS.Appclusive.Scheduler.Public.Constants.InvocationResultCodes.ERROR_SUCCESS;
                }
                else
                {
                    jobResult.Code = biz.dfch.CS.Appclusive.Scheduler.Public.Constants.InvocationResultCodes.ERROR_INVALID_FUNCTION;
                }

                jobResult.Succeeded = result;
                jobResult.Description = description;
                jobResult.Message = message;
            }
            catch(Exception ex)
            {
                jobResult.Succeeded = result;
                jobResult.Code = ex.HResult;
                jobResult.Message = ex.Message;
                jobResult.Description = ex.StackTrace;

                throw;
            }

            return jobResult.Succeeded;
        }