VS2019からArticle030.aspxのコードビハインド(Article030.aspx.cs)を選択して表示したら以下のコードを入力します。
Page_Load()イベント処理:
Article030.aspx.cs:
private const string ssPublicVariableObject = "PassingPublicVariableObject";
private const string ssPassingTraceWriteObject = "PassingTraceWriteObject";
public WebConfigArgs wc;
public PublicVaribleArgs pv;
public TraceWrite tw;
protected void Page_Load(object sender, EventArgs e)
{
wc = WebConfig.GetWebConfigAmazon();
pv = PublicVariable.GetPublicVarialbe(bolDebugMode: false, bolTraceMode: false, lblMessage: lblMessage, lblTrace: lblMessage);
Session[ssPublicVariableObject] = pv;
tw = new TraceWrite(lblTrace, suppress: false, id: "Article030.aspx");
Session[ssPassingTraceWriteObject] = tw;
lblTrace.Text = "";
tw.aspX(string.Format("Page_Load(Page.IsPostBack={0})", Page.IsPostBack)); // black
}
btnGetPrice1_Click()イベント処理:
Article030.aspx.cs:
protected void btnGetPrice1_Click(object sender, EventArgs e)
{
tw.aspX2(String.Format("btnGetPrice1_Click()")); // blue
string strASIN1 = txtASIN1.Text.Trim();
string strASIN2 = txtASIN2.Text.Trim();
string strASIN3 = txtASIN3.Text.Trim();
// Create a configuration object
MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig();
config.ServiceURL = wc.strServiceUrlAu;
tw.aspX3(String.Format("..config = new MarketplaceWebServiceProductsConfig(ServiceURL={0})", wc.strServiceUrlAu)); // green
// Create the client itself
MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient(wc.strAppName, wc.strAppVersion, wc.strAccessKeyAu, wc.strSecretKeyAu, config);
tw.aspX3(String.Format("..client = new MarketplaceWebServiceProductsClient(config)"));
ASINListType asinList = new ASINListType();
asinList.ASIN.Add(strASIN1);
if (!String.IsNullOrEmpty(strASIN2))
{
asinList.ASIN.Add(strASIN2);
}
if (!String.IsNullOrEmpty(strASIN3))
{
asinList.ASIN.Add(strASIN3);
}
try
{
// Create a request.
GetLowestOfferListingsForASINRequest request = new GetLowestOfferListingsForASINRequest(wc.strSellerIdAu, wc.strMarketplaceIdAu, asinList);
request.ExcludeMe = true;
request.ItemCondition = "New"; // New,Used,Collectible,Refurbished,Club,Default(All)
GetLowestOfferListingsForASINResponse response = client.GetLowestOfferListingsForASIN(request);
string strMessageRef = "";
string strStatus = GetLowestOfferListingsForASIN_Status(response, ref strMessageRef); // ClientError or Success
tw.aspX3(String.Format("..client.GetLowestOfferListingsForASIN(ASIN={0}, ExcludeMe={1}, ItemCondition={2}) ▶ Response.Status({3})", strASIN1, true, "New", strStatus));
// GetLowestOfferListingsForASINResponse
if (response.IsSetGetLowestOfferListingsForASINResult())
{
// Successfull Call?
if (strStatus == "Success")
{
int intProdCount = 0;
// GetLowestOfferListingsForSKUResult
foreach (GetLowestOfferListingsForASINResult getLowestOfferListingsForASINResult in response.GetLowestOfferListingsForASINResult)
{
// Product
if (getLowestOfferListingsForASINResult.IsSetProduct())
{
Product product = getLowestOfferListingsForASINResult.Product;
intProdCount++;
// 1) Identifiers
if (product.IsSetIdentifiers())
{
// MarketplaceASIN
string strASIN = "";
// Get ASIN/SKU
if (product.Identifiers.IsSetMarketplaceASIN())
{
strASIN = product.Identifiers.MarketplaceASIN.ASIN;
tw.aspX4(String.Format("..product.Identifiers.MarketplaceASIN.ASIN={0}", product.Identifiers.MarketplaceASIN.ASIN));
}
// 2) LowestOfferListings
if (product.IsSetLowestOfferListings())
{
int i = 0; // 0 based index
int intSellerCnt = 0; // 1 based
LowestOfferListingList lowestOfferListingList = product.LowestOfferListings;
// 2-1) LowestOfferListing
if (lowestOfferListingList.IsSetLowestOfferListing())
{
foreach (LowestOfferListingType lowestOfferListingType in lowestOfferListingList.LowestOfferListing)
{
intSellerCnt++; // 1 based counter
// 2-1-1) Qualifiers
if (lowestOfferListingType.IsSetQualifiers())
{
QualifiersType qualifiersType = lowestOfferListingType.Qualifiers;
// 2-1-1-1) ItemCondition, ItemSubCondition, FilfillmentChannel
if (qualifiersType.IsSetItemCondition())
{
tw.aspX4(String.Format("..ItemCondition={0}", qualifiersType.ItemCondition)); // New, Used, Collectible, Refurbished, Club
}
if (qualifiersType.IsSetItemSubcondition())
{
tw.aspX4(String.Format("..ItemSubCondition={0}", qualifiersType.ItemSubcondition)); // New, Mint, VeryGood, Good, Acceptable, Poor, Club, OEM, Warranty, Refurbished
}
if (qualifiersType.IsSetFulfillmentChannel())
{
tw.aspX4(String.Format("..FulfillmentChannel={0}", qualifiersType.FulfillmentChannel)); // Amazon, Merchant
}
// 2-1-1-2) ShippingTime (14 or more days)
if (qualifiersType.IsSetShippingTime())
{
tw.aspX4(String.Format("..ShippingTime.Max={0}", qualifiersType.ShippingTime.Max)); // ShippingTime (Max) 2-3 days, 8-13 days, 14 or more days,...
}
// 2-1-1-3) Seller Positive Feedback Rating (90-100%)
if (qualifiersType.IsSetSellerPositiveFeedbackRating())
{
tw.aspX4(String.Format("..FeedbackRating={0}", qualifiersType.SellerPositiveFeedbackRating)); // 90-94% or 90-100% or Less than 70% or Just Launched
}
}
// 2-1-2) SellerFeedbackCount
if (lowestOfferListingType.IsSetSellerFeedbackCount())
{
tw.aspX4(String.Format("..FeedbackCount={0}", Convert.ToInt32(lowestOfferListingType.SellerFeedbackCount)));
}
// 2-1-3) Price (Lowest Price)
if (lowestOfferListingType.IsSetPrice())
{
PriceType priceType = lowestOfferListingType.Price;
if (priceType.IsSetLandedPrice())
{
tw.aspX4(String.Format("..LandedPrice.Amount={0:n0}, CurrencyCode={1}",
priceType.LandedPrice.Amount, priceType.LandedPrice.CurrencyCode)); // Price + Shipping - Points
}
if (priceType.IsSetListingPrice())
{
tw.aspX4(String.Format("..ListingPrice.Amount={0:n0}, CurrencyCode={1}",
priceType.ListingPrice.Amount, priceType.ListingPrice.CurrencyCode)); // Listing Price (Not Used)
}
if (priceType.IsSetShipping())
{
tw.aspX4(String.Format("..Shipping.Amount={0:n0}, CurrencyCode={1}",
priceType.Shipping.Amount, priceType.Shipping.CurrencyCode)); // Shipping Fee (Not Used)
}
if (priceType.IsSetPoints())
{
tw.aspX4(String.Format("..Points.PointsNumbe={0}", priceType.Points.PointsNumber));
tw.aspX4(String.Format("..Points.PointsMonetaryValue.Amount={0:n0}, CurrencyCode={1}",
priceType.Points.PointsMonetaryValue.Amount, priceType.Points.PointsMonetaryValue.CurrencyCode)); // Points (Not Used)
}
}
else
{
tw.aspX4(String.Format("..if (lowestOfferListingType.IsSetPrice()) else: No Price"));
}
tw.aspX3(String.Format("------------------------- end of Seller {0}", intSellerCnt));
i++;
}
}
else
{
tw.aspX3(String.Format("..if (lowestOfferListingList.IsSetLowestOfferListing()) else: No Sellers for ASIN={0}", strASIN));
}
}
else
{
tw.aspX3(String.Format("..if (product.IsSetLowestOfferListings()) else: No Sellers for ASIN={0}", strASIN));
}
}
else
{
tw.aspX3(String.Format("..if (product.IsSetIdentifiers()) else: No Sellers for ASIN={0}", strASIN1));
}
}
else
{
tw.aspX3(String.Format("..if (getLowestOfferListingsForASINResult.IsSetProduct()) else: No Sellers for ASIN={0}", strASIN1));
}
}
}
else
{
// "NoBuyableOffers" ?
if (strMessageRef.IndexOf("NoBuyableOffers") != -1)
{
tw.aspX3(String.Format("..**Warning** GetLowestOfferListingsForASIN(): Status={0}, {1}", strStatus, strMessageRef));
}
else
{
tw.aspX3(String.Format("..**ERROR** GetLowestOfferListingsForASIN(): Status={0}, {1}", strStatus, strMessageRef));
}
}
}
}
catch (Exception ex)
{
lblMessage.Text = String.Format("An exception occurred while executing GetLowestOfferListingsForASIN() : {0}", ex == null ? "null" : ex.Message);
}
}
GetLowestOfferListingsForASIN_Status()処理:
Article030.aspx.cs:
private string GetLowestOfferListingsForASIN_Status(GetLowestOfferListingsForASINResponse response, ref string strMessageRef)
{
string strStatus = "Invalid Call"; // ClientError or Success
if (response.IsSetGetLowestOfferListingsForASINResult())
{
// XPath
XmlDocument doc = new XmlDocument();
doc.LoadXml(response.ToXML());
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("mws", "http://mws.amazonservices.com/schema/Products/2011-10-01");
nsmgr.AddNamespace("ns2", "http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd");
XmlNode node;
// Get Status
node = doc.SelectSingleNode("/mws:GetLowestOfferListingsForASINResponse/mws:GetLowestOfferListingsForASINResult", nsmgr);
if (node != null)
{
strStatus = node.Attributes["status"].Value; // ClientError or Success
// Error ?
if (strStatus == "ClientError")
{
const string cstrErrorBasePath = "/mws:GetLowestOfferListingsForASINResponse/mws:GetLowestOfferListingsForASINResult/mws:Error";
string strType = "";
string strCode = "";
string strMessage = "";
// Get Error Type
node = doc.SelectSingleNode(cstrErrorBasePath + "/mws:Type", nsmgr);
if (node != null)
{
strType = node.InnerText;
}
// Get Error Code
node = doc.SelectSingleNode(cstrErrorBasePath + "/mws:Code", nsmgr);
if (node != null)
{
strCode = node.InnerText;
}
// Get Error Message
node = doc.SelectSingleNode(cstrErrorBasePath + "/mws:Message", nsmgr);
if (node != null)
{
strMessage = node.InnerText;
}
strMessageRef = String.Format("Error Info=[Type={0}, Code={1}, Message={2}]", strType, strCode, strMessage);
}
else // Success
{
strMessageRef = String.Format("GetLowestOfferListingsForASIN() Call Successfully Completed!");
}
}
}
return (strStatus); // Success or ClientError
}
VS2019から新規クラスTraceWrite.csを作成したら以下のコードを入力します。
TraceWrite.cs:
public class TraceWrite
{
public Label lblTrace { get; set; } // Trace Output Label
public bool bolSuppress { get; set; } // True - Suppress Trace, False - Write trace
public string strID { get; set; } // ID - Article999.aspx, AccessDb.Stats, AccessDb.Category,...
public string strMessage { get; set; } // Message
public TraceWrite()
{
this.bolSuppress = false;
this.strID = "Article???.aspx";
}
public TraceWrite(Label trace)
{
this.lblTrace = trace;
this.bolSuppress = false;
this.strID = "Article???.aspx";
}
public TraceWrite(Label trace, bool suppress)
{
this.lblTrace = trace;
this.bolSuppress = suppress;
this.strID = "Article???.aspx";
}
public TraceWrite(Label trace, bool suppress, string id)
{
this.lblTrace = trace;
this.bolSuppress = suppress;
this.strID = id; // Artice999.aspx, AccessDb.Stats, AccessDb.Category,...
}
public void TW(string message)
{
if (!bolSuppress)
{
this.strID = "TW";
this.strMessage = message;
this.lblTrace.Text += String.Format("{0}: {1} <br />", this.strID, this.strMessage);
}
}
public void TW(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("{0}: {1} <br />", this.strID, this.strMessage);
}
}
public void Stats(string message)
{
if (!bolSuppress)
{
this.strID = "AccessDb.Stats";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void Stats(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void Category(string message)
{
if (!bolSuppress)
{
this.strID = "AccessDb.Category";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void Category(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void csClass(string message)
{
if (!bolSuppress)
{
this.strID = this.strID ?? "???.cs";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: blue;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void csClass(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: blue;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX(string message)
{
if (!bolSuppress)
{
this.strID = this.strID ?? "Article???.aspx";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: black;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: black;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX2(string message)
{
if (!bolSuppress)
{
this.strID = this.strID ?? "Article???.aspx";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: blue;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX2(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: blue;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX3(string message)
{
if (!bolSuppress)
{
this.strID = this.strID ?? "Article???.aspx";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: green;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX3(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: green;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX4(string message)
{
if (!bolSuppress)
{
this.strID = this.strID ?? "Article???.aspx";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: DarkViolet;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void aspX4(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: DarkViolet;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void TraceWriteX(string message)
{
if (!bolSuppress)
{
this.strID = "TraceWrite";
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
public void TraceWriteX(string id, string message)
{
if (!bolSuppress)
{
this.strID = id;
this.strMessage = message;
this.lblTrace.Text += String.Format("<span style=\"color: red;\">{0}: {1} </span><br />", this.strID, this.strMessage);
}
}
}