コード例 #1
0
ファイル: MainForm.cs プロジェクト: tnaidenov/net-examples
        private void SendMessage(string message)
        {
            // send a call to all targets that implement that endpoint, passing some id and the message.
            _glue42.Interop.Invoke(_chatEndpointName, mib => mib
                                   // set the invocation context (any arguments to be sent over to the targets)
                                   .SetContext(cb => cb
                                   // e.g. we can add some id
                                               .AddValue("id", Guid.NewGuid().ToString("N"))
                                   // and the time
                                               .AddValue("time", DateTime.UtcNow)
                                   // and then a message
                                               .AddValue("message", message)),
                                   new TargetSettings()
                                   // timeout if a target has not responsed in 8 seconds
                                   .WithTargetInvokeTimeout(TimeSpan.FromSeconds(8))
                                   // invoke all available targets
                                   .WithTargetType(MethodTargetType.All))
            .ContinueWith(
                r =>
            {
                // consume the result
                if (r.IsFaulted)
                {
                    Log($"Invocation failed with {r.Exception?.Flatten()}");
                    return;
                }
                IClientMethodResult result = r.Result;

                // since we're sending an 'All' call, we have to check the inner results (per target)
                foreach (var inner in result.InnerClientMethodResults)
                {
                    //Log($"{inner.Server}: Result arrived for: {inner.ResultContext.First(cv => cv.Name == "id").Value}");
                }
            });
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: tnaidenov/net-examples
        private void TargetsMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var item = targets_.GetItemAt(e.X, e.Y);

            if (!(item?.Tag is IInstance target))
            {
                return;
            }

            // create a sample transaction
            var transaction = CreateTransaction();

            // invoke the target passing the transaction as an argument
            _glue42.Interop.Invoke(endpointName_, builder => builder.AddObject("transaction", transaction),
                                   // specify that we want the selected target only
                                   new TargetSettings().WithTargetSelector((method, instance) =>
                                                                           instance.InstanceId == target.InstanceId))
            .ContinueWith(cmrT =>
            {
                if (cmrT.IsFaulted)
                {
                    Log($"Invocation failed with {cmrT.Exception?.Flatten()}");
                    return;
                }

                IClientMethodResult cmr = cmrT.Result;
                Log(
                    $"Server said {cmr.ResultMessage} with transactionId = {cmr.ResultContext.GetValueByName("transactionId", v => v.AsString)}");
            });
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: tnaidenov/net-examples
        private static void InvocationResultHandler(Task <IClientMethodResult> invocationResult)
        {
            if (invocationResult.IsFaulted)
            {
                Log($"Invocation failed with {invocationResult.Exception?.Flatten()}");
                return;
            }

            IClientMethodResult cmr = invocationResult.Result;

            Log($"Invoked: {invocationResult.Status} - {cmr.Status} - {cmr.ResultMessage}");
        }