本文整理汇总了C#中Jayrock.Json.JsonTextWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.Flush方法的具体用法?C# JsonTextWriter.Flush怎么用?C# JsonTextWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jayrock.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.Flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWorkRpc
/// <summary>
/// Invokes the 'getwork' JSON method and parses the result into a new <see cref="T:Work"/> instance.
/// </summary>
/// <returns></returns>
public Work GetWorkRpc(IMiner miner, string comment)
{
var req = OpenRpc(miner, comment);
if (req == null)
return null;
// submit method invocation
using (var txt = new StreamWriter(req.GetRequestStream()))
using (var wrt = new JsonTextWriter(txt))
{
wrt.WriteStartObject();
wrt.WriteMember("id");
wrt.WriteString("json");
wrt.WriteMember("method");
wrt.WriteString("getwork");
wrt.WriteMember("params");
wrt.WriteStartArray();
wrt.WriteEndArray();
wrt.WriteEndObject();
wrt.Flush();
}
return ParseGetWork(req.GetResponse());
}
示例2: SubmitWorkRpc
/// <summary>
/// Invokes the 'getwork' JSON method, submitting the proposed work. Returns <c>true</c> if the service accepts
/// the proposed work.
/// </summary>
/// <param name="work"></param>
/// <returns></returns>
public bool SubmitWorkRpc(IMiner miner, Work work, string comment)
{
var req = OpenRpc(miner, comment);
if (req == null)
return false;
// header needs to have SHA-256 padding appended
var data = Sha256.AllocateInputBuffer(80);
// prepare header buffer with SHA-256
Sha256.Prepare(data, 80, 0);
Sha256.Prepare(data, 80, 1);
// dump header data on top of padding
Array.Copy(work.Header, data, 80);
// encode in proper format
var solution = Memory.Encode(data);
Console.WriteLine();
Console.WriteLine("SOLUTION: {0,10} {1}", miner.GetType().Name, Memory.Encode(work.Header));
Console.WriteLine();
Console.WriteLine();
using (var txt = new StreamWriter(req.GetRequestStream()))
using (var wrt = new JsonTextWriter(txt))
{
wrt.WriteStartObject();
wrt.WriteMember("id");
wrt.WriteString("json");
wrt.WriteMember("method");
wrt.WriteString("getwork");
wrt.WriteMember("params");
wrt.WriteStartArray();
wrt.WriteString(solution);
wrt.WriteEndArray();
wrt.WriteEndObject();
wrt.Flush();
}
using (var txt = new StreamReader(req.GetResponse().GetResponseStream()))
using (var rdr = new JsonTextReader(txt))
{
if (!rdr.MoveToContent() && rdr.Read())
throw new JsonException("Unexpected content from 'getwork <data>'.");
var response = JsonConvert.Import<JsonSubmitWork>(rdr);
if (response == null)
throw new JsonException("No response returned.");
if (response.Error != null)
Console.WriteLine("JSON-RPC: {0}", response.Error);
Console.WriteLine();
Console.WriteLine("{0}: {1,10} {2}", response.Result ? "ACCEPTED" : "REJECTED", miner.GetType().Name, Memory.Encode(work.Header));
Console.WriteLine();
Console.WriteLine();
return response.Result;
}
}