예제 #1
0
        // Attach and send the current production
        public async Task <Dictionary <string[], WsResponse> > sendProd()
        {
            try {
                // preparing request HEADER
                HttpClientHandler handler    = new HttpClientHandler();
                HttpClient        client     = new HttpClient();
                byte[]            Basic_Auth = Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["id"] + ":" + ConfigurationManager.AppSettings["pass"]); // tester cet appel je vais pas y revenir une autre fois.
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Basic_Auth));
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                client.DefaultRequestHeaders.Add("Accept-Charset", "UTF-8");
                //preparing request BODY
                MultipartFormDataContent requestContent = new MultipartFormDataContent();        // default boundary
                                                                                                 //string boundary = "----MyBoundary" + DateTime.Now.Ticks.ToString("x");
                                                                                                 //requestContent.Headers.Remove("Content-Type");
                                                                                                 //requestContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary);
                ByteArrayContent json = new ByteArrayContent(Encoding.UTF8.GetBytes(genJson())); // encodage a verifier apres !!
                json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");       // can be configured
                requestContent.Add(json, "arbitrage");

                foreach (binaries bin in this.binaires)
                { // this can be optimised we have the files dupliated on bianries List Class and pieces List Class
                    ByteArrayContent binaryFile = new ByteArrayContent(bin.ficheirPDF);
                    binaryFile.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
                    requestContent.Add(binaryFile, "file", bin.nomFichie);
                }
                //POST ASYNC CALL
                HttpResponseMessage message = await client.PostAsync(ConfigurationManager.AppSettings["route"] + this.NumContrat + "/arbitrages", requestContent); // must be extracted

                LogTrace.Trace("SPI-WS Return Value", LogTrace.MESSAGE_INFO, message.ToString());
                string returnMessages = await message.Content.ReadAsStringAsync();

                LogTrace.Trace("SPI-WS Return Messages", LogTrace.MESSAGE_INFO, returnMessages);
                Dictionary <string[], WsResponse> response = new Dictionary <string[], WsResponse>();
                response.Add(new string[] { this.ReferenceInterne, this.prodActeID },
                             new WsResponse
                {
                    isSuccessCall = message.IsSuccessStatusCode,
                    message       = getMessage(returnMessages, message),
                    status_xml    = getStatusXml(message),
                }
                             );
                // 1 acte success => prod success
                if (message.IsSuccessStatusCode)
                {
                    SuccessActes.Add(this.ReferenceInterne);
                    isSuccess = true;
                }
                //waiting until we get the JSON response !
                return(response);
            } catch (Exception ex)
            {
            }
            return(new Dictionary <string[], WsResponse>());
        }
예제 #2
0
        //method that serialise the current object (this) into a JSON flow (this method rely on the ShouldSerialiseContratResolver Class)
        private string genJson()
        {
            JsonSerializerSettings jsonSetting = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                ContractResolver      = new ShouldSerializeContractResolver()
            };

            Definition.connexionQualif.Close();

            LogTrace.Trace("SPI-WS JSON", LogTrace.MESSAGE_INFO, JsonConvert.SerializeObject(this, jsonSetting));
            return(JsonConvert.SerializeObject(this, jsonSetting));
        }