public WorkerData(string name, string delegateName, string caller, IBinaryObject dataParams) { Name = name; Delegate = delegateName; Caller = caller; Params = dataParams; }
/// <summary> /// Determines whether the specified objects are equal. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// true if the specified objects are equal; otherwise, false. /// </returns> public static bool Equals(IBinaryObject x, IBinaryObject y) { if (x == null) return y == null; if (y == null) return false; if (ReferenceEquals(x, y)) return true; var binx = GetBinaryObject(x); var biny = GetBinaryObject(y); var lenx = GetDataLength(binx); var leny = GetDataLength(biny); if (lenx != leny) return false; var startx = GetDataStart(binx); var starty = GetDataStart(biny); var arrx = binx.Data; var arry = biny.Data; for (var i = 0; i < lenx; i++) { if (arrx[i + startx] != arry[i + starty]) return false; } return true; }
/** <inheritdoc /> */ public IBinaryObject PersonMethodBinary(IBinaryObject person) { return(person .ToBuilder() .SetField("Id", person.GetField <int>("Id") + 1) .Build()); }
/// <summary> /// Initializes a new instance of the <see cref="IgniteException"/> class. /// </summary> /// <param name="info">Serialization information.</param> /// <param name="ctx">Streaming context.</param> protected ServiceDeploymentException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { _binaryCause = (IBinaryObject)info.GetValue(KeyBinaryCause, typeof(IBinaryObject)); _failedCfgs = (ICollection <ServiceConfiguration>)info.GetValue(KeyFailedConfigurations, typeof(ICollection <ServiceConfiguration>)); }
private static void ComplexObjects() { var cfg = new IgniteConfiguration { // Register custom class for Ignite serialization BinaryConfiguration = new BinaryConfiguration(typeof(Person)) }; IIgnite ignite = Ignition.Start(cfg); ICache <int, Person> cache = ignite.GetOrCreateCache <int, Person>("persons"); cache[1] = new Person { Name = "John Doe", Age = 27 }; foreach (ICacheEntry <int, Person> cacheEntry in cache) { Console.WriteLine(cacheEntry); } var binCache = cache.WithKeepBinary <int, IBinaryObject>(); IBinaryObject binPerson = binCache[1]; Console.WriteLine(binPerson.GetField <string>("Name")); }
static void Main() { AdoNetCacheStore.InitializeDb(); using (var ignite = Ignition.StartFromApplicationConfiguration()) { var cacheCfg = new CacheConfiguration { Name = "cars", CacheStoreFactory = new AdoNetCacheStoreFactory(), KeepBinaryInStore = true, ReadThrough = true, WriteThrough = true }; ICache <int, IBinaryObject> cars = ignite.GetOrCreateCache <int, object>(cacheCfg).WithKeepBinary <int, IBinaryObject>(); IBinaryObject car = ignite.GetBinary() .GetBuilder("Car") .SetStringField("Name", "Honda NSX") .SetIntField("Power", 600) .Build(); // Put an entry to Ignite cache, this causes AdoNetCacheStore.Write call. cars.Put(1, car); // Remove an entry from Ignite cache, but not from cache store. Console.WriteLine("Cache size before Clear: " + cars.GetSize()); cars.Clear(); Console.WriteLine("Cache size after Clear: " + cars.GetSize()); // Get an entry by key, which delegates to AdoNetCacheStore.Load. Console.WriteLine("Requesting key from Ignite cache..."); IBinaryObject carFromStore = cars.Get(1); Console.WriteLine("Entry from cache store: " + carFromStore); // Read data from SQL server directly. Console.WriteLine("\nData from SQL server:"); using (var conn = new SqlCeConnection(AdoNetCacheStore.ConnectionString)) { using (var cmd = new SqlCeCommand(@"SELECT * FROM Cars", conn)) { conn.Open(); foreach (IDataRecord row in cmd.ExecuteReader()) { Console.WriteLine("SQL row: "); for (var i = 0; i < row.FieldCount; i++) { Console.Write(row.GetValue(i) + "; "); } } } } Console.WriteLine(); } }
public static void AreEqual(IBinaryObject expected, IBinaryObject actual, string message = "") { //Compare object properties AreEqual((object)expected, actual, message); BytesAssert.AreEqual(expected.ToBytes(), actual.ToBytes(), $@"{nameof(ObjectAssert)}.{nameof(AreEqual)} ToBytes test failed. {message}"); }
/** <inheritDoc /> */ public IBinaryObject testBinaryObject(IBinaryObject x) { if (x == null) { return(null); } return(x.ToBuilder().SetField("field", 15).Build()); }
/// <summary> /// Casts to <see cref="BinaryObject"/> or throws an error. /// </summary> private static BinaryObject GetBinaryObject(IBinaryObject obj) { var binObj = obj as BinaryObject; if (binObj != null) return binObj; throw new NotSupportedException(string.Format("{0} of type {1} is not supported.", typeof(IBinaryObject), obj.GetType())); }
/// <summary> /// Verifies the field types. /// </summary> private static void VerifyFieldTypes(IBinaryObject bin) { var binType = bin.GetBinaryType(); Assert.AreEqual("byte", binType.GetFieldTypeName("byte")); Assert.AreEqual("byte", binType.GetFieldTypeName("sbyte")); Assert.AreEqual("byte[]", binType.GetFieldTypeName("bytes")); Assert.AreEqual("byte[]", binType.GetFieldTypeName("sbytes")); Assert.AreEqual("boolean", binType.GetFieldTypeName("bool")); Assert.AreEqual("boolean[]", binType.GetFieldTypeName("bools")); Assert.AreEqual("char", binType.GetFieldTypeName("char")); Assert.AreEqual("char[]", binType.GetFieldTypeName("chars")); Assert.AreEqual("short", binType.GetFieldTypeName("short")); Assert.AreEqual("short[]", binType.GetFieldTypeName("shorts")); Assert.AreEqual("short", binType.GetFieldTypeName("ushort")); Assert.AreEqual("short[]", binType.GetFieldTypeName("ushorts")); Assert.AreEqual("int", binType.GetFieldTypeName("int")); Assert.AreEqual("int[]", binType.GetFieldTypeName("ints")); Assert.AreEqual("int", binType.GetFieldTypeName("uint")); Assert.AreEqual("int[]", binType.GetFieldTypeName("uints")); Assert.AreEqual("long", binType.GetFieldTypeName("long")); Assert.AreEqual("long[]", binType.GetFieldTypeName("longs")); Assert.AreEqual("long", binType.GetFieldTypeName("ulong")); Assert.AreEqual("long[]", binType.GetFieldTypeName("ulongs")); Assert.AreEqual("float", binType.GetFieldTypeName("float")); Assert.AreEqual("float[]", binType.GetFieldTypeName("floats")); Assert.AreEqual("double", binType.GetFieldTypeName("double")); Assert.AreEqual("double[]", binType.GetFieldTypeName("doubles")); Assert.AreEqual("decimal", binType.GetFieldTypeName("decimal")); Assert.AreEqual("Object", binType.GetFieldTypeName("decimals")); Assert.AreEqual("UUID", binType.GetFieldTypeName("guid")); Assert.AreEqual("Object", binType.GetFieldTypeName("guids")); Assert.AreEqual("Object", binType.GetFieldTypeName("datetime")); Assert.AreEqual("Object", binType.GetFieldTypeName("datetimes")); Assert.AreEqual("Object", binType.GetFieldTypeName("intptr")); Assert.AreEqual("Object", binType.GetFieldTypeName("intptrs")); Assert.AreEqual("Object", binType.GetFieldTypeName("uintptr")); Assert.AreEqual("Object", binType.GetFieldTypeName("uintptrs")); }
/** <inheritDoc /> */ public IBinaryObjectBuilder GetBuilder(IBinaryObject obj) { IgniteArgumentCheck.NotNull(obj, "obj"); BinaryObject obj0 = obj as BinaryObject; if (obj0 == null) throw new ArgumentException("Unsupported object type: " + obj.GetType()); IBinaryTypeDescriptor desc = _marsh.GetDescriptor(true, obj0.TypeId); return Builder0(null, obj0, desc); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <param name="obj">The object.</param> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public static int GetHashCode(IBinaryObject obj) { if (obj == null) return 0; var binObj = GetBinaryObject(obj); var arg = new KeyValuePair<int, int>(GetDataStart(binObj), GetDataLength(binObj)); using (var stream = new BinaryHeapStream(binObj.Data)) { return stream.Apply(HashCodeProcessor, arg); } }
/// <summary> /// Reads binary object fields and modifies them. /// </summary> /// <param name="cache">Cache.</param> private static void ReadModifyExample(ICacheClient <int, IBinaryObject> cache) { const int id = 1; IBinaryObject person = cache[id]; string name = person.GetField <string>(NameField); Console.WriteLine(); Console.WriteLine(">>> Name of the person with id {0}: {1}", id, name); // Modify the binary object. cache[id] = person.ToBuilder().SetField("Name", name + " Jr.").Build(); Console.WriteLine(">>> Modified person with id {0}: {1}", id, cache[1]); }
/// <summary> /// Reads binary object fields and modifies them. /// </summary> /// <param name="cache">Cache.</param> private static void ReadModifyExample(ICache <int, IBinaryObject> cache) { const int id = 1; IBinaryObject person = cache[id]; string name = person.GetField <string>(NameField); Console.WriteLine(); Console.WriteLine($">>> Name of the person with id {id}: {name}"); // Modify the binary object. cache[id] = person.ToBuilder().SetField("Name", $"{name} Jr.").Build(); Console.WriteLine($">>> Modified person with id {id}: {cache[1]}"); }
public IBinaryObject[] GetBinaryModels(IBinaryObjectBuilder builder) { var entry = new double[1000 * 32]; var data = new IBinaryObject[Params.Instance.Value.TotalObjects]; var random = new Random(); for (var i = 0; i < data.Length; i++) { for (var j = 0; j < entry.Length; j++) { entry[j] = random.NextDouble(); } data[i] = builder.SetDoubleArrayField("data", entry).Build(); } return(data); }
static void Main(string[] args) { var cfg = new IgniteConfiguration { // Register custom class for ignite serialization BinaryConfiguration = new BinaryConfiguration(typeof(Person)) }; IIgnite ignite = Ignition.Start(cfg); ICache <int, Person> cache = ignite.GetOrCreateCache <int, Person>("person"); cache[1] = new Person { name = "Razi Ahmad", age = 27 }; cache[2] = new Person { name = "Harsh Babu", age = 22 }; cache[3] = new Person { name = "Razi Ahmad", age = 27 }; cache[2] = new Person { name = "Harsh Babu", age = 22 }; foreach (ICacheEntry <int, Person> cacheEntry in cache) { Console.WriteLine(cacheEntry); } var binCache = cache.WithKeepBinary <int, IBinaryObject>(); IBinaryObject binPerson1 = binCache[1]; Console.WriteLine(binPerson1.GetField <string>("name") + " : " + binPerson1.GetField <int>("age")); IBinaryObject binPerson2 = binCache[2]; Console.WriteLine(binPerson2.GetField <string>("name") + " : " + binPerson2.GetField <int>("age")); IBinaryObject binPerson3 = binCache[3]; Console.WriteLine(binPerson3.GetField <string>("name") + " : " + binPerson3.GetField <int>("age")); Console.ReadKey(); }
public void TestEchoTaskBinarizableNoClass() { ICompute compute = _grid1.GetCompute(); compute.WithKeepBinary(); IBinaryObject res = compute.ExecuteJavaTask <IBinaryObject>(EchoTask, EchoTypeBinarizableJava); Assert.AreEqual(1, res.GetField <int>("field")); // This call must fail because "keepBinary" flag is reset. var ex = Assert.Throws <BinaryObjectException>(() => { compute.ExecuteJavaTask <IBinaryObject>(EchoTask, EchoTypeBinarizableJava); }); Assert.AreEqual("Unknown pair [platformId=1, typeId=2009791293]", ex.Message); }
static void Main(string[] args) { IIgnite ignite = Ignition.Start(); ICache <int, Person> cache = ignite.GetOrCreateCache <int, Person>("persons"); cache[1] = new Person { name = "Razi" }; ICache <int, IBinaryObject> binaryCache = cache.WithKeepBinary <int, IBinaryObject>(); IBinaryObject binaryPerson = binaryCache[1]; string name = binaryPerson.GetField <string>("name"); Console.WriteLine(name); Console.ReadKey(); }
public void TestAffinityBinary() { IIgnite g = Ignition.GetIgnite("grid-0"); ICacheAffinity aff = g.GetAffinity("default"); IBinaryObject affKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(0, 1)); IClusterNode node = aff.MapKeyToNode(affKey); for (int i = 0; i < 10; i++) { IBinaryObject otherAffKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(i, 1)); Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id); } }
//set binary data into cache private void btnInsert_Click(object sender, EventArgs e) { try { List <Person> lstData = GeneratePersonData(5); var ccfg = new CacheConfiguration { Name = "BINARY_DATA", CacheMode = CacheMode.Replicated }; var cfg = new IgniteConfiguration { SpringConfigUrl = configURL, BinaryConfiguration = new BinaryConfiguration(typeof(Person), typeof(PersonFilter)) }; Ignition.ClientMode = true; using (var ignite = Ignition.Start(cfg)) { ICache <int, IBinaryObject> persons = ignite.GetOrCreateCache <int, object>(ccfg).WithKeepBinary <int, IBinaryObject>(); int i = 1; foreach (Person p in lstData) { IBinaryObject person = ignite.GetBinary() .GetBuilder("Person") .SetIntField("Power", p.Id) .SetStringField("Name", p.Name) .SetIntField("Age", p.Age) .SetStringField("Designation", p.Designation) .SetIntField("Salary", p.Salary) .Build(); persons.Put(i++, person); } } txtMsg.Text = "Binary data pushed into cache 'BINARY_DATA' heap........."; } catch (Exception ex) { txtMsg.Text = ex.Message; } }
public static object Deserialize(this IBinaryObject blob, ISurrogateSelector selector) { if (blob == null) { return(null); } try { using (var input = blob.GetInputStream()) { var formatter = new BinaryFormatter(); formatter.SurrogateSelector = selector; formatter.TypeFormat = FormatterTypeStyle.TypesWhenNeeded; return(formatter.Deserialize(input)); } } catch (TypeLoadException e) { throw new ApplicationException("Type not found: " + e.Message); } catch (IOException e) { throw new ApplicationException("De-serialization error: " + e.Message); } }
public static void AdvancedConfigBinaryMode() { var ignite = Ignition.Start(); //tag::advancedConfigBinaryMode[] var cacheCfg = new CacheConfiguration("people") { PlatformCacheConfiguration = new PlatformCacheConfiguration { KeepBinary = true } }; var cache = ignite.CreateCache <int, Person>(cacheCfg) .WithKeepBinary <int, IBinaryObject>(); IBinaryObject binaryPerson = cache.Get(1); //end::advancedConfigBinaryMode[] }
/** <inheritDoc /> */ public IBinaryObjectBuilder GetBuilder(IBinaryObject obj) { IgniteArgumentCheck.NotNull(obj, "obj"); BinaryObject obj0 = obj as BinaryObject; if (obj0 == null) { throw new ArgumentException("Unsupported object type: " + obj.GetType()); } if (obj0 is BinaryEnum) { throw new InvalidOperationException("Builder cannot be created for enum."); } IBinaryTypeDescriptor desc = _marsh.GetDescriptor(true, obj0.TypeId); return(Builder0(null, obj0, desc)); }
public void WriteIntoArchive(IBinaryObject file, string archivePath, string fileName, bool overwrite) { if (archivePath.LastIndexOf('.') != archivePath.Length - 4) throw new ArgumentException("Archive file's extension's length must be 3 for now!", archivePath); if (File.Exists(archivePath)) { if (overwrite) { var tmpArch = ZipFile.Open(archivePath, ZipArchiveMode.Update); tmpArch.ClearArchive(); tmpArch.Dispose(); } } else { DirectoryInfo di; do { //To secure no directory gets overriden di = new DirectoryInfo("" + RANDOM.Next()); } while (di.Exists); di.Create(); ZipFile.CreateFromDirectory(di.FullName, archivePath, CompressionLevel.Optimal, false); di.Delete(); } var bytes = file.GetBytes(); var archive = ZipFile.Open(archivePath, ZipArchiveMode.Update); archive.CreateEntry(fileName); using (Stream stream = archive.GetEntry(fileName).Open()) { stream.Write(bytes, 0, bytes.Length); } archive.Dispose(); }
//get all binary data private void button3_Click(object sender, EventArgs e) { try { List <Person> lstData = new List <Person>(); var ccfg = new CacheConfiguration { Name = "BINARY_DATA", CacheMode = CacheMode.Replicated }; var cfg = new IgniteConfiguration { SpringConfigUrl = configURL, BinaryConfiguration = new BinaryConfiguration(typeof(Person), typeof(PersonFilter)) }; Ignition.ClientMode = true; using (var ignite = Ignition.Start(cfg)) { ICache <int, IBinaryObject> persons = ignite.GetOrCreateCache <int, Person>(ccfg).WithKeepBinary <int, IBinaryObject>(); //var cache = ignite.GetOrCreateCache<int, Person>(ccfg); //getting single object with key IBinaryObject p = persons.Get(1); //casting issue in iteration.. //foreach (IBinaryObject item in persons) //{ // int i = 0; //} //further coding } txtMsg.Text = "Binary data pushed into cache 'BINARY_DATA' heap........."; } catch (Exception ex) { txtMsg.Text = ex.Message; } }
public void TestPutLoadBinarizable() { var cache = GetBinaryStoreCache <int, Value>(); cache.Put(1, new Value(1)); IDictionary map = StoreMap(); Assert.AreEqual(1, map.Count); IBinaryObject v = (IBinaryObject)map[1]; Assert.AreEqual(1, v.GetField <int>("_idx")); cache.LocalEvict(new[] { 1 }); Assert.AreEqual(0, cache.GetSize()); Assert.AreEqual(1, cache.Get(1).Index()); Assert.AreEqual(1, cache.GetSize()); }
public void WriteToFile(IBinaryObject obj, string filePath, bool overwrite) { //TODO: decide which filename (in the archive) to use WriteIntoArchive(obj, filePath, Path.GetFileNameWithoutExtension(filePath), overwrite); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceInvocationException"/> class. /// </summary> /// <param name="message">The message.</param> /// <param name="binaryCause">The binary cause.</param> public ServiceInvocationException(string message, IBinaryObject binaryCause) :base(message) { _binaryCause = binaryCause; }
/// <summary> /// Initializes a new instance of the <see cref="IgniteException"/> class. /// </summary> /// <param name="info">Serialization information.</param> /// <param name="ctx">Streaming context.</param> protected ServiceInvocationException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { _binaryCause = (IBinaryObject) info.GetValue(KeyBinaryCause, typeof (IBinaryObject)); }
/** <inheritdoc /> */ public IBinaryObject BinarizableArgAndResultMethod(int arg1, IBinaryObject arg2) { return(_binary.ToBinary <IBinaryObject>(arg2.Deserialize <TestBinarizableClass>())); }
/** <inheritdoc /> */ public TestBinarizableClass BinarizableArgMethod(int arg1, IBinaryObject arg2) { return(arg2.Deserialize <TestBinarizableClass>()); }
/// <summary> /// Checks the string date guid enum values. /// </summary> private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Guid? nGuid) { Assert.AreEqual(100, binObj.GetHashCode()); IBinaryType meta = binObj.GetBinaryType(); Assert.AreEqual(typeof(StringDateGuidEnum).Name, meta.TypeName); Assert.AreEqual(10, meta.Fields.Count); Assert.AreEqual(BinaryTypeNames.TypeNameString, meta.GetFieldTypeName("fStr")); Assert.AreEqual(BinaryTypeNames.TypeNameObject, meta.GetFieldTypeName("fNDate")); Assert.AreEqual(BinaryTypeNames.TypeNameTimestamp, meta.GetFieldTypeName("fNTimestamp")); Assert.AreEqual(BinaryTypeNames.TypeNameGuid, meta.GetFieldTypeName("fNGuid")); Assert.AreEqual(BinaryTypeNames.TypeNameEnum, meta.GetFieldTypeName("fEnum")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayString, meta.GetFieldTypeName("fStrArr")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayObject, meta.GetFieldTypeName("fDateArr")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayTimestamp, meta.GetFieldTypeName("fTimestampArr")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayGuid, meta.GetFieldTypeName("fGuidArr")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayEnum, meta.GetFieldTypeName("fEnumArr")); Assert.AreEqual("str", binObj.GetField<string>("fStr")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp")); Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid")); Assert.AreEqual(TestEnum.One, binObj.GetField<TestEnum>("fEnum")); Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr")); Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr")); Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr")); Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr")); Assert.AreEqual(new[] {TestEnum.One}, binObj.GetField<TestEnum[]>("fEnumArr")); StringDateGuidEnum obj = binObj.Deserialize<StringDateGuidEnum>(); Assert.AreEqual("str", obj.FStr); Assert.AreEqual(nDate, obj.FnDate); Assert.AreEqual(nDate, obj.FnTimestamp); Assert.AreEqual(nGuid, obj.FnGuid); Assert.AreEqual(TestEnum.One, obj.FEnum); Assert.AreEqual(new[] {"str"}, obj.FStrArr); Assert.AreEqual(new[] {nDate}, obj.FDateArr); Assert.AreEqual(new[] {nGuid}, obj.FGuidArr); Assert.AreEqual(new[] {TestEnum.One}, obj.FEnumArr); // Check builder field caching. var builder = _grid.GetBinary().GetBuilder(binObj); Assert.AreEqual("str", builder.GetField<string>("fStr")); Assert.AreEqual(nDate, builder.GetField<DateTime?>("fNDate")); Assert.AreEqual(nDate, builder.GetField<DateTime?>("fNTimestamp")); Assert.AreEqual(nGuid, builder.GetField<Guid?>("fNGuid")); Assert.AreEqual(TestEnum.One, builder.GetField<TestEnum>("fEnum")); Assert.AreEqual(new[] {"str"}, builder.GetField<string[]>("fStrArr")); Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fDateArr")); Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fTimestampArr")); Assert.AreEqual(new[] {nGuid}, builder.GetField<Guid?[]>("fGuidArr")); Assert.AreEqual(new[] {TestEnum.One}, builder.GetField<TestEnum[]>("fEnumArr")); // Check reassemble. binObj = builder.Build(); Assert.AreEqual("str", binObj.GetField<string>("fStr")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp")); Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid")); Assert.AreEqual(TestEnum.One, binObj.GetField<TestEnum>("fEnum")); Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr")); Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr")); Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr")); Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr")); Assert.AreEqual(new[] {TestEnum.One}, binObj.GetField<TestEnum[]>("fEnumArr")); obj = binObj.Deserialize<StringDateGuidEnum>(); Assert.AreEqual("str", obj.FStr); Assert.AreEqual(nDate, obj.FnDate); Assert.AreEqual(nDate, obj.FnTimestamp); Assert.AreEqual(nGuid, obj.FnGuid); Assert.AreEqual(TestEnum.One, obj.FEnum); Assert.AreEqual(new[] {"str"}, obj.FStrArr); Assert.AreEqual(new[] {nDate}, obj.FDateArr); Assert.AreEqual(new[] {nGuid}, obj.FGuidArr); Assert.AreEqual(new[] {TestEnum.One}, obj.FEnumArr); }
/// <summary> /// Checks the primitive array fields. /// </summary> private static void CheckPrimitiveArrayFields2(IBinaryObject binObj) { Assert.AreEqual(200, binObj.GetHashCode()); Assert.AreEqual(new byte[] { 7 }, binObj.GetField<byte[]>("fByte")); Assert.AreEqual(new[] { false }, binObj.GetField<bool[]>("fBool")); Assert.AreEqual(new short[] { 8 }, binObj.GetField<short[]>("fShort")); Assert.AreEqual(new[] { 'b' }, binObj.GetField<char[]>("fChar")); Assert.AreEqual(new[] { 9 }, binObj.GetField<int[]>("fInt")); Assert.AreEqual(new long[] { 10 }, binObj.GetField<long[]>("fLong")); Assert.AreEqual(new float[] { 11 }, binObj.GetField<float[]>("fFloat")); Assert.AreEqual(new double[] { 12 }, binObj.GetField<double[]>("fDouble")); Assert.AreEqual(new decimal?[] { 13.13m }, binObj.GetField<decimal?[]>("fDecimal")); var obj = binObj.Deserialize<PrimitiveArrays>(); Assert.AreEqual(new byte[] { 7 }, obj.FByte); Assert.AreEqual(new[] { false }, obj.FBool); Assert.AreEqual(new short[] { 8 }, obj.FShort); Assert.AreEqual(new[] { 'b' }, obj.FChar); Assert.AreEqual(new[] { 9 }, obj.FInt); Assert.AreEqual(new long[] { 10 }, obj.FLong); Assert.AreEqual(new float[] { 11 }, obj.FFloat); Assert.AreEqual(new double[] { 12 }, obj.FDouble); Assert.AreEqual(new decimal?[] { 13.13m }, obj.FDecimal); }
/// <summary> /// Checks the primitive array fields. /// </summary> private static void CheckPrimitiveArrayFields1(IBinaryObject binObj) { Assert.AreEqual(100, binObj.GetHashCode()); IBinaryType meta = binObj.GetBinaryType(); Assert.AreEqual(typeof(PrimitiveArrays).Name, meta.TypeName); Assert.AreEqual(9, meta.Fields.Count); Assert.AreEqual(BinaryTypeNames.TypeNameArrayByte, meta.GetFieldTypeName("fByte")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayBool, meta.GetFieldTypeName("fBool")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayShort, meta.GetFieldTypeName("fShort")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayChar, meta.GetFieldTypeName("fChar")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayInt, meta.GetFieldTypeName("fInt")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayLong, meta.GetFieldTypeName("fLong")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayFloat, meta.GetFieldTypeName("fFloat")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayDouble, meta.GetFieldTypeName("fDouble")); Assert.AreEqual(BinaryTypeNames.TypeNameArrayDecimal, meta.GetFieldTypeName("fDecimal")); Assert.AreEqual(new byte[] { 1 }, binObj.GetField<byte[]>("fByte")); Assert.AreEqual(new[] { true }, binObj.GetField<bool[]>("fBool")); Assert.AreEqual(new short[] { 2 }, binObj.GetField<short[]>("fShort")); Assert.AreEqual(new[] { 'a' }, binObj.GetField<char[]>("fChar")); Assert.AreEqual(new[] { 3 }, binObj.GetField<int[]>("fInt")); Assert.AreEqual(new long[] { 4 }, binObj.GetField<long[]>("fLong")); Assert.AreEqual(new float[] { 5 }, binObj.GetField<float[]>("fFloat")); Assert.AreEqual(new double[] { 6 }, binObj.GetField<double[]>("fDouble")); Assert.AreEqual(new decimal?[] { 7.7m }, binObj.GetField<decimal?[]>("fDecimal")); PrimitiveArrays obj = binObj.Deserialize<PrimitiveArrays>(); Assert.AreEqual(new byte[] { 1 }, obj.FByte); Assert.AreEqual(new[] { true }, obj.FBool); Assert.AreEqual(new short[] { 2 }, obj.FShort); Assert.AreEqual(new[] { 'a' }, obj.FChar); Assert.AreEqual(new[] { 3 }, obj.FInt); Assert.AreEqual(new long[] { 4 }, obj.FLong); Assert.AreEqual(new float[] { 5 }, obj.FFloat); Assert.AreEqual(new double[] { 6 }, obj.FDouble); Assert.AreEqual(new decimal?[] { 7.7m }, obj.FDecimal); }
/// <summary> /// Checks the primitive fields values. /// </summary> private static void CheckPrimitiveFields2(IBinaryObject binObj) { Assert.AreEqual(200, binObj.GetHashCode()); Assert.AreEqual(7, binObj.GetField<byte>("fByte")); Assert.AreEqual(false, binObj.GetField<bool>("fBool")); Assert.AreEqual(8, binObj.GetField<short>("fShort")); Assert.AreEqual('b', binObj.GetField<char>("fChar")); Assert.AreEqual(9, binObj.GetField<int>("fInt")); Assert.AreEqual(10, binObj.GetField<long>("fLong")); Assert.AreEqual(11, binObj.GetField<float>("fFloat")); Assert.AreEqual(12, binObj.GetField<double>("fDouble")); Assert.AreEqual(13.13m, binObj.GetField<decimal>("fDecimal")); var obj = binObj.Deserialize<Primitives>(); Assert.AreEqual(7, obj.FByte); Assert.AreEqual(false, obj.FBool); Assert.AreEqual(8, obj.FShort); Assert.AreEqual('b', obj.FChar); Assert.AreEqual(9, obj.FInt); Assert.AreEqual(10, obj.FLong); Assert.AreEqual(11, obj.FFloat); Assert.AreEqual(12, obj.FDouble); Assert.AreEqual(13.13m, obj.FDecimal); }
/// <summary> /// Checks the primitive fields values. /// </summary> private static void CheckPrimitiveFields1(IBinaryObject binObj) { Assert.AreEqual(100, binObj.GetHashCode()); IBinaryType meta = binObj.GetBinaryType(); Assert.AreEqual(typeof(Primitives).Name, meta.TypeName); Assert.AreEqual(9, meta.Fields.Count); Assert.AreEqual(BinaryTypeNames.TypeNameByte, meta.GetFieldTypeName("fByte")); Assert.AreEqual(BinaryTypeNames.TypeNameBool, meta.GetFieldTypeName("fBool")); Assert.AreEqual(BinaryTypeNames.TypeNameShort, meta.GetFieldTypeName("fShort")); Assert.AreEqual(BinaryTypeNames.TypeNameChar, meta.GetFieldTypeName("fChar")); Assert.AreEqual(BinaryTypeNames.TypeNameInt, meta.GetFieldTypeName("fInt")); Assert.AreEqual(BinaryTypeNames.TypeNameLong, meta.GetFieldTypeName("fLong")); Assert.AreEqual(BinaryTypeNames.TypeNameFloat, meta.GetFieldTypeName("fFloat")); Assert.AreEqual(BinaryTypeNames.TypeNameDouble, meta.GetFieldTypeName("fDouble")); Assert.AreEqual(BinaryTypeNames.TypeNameDecimal, meta.GetFieldTypeName("fDecimal")); Assert.AreEqual(1, binObj.GetField<byte>("fByte")); Assert.AreEqual(true, binObj.GetField<bool>("fBool")); Assert.AreEqual(2, binObj.GetField<short>("fShort")); Assert.AreEqual('a', binObj.GetField<char>("fChar")); Assert.AreEqual(3, binObj.GetField<int>("fInt")); Assert.AreEqual(4, binObj.GetField<long>("fLong")); Assert.AreEqual(5, binObj.GetField<float>("fFloat")); Assert.AreEqual(6, binObj.GetField<double>("fDouble")); Assert.AreEqual(7.7m, binObj.GetField<decimal>("fDecimal")); Primitives obj = binObj.Deserialize<Primitives>(); Assert.AreEqual(1, obj.FByte); Assert.AreEqual(true, obj.FBool); Assert.AreEqual(2, obj.FShort); Assert.AreEqual('a', obj.FChar); Assert.AreEqual(3, obj.FInt); Assert.AreEqual(4, obj.FLong); Assert.AreEqual(5, obj.FFloat); Assert.AreEqual(6, obj.FDouble); Assert.AreEqual(7.7m, obj.FDecimal); }
/// <summary> /// Checks the string date guid enum values. /// </summary> private static void CheckStringDateGuidEnum2(IBinaryObject binObj, DateTime? nDate, Guid? nGuid) { Assert.AreEqual(200, binObj.GetHashCode()); Assert.AreEqual("str2", binObj.GetField<string>("fStr")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate")); Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp")); Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid")); Assert.AreEqual(TestEnum.Two, binObj.GetField<TestEnum>("fEnum")); Assert.AreEqual(new[] { "str2" }, binObj.GetField<string[]>("fStrArr")); Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fDateArr")); Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fTimestampArr")); Assert.AreEqual(new[] { nGuid }, binObj.GetField<Guid?[]>("fGuidArr")); Assert.AreEqual(new[] { TestEnum.Two }, binObj.GetField<TestEnum[]>("fEnumArr")); var obj = binObj.Deserialize<StringDateGuidEnum>(); Assert.AreEqual("str2", obj.FStr); Assert.AreEqual(nDate, obj.FnDate); Assert.AreEqual(nDate, obj.FnTimestamp); Assert.AreEqual(nGuid, obj.FnGuid); Assert.AreEqual(TestEnum.Two, obj.FEnum); Assert.AreEqual(new[] { "str2" }, obj.FStrArr); Assert.AreEqual(new[] { nDate }, obj.FDateArr); Assert.AreEqual(new[] { nGuid }, obj.FGuidArr); Assert.AreEqual(new[] { TestEnum.Two }, obj.FEnumArr); }
static void Main(string[] args) { string s; DateTime startTime; DateTime endTime; IgniteConfiguration cfg = new IgniteConfiguration() { IgniteInstanceName = "TRex", // Register custom class for Ignite serialization BinaryConfiguration = new Apache.Ignite.Core.Binary.BinaryConfiguration(typeof(MyCacheClass)) }; IIgnite ignite = Ignition.Start(cfg); // Add a cache to Ignite ICache <string, MyCacheClass> cache = ignite.CreateCache <string, MyCacheClass> (new CacheConfiguration() { Name = "TestCache", CopyOnRead = false, KeepBinaryInStore = false, CacheStoreFactory = new TRexCacheStoreFactory(), ReadThrough = true, WriteThrough = true, WriteBehindFlushFrequency = new TimeSpan(0, 0, 5), // 5 seconds EvictionPolicy = new LruEvictionPolicy() { MaxMemorySize = 1000000, } }); int NumCacheEntries = 5000; // Add a cache item cache.Put("First", new MyCacheClass("FirstItem")); // Add a collectikon of items startTime = DateTime.Now; for (int i = 0; i < NumCacheEntries; i++) { cache.Put("First" + i, new MyCacheClass("First" + i)); } endTime = DateTime.Now; s = string.Format("{0}", endTime - startTime); Console.WriteLine("Time to add cache items with serialisation: {0}", s); int sumsum = 0; // Query back the cache items with serialisation startTime = DateTime.Now; for (int i = 0; i < NumCacheEntries; i++) { MyCacheClass first = cache.Get("First" + i); int sum = 0; for (int ii = 0; ii < first.localData.Length; ii++) { sum += first.localData[ii]; } sumsum += sum; } endTime = DateTime.Now; s = string.Format("{0}", endTime - startTime); Console.WriteLine("Time to query cache items with serialisation: {0}, sum = {1}", s, sumsum); var binCache = cache.WithKeepBinary <string, IBinaryObject>(); // IBinaryObject binCacheItem = binCache["First"]; // Console.WriteLine(binCacheItem.GetField<string>("Name")); // Query back the cache items without serialisation (using BinaryObject) startTime = DateTime.Now; for (int i = 0; i < NumCacheEntries; i++) { IBinaryObject binCacheItem = binCache["First" + i]; byte[] bytes = binCacheItem.GetField <byte[]>("localData"); int sum = 0; for (int ii = 0; ii < bytes.Length; ii++) { sum += bytes[ii]; } sumsum += sum; } endTime = DateTime.Now; s = string.Format("{0}", endTime - startTime); Console.WriteLine("Time to query cache items without serialisation: {0}, sum = {1}", s, sumsum); // Get compute instance over all nodes in the cluster. ICompute compute = ignite.GetCompute(); IClusterGroup compute2 = ignite.GetCompute().ClusterGroup; // Execute a map reduce on the cluster if (compute2.ForServers()?.GetNodes()?.Any() == true) { try { string mapReduceResult = ignite.GetCompute().Execute <string, string, string>(new MyComputeTask(), "Bob"); Console.WriteLine("Mapreduce result = '{0}'", mapReduceResult); } catch (Exception e) { Console.WriteLine("Exception executing mapReduce execution\r\n: {0}", e); } } else { Console.WriteLine("Calling cluster mapReduce broadcast function: No servers present in cluster"); } // Execute a command using affinity on the cluster try { string affinityResult = ignite.GetCompute().AffinityCall <string>("TestCache", "First", new AffinityComputeFunc("First")); Console.WriteLine("Affinity result = '{0}'", affinityResult); } catch (Exception e) { Console.WriteLine("Exception executing affinity execution\r\n: {0}", e); } if (ignite == null) { Console.WriteLine("Ignite instance is null at end of method"); } Console.ReadKey(); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceDeploymentException"/> class. /// </summary> /// <param name="message">The message.</param> /// <param name="binaryCause">The binary cause.</param> /// <param name="failedCfgs">List of failed configurations</param> public ServiceDeploymentException(string message, IBinaryObject binaryCause, ICollection <ServiceConfiguration> failedCfgs) : base(message) { _binaryCause = binaryCause; _failedCfgs = failedCfgs; }
/// <summary> /// Initializes a new instance of the <see cref="IgniteException"/> class. /// </summary> /// <param name="info">Serialization information.</param> /// <param name="ctx">Streaming context.</param> protected ServiceInvocationException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { _binaryCause = (IBinaryObject)info.GetValue(KeyBinaryCause, typeof(IBinaryObject)); }