/* Microsoft SQL Server Integration Services Script Component * Write scripts using Microsoft Visual C# 2008. * ScriptMain is the entry point class of the script.*/ using System; using System.Data; using Microsoft.SqlServer.Dts.Pipeline.Wrapper; using Microsoft.SqlServer.Dts.Runtime.Wrapper; using System.Net; using System.IO; using System.Globalization; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Collections.Generic; using System.Runtime.Serialization; using System.Web.Extensions; using System.Web.Script.Serialization; using Newtonsoft.Json; [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] public class ScriptMain : UserComponent { public static string responseFromServer = ""; // public static string URL = "http://172.16.5.99:55561/GIS/ProductSvc/REST/GetProductList/test/1/*/*"; public static string URL = "http://172.16.5.233:55561/GIS/ProductSvc/REST/GetProductList/skarp/1/*/TVK!|^U;ANR<=39"; public static int temp = 0; // public static string test2 = ""; //public static string test3 = ""; // public static string test1 = ""; public override void PreExecute() { base.PreExecute(); /* Add your code here for preprocessing or remove if not needed */ } public override void PostExecute() { base.PostExecute(); /* Add your code here for postprocessing or remove if not needed You can set read/write variables here, for example: Variables.MyIntVar = 100 */ } [DataContract] public class Article { [DataMember] public List ProductText{ get; set; } public string ProductNo {get; set;} public string Description { get; set; } public string Category { get; set; } public int AmountPerUnit { get; set; } public decimal Price { get; set; } public string DiscountSalesCode { get; set; } public string SupplierNo { get; set; } public string SupplierProductNo { get; set; } public decimal PurchasePrice { get; set; } public string PurchaseCurrencyCode { get; set; } public decimal StandardPrice { get; set; } public string OriginType { get; set; } } [DataContract] public class ProductText { [DataMember] public string Code { get; set; } public string Field { get; set; } public string Value { get; set; } } public override void CreateNewOutputRows() { JavaScriptSerializer serialize = new JavaScriptSerializer(); serialize.MaxJsonLength = int.MaxValue; WebRequest request = WebRequest.Create(URL); request.Method = "GET"; request.Timeout = 10000000; WebResponse webresponse = request.GetResponse(); Console.WriteLine(((HttpWebResponse)webresponse).StatusDescription); Stream dataStream = webresponse.GetResponseStream(); using (var streamReader = new StreamReader(dataStream)) { try { string json = streamReader.ReadToEnd(); List
c = serialize.Deserialize>(json); //MessageBox.Show(c.Count.ToString()); foreach (Article co in c) { Output0Buffer.AddRow(); Output0Buffer.ArticleNumber = co.ProductNo; // Output0Buffer.Name = co.Description; Output0Buffer.Price = co.Price; // test1 = co.Category; // test2 = co.DiscountSalesCode; // test3 = co.SupplierNo; if (co.ProductText != null) { string secondlabel = ""; foreach (var item in co.ProductText) { if (item.Code == "f") { secondlabel = item.Value; } } if (secondlabel != "") { Output0Buffer.Name = co.Description + " " + secondlabel; } else { Output0Buffer.Name = co.Description; } } else { Output0Buffer.Name = co.Description; } //for (int i = 0; i < co.ProductText.Count; i++) //{ // extraText = "Hi"; //if (co.ProductText[i].Code == "f") //{ // extraText = co.ProductText[i].Value; //} // } if (!int.TryParse(co.Category, out temp)) { Output0Buffer.Category = 0; } else { Output0Buffer.Category = Convert.ToInt32(co.Category); } Output0Buffer.Quantity = co.AmountPerUnit; if (!int.TryParse(co.DiscountSalesCode, out temp)) { Output0Buffer.Discount = 0; } else { Output0Buffer.Discount = Convert.ToInt32(co.DiscountSalesCode); } if (!int.TryParse(co.SupplierNo, out temp)) { Output0Buffer.LevNumber = 0; } else { Output0Buffer.LevNumber = Convert.ToInt32(co.SupplierNo); } Output0Buffer.CostPrice = co.PurchasePrice; Output0Buffer.Currency = co.PurchaseCurrencyCode; Output0Buffer.StandardPrice = co.StandardPrice; Output0Buffer.TK = co.OriginType; Output0Buffer.SupplierProductNo = co.SupplierProductNo; } } catch (Exception e) { // System.Windows.Forms.MessageBox.Show(test1); // System.Windows.Forms.MessageBox.Show(test2); // System.Windows.Forms.MessageBox.Show(test3); System.Windows.Forms.MessageBox.Show(e.ToString()); Console.WriteLine(e); } streamReader.Close(); dataStream.Close(); webresponse.Close(); } } }