private void GetSecurityToken() { // we expect this file to be open by now // because we get here from auth exception String coltFileName = GetCOLTFile(); if (coltFileName != null) { try { JsonRpcClient client = new JsonRpcClient(coltFileName); // knock client.Invoke("requestShortCode", new Object[] { "FlashDevelop" /*LocaleHelper.GetString("Info.Description").TrimEnd(new Char[] { '.' })*/ }); // if still here, user needs to enter the code Forms.FirstTimeDialog dialog = new Forms.FirstTimeDialog(settingObject.InterceptBuilds, settingObject.AutoRun); dialog.ShowDialog(); // regardless of the code, set boolean options settingObject.AutoRun = dialog.AutoRun; settingObject.InterceptBuilds = dialog.InterceptBuilds; if ((dialog.ShortCode != null) && (dialog.ShortCode.Length == 4)) { // short code looks right - request security token settingObject.SecurityToken = client.Invoke("obtainAuthToken", new Object[] { dialog.ShortCode }).ToString(); } } catch (Exception details) { HandleAuthenticationExceptions(details); } } }
public void TestNoRpcMethod() { using (new AssertionScope()) { Action testAction = () => _client.Invoke <string>("SomeMethodThatDoesNotExist").Wait(); testAction.Should().Throw <MethodNotFoundException>(); testAction = () => _client.Notify("SomeMethodThatDoesNotExist").Wait(); //notifications do not supply errors testAction.Should().NotThrow(); } }
public void TestPreProcessingException() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "RequiresCredentials"; string input = "BadPassword"; JsonResponse <string[]> result = null; var myObs = rpc.Invoke <string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result == null); var res = result.Error; Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); if (res is JsonRpcException) { Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcTest.Global.PreProcess, Not Authenticated"); } }
public void TestSettingJsonRpcExceptionWithContext() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "error4"; string input = "Hello"; JsonResponse <string[]> result = null; var myObs = rpc.Invoke <string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result == null); var res = result.Error; Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); if (res is JsonRpcException) { Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcContext.Current().SetException()"); } }
public void TestEcho() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "internal.echo"; string input = "Echo this sucka"; JsonResponse <string> result = null; var myObs = rpc.Invoke <string>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; Assert.IsTrue(res == input.ToString()); }
public void TestMetaData() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "?"; JsonResponse <Newtonsoft.Json.Linq.JObject> result = null; var myObs = rpc.Invoke <Newtonsoft.Json.Linq.JObject>(method, null, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; }
public Object JsonCommand(string cmd, Object parameter) { if (!_configured) { return(null); } var client = new JsonRpcClient { Url = GetJsonPath(), Timeout = GetTimeout() }; var creds = GetCredentials(); if (creds != null) { client.Credentials = creds; } object retval = null; var logparam = ""; if (parameter != null) { logparam = parameter.GetType().ToString() == "System.String[]" ? String.Join(",", (string[])parameter) : parameter.ToString(); } try { lock (Locker) { retval = JsonConvert.Import(client.Invoke(cmd, parameter).ToString()); } if (cmd != "JSONRPC.Ping" && cmd != "VideoPlayer.GetTime" && cmd != "System.GetInfoLabels" && cmd != "AudioPlayer.GetTime") { Log("JSONCMD : " + cmd + ((parameter == null) ? "" : " - " + logparam)); } else { Trace("JSONCMD : " + cmd + ((parameter == null) ? "" : " - " + logparam)); } } catch (JsonException e) { if (cmd != "JSONRPC.Ping") { Log("JSONCMD : " + cmd + ((parameter == null) ? "" : " : " + logparam) + " - " + e.Message); } else { Trace("JSONCMD : " + cmd + ((parameter == null) ? "" : " : " + logparam) + " - " + e.Message); } } finally { client.Dispose(); } if (retval != null) { Trace(retval.ToString()); } return(retval); }
public int Action() { IPEndPoint point = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8055); JsonRpcClient client = new JsonRpcClient(point, Encoding.UTF8); var result = client.Invoke <int>("Incr", new object[] { TargetNumber }); result.Subscribe(new ResponseObserver()); return(1); }
public int Action() { IPEndPoint point = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8055); JsonRpcClient client = new JsonRpcClient(point, Encoding.UTF8); var result = client.Invoke <int>("Incr", new object[] { TargetNumber }); result.Subscribe((JsonResponse <int> response) => { Console.WriteLine(response.Result); }); return(1); }
private void SendRequestsAndWait(JsonRpcClient client, IObservable <JObject> requestStream) { // chaining is fun var mre = new ManualResetEventSlim(false); using ((from request in requestStream select client.Invoke <Newtonsoft.Json.Linq.JObject>("testArbitraryJObject", request, Scheduler.TaskPool)) .Merge() .Subscribe( onNext: _ => { /* do nothing and like it */ }, onError: _ => { Debug.WriteLine(_.Message); mre.Set(); }, onCompleted: mre.Set)) { mre.Wait(); } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); JsonRpcClient client = new JsonRpcClient(new Uri("http://localhost:49718/json.rpc")); var request = client.Invoke<object>("internal.echo", "hi", Scheduler.ThreadPool); request.Subscribe( response => { this.response = response; }, error => { ex = error; }, () => { done = true; } ); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); JsonRpcClient client = new JsonRpcClient(new Uri("http://localhost:49718/json.rpc")); var request = client.Invoke <object>("internal.echo", "hi", Scheduler.ThreadPool); request.Subscribe( response => { this.response = response; }, error => { ex = error; }, () => { done = true; } ); }
public void TestSimpleString() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "testSimpleString"; string input = "Hello"; JsonResponse <string[]> result = null; var myObs = rpc.Invoke <string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; Assert.IsTrue(res is IList <string>); var il = res as IList <string>; Assert.IsTrue(il[0] == "one"); Assert.IsTrue(il[1] == "two"); Assert.IsTrue(il[2] == "three"); Assert.IsTrue(il[3] == input.ToString()); Assert.IsTrue(il.Count == 4); }
public void TestMultipleParameters() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "testMultipleParameters"; var anon = new CustomString { str = "Hello" }; var input = new object[] { "one", 2, 3.3f, anon }; JsonResponse <object[]> result = null; var myObs = rpc.Invoke <object[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result != null); var res = result.Result; Assert.IsTrue(res.Length == 4); Assert.IsTrue((string)res[0] == (string)input[0]); Assert.IsTrue((long)res[1] == (long)(int)input[1]); Assert.IsTrue((double)res[2] == Double.Parse(input[2].ToString())); Assert.IsTrue(Newtonsoft.Json.JsonConvert.DeserializeObject <CustomString>(res[3].ToString()).str == anon.str); }
static void Main() { // // Demonstration of client calls to a JSON-RPC service. // JsonRpcClient client = new JsonRpcClient(); client.Url = "http://www.raboof.com/projects/jayrock/demo.ashx"; Console.WriteLine(client.Invoke("system.about")); Console.WriteLine(client.Invoke("system.version")); Console.WriteLine(string.Join(Environment.NewLine, (string[])(new ArrayList((ICollection)client.Invoke("system.listMethods"))).ToArray(typeof(string)))); Console.WriteLine(client.Invoke("now")); Console.WriteLine(((DateTime)client.Invoke(typeof(DateTime), "now")).ToString("r")); Console.WriteLine(client.InvokeVargs("sum", 123, 456)); Console.WriteLine(client.Invoke("sum", new JsonObject { { "a", 123 }, { "b", 456 } })); Console.WriteLine(client.InvokeVargs("total", new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 })); client.CookieContainer = new CookieContainer(); Console.WriteLine(client.Invoke("counter")); Console.WriteLine(client.Invoke("counter")); }
public void TestPreProcessingException() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "RequiresCredentials"; string input = "BadPassword"; JsonResponse<string[]> result = null; var myObs = rpc.Invoke<string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result == null); var res = result.Error; Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); if (res is JsonRpcException) { Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcTest.Global.PreProcess, Not Authenticated"); } }
public void TestSettingJsonRpcExceptionWithContext() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "error4"; string input = "Hello"; JsonResponse<string[]> result = null; var myObs = rpc.Invoke<string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result == null); var res = result.Error; Assert.IsTrue(res is AustinHarris.JsonRpc.JsonRpcException); if (res is JsonRpcException) { Assert.IsTrue(res.message == "This exception was thrown using: JsonRpcContext.Current().SetException()"); } }
public void TestEcho() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "internal.echo"; string input = "Echo this sucka"; JsonResponse<string> result = null; var myObs = rpc.Invoke<string>(method, input , Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; Assert.IsTrue(res == input.ToString()); }
public void TestMetaData() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "?"; JsonResponse<Newtonsoft.Json.Linq.JObject> result = null; var myObs = rpc.Invoke<Newtonsoft.Json.Linq.JObject>(method, null, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; }
private void SendRequestsAndWait(JsonRpcClient client, IObservable<JObject> requestStream) { // chaining is fun var mre = new ManualResetEventSlim(false); using ((from request in requestStream select client.Invoke<Newtonsoft.Json.Linq.JObject>("testArbitraryJObject", request, Scheduler.TaskPool)) .Merge() .Subscribe( onNext: _ => { /* do nothing and like it */ }, onError: _ => {Debug.WriteLine(_.Message); mre.Set();}, onCompleted: mre.Set)) { mre.Wait(); } }
public void TestCustomString() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "testCustomString"; var input = new { str = "Hello" }; JsonResponse<string[]> result = null; var myObs = rpc.Invoke<string[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); var res = result.Result; Assert.IsTrue(res is IList<string>); var il = res as IList<string>; Assert.IsTrue(il[0] == "one"); Assert.IsTrue(il[1] == "two"); Assert.IsTrue(il[2] == "three"); Assert.IsTrue(il[3] == input.str); Assert.IsTrue(il.Count == 4); }
public void Introspect() { var client = new JsonRpcClient("http://pcmpc/jsonrpc"); var result = client.Invoke("JSONRPC.Introspect"); }
public void TestMultipleParameters() { AutoResetEvent are = new AutoResetEvent(false); var rpc = new JsonRpcClient(remoteUri); string method = "testMultipleParameters"; var anon = new CustomString { str = "Hello" }; var input = new object[] {"one", 2, 3.3f, anon}; JsonResponse<object[]> result = null; var myObs = rpc.Invoke<object[]>(method, input, Scheduler.TaskPool); myObs.Subscribe( onNext: _ => { result = _; are.Set(); }, onError: _ => { are.Set(); }, onCompleted: () => { are.Set(); } ); are.WaitOne(); Assert.IsTrue(result != null); Assert.IsTrue(result.Result != null); var res = result.Result; Assert.IsTrue(res.Length == 4); Assert.IsTrue((string)res[0] == (string)input[0]); Assert.IsTrue((long)res[1] == (long)(int)input[1]); Assert.IsTrue((double)res[2] == Double.Parse(input[2].ToString())); Assert.IsTrue(Newtonsoft.Json.JsonConvert.DeserializeObject<CustomString>(res[3].ToString()).str == anon.str); }
public void PlayPause() { Client.Invoke("PicturePlayer.PlayPause"); }