Пример #1
0
        // TODO check comment, if only vs. only if
        /// <summary>
        /// Restore the content references if only the content types array is
        /// present. The content references are removed when decoding a message. That
        /// means if a message was received it cannot be used a second time as the
        /// content references are not there anymore. This method restores the
        /// content references based on the content types of the message.
        /// </summary>
        public void RestoreContentReferences()
        {
            IDictionary <Content, int> references = new Dictionary <Content, int>(ContentTypes.Count() * 2);

            foreach (var contentType in ContentTypes)
            {
                // TODO what about Content.Undefined
                if (contentType == Content.Empty)
                {
                    return;
                }

                int index = 0;
                if (contentType == Content.PublicKeySignature || contentType == Content.PublicKey)
                {
                    int j = references[Content.PublicKeySignature];
                    if (j != default(int))
                    {
                        index = j;
                    }
                    else
                    {
                        j = references[Content.PublicKey];
                        if (j != default(int))
                        {
                            index = j;
                        }
                    }
                }

                if (!references.ContainsKey(contentType))
                {
                    references.Add(contentType, index);
                }
                else
                {
                    index = references[contentType];
                }

                ContentReferences.Enqueue(new MessageContentIndex(index, contentType));
                references.Add(contentType, index + 1);
            }
        }
Пример #2
0
        public int AddContentReference(ContentReference contentReference)
        {
            if (contentReference == null)
            {
                return(ChunkReference.NullIdentifier);
            }

            // TODO: This behavior should be controllable
            if (contentReference.State != ContentReferenceState.NeverLoad && contentReference.ObjectValue != null)
            {
                // Auto-generate URL if necessary
                var serializer = AssetManager.Serializer.GetSerializer(null, contentReference.ObjectValue.GetType());
                BuildUrl(contentReference, serializer.ActualType);
                //Executor.ProcessObject(this, contentReference.Type, contentReference);
                ContentReferences.Add(contentReference);
            }

            return(AddChunkReference(contentReference.Location, contentReference.Type));
        }