示例#1
0
        public static IntAndString GetItemWithMaxIntAndOrStrLen(this IEnumerable <IntAndString> list)
        {
            if (list == null)
            {
                return(null);
            }
            IntAndString maxVal = null;

            foreach (IntAndString item in list)
            {
                if (maxVal == null)
                {
                    maxVal = item;
                }
                else
                {
                    if (item.Integer > maxVal.Integer)
                    {
                        maxVal = item;
                    }
                    else if (item.Integer == maxVal.Integer && item.String.Length > maxVal.String.Length)
                    {
                        maxVal = item;
                    }
                }
            }
            if (maxVal != null)
            {
                return(maxVal);
            }
            else
            {
                return(null);
            }
        }
 public Action<Message> persistDB(DBEngine<int, DBElement<int, string>> db)
 {
     Action<Message> PersistDB = (msg) =>
     {
         IntAndString pe = new IntAndString(db);
         XDocument doc = XDocument.Parse(msg.content);
         string XmlFile = doc.Descendants("Msg").Descendants("Data").Descendants("FileName").ElementAt(0).Value;
         pe.writeToXML(XmlFile);
         msg.content = "Persist success";
         Utilities.swapUrls(ref msg);
         Console.Write("\n\n The database has been persisted");
     };
     return PersistDB;
 }
示例#3
0
        public void Working_with_Generic_types()
        {
            using (var redisClient = new RedisClient(TestConfig.SingleHost))
            {
                //Create a typed Redis client that treats all values as IntAndString:
                var typedRedis = redisClient.GetTypedClient <IntAndString>();

                var pocoValue = new IntAndString {
                    Id = 1, Letter = "A"
                };
                typedRedis.SetEntry("pocoKey", pocoValue);
                IntAndString toPocoValue = typedRedis.GetValue("pocoKey");

                Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));

                var pocoListValues = new List <IntAndString> {
                    new IntAndString {
                        Id = 2, Letter = "B"
                    },
                    new IntAndString {
                        Id = 3, Letter = "C"
                    },
                    new IntAndString {
                        Id = 4, Letter = "D"
                    },
                    new IntAndString {
                        Id = 5, Letter = "E"
                    },
                };

                IRedisList <IntAndString> pocoList = typedRedis.Lists["pocoListKey"];

                //Adding all IntAndString objects into the redis list 'pocoListKey'
                pocoListValues.ForEach(x => pocoList.Add(x));

                List <IntAndString> toPocoListValues = pocoList.ToList();

                for (var i = 0; i < pocoListValues.Count; i++)
                {
                    pocoValue   = pocoListValues[i];
                    toPocoValue = toPocoListValues[i];
                    Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                    Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
                }
            }
        }
        private void comboAdditionalMessagesIndex_SelectedIndexChanged(object sender, EventArgs e)
        {
            IntAndString tag = comboAdditionalMessagesIndex.SelectedItem as IntAndString;

            if (!string.IsNullOrWhiteSpace(tag.String))
            {
                lblAdditionalMessage.Enabled  = true;
                txtAdditionalMessages.Enabled = true;
                txtAdditionalMessages.Text    = tag.String;
            }
            else
            {
                lblAdditionalMessage.Enabled  = false;
                txtAdditionalMessages.Enabled = false;
                txtAdditionalMessages.Text    = string.Empty;
            }
        }
        public async Task Working_with_Generic_types()
        {
            await using var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly();
            //Create a typed Redis client that treats all values as IntAndString:
            var typedRedis = redisClient.As <IntAndString>();

            var pocoValue = new IntAndString {
                Id = 1, Letter = "A"
            };
            await typedRedis.SetValueAsync("pocoKey", pocoValue);

            IntAndString toPocoValue = await typedRedis.GetValueAsync("pocoKey");

            Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
            Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));

            var pocoListValues = new List <IntAndString> {
                new IntAndString {
                    Id = 2, Letter = "B"
                },
                new IntAndString {
                    Id = 3, Letter = "C"
                },
                new IntAndString {
                    Id = 4, Letter = "D"
                },
                new IntAndString {
                    Id = 5, Letter = "E"
                },
            };

            IRedisListAsync <IntAndString> pocoList = typedRedis.Lists["pocoListKey"];

            //Adding all IntAndString objects into the redis list 'pocoListKey'
            await pocoListValues.ForEachAsync(async x => await pocoList.AddAsync(x));

            List <IntAndString> toPocoListValues = await pocoList.ToListAsync();

            for (var i = 0; i < pocoListValues.Count; i++)
            {
                pocoValue   = pocoListValues[i];
                toPocoValue = toPocoListValues[i];
                Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
            }
        }
        public void Working_with_Generic_types()
        {
            using (var redisClient = new RedisClient())
            {
                //Create a typed Redis client that treats all values as IntAndString:
                var typedRedis = redisClient.GetTypedClient<IntAndString>();

                var pocoValue = new IntAndString { Id = 1, Letter = "A" };
                typedRedis.SetEntry("pocoKey", pocoValue);
                IntAndString toPocoValue = typedRedis.GetValue("pocoKey");

                Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));

                var pocoListValues = new List<IntAndString> {
                    new IntAndString {Id = 2, Letter = "B"},
                    new IntAndString {Id = 3, Letter = "C"},
                    new IntAndString {Id = 4, Letter = "D"},
                    new IntAndString {Id = 5, Letter = "E"},
                };

                IRedisList<IntAndString> pocoList = typedRedis.Lists["pocoListKey"];

                //Adding all IntAndString objects into the redis list 'pocoListKey'
                pocoListValues.ForEach(x => pocoList.Add(x));

                List<IntAndString> toPocoListValues = pocoList.ToList();

                for (var i = 0; i < pocoListValues.Count; i++)
                {
                    pocoValue = pocoListValues[i];
                    toPocoValue = toPocoListValues[i];
                    Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                    Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
                }
            }
        }
示例#7
0
 public void TestIntAndString(IntAndString cl)
 {
 }