/// <summary>
        /// Creates PortableConfiguration.
        /// </summary>
        /// <returns>PortableConfiguration</returns>
        public PortableConfiguration ToPortableConfiguration()
        {
            PortableConfiguration res = new PortableConfiguration();

            if (TypeConfigurations != null)
            {
                List<PortableTypeConfiguration> typeCfgs = new List<PortableTypeConfiguration>();

                foreach (InteropDotNetPortableTypeConfiguration dotNetTypeCfg in TypeConfigurations)
                    typeCfgs.Add(dotNetTypeCfg.ToPortableTypeConfiguration());

                res.TypeConfigurations = typeCfgs;
            }

            res.Types = Types;
            res.DefaultNameMapper =
                (IPortableNameMapper) InteropDotNetPortableTypeConfiguration.CreateInstance(DefaultNameMapper);
            res.DefaultIdMapper =
                (IPortableIdMapper) InteropDotNetPortableTypeConfiguration.CreateInstance(DefaultIdMapper);
            res.DefaultSerializer =
                (IPortableSerializer) InteropDotNetPortableTypeConfiguration.CreateInstance(DefaultSerializer);
            res.DefaultMetadataEnabled = DefaultMetadataEnabled;
            res.DefaultKeepDeserialized = DefaultKeepDeserialized;

            return res;
        }
        /// <summary>
        /// Constrcutor.
        /// </summary>
        /// <param name="cfg">Portable configuration.</param>
        /// <param name="name">Type name.</param>
        public PortableSurrogateTypeDescriptor(PortableConfiguration cfg, string name)
        {
            _cfg = cfg;
            _name = name;

            _id = PortableUtils.TypeId(name, cfg.DefaultNameMapper, cfg.DefaultIdMapper);
        }
        /// <summary>
        /// Copying constructor.
        /// </summary>
        /// <param name="cfg">Configuration to copy.</param>
        public PortableConfiguration(PortableConfiguration cfg)
        {
            DefaultIdMapper = cfg.DefaultIdMapper;
            DefaultNameMapper = cfg.DefaultNameMapper;
            DefaultMetadataEnabled = cfg.DefaultMetadataEnabled;
            DefaultKeepDeserialized = cfg.DefaultKeepDeserialized;
            DefaultSerializer = cfg.DefaultSerializer;

            Types = cfg.Types != null ? new List<string>(cfg.Types) : null;

            if (cfg.TypeConfigurations != null)
            {
                TypeConfigurations = new List<PortableTypeConfiguration>(cfg.TypeConfigurations.Count);

                foreach (PortableTypeConfiguration typeCfg in cfg.TypeConfigurations) 
                    TypeConfigurations.Add(new PortableTypeConfiguration(typeCfg));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Copying constructor.
        /// </summary>
        /// <param name="cfg">Configuration to copy.</param>
        public PortableConfiguration(PortableConfiguration cfg)
        {
            DefaultIdMapper         = cfg.DefaultIdMapper;
            DefaultNameMapper       = cfg.DefaultNameMapper;
            DefaultMetadataEnabled  = cfg.DefaultMetadataEnabled;
            DefaultKeepDeserialized = cfg.DefaultKeepDeserialized;
            DefaultSerializer       = cfg.DefaultSerializer;

            Types = cfg.Types != null ? new List <string>(cfg.Types) : null;

            if (cfg.TypeConfigurations != null)
            {
                TypeConfigurations = new List <PortableTypeConfiguration>(cfg.TypeConfigurations.Count);

                foreach (PortableTypeConfiguration typeCfg in cfg.TypeConfigurations)
                {
                    TypeConfigurations.Add(new PortableTypeConfiguration(typeCfg));
                }
            }
        }
        /// <summary>
        /// Create configuration.
        /// </summary>
        /// <param name="name">Grid name.</param>
        /// <param name="springCfg">Spring configuration.</param>
        /// <returns>Configuration.</returns>
        private static IgniteConfigurationEx CreateConfiguration(string name, string springCfg)
        {
            IgniteConfigurationEx cfg = new IgniteConfigurationEx();

            PortableConfiguration portCfg = new PortableConfiguration();

            ICollection<PortableTypeConfiguration> portTypeCfgs = new List<PortableTypeConfiguration>();

            portTypeCfgs.Add(new PortableTypeConfiguration(typeof(DynamicTestKey)));
            portTypeCfgs.Add(new PortableTypeConfiguration(typeof(DynamicTestValue)));

            portCfg.TypeConfigurations = portTypeCfgs;

            cfg.GridName = name;
            cfg.PortableConfiguration = portCfg;
            cfg.JvmClasspath = TestUtils.CreateTestClasspath();
            cfg.JvmOptions = TestUtils.TestJavaOptions();
            cfg.SpringConfigUrl = springCfg;

            return cfg;
        }
        public void TestKeepSerializedDefaultFalse()
        {
            PortableConfiguration cfg = new PortableConfiguration();

            cfg.DefaultKeepDeserialized = false;

            CheckKeepSerialized(cfg, false);
        }
        public void TestPrimitiveFieldsSerializer()
        {
            var typeCfgs = new List<PortableTypeConfiguration>
            {
                new PortableTypeConfiguration(typeof (PrimitiveFieldType))
                {
                    Serializer = new PrimitiveFieldsSerializer()
                }
            };

            PortableConfiguration cfg = new PortableConfiguration {TypeConfigurations = typeCfgs};

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            PrimitiveFieldType obj = new PrimitiveFieldType();

            CheckPrimitiveFields(marsh, obj);
        }
        public void TestHandles()
        {
            ICollection<PortableTypeConfiguration> typeCfgs =
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(HandleInner)));
            typeCfgs.Add(new PortableTypeConfiguration(typeof(HandleOuter)));

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            HandleOuter outer = new HandleOuter();

            outer.Before = "outBefore";
            outer.After = "outAfter";
            outer.RawBefore = "outRawBefore";
            outer.RawAfter = "outRawAfter";

            HandleInner inner = new HandleInner();

            inner.Before = "inBefore";
            inner.After = "inAfter";
            inner.RawBefore = "inRawBefore";
            inner.RawAfter = "inRawAfter";

            outer.Inner = inner;
            outer.RawInner = inner;

            inner.Outer = outer;
            inner.RawOuter = outer;

            byte[] bytes = marsh.Marshal(outer);

            IPortableObject outerObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            HandleOuter newOuter = outerObj.Deserialize<HandleOuter>();
            HandleInner newInner = newOuter.Inner;

            CheckHandlesConsistency(outer, inner, newOuter, newInner);

            // Get inner object by field.
            IPortableObject innerObj = outerObj.Field<IPortableObject>("inner");

            newInner = innerObj.Deserialize<HandleInner>();
            newOuter = newInner.Outer;

            CheckHandlesConsistency(outer, inner, newOuter, newInner);

            // Get outer object from inner object by handle.
            outerObj = innerObj.Field<IPortableObject>("outer");

            newOuter = outerObj.Deserialize<HandleOuter>();
            newInner = newOuter.Inner;

            CheckHandlesConsistency(outer, inner, newOuter, newInner);
        }
        public void TestKeepSerializedTypeCfgTrue()
        {
            PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(typeof(PropertyType));
            typeCfg.KeepDeserialized = true;

            PortableConfiguration cfg = new PortableConfiguration();
            cfg.DefaultKeepDeserialized = false;

            cfg.TypeConfigurations = new List<PortableTypeConfiguration> { typeCfg };

            CheckKeepSerialized(cfg, true);
        }
        public void TestCollectionsReflective()
        {
            ICollection<PortableTypeConfiguration> typeCfgs =
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(CollectionsType)));
            typeCfgs.Add(new PortableTypeConfiguration(typeof(InnerObjectType)));

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            CollectionsType obj = new CollectionsType();

            ArrayList list = new ArrayList();

            list.Add(true);
            list.Add((byte)1);
            list.Add((short)2);
            list.Add('a');
            list.Add(3);
            list.Add((long)4);
            list.Add((float)5);
            list.Add((double)6);

            list.Add("string");
            list.Add(Guid.NewGuid());

            InnerObjectType innerObj = new InnerObjectType();

            innerObj.PInt1 = 1;
            innerObj.PInt2 = 2;
            
            list.Add(innerObj);

            obj.Col1 = list;

            byte[] bytes = marsh.Marshal(obj);

            IPortableObject portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            Assert.AreEqual(obj.GetHashCode(), portObj.GetHashCode());

            CollectionsType newObj = portObj.Deserialize<CollectionsType>();

            Assert.AreEqual(obj, newObj);

            obj.Col1 = null;

            Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj)));

            obj.Col1 = list;
            obj.Col2 = list;

            Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj)));

            obj.Col2 = new TestList();

            Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj)));
        }
        public void TestObjectReflective()
        {
            ICollection<PortableTypeConfiguration> typeCfgs = 
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(OuterObjectType)));
            typeCfgs.Add(new PortableTypeConfiguration(typeof(InnerObjectType)));

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            CheckObject(marsh, new OuterObjectType(), new InnerObjectType());
        }
        public void TestSpecialArrays()
        {
            ICollection<PortableTypeConfiguration> typeCfgs =
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(SpecialArray)));
            typeCfgs.Add(new PortableTypeConfiguration(typeof(SpecialArrayMarshalAware)));

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            Guid[] guidArr = { Guid.NewGuid() };
            Guid?[] nGuidArr = { Guid.NewGuid() };
            DateTime[] dateArr = { DateTime.Now.ToUniversalTime() };
            DateTime?[] nDateArr = { DateTime.Now.ToUniversalTime() };

            // Use special object.
            SpecialArray obj1 = new SpecialArray();

            obj1.GuidArr = guidArr;
            obj1.NGuidArr = nGuidArr;
            obj1.DateArr = dateArr;
            obj1.NDateArr = nDateArr;

            byte[] bytes = marsh.Marshal(obj1);

            IPortableObject portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            Assert.AreEqual(guidArr, portObj.Field<Guid[]>("guidArr"));
            Assert.AreEqual(nGuidArr, portObj.Field<Guid?[]>("nGuidArr"));
            Assert.AreEqual(dateArr, portObj.Field<DateTime[]>("dateArr"));
            Assert.AreEqual(nDateArr, portObj.Field<DateTime?[]>("nDateArr"));

            obj1 = portObj.Deserialize<SpecialArray>();

            Assert.AreEqual(guidArr, obj1.GuidArr);
            Assert.AreEqual(nGuidArr, obj1.NGuidArr);
            Assert.AreEqual(dateArr, obj1.DateArr);
            Assert.AreEqual(nDateArr, obj1.NDateArr);

            // Use special with IGridPortableMarshalAware.
            SpecialArrayMarshalAware obj2 = new SpecialArrayMarshalAware();

            obj2.GuidArr = guidArr;
            obj2.NGuidArr = nGuidArr;
            obj2.DateArr = dateArr;
            obj2.NDateArr = nDateArr;

            bytes = marsh.Marshal(obj2);

            portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            Assert.AreEqual(guidArr, portObj.Field<Guid[]>("a"));
            Assert.AreEqual(nGuidArr, portObj.Field<Guid?[]>("b"));
            Assert.AreEqual(dateArr, portObj.Field<DateTime[]>("c"));
            Assert.AreEqual(nDateArr, portObj.Field<DateTime?[]>("d"));

            obj2 = portObj.Deserialize<SpecialArrayMarshalAware>();

            Assert.AreEqual(guidArr, obj2.GuidArr);
            Assert.AreEqual(nGuidArr, obj2.NGuidArr);
            Assert.AreEqual(dateArr, obj2.DateArr);
            Assert.AreEqual(nDateArr, obj2.NDateArr);
        }
        public void TestPrimitiveFieldsRawSerializer()
        {
            ICollection<PortableTypeConfiguration> typeCfgs = 
                new List<PortableTypeConfiguration>();

            PortableTypeConfiguration typeCfg =
                new PortableTypeConfiguration(typeof(PrimitiveFieldType));

            typeCfg.Serializer = new PrimitiveFieldsRawSerializer();

            typeCfgs.Add(typeCfg);

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            PrimitiveFieldType obj = new PrimitiveFieldType();

            CheckPrimitiveFields(marsh, obj);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="cfg">Portable configuration.</param>
 /// <param name="id">Type ID.</param>
 public PortableSurrogateTypeDescriptor(PortableConfiguration cfg, int id)
 {
     _cfg = cfg;
     _id = id;
 }
        public void TestPrimitiveFieldsReflective()
        {
            ICollection<PortableTypeConfiguration> typeCfgs = 
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(PrimitiveFieldType)));

            PortableConfiguration cfg = new PortableConfiguration {TypeConfigurations = typeCfgs};

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            PrimitiveFieldType obj = new PrimitiveFieldType();

            CheckPrimitiveFields(marsh, obj);
        }
        public void TestProperty()
        {
            ICollection<PortableTypeConfiguration> typeCfgs = 
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(PropertyType)));

            PortableConfiguration cfg = new PortableConfiguration {TypeConfigurations = typeCfgs};

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            PropertyType obj = new PropertyType
            {
                Field1 = 1,
                Field2 = 2
            };

            byte[] data = marsh.Marshal(obj);

            PropertyType newObj = marsh.Unmarshal<PropertyType>(data);

            Assert.AreEqual(obj.Field1, newObj.Field1);
            Assert.AreEqual(obj.Field2, newObj.Field2);

            IPortableObject portNewObj = marsh.Unmarshal<IPortableObject>(data, PortableMode.ForcePortable);

            Assert.AreEqual(obj.Field1, portNewObj.Field<int>("field1"));
            Assert.AreEqual(obj.Field2, portNewObj.Field<int>("Field2"));
        }
        public void TestDateObject()
        {
            ICollection<PortableTypeConfiguration> typeCfgs =
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(DateTimeType)));

            PortableConfiguration cfg = new PortableConfiguration {TypeConfigurations = typeCfgs};

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            DateTime now = DateTime.Now;

            DateTimeType obj = new DateTimeType(now);

            DateTimeType otherObj = marsh.Unmarshal<DateTimeType>(marsh.Marshal(obj));

            Assert.AreEqual(obj.Loc, otherObj.Loc);
            Assert.AreEqual(obj.Utc, otherObj.Utc);
            Assert.AreEqual(obj.LocNull, otherObj.LocNull);
            Assert.AreEqual(obj.UtcNull, otherObj.UtcNull);            
            Assert.AreEqual(obj.LocArr, otherObj.LocArr);
            Assert.AreEqual(obj.UtcArr, otherObj.UtcArr);

            Assert.AreEqual(obj.LocRaw, otherObj.LocRaw);
            Assert.AreEqual(obj.UtcRaw, otherObj.UtcRaw);
            Assert.AreEqual(obj.LocNullRaw, otherObj.LocNullRaw);
            Assert.AreEqual(obj.UtcNullRaw, otherObj.UtcNullRaw);
            Assert.AreEqual(obj.LocArrRaw, otherObj.LocArrRaw);
            Assert.AreEqual(obj.UtcArrRaw, otherObj.UtcArrRaw);
        }
        private static void CheckKeepSerialized(PortableConfiguration cfg, bool expKeep)
        {
            if (cfg.TypeConfigurations == null)
            {
                cfg.TypeConfigurations = new List<PortableTypeConfiguration>
                {
                    new PortableTypeConfiguration(typeof(PropertyType))
                };
            }

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            byte[] data = marsh.Marshal(new PropertyType());

            IPortableObject portNewObj = marsh.Unmarshal<IPortableObject>(data, PortableMode.ForcePortable);

            PropertyType deserialized1 = portNewObj.Deserialize<PropertyType>();
            PropertyType deserialized2 = portNewObj.Deserialize<PropertyType>();

            Assert.NotNull(deserialized1);

            Assert.AreEqual(expKeep, deserialized1 == deserialized2);
        }
        public void TestDecimalFields()
        {
            PortableConfiguration cfg = new PortableConfiguration
            {
                TypeConfigurations = new List<PortableTypeConfiguration>
                {
                    new PortableTypeConfiguration(typeof (DecimalReflective)),
                    new PortableTypeConfiguration(typeof (DecimalMarshalAware))
                }
            };

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            // 1. Test reflective stuff.
            DecimalReflective obj1 = new DecimalReflective
            {
                Val = decimal.Zero,
                ValArr = new[] {decimal.One, decimal.MinusOne}
            };

            IPortableObject portObj = marsh.Unmarshal<IPortableObject>(marsh.Marshal(obj1), PortableMode.ForcePortable);

            Assert.AreEqual(obj1.Val, portObj.Field<decimal>("val"));
            Assert.AreEqual(obj1.ValArr, portObj.Field<decimal[]>("valArr"));

            Assert.AreEqual(obj1.Val, portObj.Deserialize<DecimalReflective>().Val);
            Assert.AreEqual(obj1.ValArr, portObj.Deserialize<DecimalReflective>().ValArr);

            // 2. Test marshal aware stuff.
            DecimalMarshalAware obj2 = new DecimalMarshalAware();

            obj2.Val = decimal.Zero;
            obj2.ValArr = new[] { decimal.One, decimal.MinusOne };
            obj2.RawVal = decimal.MaxValue;
            obj2.RawValArr = new[] { decimal.MinusOne, decimal.One} ;

            portObj = marsh.Unmarshal<IPortableObject>(marsh.Marshal(obj2), PortableMode.ForcePortable);

            Assert.AreEqual(obj2.Val, portObj.Field<decimal>("val"));
            Assert.AreEqual(obj2.ValArr, portObj.Field<decimal[]>("valArr"));

            Assert.AreEqual(obj2.Val, portObj.Deserialize<DecimalMarshalAware>().Val);
            Assert.AreEqual(obj2.ValArr, portObj.Deserialize<DecimalMarshalAware>().ValArr);
            Assert.AreEqual(obj2.RawVal, portObj.Deserialize<DecimalMarshalAware>().RawVal);
            Assert.AreEqual(obj2.RawValArr, portObj.Deserialize<DecimalMarshalAware>().RawValArr);
        }
        /// <summary>
        /// Configuration for node.
        /// </summary>
        /// <param name="path">Path to Java XML configuration.</param>
        /// <returns>Node configuration.</returns>
        protected IgniteConfiguration Configuration(string path)
        {
            IgniteConfiguration cfg = new IgniteConfiguration();

            if (!_fork)
            {
                PortableConfiguration portCfg = new PortableConfiguration();

                ICollection<PortableTypeConfiguration> portTypeCfgs = new List<PortableTypeConfiguration>();

                PortableTypeConfigurations(portTypeCfgs);

                portCfg.TypeConfigurations = portTypeCfgs;

                cfg.PortableConfiguration = portCfg;
            }

            cfg.JvmClasspath = TestUtils.CreateTestClasspath();

            cfg.JvmOptions = TestUtils.TestJavaOptions();

            cfg.SpringConfigUrl = path;

            return cfg;
        }