public void StringDictionaryFilter()
        {
            Energy.Base.Collection.StringDictionary x = new Energy.Base.Collection.StringDictionary();
            x.Add("111-222-333", "111-222-333");
            x.Add("111-88888888-333", "111-88888888-333");
            x.Add("111-222", "111-222");
            x.Add("555-ABC-XYZ", "555-ABC-XYZ");
            x.Add("Ąę€", "Ąę€");

            string[] filters;
            Energy.Base.Collection.StringDictionary y;

            filters = new string[] { "111-" };

            y = x.Filter(Enumeration.MatchStyle.Any, Enumeration.MatchMode.Simple, true, filters);
            Assert.AreEqual(3, y.Count);

            filters = new string[]
            {
                "111-222"
            };
            y = x.Filter(Enumeration.MatchMode.Same, true, filters);
            Assert.AreEqual(1, y.Count);
            y = x.Filter(Enumeration.MatchMode.Simple, true, filters);
            Assert.AreEqual(2, y.Count);
        }
Example #2
0
        private static void TestC1()
        {
            Energy.Base.Collection.StringDictionary x = new Energy.Base.Collection.StringDictionary();
            x.Add("111-222-333", "111-222-333");
            x.Add("111-88888888-333", "111-88888888-333");
            x.Add("111-222", "111-222");
            x.Add("555-ABC-XYZ", "555-ABC-XYZ");
            x.Add("Ąę€", "Ąę€");

            string[] filters;
            Energy.Base.Collection.StringDictionary y;

            filters = new string[] { "111-" };

            y = x.Filter(Energy.Enumeration.MatchMode.Simple, true, filters);

            Console.WriteLine(y.ToString(": "));
            Console.WriteLine();

            filters = new string[] { "111-222" };
            y       = x.Filter(Energy.Enumeration.MatchMode.Same, true, filters);
            Console.WriteLine(y.ToString(": "));
            Console.WriteLine();

            y = x.Filter(Energy.Enumeration.MatchMode.Simple, true, filters);
            Console.WriteLine(y.ToString(": "));
            Console.WriteLine();
        }
        public void StringDictionaryToObjectArray()
        {
            var dictionary = new Energy.Base.Collection.StringDictionary <object>();

            dictionary["X"]          = "Y";
            dictionary["TestClass1"] = new StringDictionaryToObjectArrayTestClass1[]
            {
                new StringDictionaryToObjectArrayTestClass1()
                {
                    Vorname = "Hans",
                    Name    = "Bauer",
                    Zuname  = "Bauer",
                },
                new StringDictionaryToObjectArrayTestClass1()
                {
                    Vorname = "Hans",
                    Name    = "Bauer",
                    Zuname  = "Bauer",
                },
            };
            object[] objectArray1 = dictionary.ToObjectArray();
            Assert.IsNotNull(objectArray1);
            Assert.AreNotEqual(0, objectArray1.Length);
            object[] objectArray2 = Energy.Base.Cast.StringDictionaryToObjectArray <object>(dictionary);
            Assert.IsNotNull(objectArray2);
            Assert.AreEqual(objectArray1.Length, objectArray2.Length);
        }
Example #4
0
 public Bag()
 {
     _Values = new Energy.Base.Collection.StringDictionary <object>()
     {
         CaseSensitive = false,
     };
     _Types = new Energy.Base.Collection.StringDictionary <Energy.Enumeration.FormatType>()
     {
         CaseSensitive = false,
     };
 }
Example #5
0
 public static void GetAllAssemblies()
 {
     Assembly[] assemblies = Energy.Base.Class.GetAssemblies();
     if (assemblies == null)
     {
         return;
     }
     WriteAssemblies(assemblies);
     Energy.Core.Tilde.WriteLine("~c~Filtering out only ~w~System.~c~ elements");
     Energy.Base.Collection.StringDictionary <Assembly> dictionary = Energy.Base.Class.GetAssembliesDictionaryByShortName(assemblies);
     dictionary = dictionary.Filter(Energy.Enumeration.MatchMode.Simple, true, new string[] { "System." });
     WriteAssemblies(dictionary.GetValueArray());
 }
Example #6
0
 public Syntax()
 {
     this.Dictionary = new Energy.Base.Collection.StringDictionary <object>()
     {
         CaseSensitive = false,
     };
     this.Brackets = new Base.Bracket.Array();
     this.Brackets.Add(new Energy.Base.Bracket()
     {
         Prefix = "{{",
         Suffix = "}}",
     });
 }
Example #7
0
        private static void TestA1()
        {
            Random random = new Random();

            Energy.Base.Collection.StringDictionary d = new Energy.Base.Collection.StringDictionary();
            d.CaseSensitive = false;
            for (int i = 0; i < 100000; i++)
            {
                string key   = random.Next(10000).ToString();
                string value = random.Next(10000).ToString();
                d.Set(key, value);
            }
        }
        public void StringDictionaryCaseSensitive()
        {
            var dictionary = new Energy.Base.Collection.StringDictionary <object>();

            dictionary.SelectionOfDuplicates = Energy.Enumeration.MultipleBehaviour.First;

            dictionary["One"] = 1;
            dictionary["TWO"] = 2;
            dictionary["ONE"] = 1 + (int)(dictionary["two"] ?? 1);

            Assert.AreEqual("ONE=2 one=", string.Concat("", "ONE=", dictionary["ONE"], " one=", dictionary["one"]));

            dictionary.CaseSensitive = false;

            Assert.AreEqual("ONE=1 one=1", string.Concat("", "ONE=", dictionary["ONE"], " one=", dictionary["one"]));

            string result;
            string expect;

            Energy.Base.Collection.StringDictionary sd;

            sd = new Energy.Base.Collection.StringDictionary();
            sd.CaseSensitive = false;
            sd.Set("Product", "123");
            sd.Set("product", "123456789");
            result = sd.Get("Product");
            expect = "123456789";
            Assert.AreEqual(expect, result);
            sd.CaseSensitive = true;
            result           = sd.Get("Product");
            expect           = "123456789";
            Assert.AreEqual(expect, result);

            sd = new Energy.Base.Collection.StringDictionary();
            sd.Set("Product", "123");
            sd.Set("product", "123456789");
            sd.Set("zzz1", "abc");

            result = sd.Get("Product");
            expect = "123";
            Assert.AreEqual(expect, result);

            result = sd.Get("zzz1");
            expect = "abc";
            Assert.AreEqual(expect, result);

            sd.CaseSensitive = false;
            result           = sd.Get("Product");
            expect           = "123456789";
            Assert.AreEqual(expect, result);
        }
Example #9
0
        private static void TestB1()
        {
            Energy.Base.Collection.StringDictionary d = new Energy.Base.Collection.StringDictionary();
            d.CaseSensitive = true;
            Console.WriteLine("Setting \"Option\" to \"Value\"");
            d.Set("Option", "Value");
            string value;

            value = d.Get("option");
            Console.WriteLine("Value of \"option\" when CaseSensitive is true: {0}", value);
            d.CaseSensitive = false;
            value           = d.Get("option");
            Console.WriteLine("Value of \"option\" when CaseSensitive is false: {0}", value);
        }
Example #10
0
        private static void TestB3()
        {
            var dictionary = new Energy.Base.Collection.StringDictionary <object>();

            dictionary["One"] = 1;
            dictionary["TWO"] = 2;
            dictionary["ONE"] = 1 + (int)(dictionary["two"] ?? 1);

            Console.WriteLine(string.Concat("", "ONE=", dictionary["ONE"], " one=", dictionary["one"]));

            dictionary.CaseSensitive = false;

            Console.WriteLine(string.Concat("", "ONE=", dictionary["ONE"], " one=", dictionary["one"]));

            string xml = Energy.Base.Xml.Serialize(dictionary, "Dictionary");

            Console.WriteLine(xml);
        }
Example #11
0
        static void Main(string[] args)
        {
            Energy.Core.Program.SetConsoleEncoding();
            Energy.Core.Tilde.WriteLine("This example demonstrates usage of ~w~Energy~0~.~w~Base~0~.~w~Collection~0~.~y~StringDictionary~0~.");

            PrintMemoryUsage();

            TestB1();
            TestB2();
            TestB3();

            string[] dictionary = new string[] { "key1", "value1", "key2", "value2" };
            var      x          = new Energy.Base.Collection.StringDictionary <string>(dictionary);

            Console.WriteLine(x.ToString("="));

            Energy.Core.Benchmark.Result result;

            result = Energy.Core.Benchmark.Profile(TestA1, 5);
            Console.WriteLine(result.ToString(false, "0.0000000"));

            PrintMemoryUsage();

            result = Energy.Core.Benchmark.Profile(TestA2, 5);
            Console.WriteLine(result.ToString(false, "0.0000000"));

            PrintMemoryUsage();

            result = Energy.Core.Benchmark.Profile(TestA1, 5);
            Console.WriteLine(result.ToString(false, "0.0000000"));

            PrintMemoryUsage();

            result = Energy.Core.Benchmark.Profile(TestA2, 5);
            Console.WriteLine(result.ToString(false, "0.0000000"));

            PrintMemoryUsage();

            TestC1();

            Console.ReadLine();
        }
Example #12
0
        public void StringDictionaryConstructor()
        {
            Dictionary <string, object> d;

            d = new Energy.Base.Collection.StringDictionary <object>("a");

            Assert.IsNotNull(d);
            Assert.AreEqual(0, d.Count);

            d = new Energy.Base.Collection.StringDictionary <object>("a", "b");

            Assert.IsNotNull(d);
            Assert.AreEqual(1, d.Count);
            Assert.AreEqual("b", d["a"]);

            d = new Energy.Base.Collection.StringDictionary <object>("a", "b", null);

            Assert.IsNotNull(d);
            Assert.AreEqual(1, d.Count);
            Assert.AreEqual("b", d["a"]);
        }
Example #13
0
        private static void TestB2()
        {
            Energy.Base.Collection.StringDictionary d = new Energy.Base.Collection.StringDictionary();
            d.CaseSensitive = true;
            Console.WriteLine("Setting \"Option\", \"option\" and \"OPTION\" to different values");
            d["Option"] = "Value1";
            d["option"] = "Value2";
            d["OPTION"] = "Value3";
            string value;

            value = d.Get("option");
            Console.WriteLine("Value of \"option\" when CaseSensitive is true: {0}", value);
            d.CaseSensitive = false;
            value           = d.Get("option");
            Console.WriteLine("Value of \"option\" when CaseSensitive is false: {0}", value);
            d.CaseSensitive = true;
            Energy.Core.Tilde.WriteLine("~y~Array when CaseSensitive is true");
            Console.WriteLine(string.Join(", ", d.ToArray("=")));
            d.CaseSensitive = false;
            Energy.Core.Tilde.WriteLine("~y~Array when CaseSensitive is false");
            Console.WriteLine(string.Join(", ", d.ToArray("=")));
        }
Example #14
0
        public static void Main()
        {
            Energy.Core.Application.SetDefaultLanguage();
            Console.WriteLine("Hello World");
            Item _ = new Item()
            {
                Name = "Example name", Count = 12345,
            };

            Console.WriteLine(Energy.Base.Xml.Serialize(_));

            Energy.Base.Collection.SerializableDictionary <string, int> x
                = new Energy.Base.Collection.SerializableDictionary <string, int>();
            x.Add("test", 12);
            x.Add("xyz", 321);

            string xml1 = Energy.Base.Xml.Serialize(x);

            Console.WriteLine(xml1);
            Energy.Base.Collection.SerializableDictionary <string, int> x2
                = Energy.Base.Xml.Deserialize <Energy.Base.Collection.SerializableDictionary <string, int> >(xml1);
            Console.WriteLine(x2.Count);
            Energy.Base.Collection.StringDictionary <Item> s = new Energy.Base.Collection.StringDictionary <Item>();
            s.Add("x", _);
            _.Name = "Example name 2";
            s.Add("y", _);
            Console.WriteLine(Energy.Base.Xml.Serialize(s));
            Console.WriteLine();

            Test test = new Test();

            test.SerializeBaseTable();

            test.SerializeDataTable();

            Console.ReadLine();
        }
Example #15
0
        public static int Request(string method, string url, byte[] data
                                  , string contentType
                                  , string acceptType
                                  , string[] requestHeaders
                                  , out string[] responseHeaders
                                  , out byte[] responseData
                                  )
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = method;
            if (!string.IsNullOrEmpty(contentType))
            {
                request.ContentType = contentType;
            }
            if (!string.IsNullOrEmpty(acceptType))
            {
                request.Accept = acceptType;
            }

            if (requestHeaders != null && requestHeaders.Length > 0)
            {
                //for (int i = 0; i < requestHeaders.Length / 2; i++)
                //{
                //    request.Headers.Add(requestHeaders[i], requestHeaders[i + 1]);
                //}
                for (int i = 0; i < requestHeaders.Length; i++)
                {
                    request.Headers.Add(requestHeaders[i]);
                }
            }

            int statusCode = 0;

            responseHeaders = null;
            responseData    = null;

            if (data != null && data.Length > 0)
            {
                request.ContentLength = data.Length;

                using (Stream requestStream = request.GetRequestStream())
                {
                    if (requestStream == null)
                    {
                        return(0);
                    }

                    requestStream.Write(data, 0, data.Length);
                    requestStream.Flush();
                    requestStream.Close();
                }
            }

            using (HttpWebResponse response = (HttpWebResponse)GetResponseWithoutException(request))
            {
                statusCode = (int)response.StatusCode;
                if (response.Headers.Count > 0)
                {
                    Energy.Base.Collection.StringDictionary d = new Energy.Base.Collection.StringDictionary();
                    string[] keys = response.Headers.AllKeys;
                    for (int i = 0; i < keys.Length; i++)
                    {
                        d[keys[i]] = response.Headers[i];
                    }
                    responseHeaders = d.ToArray();
                }
                using (Stream responseStream = response.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (Energy.Base.ByteArrayBuilder builder = new Energy.Base.ByteArrayBuilder(responseStream))
                        {
                            responseData = builder.ToArray();
                        }
                    }
                    return(statusCode);
                }
            }
        }