Пример #1
0
        /// <summary>
        ///   Retrieve transport/topic statistics.
        /// </summary>
        /// <param name="callerId"> ROS caller ID. </param>
        /// <returns> stats </returns>
        public Task<BusStatistics> GetBusStatsAsync(string callerId)
        {
            return Task<object[]>.Factory.FromAsync(_proxy.BeginGetBusStats, _proxy.EndGetBusStats, callerId, null)
                .ContinueWith(task =>
                {
                    if ((StatusCode) task.Result[0] != StatusCode.Success) throw new InvalidOperationException((string) task.Result[1]);

                    var statistics = (object[])task.Result[2];

                    var ret = new BusStatistics();

                    if (statistics[0] is object[])
                    {
                        ret.PublishStatistics = ((object[]) statistics[0])
                            .Cast<object[]>()
                            .Select(x => new PublishStatistic()
                            {
                                TopicName = (string) x[0],
                                MessageDataSent = (int)x[1],
                                ConnectionData = ((object[]) x[2])
                                    .Cast<object[]>()
                                    .Select(y=>new PublishConnectionData()
                                    {
                                        ConnectionId = (int)y[0],
                                        BytesSent = (int)y[1],
                                        NumSent = (int)y[2],
                                        Connected = (bool)y[3]
                                    })
                                    .ToList(),
                            }).ToList();
                    }
                    if (statistics[1] is object[])
                    {
                        ret.SubscribeStatistics = ((object[])statistics[1])
                            .Cast<object[]>()
                            .Select(x => new SubscirbeStatistic()
                            {
                                TopicName = (string) x[0],
                                ConnectionData = ((object[])x[1])
                                    .Cast<object[]>()
                                    .Select(y=>new SubscribeConnectionData()
                                    {
                                        ConnectionId = (int)y[0],
                                        BytesReceived = (int)y[1],
                                        NumSent = (int)y[2],
                                        DropEstimate = (int)y[3],
                                        Connected = (bool)y[4]
                                    })
                                    .ToList(),
                            }).ToList();
                    }
                    if (statistics[2] is object[])
                    {
                        //proposed...
                    }
                    return ret;
                });
        }
Пример #2
0
        /// <summary>
        ///   Retrieve transport/topic statistics.
        /// </summary>
        /// <param name="callerId"> ROS caller ID. </param>
        /// <returns> stats </returns>
        public Task <BusStatistics> GetBusStatsAsync(string callerId)
        {
            return(Task <object[]> .Factory.FromAsync(_proxy.BeginGetBusStats, _proxy.EndGetBusStats, callerId, null)
                   .ContinueWith(task =>
            {
                if ((StatusCode)task.Result[0] != StatusCode.Success)
                {
                    throw new InvalidOperationException((string)task.Result[1]);
                }

                var statistics = (object[])task.Result[2];

                var ret = new BusStatistics();

                if (statistics[0] is object[])
                {
                    ret.PublishStatistics = ((object[])statistics[0])
                                            .Cast <object[]>()
                                            .Select(x => new PublishStatistic()
                    {
                        TopicName = (string)x[0],
                        MessageDataSent = (int)x[1],
                        ConnectionData = ((object[])x[2])
                                         .Cast <object[]>()
                                         .Select(y => new PublishConnectionData()
                        {
                            ConnectionId = (int)y[0],
                            BytesSent = (int)y[1],
                            NumSent = (int)y[2],
                            Connected = (bool)y[3]
                        })
                                         .ToList(),
                    }).ToList();
                }
                if (statistics[1] is object[])
                {
                    ret.SubscribeStatistics = ((object[])statistics[1])
                                              .Cast <object[]>()
                                              .Select(x => new SubscirbeStatistic()
                    {
                        TopicName = (string)x[0],
                        ConnectionData = ((object[])x[1])
                                         .Cast <object[]>()
                                         .Select(y => new SubscribeConnectionData()
                        {
                            ConnectionId = (int)y[0],
                            BytesReceived = (int)y[1],
                            NumSent = (int)y[2],
                            DropEstimate = (int)y[3],
                            Connected = (bool)y[4]
                        })
                                         .ToList(),
                    }).ToList();
                }
                if (statistics[2] is object[])
                {
                    //proposed...
                }
                return ret;
            }));
        }