当前位置: 首页>>代码示例>>C#>>正文


C# RequestContext.SendCompleted方法代码示例

本文整理汇总了C#中RequestContext.SendCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# RequestContext.SendCompleted方法的具体用法?C# RequestContext.SendCompleted怎么用?C# RequestContext.SendCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestContext的用法示例。


在下文中一共展示了RequestContext.SendCompleted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddProcedure

            /// <summary>
            /// Adds a procedure that can be called by remote peer to the scene.
            /// </summary>
            /// <param name="route"></param>
            /// <param name="handler"></param>
            /// <param name="ordered">True if the message should be alwayse receive in order, false otherwise.</param>
            /// <remarks>
            /// The procedure is added to the scene to which this service is attached.
            /// </remarks>
            public void AddProcedure(string route, Func<RequestContext<IScenePeer>, Task> handler, bool ordered)
            {
                this._scene.AddRoute(route, p =>
                {
                    var buffer = new byte[2];
                    p.Stream.Read(buffer, 0, 2);
                    var id = BitConverter.ToUInt16(buffer, 0);
                    var cts = new CancellationTokenSource();
                    var ctx = new RequestContext<IScenePeer>(p.Connection, _scene, id, ordered,cts.Token);
                    if (_runningRequests.TryAdd(id, cts))
                    {
                        handler(ctx).ContinueWith(t =>
                        {
                            _runningRequests.TryRemove(id, out cts);
                            if (t.IsCompleted)
                            {
                                ctx.SendCompleted();
                            }
                            else
                            {
								_scene.resolver.GetComponent<ILogger>().Log(Stormancer.Diagnostics.LogLevel.Error, _scene.Id, "failed to create procedure");
                                var ex = t.Exception.InnerExceptions.OfType<ClientException>();
                                if (ex.Any())
                                {
                                    ctx.SendError(string.Join("|", ex.Select(e => e.Message).ToArray()));
                                }
                            }

                        });

                    }
                }, new Dictionary<string, string> { { "stormancer.plugins.rpc", "1.0.0" } });
				_scene.resolver.GetComponent<ILogger>().Log(Stormancer.Diagnostics.LogLevel.Trace, _scene.Id, "Procedure succesfully created");
            }
开发者ID:LaurentQUERSIN,项目名称:Project-EW2D,代码行数:43,代码来源:RpcClientPlugin.cs

示例2: AddProcedure

            /// <summary>
            /// Adds a procedure that can be called by remote peer to the scene.
            /// </summary>
            /// <param name="route"></param>
            /// <param name="handler"></param>
            /// <param name="ordered">True if the message should be alwayse receive in order, false otherwise.</param>
            /// <remarks>
            /// The procedure is added to the scene to which this service is attached.
            /// </remarks>
            public void AddProcedure(string route, Func<RequestContext<IScenePeer>, Task> handler, bool ordered)
            {
                this._scene.AddRoute(route, p =>
                {
                    var buffer = new byte[2];
                    p.Stream.Read(buffer, 0, 2);
                    var id = BitConverter.ToUInt16(buffer, 0);
                    var cts = new CancellationTokenSource();
                    var ctx = new RequestContext<IScenePeer>(p.Connection, _scene, id, ordered, new SubStream(p.Stream, false), cts.Token);
                    var identifier = System.Tuple.Create(p.Connection.Id, id);
                    if (_runningRequests.TryAdd(identifier, cts))
                    {
                        handler.InvokeWrapping(ctx).ContinueWith(t =>
                        {
                            _runningRequests.TryRemove(identifier, out cts);
                            if (t.Status == TaskStatus.RanToCompletion)
                            {
                                ctx.SendCompleted();
                            }
                            else if (t.Status == TaskStatus.Faulted)
                            {
                                var errorSent = false;

                                var ex = t.Exception.InnerExceptions.OfType<ClientException>();
                                if (ex.Any())
                                {
                                    ctx.SendError(string.Join("|", ex.Select(e => e.Message).ToArray()));
                                    errorSent = true;
                                }
                                if (t.Exception.InnerExceptions.Any(e => !(e is ClientException)))
                                {
                                    string errorMessage = string.Format("An error occured while executing procedure '{0}'.", route);
                                    if (!errorSent)
                                    {
                                        var errorId = Guid.NewGuid().ToString("N");
                                        ctx.SendError(string.Format("An exception occurred on the remote peer. Error {0}.", errorId));

                                        errorMessage = string.Format("Error {0}. ", errorId) + errorMessage;
                                    }

                                    _scene.DependencyResolver.Resolve<ILogger>().Log(LogLevel.Error, "rpc.server", errorMessage, t.Exception);

                                }

                            }
                        });
                    }
                }, new Dictionary<string, string> { { RpcClientPlugin.PluginName, RpcClientPlugin.Version } });
            }
开发者ID:songotony,项目名称:RType-Client,代码行数:58,代码来源:RpcClientPlugin.cs


注:本文中的RequestContext.SendCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。