public RequestSection(Session req, ScriptSCL script, string stepName,
                       Dictionary <string, ParametrizedValue> parametrizedValues, bool isPrimary)
 {
     Request             = req;
     Script              = script;
     StepName            = stepName;
     _parametrizedValues = parametrizedValues;
     Validation          = null;
     _result             = WriteCodeInt(isPrimary);
 }
        public string AddRequest(Session req, bool primary)
        {
            var url = req.fullUrl;

            url = PreviousRedirectURL == req.fullUrl ? "redirectUrl+\"" : SplitAndParametrizeUrl(url, Script);

            //string cookies = SessionUtils.GetCookies(req.oRequest.headers, this.Script);
            var connectionID = GetConnectionID(Request);

            var primaryString = "";

            if (primary)
            {
                primaryString = "PRIMARY";
            }

            //tengo que saber cuando es get y cuando es post
            var isGet = req.oRequest.headers.HTTPMethod == "GET";

            var openSTAHeaders = GetOpenSTAHeaders();

            var result = "";

            if (isGet)
            {
                result += string.Format("\n\t{0} GET URI {1} HTTP/1.1\" ON {2} &\n\t{3}\n\n"
                                        , primaryString, url, connectionID, openSTAHeaders);
            }
            else
            {
                result += "\n\t" + primaryString + " POST URI " + url + " HTTP/1.1\" ON " + connectionID + " &\n\t" +
                          openSTAHeaders + "		 &\n"+
                          "\t,BODY \"" + SplitBody(Request.GetRequestBodyAsString()) + "\n\n";
            }

            //si hay cookies para cargar tengo que cargarlas
            result += LoadCookies(connectionID);
            if (primary)
            {
                var lrs = new LogResponsesSection(connectionID);
                result += lrs.WriteCode();

                switch (Request.responseCode)
                {
                case 200:
                    //pongo el codigo para la validacion de texto
                    Validation = new AppearTextSection("<Text to validate>", connectionID,
                                                       OpenSTAUtils.SplitStringIfNecesary("Step " + StepCounter +
                                                                                          " - " +
                                                                                          Script.GetUsedDataFriendly
                                                                                              ()));
                    StepCounter++;
                    //me fijo si es un pdf
                    //Content-Type: application/pdf
                    if ((req.oResponse.headers.Exists("Content-Type")) &&
                        (req.oResponse.headers["Content-Type"] == "application/pdf"))
                    {
                        Validation.Body = false;
                        Validation.Text = "application/pdf";
                    }
                    break;

                case 301:
                case 302:
                case 303:
                    //aca falta que se maneje el redirect para el proximo pedido
                    //cargo el campo location en una variable url y luego lo uso en el proximo pedido que coincida con la url
                    if (req.oResponse.headers.Exists("Location"))
                    {
                        PreviousRedirectURL = req.oResponse.headers["Location"];
                        var redVar = new Variable("redirectUrl", "CHARACTER*1024", VariablesScopes.Local);
                        Script.AddVariable(redVar);
                        result += "\tLoad Response_Info Header on " + connectionID + " into buffer\n";
                        result += "\tSet strInicial = 'Location: '\n";
                        result += "\tSet strFinal = '~<CR>'\n";
                        result += "\tcall between\n";
                        result += "\tSet redirectUrl = Straux\n\n";
                    }
                    break;

                case 401:
                    //me fijo si es el primer 401 para este pedido entonces agrego un from user, sino si es el segundo agrego un from blob
                    var blob = new Variable("blob1", "CHARACTER*2048", VariablesScopes.Local);
                    Script.AddVariable(blob);
                    if (
                        (PreviousRequestResponse.ContainsKey(req.fullUrl)) &&
                        (PreviousRequestResponse[req.fullUrl] == 401)
                        )
                    {
                        //me fijo si esta el campo WWW-Authenticate
                        if (req.oResponse.headers.Exists("WWW-Authenticate"))
                        {
                            result += string.Format(
                                "\n\tLoad Response_Info Header on {0}		&\n"+
                                "\tInto blob1	&\n"+
                                "\t,WITH \"WWW-Authenticate\"\n\n", connectionID);
                        }
                        result += new BuildBlobFromBlobSection(blob).WriteCode();
                    }
                    else
                    {
                        var usrStr = "\"<user>\"";
                        var pwdStr = "\"<pwd>\"";
                        var domain = "\"\"";
                        if (User != null)
                        {
                            usrStr = User.Name;
                            pwdStr = Pwd.Name;
                        }
                        result += new BuildBlobFromUserSection(usrStr, pwdStr, domain, connectionID).WriteCode();
                    }
                    break;
                }
            }

            if (!PreviousRequestResponse.ContainsKey(req.fullUrl))
            {
                PreviousRequestResponse.Add(req.fullUrl, req.responseCode);
            }

            return(result);
        }