本文整理汇总了C#中IWebAgent.ExecuteRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IWebAgent.ExecuteRequest方法的具体用法?C# IWebAgent.ExecuteRequest怎么用?C# IWebAgent.ExecuteRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebAgent
的用法示例。
在下文中一共展示了IWebAgent.ExecuteRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserNotes
public static IEnumerable<TBUserNote> GetUserNotes(IWebAgent webAgent, string subName)
{
var request = webAgent.CreateGet(String.Format(ToolBoxUserNotesWiki, subName));
var reqResponse = webAgent.ExecuteRequest(request);
var response = JObject.Parse(reqResponse["data"]["content_md"].Value<string>());
int version = response["ver"].Value<int>();
string[] mods = response["constants"]["users"].Values<string>().ToArray();
string[] warnings = response["constants"]["warnings"].Values<string>().ToArray();
if (version < 6) throw new ToolBoxUserNotesException("Unsupported ToolBox version");
try
{
var data = Convert.FromBase64String(response["blob"].Value<string>());
string uncompressed;
using (System.IO.MemoryStream compressedStream = new System.IO.MemoryStream(data))
{
compressedStream.ReadByte();
compressedStream.ReadByte(); //skips first to bytes to fix zlib block size
using (DeflateStream blobStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
using (var decompressedReader = new System.IO.StreamReader(blobStream))
{
uncompressed = decompressedReader.ReadToEnd();
}
}
}
JObject users = JObject.Parse(uncompressed);
List<TBUserNote> toReturn = new List<TBUserNote>();
foreach (KeyValuePair<string, JToken> user in users)
{
var x = user.Value;
foreach (JToken note in x["ns"].Children())
{
TBUserNote uNote = new TBUserNote();
uNote.AppliesToUsername = user.Key;
uNote.SubName = subName;
uNote.SubmitterIndex = note["m"].Value<int>();
uNote.Submitter = mods[uNote.SubmitterIndex];
uNote.NoteTypeIndex = note["w"].Value<int>();
uNote.NoteType = warnings[uNote.NoteTypeIndex];
uNote.Message = note["n"].Value<string>();
uNote.Timestamp = UnixTimeStamp.UnixTimeStampToDateTime(note["t"].Value<long>());
uNote.Url = UnsquashLink(subName, note["l"].ValueOrDefault<string>());
toReturn.Add(uNote);
}
}
return toReturn;
}
catch (Exception e)
{
throw new ToolBoxUserNotesException("An error occured while processing Usernotes wiki. See inner exception for details", e);
}
}