public static string getNextFileFromFolder(string targetDirectory, string archiveDirectory) { string fileToProcess = ""; // Process the list of files found in the directory. string[] fileEntries = Directory.GetFiles(targetDirectory); foreach (string fileName in fileEntries) { if (isAcquittement(fileName)) { // on cherche le fichier correspondant fileToProcess = fileName; fileToProcess = fileToProcess.Replace("acq", "txt"); //on déplace le fichier acquittement dans archive FileUtilities.moveFileToFolder(archiveDirectory, fileName); if (File.Exists(fileToProcess)) { ig.setRichTextBox("\nTraitement du fichier " + fileToProcess, false, Parameters.productId); return(fileToProcess); } else { ig.setRichTextBox("\nAvertissement : fichier acquittement trouvé sans fichier txt " + fileName, false, Parameters.productId); } } } return(null); }
internal static void makeSoapRequest(string postData) { var request = (HttpWebRequest)WebRequest.Create(Program.Products.wsURL); request.ContentType = "text/xml; charset=utf-8"; request.Method = "POST"; //Accept - Encoding: // request.Timeout = 10000; //request.Credentials = new NetworkCredential(Program.Products.username, Program.Products.password); //request.Headers.Add("Accept-Encoding", "*"); request.Headers.Add("SoapAction", @"http://RedouteFrance/seller/items/1.1"); request.Headers.Add("Authorization", "Basic " + FileUtilities.Base64Encode(Program.Products.username + ":" + Program.Products.password)); request.KeepAlive = true; request.Headers.Add("mime-version", "1.0"); request.Expect = null; //préparation de la requête SOAP Attachment request.ContentType = @"multipart/related;boundary=emova;type=text/xml;start=""<main_envelope>"""; //Message SOAP var requestData = composeMessage(postData); byte[] info = new UTF8Encoding(true).GetBytes(requestData); request.ContentLength = info.Length; ig.setRichTextBox("\n-------Requête d'envoi des produits\n" + requestData, false, Parameters.productId); using (Stream stream = request.GetRequestStream()) { /* stream.Write(info, 0, info.Length); * stream.Close();*/ using (var writer = new StreamWriter(stream)) { writer.Write(requestData); } } WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); String responseString = reader.ReadToEnd(); ig.setRichTextBox("\n\n-------Response du web services produits \n" + responseString, false, Parameters.productId); } response.Close(); }
public static void ThreadLoop() { Boolean fileExists = false; string filename; while (Thread.CurrentThread.IsAlive) { Thread.Sleep(Program.Products.execIntDelay); MainInterface ig = (MainInterface)Application.OpenForms["MainInterface"]; ig.setRichTextBox("\nRecherche de nouveaux produits à envoyer", false, Parameters.productId); //Lecture répertoire source pour rechercher les fichiers //Pour chaque fichier trouvé appeller WSProducts filename = FileUtilities.getNextFileFromFolder(Program.Products.source, Program.Products.archive); while (filename != null) { WSProducts.createXMLFile(filename); FileUtilities.moveFileToFolder(Program.Products.archive, filename); filename = FileUtilities.getNextFileFromFolder(Program.Products.source, Program.Products.archive); } Thread.Sleep(Program.Products.execInterval); } }
// static string REQUEST_BODY = @"<?xml version=""1.0"" encoding=""UTF-8""?><SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""><SOAP-ENV:Body><attachment/></SOAP-ENV:Body></SOAP-ENV:Envelope>"; // static string REQUEST_BEGIN = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns=""http://RedouteFrance/seller/items/1.1""><soapenv:Header/><soapenv:Body><ns:injectItems><api-key>"; // static string REQUEST_END = "</api-key></ns:injectItems></soapenv:Body></soapenv:Envelope>"; internal static string makeSoapRequest(string flux, string SoapAction, int method) { var request = (HttpWebRequest)WebRequest.Create(Program.Commands.wsURL); request.Method = "POST"; request.Headers.Add("SoapAction", SoapAction); //request.Accept = "text/xml"; request.Headers.Add("Authorization", "Basic " + FileUtilities.Base64Encode(Program.Commands.username + ":" + Program.Commands.password)); //Message SOAP var requestData = ""; if (method == 0) { requestData = composeMessageRecup(flux); ig.setRichTextBox("\n------- requête de récupération des commandes \n" + requestData, false, Parameters.commandId); } else if (method == 1) { requestData = flux; ig.setRichTextBox("\n------- requête de mise à jour des commandes\n" + requestData, false, Parameters.commandId); } /*byte[] info = new UTF8Encoding(true).GetBytes(requestData); * request.ContentLength = info.Length;*/ using (Stream stream = request.GetRequestStream()) { /* stream.Write(info, 0, info.Length); * stream.Close();*/ using (var writer = new StreamWriter(stream)) { writer.Write(requestData); } } try { WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); String responseString = reader.ReadToEnd(); ig.setRichTextBox("\n\n-------Response du web service \n" + responseString, false, Parameters.commandId); return(responseString); } response.Close(); } catch (Exception e) { ig.setRichTextBox("\nUne erreur s'est produite : " + e.Message, false, Parameters.commandId); } return(null); }
public static void ThreadLoop() { Boolean fileExists = false; string filename; while (Thread.CurrentThread.IsAlive) { Thread.Sleep(Program.Commands.execIntDelay); MainInterface ig = (MainInterface)Application.OpenForms["MainInterface"]; ig.setRichTextBox("\nRecherche de nouvelles commandes à réceptionner", false, Parameters.commandId); //Lecture répertoire source pour rechercher les fichiers //Pour chaque fichier trouvé appeller WSProducts // filename = FileUtilities.getNextFileFromFolder(Program.Commands.source, Program.Commands.archive); // while (filename != null) // { WSCommands.initOdersWorkflow(); // FileUtilities.moveFileToFolder(Program.Commands.archive, filename); // filename = FileUtilities.getNextFileFromFolder(Program.Commands.source, Program.Commands.archive); // } Thread.Sleep(Program.Commands.execInterval); } }
internal static void makeSoapRequest(string filename, string postData) { var request = (HttpWebRequest)WebRequest.Create(Program.Offers.wsURL); //request.ContentType = "application/soap+xml; charset=utf-8"; request.Method = "POST"; //Accept - Encoding: // request.Timeout = 10000; //request.Credentials = new NetworkCredential(Program.Products.username, Program.Products.password); request.Headers.Add("Accept-Encoding", "gzip,deflate"); request.Headers.Add("SoapAction", "InjectFile_1.0"); request.Accept = "application/soap+xml";//"text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; request.Headers.Add("Authorization", "Basic " + FileUtilities.Base64Encode(Program.Offers.username + ":" + Program.Offers.password)); // request.KeepAlive = true; request.Headers.Add("mime-version", "1.0"); request.Expect = null; //préparation de la requête SOAP Attachment request.ContentType = @"Multipart/Related;boundary=emova;type=""application/soap+xml""charset=""utf-8"";start=""<main_envelope>"""; var requestData = composeMessage(filename, postData); byte[] info = new UTF8Encoding(true).GetBytes(requestData); request.ContentLength = info.Length; ig.setRichTextBox("\n------- requête d'envoi des offres \n" + requestData, false, Parameters.offerId); using (Stream stream = request.GetRequestStream()) { /* stream.Write(info, 0, info.Length); * stream.Close();*/ using (var writer = new StreamWriter(stream)) { writer.Write(requestData); } } portTypeClient client = new portTypeClient(); //string response = client.InjectFileToOverride_10Op(Program.Globals.vendorId, "400", "MKP_SellerOffer", "001", Path.GetFileNameWithoutExtension(filename), Path.GetDirectoryName(filename), 0, true); string bacchid = null; ErrorType err = null; client.Open(); bool response = client.InjectFile_10Op(Program.Globals.vendorId, "400", "MKP_SellerOffer", "001", Path.GetFileName(filename), "", 1, true, null, true, out bacchid, out err); ig.setRichTextBox("\n\n-------Response = " + response, false, Parameters.offerId); ig.setRichTextBox("\n\n-------Bacchid = " + bacchid, false, Parameters.offerId); ig.setRichTextBox("\n\n-------Erreur = " + err.Message, false, Parameters.offerId); //InjectFile_10OpRequest req = new InjectFile_10OpRequest(Program.Globals.vendorId, "400", "MKP_SellerOffer", "001", Path.GetFileNameWithoutExtension(filename), Path.GetDirectoryName(filename),0, true,null,true); /*InjectFile_10OpResponse resp = req. * resp.*/ /* * try * { * WebResponse response = request.GetResponse(); * * using (Stream stream = response.GetResponseStream()) * { * StreamReader reader = new StreamReader(stream, Encoding.UTF8); * String responseString = reader.ReadToEnd(); * ig.setRichTextBox("\n\n-------Response du web service offres = \n" + responseString, false, Parameters.offerId); * } * response.Close(); * } * catch (Exception e) * { * * ig.setRichTextBox("\nUne erreur s'est produite : " + e.Message, false, Parameters.offerId); * }*/ }