/// <summary>
        /// Adds the URL call definition.
        /// </summary>
        /// <param name="assemblyCode">
        /// The assembly code.
        /// </param>
        /// <param name="process">
        /// The process.
        /// </param>
        /// <param name="callDefinition">
        /// The call definition.
        /// </param>
        /// <param name="variableCollection">
        /// The variable collection.
        /// </param>
        /// <returns>
        /// The <see cref="VariableInfo"/>.
        /// </returns>
        private VariableInfo AddUrlCallDefinition(
            StringBuilder assemblyCode,
            IProcessDefinition process,
            IntegrationServiceCallDefinition callDefinition,
            VariableCollection variableCollection)
        {
            var callSettings = (IntegrationServiceUrlCallDefinition)callDefinition.CallSettings;
            var variableInfo = variableCollection.NewVariable();
            var variableName = variableInfo.Name;

            assemblyCode.AppendFormat(
                @"
            var {0} = new Cebos.Veyron.SharedTypes.Integration.UrlCallDefinition();
            {0}.Name = {1};
            {0}.CallLocation = Cebos.Veyron.SharedTypes.UrlServiceCallLocation.{2};
            {0}.HttpMethod = Cebos.Veyron.SharedTypes.UrlServiceCallMethod.{3};
            {0}.Guid = System.Guid.Parse({4});
            {0}.ProcessDisplayName = {5};",
                variableName,
                callDefinition.Name.ToLiteral(),
                callSettings.CallLocation,
                callSettings.HttpMethod,
                callDefinition.Guid.ToString().ToLiteral(),
                process.DisplayName.ToLiteral());

            if (!string.IsNullOrEmpty(callSettings.AddressExpression))
            {
                var script = ExpressionService.PrepareScriptFromXml(callSettings.AddressExpression);
                assemblyCode.AppendFormat(@"
            {0}.AddressExpression = item => Cebos.Veyron.SharedTypes.SafeTypeConverter.Convert<string>({1});", variableName, script);
            }

            foreach (var parameterDefinition in callSettings.Parameters)
            {
                var parameterVariable = AddUrlCallParameterDefinition(assemblyCode, parameterDefinition, variableCollection);
                assemblyCode.AppendFormat(@"
            {0}.ParameterDefinitions.Add({1});
", variableName, parameterVariable.Name);
            }

            foreach (var rule in callDefinition.Rules)
            {
                assemblyCode.AppendFormat(@"
            {0}.Rules.Add({1}Metadata.RuleManager.GetRule(new System.Guid(""{2}"")));
", variableName, process.Name, rule.Guid);
            }

            return variableInfo;
        }
        /// <summary>
        /// Adds the URL call definition.
        /// </summary>
        /// <param name="assemblyCode">The assembly code.</param>
        /// <param name="callDefinition">The call definition.</param>
        /// <param name="variableIndex">Index of the variable.</param>
        /// <returns>System.String.</returns>
        private string AddUrlCallDefinition(StringBuilder assemblyCode, IntegrationServiceCallDefinition callDefinition, ref int variableIndex)
        {
            var callSettings = (IntegrationServiceUrlCallDefinition)callDefinition.CallSettings;
            var variableName = "v" + variableIndex++;

            assemblyCode.AppendFormat(
                @"
            var {0} = new Cebos.Veyron.SharedTypes.Integration.UrlCallDefinition();
            {0}.Name = {1};
            {0}.CallLocation = Cebos.Veyron.SharedTypes.UrlServiceCallLocation.{2};
            {0}.HttpMethod = Cebos.Veyron.SharedTypes.UrlServiceCallMethod.{3};
            {0}.Guid = System.Guid.Parse({4});", variableName, callDefinition.Name.ToLiteral(), callSettings.CallLocation, callSettings.HttpMethod, callDefinition.Guid.ToString().ToLiteral());

            return variableName;
        }
        /// <summary>
        /// Adds the web method call definition.
        /// </summary>
        /// <param name="assemblyCode">
        /// The assembly code.
        /// </param>
        /// <param name="process">
        /// The process.
        /// </param>
        /// <param name="callDefinition">
        /// The call definition.
        /// </param>
        /// <param name="variableCollection">
        /// The variable collection.
        /// </param>
        /// <returns>
        /// The <see cref="VariableInfo"/>.
        /// </returns>
        private VariableInfo AddWebMethodCallDefinition(
            StringBuilder assemblyCode,
            IProcessDefinition process,
            IntegrationServiceCallDefinition callDefinition,
            VariableCollection variableCollection)
        {
            var callSettings = (IntegrationServiceWebMethodCallDefinition)callDefinition.CallSettings;
            var variableInfo = variableCollection.NewVariable();
            var variableName = variableInfo.Name;
            var soapHeaderMappings = ExpressionService.PrepareScriptsForDestinationNode(
                callSettings.ParametersMapping,
                Constants.WebMethodCallSoapHeadersExpressionName);
            var parameterMappings = ExpressionService.PrepareScriptsForDestinationNode(
                callSettings.ParametersMapping,
                Constants.WebMethodCallMethodParametersExpressionName);

            assemblyCode.AppendFormat(
                @"
            var {0} = new Cebos.Veyron.SharedTypes.Integration.WebMethodCallDefinition();
            {0}.Name = {1};
            {0}.Guid = System.Guid.Parse({2});
            {0}.ContractTypeName = {3};
            {0}.MethodName = {4};
            {0}.ServiceDescriptionId = {5};
            {0}.ProcessName = {6};
            {0}.ProcessDisplayName = {7};
            {0}.Username = {8};
            {0}.Password = {9};
            {0}.EndpointConfiguration = {10};
",
                variableName,
                callDefinition.Name.ToLiteral(),
                callDefinition.Guid.ToString().ToLiteral(),
                callSettings.ContractTypeName.ToLiteral(),
                callSettings.MethodName.ToLiteral(),
                callSettings.ServiceDescriptionId.ToLiteral(),
                process.Name.ToLiteral(),
                process.DisplayName.ToLiteral(),
                callSettings.Username.ToLiteral(),
                callSettings.Password.ToLiteral(),
                callSettings.EndpointConfiguration.ToLiteral());

            foreach (var header in callSettings.SoapHeaders)
            {
                var headerVariable = AddWebMethodCallHeaderDefinition(assemblyCode, header, soapHeaderMappings, variableCollection);
                assemblyCode.AppendFormat(@"
            {0}.HeaderMappings.Add({1});
", variableName, headerVariable.Name);
            }

            foreach (var parameter in callSettings.Parameters)
            {
                var parameterVariable = AddWebMethodCallParameterDefinition(assemblyCode, parameter, parameterMappings, variableCollection);
                assemblyCode.AppendFormat(@"
            {0}.ParameterMappings.Add({1});
", variableName, parameterVariable.Name);
            }

            foreach (var rule in callDefinition.Rules)
            {
                assemblyCode.AppendFormat(@"
            {0}.Rules.Add({1}Metadata.RuleManager.GetRule(new System.Guid(""{2}"")));", variableName, process.Name, rule.Guid);
            }

            var resultMappings = ExpressionService.PrepareScriptForMultipleDestinations(callSettings.ResultMapping, null);
            foreach (var fieldMapping in callSettings.DestinationFields)
            {
                var resultMappingVariable = AddFieldMapping(assemblyCode, fieldMapping, resultMappings, variableCollection);
                assemblyCode.AppendFormat(@"
            {0}.ResultMappings.Add({1});
", variableName, resultMappingVariable.Name);
            }

            return variableInfo;
        }
        /// <summary>
        /// Adds the web method call definition.
        /// </summary>
        /// <param name="assemblyCode">The assembly code.</param>
        /// <param name="callDefinition">The call definition.</param>
        /// <param name="variableIndex">Index of the variable.</param>
        /// <returns>System.String.</returns>
        private string AddWebMethodCallDefinition(StringBuilder assemblyCode, IntegrationServiceCallDefinition callDefinition, ref int variableIndex)
        {
            var variableName = "v" + variableIndex++;

            assemblyCode.AppendFormat(
                @"
            var {0} = new Cebos.Veyron.SharedTypes.Integration.WebMethodCallDefinition();
            {0}.Name = {1};
            {0}.Guid = System.Guid.Parse({2});
", variableName, callDefinition.Name.ToLiteral(), callDefinition.Guid.ToString().ToLiteral());

            return variableName;
        }