Esempio n. 1
0
        private string CreateSoapRequest()
        {
            // The name of the request and the expected return file. The standard format is:
            // <numsaisi_parcelle> _ <code_produit> _ <timestamp_de_the_requete>
            var RequestName = "POCWiuzRequest";
            // Customer's IP
            var requestIp   = IpAddress.GetIpAddress().ToString();
            var requestTime = DateTime.Now.ToString("yyyyMMddHHmmss");

            RequestName += $"_{requestTime}";
            //Code of operator
            var exploitantId = "ADS_d31ecb24dfd4187dee585427b70cfc08";
            //Organization Code
            var exploitantOrganisme = "ADS";



            var parametresProjection = "WGS84";

            //Product code
            var productCode = "COLZA02";
            //Entered number of the parcel
            var productParcelle = "I-568586-4";
            //
            var productLibelle         = "PRECO_AZOTE_COLZA";
            var productSurfaceDeclaree = 13.31;
            //Type of product chosen
            var parametresTypeazote = Typeazote.Solide;
            //Quantity to add or subtract in nitrogen unit
            var parametresAjoutazote         = 60;
            var parametresConcentrationAzote = 27;
            var sb = new StringBuilder();

            sb.Append($@"<x.:Request name=""{RequestName}"" ip=""{requestIp}"" time=""{requestTime}"">");
            sb.Append($@"<x.:Exploitant id=""{exploitantId}"" organisme=""{exploitantOrganisme}""/>");
            sb.Append($@"<x.:Product code=""{productCode}"" parcelle=""{productParcelle}"" libelle=""{productLibelle}"" surfacedeclaree=""{productSurfaceDeclaree}""/>");
            sb.Append(@"<x.:Personnalisation>");
            sb.Append($@"<x.:Parametres format=""SHP"" projection=""{parametresProjection}"" concentrationazote=""{parametresConcentrationAzote}"" typeazote=""{parametresTypeazote}"" ajoutazote=""{parametresAjoutazote}"" ajoutpourcentage=""False"" marque=""John Deere""  console=""GS2630"" />");
            sb.Append(@"</x.:Personnalisation>");
            sb.Append(@"</x.:Request>");

            Console.WriteLine(sb.ToString());

            return(sb.ToString());
        }
        private string GetErrorBody(HttpContextBase context, HttpRequestBase request, Exception exception)
        {
            string username        = null;
            bool?  isAuthenticated = context?.User?.Identity?.IsAuthenticated;

            if (isAuthenticated.HasValue && isAuthenticated.Value)
            {
                username = context?.User?.Identity?.Name;
            }

            string culture   = Thread.CurrentThread?.CurrentCulture?.Name;
            string uiCulture = Thread.CurrentThread?.CurrentUICulture?.Name;

            string currentPageUrl  = request?.Url?.AbsoluteUri;
            string referrerPageUrl = request?.UrlReferrer?.AbsoluteUri;

            string userAgent = request?.UserAgent;

            StringBuilder body = new StringBuilder();

            if (exception != null)
            {
                string[] messages = GetExceptionMessages(exception).Reverse().ToArray();

                if (messages.Any())
                {
                    body.AppendLine($"Error Message: {messages.First()}");

                    foreach (string message in messages.Skip(1))
                    {
                        body.AppendLine(message);
                    }
                }

                if (exception is HttpException)
                {
                    body.AppendLine();
                    body.AppendLine($"Http code: {(exception as HttpException).GetHttpCode()}");
                }
            }

            body.AppendLine();
            if (string.IsNullOrWhiteSpace(username) == false)
            {
                body.AppendLine($"Username: {username}");
                body.AppendLine();
            }
            if (string.IsNullOrWhiteSpace(culture) == false)
            {
                body.AppendLine($"Thread Culture: {culture}");
            }
            if (string.IsNullOrWhiteSpace(uiCulture) == false)
            {
                body.AppendLine($"Thread UI Culture: {uiCulture}");
            }
            if (string.IsNullOrWhiteSpace(culture) == false || string.IsNullOrWhiteSpace(uiCulture) == false)
            {
                body.AppendLine();
            }
            if (string.IsNullOrWhiteSpace(userAgent) == false)
            {
                body.AppendLine($"User Agent: {userAgent}");
                body.AppendLine();
            }
            body.AppendLine($"IP Address: {IpAddress.GetIpAddress()}");
            body.AppendLine();
            body.AppendLine($"Time: {DateTime.Now.ToString("G")}");
            body.AppendLine();
            if (string.IsNullOrWhiteSpace(currentPageUrl) == false)
            {
                body.AppendLine($"Current Page: {currentPageUrl}");
                body.AppendLine();
            }
            if (string.IsNullOrWhiteSpace(referrerPageUrl) == false)
            {
                body.AppendLine($"Referrer Page: {referrerPageUrl}");
            }

            if (exception != null)
            {
                string[] traces = GetExceptionStackTrace(exception).Reverse().ToArray();

                if (traces.Any())
                {
                    body.AppendLine();
                    body.AppendLine($"Stack Trace: {traces.First()}");

                    foreach (string trace in traces.Skip(1))
                    {
                        body.AppendLine(trace);
                    }
                }
            }

            return(body.ToString());
        }