示例#1
0
        /// <summary>
        /// Makes production build and optionally runs its output
        /// </summary>
        private void ProductionBuild(Boolean run)
        {
            // make sure the COLT project is open
            String path = FindAndOpen(false);

            if (path != null)
            {
                try
                {
                    JsonRpcClient client = new JsonRpcClient(path);
                    client.PingOrRunCOLT(settingObject.Executable);

                    // leverage FD launch mechanism
                    if (run)
                    {
                        client.InvokeAsync("runProductionCompilation", RunAfterProductionBuild, new Object[] { settingObject.SecurityToken, /*run*/ false });
                    }
                    else
                    {
                        client.InvokeAsync("runProductionCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken, /*run*/ false });
                    }
                }
                catch (Exception details)
                {
                    HandleAuthenticationExceptions(details);
                }
            }
        }
示例#2
0
 private static void InvokeTest(JsonRpcClient client, int testCount)
 {
     for (int i = 0; i < testCount; i++)
     {
         client.InvokeAsync("SpeedNoArgs").Wait();
     }
 }
        private async Task Example1()
        {
            var parameters = new Dictionary <string, object>
            {
                ["apiKey"] = "00000000-0000-0000-0000-000000000000"
            };

            using (var client = new JsonRpcClient(RandomServerUri))
            {
                var result = await client.InvokeAsync <KeyUsage>("getUsage", parameters).ConfigureAwait(false);

                Console.WriteLine($"getUsage, BitsLeft = {result.BitsLeft}");
            }

            using (var svc = new JsonRpcClient(RandomServerUri).AsServiceContract <IRandomApi>())
            {
                var res = await svc.GetUsage("00000000-0000-0000-0000-000000000000").ConfigureAwait(false);

                Console.WriteLine($"GetUsage, BitsLeft = {res.BitsLeft}");

                var res2 = await svc.GenerateIntegers("00000000-0000-0000-0000-000000000000", 3, -100, 200).ConfigureAwait(false);

                Console.WriteLine($"Received random numbers: {String.Join(", ",res2?.Random.Data?.Take(10) ?? new int[0])}");
            }
        }
示例#4
0
 public async Task UpdateStateAsync(ObjectStateUpdateGroup objectstateupdategroup, CancellationToken token)
 {
     try
     {
         await _rpcClient.InvokeAsync("UpdateState", objectstateupdategroup, _maxRpcDuration, CancellationToken.None);
     }
     catch (JsonRpcException e)
     {
         _logger.Error(e, "Calling method UpdateStateAsync failed: {0}. Exception:", e.RpcMessage);
         throw;
     }
     catch (Exception e)
     {
         _logger.Error(e, "Calling method UpdateStateAsync failed with exception: ");
     }
 }
 public async Task <long> InvokeAsyncWithResponseErrorAndNoParams()
 {
     try
     {
         return(await _clientResponseError.InvokeAsync <long>("m", 0L));
     }
     catch (JsonRpcServiceException)
     {
         return(default);
        private async Task Example2()
        {
            using (var client = new JsonRpcClient(SampleServerUri))
            {
                var parameters = new Dictionary <string, object>
                {
                    ["p1"] = 10,
                    ["p2"] = (long)4
                };

                var result = await client.InvokeAsync <double>("m1", parameters).ConfigureAwait(false);

                Console.WriteLine($"result = {result}");

                var result2 = await client.InvokeAsync <long>("m2", new object[] { 10, 4 }).ConfigureAwait(false);

                Console.WriteLine($"result = {result2}");
            }
        }
        protected async Task <T> ExecuteAsync <T>(JsonRpcRequest <T> request)
        {
            T result = default(T);
            JsonRpcException rpcException = null;
            Exception        exception    = null;

            try
            {
                LoadingData = true;
                if (loadDelay > 0)
                {
                    await Task.Delay(TimeSpan.FromSeconds(loadDelay));
                }
                result = await JsonRpcClient.InvokeAsync <T>(request);
            }
            catch (AggregateException ex)
            {
                exception    = ex;
                rpcException = ex.InnerException as JsonRpcException;
            }
            catch (JsonRpcException ex)
            {
                rpcException = ex;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                LoadingData = false;
            }

            if (rpcException != null)
            {
                throw rpcException;
            }
            else if (exception != null)
            {
                var errorMessage = string.Format(CultureInfo.CurrentCulture,
                                                 ResourceLoader.GetString("GeneralServiceErrorMessage"),
                                                 Environment.NewLine, exception.Message);
                await AlertMessageService.ShowAsync(errorMessage, ResourceLoader.GetString("ErrorServiceUnreachable"));

                throw exception;
            }
            return(result);
        }
示例#8
0
 public async Task <ObjectData> SubscribeAsync(ObjectReference objectReference, CancellationToken token)
 {
     try
     {
         _logger.Debug("Calling SubscribeAsync with: " + objectReference);
         return(await _rpcClient.InvokeAsync <ObjectData>("Subscribe", objectReference, _maxRpcDurationSession, token));
     }
     catch (JsonRpcException e)
     {
         _logger.Error(e, "Calling method SubscribeAsync failed: {0}. Exception: ", e.RpcMessage);
         throw;
     }
     catch (Exception e)
     {
         _logger.Error(e, "Calling method SubscribeAsync failed: ");
         throw;
     }
 }
示例#9
0
        /// <summary>
        /// Exports the project to COLT and optionally runs live session
        /// </summary>
        private void ExportAndOpen(Boolean run)
        {
            // Create COLT subfolder if does not exist yet
            // While at that, start listening for colt/compile_errors.log changes
            WatchErrorsLog(true);

            // Create COLT project in it
            COLTRemoteProject project = ExportCOLTProject();

            if (project != null)
            {
                try
                {
                    // Export the project as xml file
                    project.Save();

                    // Optionally run base compilation
                    if (run)
                    {
                        JsonRpcClient client = new JsonRpcClient(project.path);
                        client.PingOrRunCOLT(settingObject.Executable);
                        client.InvokeAsync("runBaseCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken });
                    }

                    // Enable "open" button
                    toolbarButton2.Enabled = true;

                    // Remove older *.colt files
                    foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
                    {
                        if (!project.path.Contains(Path.GetFileName(oldFile)))
                        {
                            File.Delete(oldFile);
                        }
                    }
                }
                catch (Exception details)
                {
                    HandleAuthenticationExceptions(details);
                }
            }
        }
        private async Task Example4()
        {
            Console.WriteLine("Sum, InvokeAsync:");

            using (var client = new JsonRpcClient(SampleServerUri))
            {
                var sw  = new Stopwatch();
                var ran = new Random((int)DateTime.Now.Ticks);

                for (int i = 0; i < 10; ++i)
                {
                    var x = ran.Next(0, 100);
                    var y = ran.Next(-100, 100);
                    sw.Restart();
                    var res = await client.InvokeAsync <int>("sum", new object[] { x, y }).ConfigureAwait(false);

                    Console.WriteLine($"x = {x}, y = {y}, res = {res}, duration = {sw.Elapsed.TotalMilliseconds}ms");
                }
            }

            Console.WriteLine("Sum, service method");

            using (var svc = new JsonRpcClient(SampleServerUri).AsServiceContract <ISampleServiceDisposable>())
            {
                var sw  = new Stopwatch();
                var ran = new Random((int)DateTime.Now.Ticks);

                for (int i = 0; i < 10; ++i)
                {
                    var x = ran.Next(0, 100);
                    var y = ran.Next(-100, 100);
                    sw.Restart();
                    var res = await svc.Sum(x, y).ConfigureAwait(false);

                    Console.WriteLine($"x = {x}, y = {y}, res = {res}, duration = {sw.Elapsed.TotalMilliseconds}ms");
                }
            }
        }
示例#11
0
        /// <summary>
        /// Opens the project in COLT and optionally runs live session
        /// </summary>
        private String FindAndOpen(Boolean run)
        {
            // Create COLT subfolder if does not exist yet
            // While at that, start listening for colt/compile_errors.log changes
            WatchErrorsLog(true);

            // Find COLT project to open
            String coltFileName = GetCOLTFile();

            // Open it
            if (coltFileName != null)
            {
                try
                {
                    if (run)
                    {
                        JsonRpcClient client = new JsonRpcClient(coltFileName);
                        client.PingOrRunCOLT(settingObject.Executable);
                        client.InvokeAsync("runBaseCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken });
                    }

                    return(coltFileName);
                }
                catch (Exception details)
                {
                    HandleAuthenticationExceptions(details);
                    return(null);
                }
            }

            else
            {
                toolbarButton2.Enabled = false;
                return(null);
            }
        }
 public async Task InvokeAsyncWithNotificationAndNoParams()
 {
     await _clientNotification.InvokeAsync("m");
 }