Esempio n. 1
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                var contextStatusProto = new ContextStatusProto
                {
                    context_id    = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (var source in _contextLifeCycle.ContextMessageSources)
                {
                    // Note: Please do not convert to LINQ expression, as source.Message
                    // may not return the same object in subsequent Get calls.
                    var sourceMessage = source.Message;
                    if (sourceMessage.IsPresent())
                    {
                        var contextMessageProto = new ContextStatusProto.ContextMessageProto
                        {
                            source_id = sourceMessage.Value.MessageSourceId,
                            message   = ByteUtilities.CopyBytesFrom(sourceMessage.Value.Bytes),
                        };

                        contextStatusProto.context_message.Add(contextMessageProto);
                    }
                }

                return(contextStatusProto);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                var contextStatusProto = new ContextStatusProto
                {
                    context_id    = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (var sourceMessage in _contextLifeCycle.ContextMessageSources.Where(src => src.Message.IsPresent()).Select(src => src.Message.Value))
                {
                    var contextMessageProto = new ContextStatusProto.ContextMessageProto
                    {
                        source_id = sourceMessage.MessageSourceId,
                        message   = ByteUtilities.CopyBytesFrom(sourceMessage.Bytes),
                    };
                    contextStatusProto.context_message.Add(contextMessageProto);
                }

                return(contextStatusProto);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                ContextStatusProto contextStatusProto = new ContextStatusProto()
                {
                    context_id    = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (IContextMessageSource source in _contextLifeCycle.ContextMessageSources)
                {
                    Optional <ContextMessage> contextMessageOptional = source.Message;
                    if (contextMessageOptional.IsPresent())
                    {
                        ContextStatusProto.ContextMessageProto contextMessageProto
                            = new ContextStatusProto.ContextMessageProto()
                            {
                            source_id = contextMessageOptional.Value.MessageSourceId,
                            };
                        contextMessageProto.message = ByteUtilities.CopyBytesFrom(contextMessageOptional.Value.Bytes);
                        contextStatusProto.context_message.Add(contextMessageProto);
                    }
                }
                return(contextStatusProto);
            }
        }