Beispiel #1
0
        private static byte[] getBytesForPOST(ConfigPOST config)
        {
            NiemXML       niemXML = new NiemXML();
            StringBuilder sb      = new StringBuilder();

            if (config.Base64FileName != null)
            {
                sb.Append(niemXML.getBeforeBase64(config.DocTitle));
                string attachmentStr = File.ReadAllText(config.Base64FileName, Encoding.UTF8);

                //attachmentStr = Convert.ToBase64String(Encoding.UTF8.GetBytes(attachmentStr)); //String to Base64
                //or strip newlines?
                attachmentStr = attachmentStr.Replace(System.Environment.NewLine, "");

                sb.Append(attachmentStr);
                sb.Append(niemXML.getAfterBase64(attachmentStr.Length, config.AttachmentDescription,
                                                 config.AttachmentFormatName, config.getAttachmentFileName()));
                attachmentStr = null;
                File.WriteAllText(ConfigPOST.OUT_DIR + config.getAttachmentFileName() + "(whole).xml", sb.ToString());
            }
            else if (config.CompleteDocFileName != null)
            {
                sb.Append(File.ReadAllText(config.CompleteDocFileName, Encoding.UTF8));
            }
            else
            {
                throw new Exception("config.Base64FileName or config.CompleteDocFileName must be set!");
            }
            byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
            return(xmlData);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                configFileName = args[0];
            }

            ConfigPOST config = ConfigPOST.getConfigPOST(configFileName);

            byte[] xmlData = getBytesForPOST(config);
            logFileName = ConfigPOST.OUT_DIR + "ConsolePOST_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".log";

            double byteLen = xmlData.Length;

            printLine("POSTing " + Math.Round(byteLen / 1024 / 1024, 2) + " MB (total) to:");
            printLine(config.StringURL + Environment.NewLine);

            doMultiPartPOSTs(xmlData, config);
            Console.Out.WriteLine("\n Press enter to exit.");
            Console.In.Read();
        }
Beispiel #3
0
        internal static ConfigPOST getConfigPOST(string configFileName)
        {
            ConfigPOST config = null;
            DirectoryInfo di = Directory.CreateDirectory(OUT_DIR);
            //DirectoryInfo di = Directory.CreateDirectory("console_POST");
            //config.OutputFileName = @"console_GET/ConsoleHttpGet";
            //check for config file, load if exsists,
            XmlSerializer x = new XmlSerializer(typeof(ConfigPOST));
            if (File.Exists(configFileName)) {
                FileStream fs = new FileStream(configFileName, FileMode.Open);
                // Call the Deserialize method and cast to the object type.
                config = (ConfigPOST)x.Deserialize(fs);
            } else {
                config = new ConfigPOST();
                //if not load defaults

                config.PostTimes = 1;
                config.CompleteDocFileName = "../../samplesForTransform/dental-xray.jpg.txt(whole).xml";
                //string loadFileName = @"E:\VA\VLERDoc.xml";
                //config.CompleteDocFileName = @"E:\Code\GitHub\vlerdas-ecrud\test\attachments\eCFT1MBAttachEmbeded.xml";
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_5MB_a.xml"; //6.8 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_14MB_a.xml"; //19.1 MB
                //string loadFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_17MB_a.xml"; //23.2 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_21MB_a.xml"; //28.7 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_25MB_a.xml"; //34.2 MB
                //config.Base64FileName = @"F:\Dev Tools\mongodbWin32_64.zip.b64.txt"; //138 MB
                //config.Base64FileName = @"F:\Dev Tools\SnippetManager.b64.txt"; //zip file 507 KB
                //config.Base64FileName = @"F:\Dev Tools\dental-xray.jpg.txt"; //13.7 KB
                //config.Base64FileName = @"F:\Dev Tools\snake-river4.pdf.txt"; //32.1.7 KB
                //config.Base64FileName = @"C:\vler-proto-out\generated_out\xmlAttachment-Over1MB.xml.b64"; //1.33 MB

                //config.CompleteDocFileName = @"mongodbWin32_64.zip.b64.txt(whole).xml"; //138 MB

                config.StringURL = "http://*****:*****@"E:\VA\2waySSL\clientcert.pkcs12";
                config.SslCertPasswordFileName = @"E:\VA\2waySSL\clientcert.pkcs12-password.txt";
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"F:\Downloads\ides-cftdeom.asmr.com.cer", "test123"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\dodRootCA2.cer"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\DODJITCCA-27.crt"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\ides-cftdemo.asmr.com.crt"));

                config.ClientTimeout = (int)(600000 * 1.5); //15 Min

                StreamWriter writer = new StreamWriter(configFileName);
                x.Serialize(writer, config);
                writer.Close();
            }

            //save config to file
            return config;
        }
Beispiel #4
0
 private static string getANameFromTheFile(ConfigPOST config)
 {
     return config.Base64FileName != null ? Path.GetFileName(config.Base64FileName) : Path.GetFileName(config.CompleteDocFileName);
 }
Beispiel #5
0
        internal static ConfigPOST getConfigPOST(string configFileName)
        {
            ConfigPOST    config = null;
            DirectoryInfo di     = Directory.CreateDirectory(OUT_DIR);
            //DirectoryInfo di = Directory.CreateDirectory("console_POST");
            //config.OutputFileName = @"console_GET/ConsoleHttpGet";
            //check for config file, load if exsists,
            XmlSerializer x = new XmlSerializer(typeof(ConfigPOST));

            if (File.Exists(configFileName))
            {
                FileStream fs = new FileStream(configFileName, FileMode.Open);
                // Call the Deserialize method and cast to the object type.
                config = (ConfigPOST)x.Deserialize(fs);
            }
            else
            {
                config = new ConfigPOST();
                //if not load defaults

                config.PostTimes           = 1;
                config.CompleteDocFileName = "../../samplesForTransform/dental-xray.jpg.txt(whole).xml";
                //string loadFileName = @"E:\VA\VLERDoc.xml";
                //config.CompleteDocFileName = @"E:\Code\GitHub\vlerdas-ecrud\test\attachments\eCFT1MBAttachEmbeded.xml";
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_5MB_a.xml"; //6.8 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_14MB_a.xml"; //19.1 MB
                //string loadFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_17MB_a.xml"; //23.2 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_21MB_a.xml"; //28.7 MB
                //config.CompleteDocFileName = @"C:\vler-proto-out\generated_out\xmlWithEmbeddedB64_25MB_a.xml"; //34.2 MB
                //config.Base64FileName = @"F:\Dev Tools\mongodbWin32_64.zip.b64.txt"; //138 MB
                //config.Base64FileName = @"F:\Dev Tools\SnippetManager.b64.txt"; //zip file 507 KB
                //config.Base64FileName = @"F:\Dev Tools\dental-xray.jpg.txt"; //13.7 KB
                //config.Base64FileName = @"F:\Dev Tools\snake-river4.pdf.txt"; //32.1.7 KB
                //config.Base64FileName = @"C:\vler-proto-out\generated_out\xmlAttachment-Over1MB.xml.b64"; //1.33 MB

                //config.CompleteDocFileName = @"mongodbWin32_64.zip.b64.txt(whole).xml"; //138 MB

                config.StringURL = "http://*****:*****@"E:\VA\2waySSL\clientcert.pkcs12";
                config.SslCertPasswordFileName = @"E:\VA\2waySSL\clientcert.pkcs12-password.txt";
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"F:\Downloads\ides-cftdeom.asmr.com.cer", "test123"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\dodRootCA2.cer"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\DODJITCCA-27.crt"));
                //POSTRequest.ClientCertificates.Add(new X509Certificate(@"E:\VA\DoDCerts\ides-cftdemo.asmr.com.crt"));

                config.ClientTimeout = (int)(600000 * 1.5); //15 Min

                StreamWriter writer = new StreamWriter(configFileName);
                x.Serialize(writer, config);
                writer.Close();
            }

            //save config to file
            return(config);
        }
Beispiel #6
0
 private static string getANameFromTheFile(ConfigPOST config)
 {
     return(config.Base64FileName != null?Path.GetFileName(config.Base64FileName) : Path.GetFileName(config.CompleteDocFileName));
 }
Beispiel #7
0
        internal string getAttachmentFileName()
        {
            ConfigPOST config = this;

            return(getANameFromTheFile(config));
        }
Beispiel #8
0
        private static void doMultiPartPOSTs(byte[] xmlData, ConfigPOST config)
        {
            int postCount = 0;

            while (postCount < config.PostTimes)
            {
                printLine(DateTime.Now.ToString());
                Stopwatch stopWatch = new Stopwatch();
                postCount++;
                try {
                    HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(config.StringURL);
                    //For HTTPS two way cert, must be imported to "Trusted Root Certificate Authorities", Location: IE > Tools > Internet Options > Content > Certificates
                    POSTRequest.ClientCertificates.Add(new X509Certificate(config.SslCertFileName, config.getCertPassword())); // ours/CACI
                    //End HTTPS
                    POSTRequest.Method    = "POST";
                    POSTRequest.KeepAlive = false;
                    POSTRequest.Timeout   = config.ClientTimeout;
                    //Content length of message body
                    POSTRequest.Accept = "application/xml";

                    var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", NumberFormatInfo.InvariantInfo);
                    POSTRequest.ContentType = "multipart/form-data; boundary=" + boundary;
                    boundary = "--" + boundary;

                    stopWatch.Start();
                    using (var requestStream = POSTRequest.GetRequestStream()) {
                        var buffer = Encoding.ASCII.GetBytes(boundary + Environment.NewLine);
                        requestStream.Write(buffer, 0, buffer.Length);
                        buffer = Encoding.UTF8.GetBytes(string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"{2}", "file",
                                                                      config.getAttachmentFileName(), Environment.NewLine));
                        requestStream.Write(buffer, 0, buffer.Length);
                        buffer = Encoding.ASCII.GetBytes(string.Format("Content-Type: {0}{1}{1}", "text/xml", Environment.NewLine));
                        requestStream.Write(buffer, 0, buffer.Length);

                        requestStream.Write(xmlData, 0, xmlData.Length);

                        buffer = Encoding.ASCII.GetBytes(Environment.NewLine);
                        requestStream.Write(buffer, 0, buffer.Length);

                        var boundaryBuffer = Encoding.ASCII.GetBytes(boundary + "--");
                        requestStream.Write(boundaryBuffer, 0, boundaryBuffer.Length);
                    }

                    HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();
                    StreamReader    reader       = new StreamReader(POSTResponse.GetResponseStream(), Encoding.UTF8);
                    string          daLocation   = POSTResponse.GetResponseHeader("Location");
                    HttpStatusCode  daStatusCode = POSTResponse.StatusCode;

                    string ResponseFromPost = reader.ReadToEnd().ToString();
                    POSTResponse.Close();
                    printLine("StatusCode: " + daStatusCode);

                    if (daStatusCode == HttpStatusCode.Accepted ||
                        daStatusCode == HttpStatusCode.Created ||
                        daStatusCode == HttpStatusCode.OK)
                    {
                        printLine(ResponseFromPost);
                    }
                } catch (WebException we) {
                    String errMsg = we.Message;
                    if (we.Response != null)
                    {
                        errMsg += "; " + new StreamReader(we.Response.GetResponseStream(), Encoding.UTF8).ReadToEnd().ToString();
                    }
                    printLine(errMsg);
                }
                stopWatch.Stop();
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                     ts.Hours, ts.Minutes, ts.Seconds,
                                                     ts.Milliseconds / 10);
                printLine("Elapsed Time: " + elapsedTime);
                printLine("POST Count: " + postCount + Environment.NewLine);
            }
        }
Beispiel #9
0
        private static byte[] getBytesForPOST(ConfigPOST config)
        {
            NiemXML niemXML = new NiemXML();
            StringBuilder sb = new StringBuilder();
            if (config.Base64FileName != null) {
                sb.Append(niemXML.getBeforeBase64(config.DocTitle));
                string attachmentStr = File.ReadAllText(config.Base64FileName, Encoding.UTF8);

                //attachmentStr = Convert.ToBase64String(Encoding.UTF8.GetBytes(attachmentStr)); //String to Base64
                //or strip newlines?
                attachmentStr = attachmentStr.Replace(System.Environment.NewLine, "");

                sb.Append(attachmentStr);
                sb.Append(niemXML.getAfterBase64(attachmentStr.Length, config.AttachmentDescription,
                                                    config.AttachmentFormatName, config.getAttachmentFileName()));
                attachmentStr = null;
                File.WriteAllText(ConfigPOST.OUT_DIR + config.getAttachmentFileName() + "(whole).xml", sb.ToString());
            } else if (config.CompleteDocFileName != null) {
                sb.Append(File.ReadAllText(config.CompleteDocFileName, Encoding.UTF8));
            } else {
                throw new Exception("config.Base64FileName or config.CompleteDocFileName must be set!");
            }
            byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
            return xmlData;
        }
Beispiel #10
0
        private static void doMultiPartPOSTs(byte[] xmlData, ConfigPOST config)
        {
            int postCount = 0;
            while (postCount < config.PostTimes) {
                printLine(DateTime.Now.ToString());
                Stopwatch stopWatch = new Stopwatch();
                postCount++;
                try {
                    HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(config.StringURL);
                    //For HTTPS two way cert, must be imported to "Trusted Root Certificate Authorities", Location: IE > Tools > Internet Options > Content > Certificates
                    POSTRequest.ClientCertificates.Add(new X509Certificate(config.SslCertFileName, config.getCertPassword())); // ours/CACI
                    //End HTTPS
                    POSTRequest.Method = "POST";
                    POSTRequest.KeepAlive = false;
                    POSTRequest.Timeout = config.ClientTimeout;
                    //Content length of message body
                    POSTRequest.Accept = "application/xml";

                    var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", NumberFormatInfo.InvariantInfo);
                    POSTRequest.ContentType = "multipart/form-data; boundary=" + boundary;
                    boundary = "--" + boundary;

                    stopWatch.Start();
                    using (var requestStream = POSTRequest.GetRequestStream()) {
                        var buffer = Encoding.ASCII.GetBytes(boundary + Environment.NewLine);
                        requestStream.Write(buffer, 0, buffer.Length);
                        buffer = Encoding.UTF8.GetBytes(string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"{2}", "file",
                                                            config.getAttachmentFileName(), Environment.NewLine));
                        requestStream.Write(buffer, 0, buffer.Length);
                        buffer = Encoding.ASCII.GetBytes(string.Format("Content-Type: {0}{1}{1}", "text/xml", Environment.NewLine));
                        requestStream.Write(buffer, 0, buffer.Length);

                        requestStream.Write(xmlData, 0, xmlData.Length);

                        buffer = Encoding.ASCII.GetBytes(Environment.NewLine);
                        requestStream.Write(buffer, 0, buffer.Length);

                        var boundaryBuffer = Encoding.ASCII.GetBytes(boundary + "--");
                        requestStream.Write(boundaryBuffer, 0, boundaryBuffer.Length);
                    }

                    HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();
                    StreamReader reader = new StreamReader(POSTResponse.GetResponseStream(), Encoding.UTF8);
                    string daLocation = POSTResponse.GetResponseHeader("Location");
                    HttpStatusCode daStatusCode = POSTResponse.StatusCode;

                    string ResponseFromPost = reader.ReadToEnd().ToString();
                    POSTResponse.Close();
                    printLine("StatusCode: " + daStatusCode);

                    if (daStatusCode == HttpStatusCode.Accepted ||
                        daStatusCode == HttpStatusCode.Created ||
                        daStatusCode == HttpStatusCode.OK) {
                        printLine(ResponseFromPost);
                    }
                } catch (WebException we) {
                    String errMsg = we.Message;
                    if (we.Response != null)
                        errMsg += "; " + new StreamReader(we.Response.GetResponseStream(), Encoding.UTF8).ReadToEnd().ToString();
                    printLine(errMsg);
                }
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                        ts.Hours, ts.Minutes, ts.Seconds,
                                                        ts.Milliseconds / 10);
                printLine("Elapsed Time: " + elapsedTime);
                printLine("POST Count: " + postCount + Environment.NewLine);
            }
        }