本文整理汇总了C#中IManosContext.GetItemID方法的典型用法代码示例。如果您正苦于以下问题:C# IManosContext.GetItemID方法的具体用法?C# IManosContext.GetItemID怎么用?C# IManosContext.GetItemID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IManosContext
的用法示例。
在下文中一共展示了IManosContext.GetItemID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItemData
public void GetItemData(IManosContext ctx)
{
var ratings = MyRecommender.Instance.Data;
var user_mapping = MyRecommender.Instance.UserMapping;
var item_mapping = MyRecommender.Instance.ItemMapping;
int item_id = ctx.GetItemID("items");
if (item_id < 0 || item_id > ratings.MaxItemID)
{
ctx.Response.StatusCode = 404; // TODO maybe different error
ctx.Response.End();
return;
}
var match = new Regex(@"items/\d+/(\w+)").Match(ctx.Request.Path);
string command = match.Success ? match.Groups[1].Value : string.Empty;
switch(command)
{
case "statistics":
ctx.Response.WriteLine("iid={0} num_ratings={1}", item_mapping.ToOriginalID(item_id), ratings.ByItem[item_id].Count);
break;
case "events":
var users_string = ctx.Request.QueryData.GetString("users");
if (users_string == null)
{
foreach (int index in ratings.ByItem[item_id])
ctx.Response.WriteLine("eid={0} uid={1} value={2}", index, user_mapping.ToOriginalID(ratings.Users[index]), ratings[index]);
}
else
{
var requested_users = new HashSet<int>(from u in users_string.Split(',') select user_mapping.ToInternalID(int.Parse(u)));
foreach (int index in ratings.ByItem[item_id])
{
int user_id = ratings.Users[index];
if (requested_users.Contains(user_id))
ctx.Response.WriteLine("eid={0} uid={1} value={2}", index, user_mapping.ToOriginalID(user_id), ratings[index]);
}
}
break;
case "events/ratings":
goto case "events";
case "":
ctx.Response.WriteLine("no item metadata available"); // TODO
break;
default:
ctx.Response.StatusCode = 404; // TODO maybe different error
break;
}
ctx.Response.End();
}