Beispiel #1
0
        /// <summary>
        /// Populate cache with data for this example.
        /// </summary>
        /// <param name="cache">Cache.</param>
        private static void PopulateCache(ICache <int, IBinaryObject> cache)
        {
            IBinary binary = cache.Ignite.GetBinary();

            // Populate persons.
            cache[1] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "James Wilson")
                       .SetField(CompanyIdField, -1)
                       .Build();

            cache[2] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "Daniel Adams")
                       .SetField(CompanyIdField, -1)
                       .Build();

            cache[3] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "Cristian Moss")
                       .SetField(CompanyIdField, -1)
                       .Build();

            cache[4] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "Allison Mathis")
                       .SetField(CompanyIdField, -2)
                       .Build();

            cache[5] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "Breana Robbin")
                       .SetField(CompanyIdField, -2)
                       .Build();

            cache[6] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "Philip Horsley")
                       .SetField(CompanyIdField, -2)
                       .Build();

            cache[7] = binary.GetBuilder(PersonType)
                       .SetField(NameField, "James Peters")
                       .SetField(CompanyIdField, -2)
                       .Build();

            // Populate companies.
            cache[-1] = binary.GetBuilder(CompanyType)
                        .SetField(NameField, "Apache")
                        .SetField(IdField, -1)
                        .Build();

            cache[-2] = binary.GetBuilder(CompanyType)
                        .SetField(NameField, "Microsoft")
                        .SetField(IdField, -2)
                        .Build();
        }
Beispiel #2
0
        public IBinaryObjectBuilder ReadAsBinaryObject(string typeName, IBinary binary)
        {
            if (!_stream.CanRead)
            {
                return(null);
            }

            var read = _stream.Read(_buffer, 0, _buffer.Length);

            if (read < _buffer.Length)
            {
                // EOF
                return(null);
            }

            var result = binary.GetBuilder(typeName);

            foreach (var field in _recordDescriptor.Fields)
            {
                ReadField(result, field);
            }

            return(result);
        }