/// <summary>Snippet for ImportProducts</summary> public void ImportProductsRequestObject() { // Snippet: ImportProducts(ImportProductsRequest, CallSettings) // Create client ProductServiceClient productServiceClient = ProductServiceClient.Create(); // Initialize request argument(s) ImportProductsRequest request = new ImportProductsRequest { Parent = "", InputConfig = new ProductInputConfig(), ErrorsConfig = new ImportErrorsConfig(), UpdateMask = new FieldMask(), }; // Make the request Operation <ImportProductsResponse, ImportMetadata> response = productServiceClient.ImportProducts(request); // Poll until the returned long-running operation is complete Operation <ImportProductsResponse, ImportMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result ImportProductsResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <ImportProductsResponse, ImportMetadata> retrievedResponse = productServiceClient.PollOnceImportProducts(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result ImportProductsResponse retrievedResult = retrievedResponse.Result; } // End snippet }
/************************* * /* HTTPCLIENT KULLANIMI */ /************************/ /* * public static async Task<HttpResponseMessage> PostURI(Uri u, ImportProductsRequest list) * { * * using (HttpClient httpClient = new HttpClient()) * { * * var json = JsonConvert.SerializeObject(list); * var data = new StringContent(json, Encoding.UTF8, "application/json"); * * * var responseMessage = await httpClient.PostAsync(u, data); * string result = responseMessage.Content.ReadAsStringAsync().Result; * * Console.WriteLine(result); * * return responseMessage; * * } * } */ /****************************/ /* HTTPWEBREQUEST KULLANIMI */ /****************************/ public static string PostURI(Uri u, ImportProductsRequest list) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(u); // httpWebRequest.AllowAutoRedirect = false; //redirect engelleyince 302 hatası alıyorum. httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var json = JsonConvert.SerializeObject(list); streamWriter.Write(json); } try { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); return(result.ToString()); } } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
static void Main(string[] args) { ImportProductsRequest list = ProductReader.GetProduct("sample.csv"); var t = PostProduct.PostURI(new Uri("http://dev.shopiconnect.com/api/productImport/ImportDeltaProducts"), list); /* HTTPCLIENT'lı fonksiyon için => */ // var t = Task.Run(() => ReadCsv.ProductReader.PostURI(new Uri("http://dev.shopiconnect.com/api/productImport/ImportDeltaProducts"),list)); //t.Wait(); }
/**************************************/ /* CSV DOSYASINI OKUYUP CLASS'A ATAMA */ /**************************************/ public static ImportProductsRequest GetProduct(string u) { using (var reader = new StreamReader(u)) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Configuration.Delimiter = "|"; csv.Configuration.RegisterClassMap <ProductMap>(); var list = csv.GetRecords <Product>().ToList(); var products = new ImportProductsRequest(); products.ProductList = list; for (int i = 0; i < products.ProductList.Count(); i++) //IntegrationId atama { products.ProductList[i].IntegrationId = i.ToString(); } return(products); } }
public ParseCsvFile() { productsRequest = new ImportProductsRequest(); Parse(); }