Website down due to a glasfiber modem upgrade…

Website was down for a few hours, deu to a glasfiber modem upgrade. Server seems happy after his first reboot in 2.5 years ūüôā

KPN routers force their users to use 192.168.2.xxx IP range (with a 255.255.255.0 subnet mask). So it took me some time to get all my 192.168.0.xxx devices to the new enforced 192.168.2.xxx range.

Campus Party Europe in The Netherlands

Elske and I spend two full days and one night at the Campus Party in the Jaarbeurs Utrecht. I was invited on stage to give a little talk about: How to start with Virtual Reality game development ūüôā

Overview of the stage and work area.
Me doing an unofficial talk about starting with virtual reality game development.
2000 tents, a little refugees camp for nerds.

C# – DynamicBag playing with Dynamic and Polymorphism

DynamicBag is a toy project that used a Dictionary<string, dynamic> to create a dynamic storage class.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
 
namespace Com.Okmer.DynamicTypes
{
    [Serializable]
    public class DynamicBag : Dictionary<string, dynamic>
    {
        public DynamicBag() { }
 
        public DynamicBag(int capacity) : base(capacity) { }
 
        public DynamicBag(IDictionary<string, dynamic> dictionary) : base(dictionary) { }
 
        public DynamicBag(SerializationInfo info, StreamingContext context) : base(info, context) { }
 
        public void ToBinaryFile(string fileName)
        {
            BinarySerialization.ToFile(this, fileName);
        }
 
        public static DynamicBag FromBinaryFile(string fileName)
        {
            return BinarySerialization.FromFile<DynamicBag>(fileName);
        }
    }
}

These DynamicBag(s) can be serialized to and deserialized from a file using BinarySerialization.

using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
 
namespace Com.Okmer.DynamicTypes
{
    public static class BinarySerialization
    {
        public static void ToFile<T>(T value, string fileName) where T : ISerializable
        {
            IFormatter formatter = new BinaryFormatter();
            using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                formatter.Serialize(stream, value);
            }
        }
 
        public static T FromFile<T>(string fileName) where T : ISerializable, new()
        {
            T result = new T();
            IFormatter formatter = new BinaryFormatter();
            using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                result = (T)formatter.Deserialize(stream);
            }
            return result;
        }
    }
}

The simple example application uses polymorphism to print the content of the DynamicBag(s) to the console.

using System;
using System.Collections.Generic;
 
using Com.Okmer.DynamicTypes;
 
namespace SampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            DynamicBag shoppingBag = new DynamicBag();
            DynamicBag spareBag = new DynamicBag();
 
            shoppingBag.Add("spareBag", spareBag);
            shoppingBag.Add("shoppingList", new string[] { "eggs", "milk", "cheese" });
 
            spareBag.Add("carCoin", "50ct");
            spareBag.Add("carValue", 50);
 
            Print(shoppingBag);
 
            Console.Write("---------------------------> ENTER <----: ");
            Console.ReadLine();
 
            shoppingBag.ToBinaryFile("shoppingBag.bin");
 
            DynamicBag shoppingBagFromBinaryFile = DynamicBag.FromBinaryFile("shoppingBag.bin");
 
            Print(shoppingBagFromBinaryFile);
 
            Console.Write("---------------------------> ENTER <----: ");
            Console.ReadLine();
        }
 
        private static void Print(DynamicBag bag)
        {
            Console.WriteLine("BAG BEGIN");
            foreach (string key in bag.Keys)
            {
                Console.WriteLine(key + ": ");
                Print(bag[key]);
            }
            Console.WriteLine("BAG END");
        }
 
        private static void Print(IEnumerable<dynamic> values)
        {
            Console.WriteLine("ENUMERABLE BEGIN");
            foreach (dynamic value in values)
            {
                Print(value);
            }
            Console.WriteLine("ENUMERABLE END");
        }
 
        private static void Print(bool value) => Console.WriteLine("bool -> " + value.ToString());
 
        private static void Print(int value) => Console.WriteLine("int -> " + value.ToString());
 
        private static void Print(double value) => Console.WriteLine("double -> " + value.ToString());
 
        private static void Print(string value) => Console.WriteLine("string -> " + value.ToString());
 
        private static void Print(object value) => Console.WriteLine("object-> " + value.ToString());
    }
}