using System; using System.Collections.Generic; using System.Net; using System.Configuration; using System.Diagnostics; using System.Web.UI.WebControls; /****************************************************** * Developer: Jaco van Eeden * Date: 05/03/2010 * Version 1.0 * Property of Pinnacle Africa * * Please contact the webmaster of Pinnacle Africa * for information regarding this code or the service * webmaster@pinnacle.co.za * * It is a very sad thing that nowadays there is so little useless information. * Oscar Wilde ******************************************************/ namespace TestDealerService { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { lblMessage.Text += "Dealer Test Web Services Started at " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; ; #region get the username and password from the config file. var pinUN = GetValue("pinUN"); var pinPW = GetValue("pinPW"); #endregion #region Credentials and cookies lblMessage.Text += "Set Connection: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //create login web service var wsst = new WSService.Service(); #region Session & Cookies variables var cc = new CookieContainer(); var sessioncookie = new Cookie(); var cookiecoll = new CookieCollection(); #endregion //set the cookie contained to the new varaible. wsst.CookieContainer = cc; lblMessage.Text += "Finished With Connection: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #region Service #region Testing The Login lblMessage.Text += "Starting Login " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //call the LOGIN method, using Dealer Login information if (wsst.LogIn(pinUN, pinPW)) { lblMessage.Text += "Login Successful
"; } else { lblMessage.Text += "Login Failed
"; return; } lblMessage.Text += "Login Completed " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #region Setting the credentials //get the cookie from the webservice cookiecoll = wsst.CookieContainer.GetCookies(new Uri(wsst.Url)); //set the session variable Session["sessioncookie"] = cookiecoll["CookieName"]; //checking if logged in. lblMessage.Text += String.Format(@"Logged in : {0}
", wsst.IsLoggedIn()); #endregion #endregion #region Stock Enq web service lblMessage.Text += "Get Stock WS " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //calling the StockEnq var wss = new WSStockEnq.StockEnq(); //set the session variables wss.CookieContainer = cc; sessioncookie = (Cookie)Session["sessioncookie"]; if (sessioncookie != null) { wss.CookieContainer.Add(sessioncookie); } lblMessage.Text += "All Cred Set " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #region Test if the credentials worked lblMessage.Text += "Check Stock Credentials " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //call the services in the authenticated services lblStockEnq.Text = wss.HelloWorld(); lblMessage.Text += "End Stock Credential Check " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #region Stock Item #region StockItemEngByCode lblMessage.Text += "Call StockItemEnqByCode: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; lblStockItem.Text = "Calling StockItemEnqByCode('KLV-40BX400')
"; var s = wss.StockItemEnqByCode("KLV-40BX400"); if (!s.IsNull) { lblStockItem.Text += String.Format(@"Code: {0} Price: {1} Quantity Available: {2} Active: {3}", s.Code, s.Price, s.Availability, s.Active); } else { lblStockItem.Text += "Stock Item Code Invalid"; } lblMessage.Text += "End StockItemEnqByCode: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "

"; #endregion #region StockItemEngByBrandName lblMessage.Text += "Start StockItemEnqByBrandname: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; var lst = wss.StockItemEnqByBrandName("Asonic"); lblByBrand.Text = "Calling wss.StockItemEnqByBrandName('Asonic')
"; if (lst.Length > 0) { lblByBrand.Text += "Search By Brand Name
"; foreach (var p in lst) { lblByBrand.Text += String.Format(@"Code: {0} IsNull: {1} Price: {2} Quantity Available: {3} Active: {4}
", p.Code, p.IsNull, p.Price, p.Availability, p.Active); } } else { lblByBrand.Text += "No Items"; } lblMessage.Text += "End StockItemEnqByBrandName: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "

"; #endregion #region StockItemEngNewByDate lblMessage.Text += "Start StockItemEngNewByDate: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; var lstnew = wss.StockItemEnqNewByDate(DateTime.Now.AddMonths(-3)); lblStockItemEngNewByDate.Text = "Calling wss.StockItemEnqNewByDate(DateTime.Now.AddMonths(-3))
"; if (lstnew.Length > 0) { lblStockItemEngNewByDate.Text += "New since " + DateTime.Now.AddMonths(-3) + "
"; foreach (var p in lstnew) { lblStockItemEngNewByDate.Text += String.Format(@"Code: {0} IsNull: {1} Price: {2} Quantity Available: {3} Active: {4}
", p.Code, p.IsNull, p.Price, p.Availability, p.Active); } } else { lblStockItemEngNewByDate.Text += "No Items"; } lblMessage.Text += "End StockItemEngNewByDate: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "

"; #endregion #region StockItemEngUpdatedByDate lblMessage.Text += "Start StockItemEngUpdatedByDate: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; var lstUpdated = wss.StockItemEnqUpdatedByDate(DateTime.Now.AddMonths(-3)); lblStockItemEngUpdatedByDate.Text = "Calling wss.StockItemEnqUpdatedByDate(DateTime.Now.AddMonths(-3))
"; if (lstUpdated.Length > 0) { lblStockItemEngUpdatedByDate.Text += "Updated since " + DateTime.Now.AddMonths(-3) + "
"; foreach (var p in lstUpdated) { lblStockItemEngUpdatedByDate.Text += String.Format(@"Code: {0} IsNull: {1} Price: {2} Quantity Available: {3} Active: {4}
", p.Code, p.IsNull, p.Price, p.Availability, p.Active); } } else { lblStockItemEngUpdatedByDate.Text = "No Items"; } lblMessage.Text += "End StockItemEngUpdatedByDate: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "

"; #endregion #endregion #region Product #region Set Credentials for Product Eng lblMessage.Text += "Set Credentials for Product Eng: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //calling the StockEnq var wsp = new WSProductEnq.ProductEnq(); //set the session variables wsp.CookieContainer = cc; sessioncookie = (Cookie)Session["sessioncookie"]; if (sessioncookie != null) { wsp.CookieContainer.Add(sessioncookie); } lblMessage.Text += "End Set Credentials for Product Eng: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #region ProductEnqByCode lblMessage.Text += "Start ProductEnqByCode: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; lblProductByCode.Text = "Search By Code : DWL-2100AP
"; var pp = wsp.ProductEnqByCode("DWL-2100AP"); if (!pp.IsNull) { lblProductByCode.Text += String.Format(@"Code: {0}
Name: {1}
Brand: {2}
Description: {3}
Specs: {4}
Image URL: {5}", pp.Code, pp.Name, pp.BrandName, pp.ShortDescription, pp.FullDescription, pp.ImageURL); if (pp.StockInfo != null && !pp.StockInfo.IsNull) { lblProductByCode.Text += String.Format(@"
Price: {0}
Quantity Available: {1}", pp.StockInfo.Price, pp.StockInfo.Availability); } else { lblProductByCode.Text += "
Price: Unknown
Quantity Available: Unknown
"; } } else { lblProductByCode.Text += "Product Code Invalid
"; } lblMessage.Text += "End ProductEnqByCode: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion #endregion #region Test CSV Generator //#region Document Gen web service ////calling the DocumentGen //var wsdg = new WSDocumentGen.DocumentGen(); ////set the credentials for accessing the folder //wsdg.Timeout = 6000000; ////set the session variables //wsdg.CookieContainer = cc; //sessioncookie = (Cookie)Session["sessioncookie"]; //if (sessioncookie != null) //{ // wsdg.CookieContainer.Add(sessioncookie); //} //#endregion //#region different variables for testing //bool showName = true; //bool showBrand = true; //bool showDescription = true; //bool showCategory = true; //bool showImageURL = true; //bool showPrice = true; //string priceNull = "UNKNOWN"; //bool showAvailability = true; //string availableNull = "UNKNOWN"; //#endregion //#region CAll the method and show filename //var filename = wsdg.GenCSV(showName, showBrand, showDescription, showCategory, showImageURL, showPrice, priceNull, showAvailability, availableNull); //if (String.IsNullOrEmpty(filename)) //{ // hlGenDoc.Text = "No File was generated"; // hlGenDoc.NavigateUrl = String.Empty; //} //else //{ // hlGenDoc.Text = filename; // hlGenDoc.NavigateUrl = filename; //} //#endregion #endregion #region Logout Test lblMessage.Text += "Start logout: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; //log out of the web service. wsst.LogOut(); lblLoggedOut.Text = String.Format(@"Logged in : {0}
", wsst.IsLoggedIn()); lblMessage.Text += "End Logout: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; #endregion lblMessage.Text += "Application Closing: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "
"; } catch (Exception ex) { lblMessage.Text += ex.ToString(); } } #region GetValue private static string GetValue(string key) { return ConfigurationManager.AppSettings[key]; } #endregion } }