How do I add items to ASINList list? - c#

I am trying out the Amazon MWS samples. How do I initialise request.ASINList with a list of ASINs?
My ASINs are in strings.
// Create a request.
GetLowestOfferListingsForASINRequest request = new GetLowestOfferListingsForASINRequest();
string sellerId = "example";
request.SellerId = sellerId;
string mwsAuthToken = "example";
request.MWSAuthToken = mwsAuthToken;
string marketplaceId = "example";
request.MarketplaceId = marketplaceId;
ASINListType asinList = new ASINListType();
request.ASINList = asinList;
string itemCondition = "example";
request.ItemCondition = itemCondition;
bool excludeMe = true;
request.ExcludeMe = excludeMe;
return this.client.GetLowestOfferListingsForASIN(request);
I can't seem to implicitly or explicitly cast a list or array of strings to ASINListType.

Don't know c# but in PHP you have to create an object of class "MarketplaceWebServiceProducts_Model_ASINListType"
e.g.
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asin_list->setASIN($asin_array);
$request->setASINList($asin_list);

Your request.ASINList needs to be assigned to an ASINListType. So instantiate that object, and assign your ASINs to it's ASIN property. This is just one way of doing it, but I typically do it very quickly this way:
var asinListType = new ASINListType();
asinListType.ASIN = new List<string> { "B00005TQI7", "B00AVO5XRK", etc, etc };
request.ASINList = asinListType;

Related

Nested JSON in .NET

Trying to get address and its value to be curly brackets. means json object within a json object.
var jsonObject = new JObject();
dynamic j_obj = new JObject();
j_obj.jsonrpc = "1.0";
j_obj.id = "abc";
j_obj.method = "getrawtransaction";
j_obj.#params = new JArray() as dynamic;
dynamic info = new JObject();
info.txid = "myid";
info.vout = "0";
j_obj.#params.Add(info);
var address = "myaddress";
j_obj.Add(new JProperty(address, "0.01"));
Console.WriteLine(j_obj.ToString());
What I want is "address" and its value to be json object.
This is the output I am getting now.
Output Image
You are adding a value property here
var address = "myaddress";
j_obj.Add(new JProperty(address, "0.01"));
Instead create an object for the address then use that in the property:
dynamic addressItem = new JObject();
addressItem.line1 = "foo";
var address = "myaddress";
j_obj.Add(new JProperty(address, addressItem));
Alternatively, as you have gone down the dynamics route you could do this
j_obj.myaddress = new
{
line1 = "foo"
}
Either of these would create JSON that looks like this:
{
...
"myaddress": { "line1": "foo" }
...
}

Filling textboxes with strings

I have a windows form application that has a slew of textboxes that I fill using a bunch of strings. My question is...the code works fine but it seems like a lot of wasteful typing. Can you fill the textboxes from the strings in a loop functions? Matching up the textbox with the approriate string?
Here is what I have.
var client = new WebClient { Credentials = new NetworkCredential(username, password) };
var financials = client.DownloadString("https://api.intrinio.com/data_point?identifier="+conver+"&item=beta,marketcap,52_week_high,52_week_low,adj_close_price,short_interest,analyst_target_price,next_earnings_date,percent_change,yr_percent_change,implied_volatility, dividendyield,listing_exchange,sector,average_daily_volume");
var jss = client.DownloadString("https://api.intrinio.com/companies?identifier=" + conver + "");
JObject rss = JObject.Parse(jss);
JObject fin = JObject.Parse(financials);
string RRSTITLE = (string)rss["legal_name"];
string beta = (string)fin.SelectToken("data[0].value");
string marketcap = (string)fin.SelectToken("data[1].value");
string weekhigh = (string)fin.SelectToken("data[2].value");
string weeklow = (string)fin.SelectToken("data[3].value");
string adj_close = (string)fin.SelectToken("data[4].value");
string short_interest = (string)fin.SelectToken("data[5].value");
string analyst_target = (string)fin.SelectToken("data[6].value");
string earnings = (string)fin.SelectToken("data[7].value");
string percent_change = (string)fin.SelectToken("data[8].value");
string yr_percent_change = (string)fin.SelectToken("data[9].value");
string implied = (string)fin.SelectToken("data[10].value");
string divyield = (string)fin.SelectToken("data[11].value");
string exchange = (string)fin.SelectToken("data[12].value");
string sector = (string)fin.SelectToken("data[13].value");
string volume = (string)fin.SelectToken("data[14].value");
company_textbox.Text = RRSTITLE;
beta_box.Text = beta;
marketCap_box.Text = marketcap;
wekhighbox.Text = weekhigh;
weklowbox.Text = weeklow;
adjclosebox.Text = adj_close;
shortbox.Text = short_interest;
targetestbox.Text = analyst_target;
next_earnings.Text = earnings;
Close_box.Text = percent_change;
percentytd.Text = yr_percent_change;
implivolbox.Text = implied;
divyieldbox.Text = divyield;
exchangebox.Text = exchange;
sectorbox.Text = sector;
daily_Volume_text.Text = volume;
Like #Jacky said, the straight forward answer is no. But a really hacky way would be to create two Dictionaries. Something like this
Dictionary<string, TextBox> TextBoxLookup = new Dictionary<string, TextBox>();
Dictionary<string, string> ValueLookup = new Dictionary<string, string>();
TextBoxLookup["beta"] = beta_box;
TextBoxLookup["marketcap"] = marketCap_box;
TextBoxLookup["weekhigh"] = wekhighbox;
ValueLookup["beta"] = beta;
ValueLookup["marketcap"] = marketcap;
ValueLookup["weekhigh"] = weekhigh;
foreach(string key in TextBoxLookup.Keys)
{
TextBoxLookup[key].Text = ValueLookup[key];
}
You'll have to add each textbook and its value to their respective dictionaries with the same key and iterate through the assignment foreach block everytime you need to assign.
Does this help?

How to add brand to existing eBay item?

In my application I would like add Brand and MPN to existing eBay item via API on C#, so, I run code:
string eCommerceID = (dr["eCommerceID"] ?? "").ToString().Trim();
string upc = (dr["UPC"] ?? "").ToString().Trim();
string manufacturerName = (dr["ManufacturerName"] ?? "").ToString().Trim();
string brandMPN = (dr["BrandMPN"] ?? "").ToString().Trim();
ReviseItemRequestType reviseItemRequestType = new ReviseItemRequestType();
reviseItemRequestType.Version = version;
reviseItemRequestType.Item = new ItemType();
reviseItemRequestType.Item.ItemID = eCommerceID;
reviseItemRequestType.Item.ProductListingDetails = new ProductListingDetailsType();
reviseItemRequestType.Item.ProductListingDetails.UPC = upc;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN = new BrandMPNType();
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.Brand = manufacturerName;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.MPN = brandMPN;
ReviseItemResponseType reviseItemResponseType = ebayService.ReviseItem(reviseItemRequestType);
but when I execute this code, eBay returns error:
"The item specific Brand is missing. Add Brand to this listing, enter a valid value, and then try again."
What I'm doing wrong?
Appreciate any help. Thanks.
Error:
As the error messages says:
The item specific Brand is missing
Don't use the Item.ProductListingDetails.BrandMPN in your request. Instead you will need to create two Item Specifics called Band and MPN.
<ItemSpecifics>
<NameValueList>
<Name>Brand</Name>
<Value>[BRAND VALUE]</Value>
</NameValueList>
<NameValueList>
<Name>MPN</Name>
<Value>[MPN VALUE]</Value>
</NameValueList>
</ItemSpecifics>
Here is copy paste code snippet of the C# solution.
ItemType itemType = new ItemType(); // = class eBay.Service.Core.Soap.ItemType
Int32 condCodeAsInt = 1000; // upto you to derrive this from your use case.
String myBrandValue = "Some BRAND";
String myMpnValue = "some MPN";
String myUpcValue = "Does not apply";
....
//if condition is "New" or "New with Details" then we need to set extra REQUIRED fields
if (condCodeAsInt == 1000 || condCodeAsInt == 1500)
{
//if it is "new" then remove inputted desc text completely REQUIRED
if (condCodeAsInt == 1000)
{
itemType.ConditionDescription = "";
}
// set UPC value HERE, not in ItemSpecifics.
ProductListingDetailsType pldt = new ProductListingDetailsType();
pldt.UPC = myUpcValue;
itemType.ProductListingDetails = pldt;
//init Item specifics ( and set BRAND and MPN )
itemType.ItemSpecifics = new NameValueListTypeCollection();
//brand
NameValueListType nvBrand = new NameValueListType();
nvBrand.Name = "Brand";
StringCollection brandStringCol = new StringCollection();
brandStringCol.Add(myBrandValue);
nvBrand.Value = brandStringCol;
itemType.ItemSpecifics.Add(nvBrand);
//MPN
NameValueListType nvMpn = new NameValueListType();
nvMpn.Name = "MPN";
StringCollection mpnStringCol = new StringCollection();
mpnStringCol.Add(myMpnValue);
nvMpn.Value = mpnStringCol;
itemType.ItemSpecifics.Add(nvMpn);
}

Creating the BuildDefinition in rally using C#

I was trying to create a build definition. I tried as below one.
But i do think the code below doesn't create a buildDefinition. Like it asks for BuildDefinitionRef in the code "newBuild["BuildDefinition"] = ;" I am unable to know what exactly to put which reference.
RallyRestApi RestApi = new RallyRestApi("_abcd","https://rally1.rallydev.com");
String workspaceRef = "/workspace/27154845988";
String projectRef = "/project/48152113168";
DynamicJsonObject newBuild = new DynamicJsonObject();
newBuild["Workspace"] = workspaceRef;
newBuild["Duration"] = 0.75;
newBuild["Message"] = "Master 4683 Success";
//newBuild["CreationDate"] = "";
newBuild["Status"] = "FAILURE";
newBuild["Number"] = "4683";
// newBuild["Uri"] = "http://jenkins-build:8080/hudson/view/master/job/master-deploy/4683/";
// newBuild["BuildDefinition"] = ;
If any body has any idea of first how to create the BuildDefinition.
BuildDefinition should be a createable type in WSAPI. You just need to create that first, and then when you're creating your Build object just pass the ref of the created BuildDefinition:
newBuild["BuildDefinition"] = "/builddefinition/12345";

Why can I not create this implicitly-typed array?

This is my code:
AccountMenuList = new[]
{
new {transKey = "MY_TICKETS", stateName="account.tickets", displayUrl="/account/tickets/"},
new {transKey = "TRANSACTION_HISTORY", stateName = "account.transactionhistory", displayUrl = "/account/transactions"},
new {transKey = "PAYIN", stateName = "account.payin",displayUrl = "/account/payin"},
new {transKey = "PAYOUT", stateName = "account.payout", displayUrl = "/account/payout"},
new {transKey = "TICKET_PAYOUT", stateName = "account.ticketpayout", displayUrl = "/account/ticketpayout"},
new {transKey = "SETTINGS",stateName="default",displayUrl="default",SubMenuList=new[]{new{transKey = "something"}}}
};
But I get the following error:
No best type found for implicitly-typed array
What's wrong? Can I fix this?
What is wrong?
For every anonymous type compiler creates an actual type behind the scenes, and all of your objects having same declaration are of one type, except of the last one:
new {transKey = "SETTINGS",stateName="default",displayUrl="default",SubMenuList=new[] {new{transKey = "something"}}
How to fix it?
Create custom type for your menu items which makes more sense as later you may want to dynamically add/remove/filter them.
By adding object to your array initialization you can explicitly create an array of objects (with different anonymous type instances in it):
var accountMenuList = new object[]
{
new {transKey = "MY_TICKETS", stateName="account.tickets", displayUrl="/account/tickets/"},
new {transKey = "TRANSACTION_HISTORY", stateName = "account.transactionhistory", displayUrl = "/account/transactions"},
new {transKey = "PAYIN", stateName = "account.payin",displayUrl = "/account/payin"},
new {transKey = "PAYOUT", stateName = "account.payout", displayUrl = "/account/payout"},
new {transKey = "TICKET_PAYOUT", stateName = "account.ticketpayout", displayUrl = "/account/ticketpayout"},
new {transKey = "SETTINGS",stateName="default",displayUrl="default",SubMenuList=new[]{new{transKey = "something"}}}
};
Remove the SubMenuList=new[]{new{transKey = "something"}} from the last entry. All entries must have the same type of data for implicitly-typed arrays to work.
Like others have pointed out. In this situation you may want to create a class.
Here is an example.
public class mydata
{
public string transKey { get; set; }
public string stateName { get; set; }
public string displayUrl{ get; set; }
}
And then I'd use a list of type.
List<mydata> myDataList = new List<mydata>();
To add to the list you can do like this.
// create object
mydata md = new mydata();
md.transKey = "MY_TICKETS";
md.stateName = "account.tickets";
md.displayUrl = "/account/tickets/";
// add to your list
myDataList.add(md);
And if you want to loop through myDataList you can do the following.
foreach(var items in myDataList)
{
response.write(items.transkey);
}
I hope this helps.

Categories