Пример #1
0
        internal static ClusteredList <List <Common.Protobuf.Message> > GetMessages(IList <object> result, NCache nCache, string clientId)
        {
            int estimatedSize  = 0;
            var listOfMessages = new ClusteredList <List <Common.Protobuf.Message> >();

            if (result != null && result.Count > 0)
            {
                var messagesList = new List <Common.Protobuf.Message>();
                var enu          = result.GetEnumerator();

                while (enu.MoveNext())
                {
                    if (enu.Current == null)
                    {
                        continue;
                    }

                    var cachingMessage  = (Message)enu.Current;
                    var protobufMessage = new Common.Protobuf.Message();

                    if (cachingMessage.PayLoad != null)     // Message is a user'smessage and not an event message
                    {
                        var value        = new Common.Protobuf.Value();
                        var ubObject     = default(UserBinaryObject);
                        var binaryObject = cachingMessage.PayLoad as UserBinaryObject;

                        if (binaryObject != null)
                        {
                            ubObject = binaryObject;
                        }

                        if (ubObject != default(UserBinaryObject))
                        {
                            value.data.AddRange(ubObject.DataList);
                            estimatedSize = ubObject.Size + cachingMessage.MessageId.Length * sizeof(char);
                        }
                        protobufMessage.payload = value;
                    }
                    else    // Message is an event message and not a user's message
                    {
                        protobufMessage.internalPayload = new Common.Protobuf.InternalPayload();
                        estimatedSize = estimatedSize + cachingMessage.MessageId.Length * sizeof(char);

                        if (cachingMessage is EventMessage)
                        {
                            var cachingEventMessage  = (EventMessage)cachingMessage;
                            var protobufEventMessage = CreateProtobufEventMessage(nCache, cachingEventMessage, clientId);
                            protobufMessage.internalPayload.eventMessage = protobufEventMessage;
                            protobufMessage.internalPayload.payloadType  = Common.Protobuf.InternalPayload.PayloadType.CACHE_ITEM_EVENTS;
                        }
                    }

                    protobufMessage.flag                = cachingMessage.FlagMap.Data;
                    protobufMessage.messageId           = cachingMessage.MessageId;
                    protobufMessage.creationTime        = cachingMessage.CreationTime.Ticks;
                    protobufMessage.expirationTime      = cachingMessage.MessageMetaData.ExpirationTime;
                    protobufMessage.deliveryOption      = (int)cachingMessage.MessageMetaData.DeliveryOption;
                    protobufMessage.subscriptionType    = (int)cachingMessage.MessageMetaData.SubscriptionType;
                    protobufMessage.messageRemoveReason = (int)cachingMessage.MessageMetaData.MessgeFailureReason;

                    if (cachingMessage.MessageMetaData.RecepientList != null)
                    {
                        protobufMessage.recipientList.AddRange(cachingMessage.MessageMetaData.RecepientList);
                    }

                    if (cachingMessage.MessageMetaData.SubscriptionIdentifierList != null)
                    {
                        protobufMessage.subscriptionIdentifiers.AddRange(GetSubscriptionIds(cachingMessage.MessageMetaData.SubscriptionIdentifierList));
                    }

                    messagesList.Add(protobufMessage);

                    if (estimatedSize >= ServiceConfiguration.ResponseDataSize) // If size is greater than specified size then add it and create new chunk
                    {
                        listOfMessages.Add(messagesList);
                        messagesList  = new List <Common.Protobuf.Message>();
                        estimatedSize = 0;
                    }
                }
                if (estimatedSize != 0)
                {
                    listOfMessages.Add(messagesList);
                }
            }
            else
            {
                listOfMessages.Add(new List <Common.Protobuf.Message>());
            }
            return(listOfMessages);
        }
Пример #2
0
        internal static ClusteredList <List <Common.Protobuf.Message> > GetMessages(IList <object> result)
        {
            int estimatedSize = 0;
            ClusteredList <List <Common.Protobuf.Message> > ListOfMessagesResponse = new ClusteredList <List <Common.Protobuf.Message> >();

            if (result != null && result.Count > 0)
            {
                List <Common.Protobuf.Message> messagesList = new List <Common.Protobuf.Message>();
                IEnumerator <object>           enu          = result.GetEnumerator();
                while (enu.MoveNext())
                {
                    var              message  = new Common.Protobuf.Message();
                    var              value    = new Common.Protobuf.Value();
                    var              entry    = (Message)enu.Current;
                    BitSet           flag     = entry.FlagMap;
                    UserBinaryObject ubObject = null;
                    if (entry != null)
                    {
                        var binaryObject = entry.PayLoad as UserBinaryObject;
                        if (binaryObject != null)
                        {
                            ubObject = binaryObject;
                        }
                    }
                    if (ubObject != null)
                    {
                        value.data.AddRange(ubObject.DataList);
                        estimatedSize = estimatedSize + ubObject.Size + entry.MessageId.Length * sizeof(char);
                    }
                    message.messageId           = entry.MessageId;
                    message.flag                = flag.Data;
                    message.payload             = value;
                    message.creationTime        = entry.CreationTime.Ticks;
                    message.expirationTime      = entry.MessageMetaData.ExpirationTime;
                    message.deliveryOption      = (int)entry.MessageMetaData.DeliveryOption;
                    message.subscriptionType    = (int)entry.MessageMetaData.SubscriptionType;
                    message.messageRemoveReason = (int)entry.MessageMetaData.MessgeFailureReason;
                    if (entry.MessageMetaData.RecepientList != null)
                    {
                        message.recipientList.AddRange(entry.MessageMetaData.RecepientList);
                    }

                    messagesList.Add(message);

                    if (estimatedSize >= ServiceConfiguration.ResponseDataSize) // If size is greater than specified size then add it and create new chunck
                    {
                        ListOfMessagesResponse.Add(messagesList);
                        messagesList  = new List <Common.Protobuf.Message>();
                        estimatedSize = 0;
                    }
                }

                if (estimatedSize != 0)
                {
                    ListOfMessagesResponse.Add(messagesList);
                }
            }
            else
            {
                ListOfMessagesResponse.Add(new List <Common.Protobuf.Message>());
            }
            return(ListOfMessagesResponse);
        }