mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Refactoring [WIP]
This commit is contained in:
@@ -1,17 +1,62 @@
|
||||
using Wox.Plugin;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Documents;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.RPC
|
||||
{
|
||||
public class JsonPRCModel
|
||||
public class JsonRPCErrorModel
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string jsonrpc { get; set; }
|
||||
public int Code { get; set; }
|
||||
|
||||
public string result { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
public class ActionJsonRPCResult : Result
|
||||
public class JsonRPCModelBase
|
||||
{
|
||||
public string ActionJSONRPC { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public string JsonRPC { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCResponseModel : JsonRPCModelBase
|
||||
{
|
||||
public string Result { get; set; }
|
||||
|
||||
public JsonRPCErrorModel Error { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
|
||||
{
|
||||
public List<JsonRPCResult> QueryResults
|
||||
{
|
||||
get
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<JsonRPCResult>>(Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class JsonRPCRequestModel : JsonRPCModelBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
/*
|
||||
* 1. c# can't use params as the variable name
|
||||
* 2. all prarmeter should be string type
|
||||
*/
|
||||
public List<string> Parameters { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCResult : Result
|
||||
{
|
||||
public string JSONRPCAction { get; set; }
|
||||
|
||||
public JsonRPCRequestModel JSONRPCActionModel
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ namespace Wox.RPC
|
||||
{
|
||||
public class JsonRPC
|
||||
{
|
||||
public static string GetRPC(string method, List<string> paras)
|
||||
public static string Send(string method, List<string> paras)
|
||||
{
|
||||
var list = paras.Select(s => string.Format(@"\""{0}\""", s));
|
||||
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""params\"": [{1}], \""id\"": 1}}",
|
||||
method, string.Join(",", list.ToArray()));
|
||||
}
|
||||
|
||||
public static string GetRPC(string method, string para)
|
||||
public static string Send(string method, string para)
|
||||
{
|
||||
return GetRPC(method, new List<string>() { para });
|
||||
return Send(method, new List<string>() { para });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user