static void Main(string[] args) { string connectionString = null; string tableName = null; string keyName = null; string valueName = null; var parser = new Fclp.FluentCommandLineParser(); parser.Setup <string>('c', "connectionString").Callback(x => connectionString = x); parser.Setup <string>('t', "tableName").Callback(x => tableName = x); parser.Setup <string>('k', "key").Callback(x => keyName = x); parser.Setup <string>('v', "value").Callback(x => valueName = x); parser.Parse(args); Console.WriteLine("Connecting..."); var dic1 = new SqlDictionary <int, int>(); dic1.Load(connectionString, "intint", keyName, valueName); Console.WriteLine("SqlDictionary.Clear"); dic1.Clear(); Console.WriteLine("dic1.Count == 0"); Debug.Assert(dic1.Count == 0); dic1.Add(1, 2); Console.WriteLine("dic1.Count == 1"); Debug.Assert(dic1.Count == 1); Console.WriteLine("dic1[1] == 2"); Debug.Assert(dic1[1] == 2); dic1.Remove(1); Console.WriteLine("dic1.Count == 0"); Debug.Assert(dic1.Count == 0); dic1[1] = 3; Console.WriteLine("dic1[1] == 3"); Debug.Assert(dic1[1] == 3); dic1[1] = 4; Console.WriteLine("dic1[1] == 4"); Debug.Assert(dic1[1] == 4); var dic2 = new SqlDictionary <int, string>(); dic2.Load(connectionString, "intstring", keyName, valueName); dic2.Clear(); dic2.Add(1, "2"); dic2.Remove(1); dic2[1] = "3"; dic2[1] = "4"; var dic3 = new SqlDictionary <string, string>(); dic3.Load(connectionString, "stringstring", keyName, valueName); dic3.Clear(); dic3.Add("1", "2"); dic3.Remove("1"); dic3["1"] = "3"; dic3["1"] = "4"; var dic4 = new SqlDictionary <string, SomeDto>(); dic4.Load(connectionString, "stringdto", keyName, valueName); dic4.Clear(); dic4.Add("1", new SomeDto() { Id = 1, Name = "SomeName" }); dic4.Remove("1"); dic4["1"] = new SomeDto() { Id = 2, Name = "SomeName" }; dic4["1"] = new SomeDto() { Id = 3, Name = "SomeName" }; var dic5 = new SqlNoMemoryDictionary <int, int>(); dic5.Prepare(connectionString, "lazyintint", keyName, valueName); dic5.Clear(); dic5.Add(1, 2); dic5.Remove(1); dic5[1] = 3; dic5[1] = 4; Console.WriteLine("OK!"); }
static void Main(string[] args) { string connectionString = null; string serviceOrigin = null; string serviceDestination = null; string contract = null; string messageType = null; string queueOrigin = null; string queueDestination = null; string baggageTable = null; var parser = new Fclp.FluentCommandLineParser(); parser.Setup <string>("connectionString").Callback(x => connectionString = x); parser.Setup <string>("serviceOrigin").Callback(x => serviceOrigin = x); parser.Setup <string>("serviceDestination").Callback(x => serviceDestination = x); parser.Setup <string>("contract").Callback(x => contract = x); parser.Setup <string>("messageType").Callback(x => messageType = x); parser.Setup <string>("queueOrigin").Callback(x => queueOrigin = x); parser.Setup <string>("queueDestination").Callback(x => queueDestination = x); parser.Setup <string>("baggageTable").Callback(x => baggageTable = x); parser.Parse(args); Console.WriteLine("Connecting..."); var parameters = new SqlQueueParameters(connectionString, serviceOrigin, serviceDestination, contract, messageType, queueOrigin, queueDestination, baggageTable); var queue = new SqlQueue(parameters); queue.CreateObjects(); queue.EnableQueue(); queue.Clear(); var item1 = new ItemDto(1) { InnerDto = new BaseDto.InnerBaseDto(18, "InnerDtoText") }; var item2 = new ItemDto(2); var item3 = new ItemDto(3); var ea = new SomeDomainEvent("a", "b", "c", new[] { "d" }) { User = new DomainEventArgs.UserInfo(143, "name") }; queue.Enqueue(ea); ea = queue.Dequeue <SomeDomainEvent>(); Debug.Assert(ea.User.Id == 143); Debug.Assert(ea.User.Name == "name"); var event2 = new SomeDomainEvent2(SomeDomainEvent2.InnerEnum1.EnumValue1, SomeDomainEvent2.InnerEnum2.Enum2Value2, 1, "message"); queue.Enqueue(event2); event2 = queue.Dequeue <SomeDomainEvent2>(); Debug.Assert(event2.Inner1 == SomeDomainEvent2.InnerEnum1.EnumValue1); Debug.Assert(event2.Inner2 == SomeDomainEvent2.InnerEnum2.Enum2Value2); queue.Enqueue(item1); queue.Enqueue(item2); queue.Enqueue(item3); item1 = queue.Dequeue <ItemDto>(); item2 = queue.Dequeue <ItemDto>(); item3 = queue.Dequeue <ItemDto>(); Console.WriteLine("item1.Id == 1"); Debug.Assert(item1.Int == 1); Debug.Assert(item1.Long == 5); Debug.Assert(item1.Options.Count() == 2); Debug.Assert(item1.Options[0] == ENUM.A); Debug.Assert(item1.Options[1] == ENUM.B); Debug.Assert(item1.Strings.Count() == 2); Debug.Assert(item1.Strings[0] == "abc"); Debug.Assert(item1.Strings[1] == "def"); Debug.Assert(item1.UniqueID == Guid.Parse("c060ee98-2527-4a47-88cb-e65263ed4277")); Debug.Assert(System.Text.Encoding.UTF8.GetString(item1.VeryBigBuffer) == "VERYBIGTEXT"); Debug.Assert(System.Text.Encoding.UTF8.GetString(item1.DictionaryBuffers["buffer1"]) == "BUFFER1"); Debug.Assert(System.Text.Encoding.UTF8.GetString(item1.DictionaryBuffers["buffer2"]) == "BUFFER2"); Debug.Assert(item1.BaseInt == 98); Debug.Assert(item1.BaseChild.Int == 99); Debug.Assert(item1.InnerDto.InnerDtoInt == 18); Debug.Assert(item1.InnerDto.InnerDtoText == "InnerDtoText"); Console.WriteLine("item1.Id == 2"); Debug.Assert(item2.Int == 2); Console.WriteLine("item1.Id == 3"); Debug.Assert(item3.Int == 3); queue.Enqueue(item1); var items = queue.DequeueGroup(); Debug.Assert(items.Count() == 1); Debug.Assert((items.Single() as ItemDto).Int == 1); queue.Enqueue(new NullDto()); var nullDto = queue.Dequeue <NullDto>(); Debug.Assert(nullDto.Child == null); Debug.Assert(nullDto.DateTime == null); Debug.Assert(nullDto.DictionaryBuffers == null); Debug.Assert(nullDto.Double == null); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Int == null); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Long == null); Debug.Assert(nullDto.Options == null); Debug.Assert(nullDto.Strings == null); Debug.Assert(nullDto.Text == null); Debug.Assert(nullDto.UniqueID == null); Debug.Assert(nullDto.VeryBigBuffer == null); queue.Enqueue(new NullDto() { Int = 1 }); nullDto = queue.Dequeue <NullDto>(); Debug.Assert(nullDto.Child == null); Debug.Assert(nullDto.DateTime == null); Debug.Assert(nullDto.DictionaryBuffers == null); Debug.Assert(nullDto.Double == null); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Int.HasValue); Debug.Assert(nullDto.Int == 1); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Long == null); Debug.Assert(nullDto.Options == null); Debug.Assert(nullDto.Strings == null); Debug.Assert(nullDto.Text == null); Debug.Assert(nullDto.UniqueID == null); Debug.Assert(nullDto.VeryBigBuffer == null); queue.Enqueue(new NullDto() { Text = "SOMESTRING" }); nullDto = queue.Dequeue <NullDto>(); Debug.Assert(nullDto.Child == null); Debug.Assert(nullDto.DateTime == null); Debug.Assert(nullDto.DictionaryBuffers == null); Debug.Assert(nullDto.Double == null); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Int == null); Debug.Assert(nullDto.Float == null); Debug.Assert(nullDto.Long == null); Debug.Assert(nullDto.Options == null); Debug.Assert(nullDto.Strings == null); Debug.Assert(nullDto.Text == "SOMESTRING"); Debug.Assert(nullDto.UniqueID == null); Debug.Assert(nullDto.VeryBigBuffer == null); var item5 = new ItemDto(5); var item6 = new ItemDto(6); queue.Enqueue(new[] { item5, item6 }); var itemdtos = queue.DequeueGroup().Cast <ItemDto>(); Debug.Assert(itemdtos.Skip(0).First().Int == 5); Debug.Assert(itemdtos.Skip(1).First().Int == 6); try { queue.Enqueue(new NonSerializableDto()); var nonserializable = queue.Dequeue <NonSerializableDto>(); Debug.Assert(false); } catch { } // Transactional processing must work var itemT1 = new ItemDto(6); queue.Enqueue(itemT1); queue.DequeueGroup(messages => { Debug.Assert(messages.Count() == 1); Debug.Assert((messages.First() as ItemDto).Int == 6); }); // Transactional retry must work var dic = new SqlNoMemoryDictionary <Guid, QueuItemEnvelope>(); dic.Prepare(connectionString, "QUEUESTATUS", "Oid", "Status"); dic.Clear(); queue.Clear(); queue.Enqueue(new[] { new ItemDto(5, Guid.NewGuid()), new ItemDto(6, Guid.NewGuid()) }); queue.DequeueGroup(messages => { foreach (ItemDto mesage in messages) { dic.Add(mesage.UniqueID, new QueuItemEnvelope(mesage)); throw new Exception(); } }); queue.DequeueGroup <Guid>(dic, x => (x as ItemDto).UniqueID, message => { Console.Write(message); }); Guid g1 = Guid.Parse("855a88f3-e2f8-4cbb-8ef5-130d86f27913"); Guid g2 = Guid.Parse("6abaeacc-f47b-4c77-b0fc-ecd873dea12a"); queue.Enqueue(new[] { new ItemDto(5, g1), new ItemDto(6, g2) }); queue.DequeueGroup(dic, x => (x as ItemDto).UniqueID, message => { throw new Exception(); }); queue.DequeueGroup(dic, x => (x as ItemDto).UniqueID, message => { Console.Write(message); }); queue.Enqueue(new[] { new ItemDto(5, g1), new ItemDto(6, g2) }); queue.DequeueGroup(dic, x => (x as ItemDto).UniqueID, message => { Debug.Assert(false); }); //VERY BIG mESSAGE var bigdto = new ItemDto(1) { Text = new string('a', 2000 * 1000 ) }; queue.Enqueue(bigdto); bigdto = queue.Dequeue <ItemDto>(); Debug.Assert(bigdto.Text.Length == 2000 * 1000); var emptyDicMsg = new EmptyDicDomainEventArgs(); queue.Enqueue(emptyDicMsg); emptyDicMsg = queue.Dequeue <EmptyDicDomainEventArgs>(); Console.WriteLine(""); Console.WriteLine("OK!"); //Console.ReadLine(); }