//Method converts last persisted database XML file to a database
        public DatabaseDictionary <int, Element <int, string> > XMLtoIntDB()
        {
            XDocument IntDBXML = XDocument.Load("PersistedIntDB.xml");
            var       Query    = from KV in IntDBXML.Elements("KeyValuePairs").Elements("KeyValuePair").Descendants() select KV;

            foreach (var KVP in Query)
            {
                if (KVP.Name.ToString() == "Key")
                {
                    DBKey = int.Parse(KVP.FirstAttribute.Value);
                }
                if (KVP.Name.ToString() == "Value")
                {
                    Element <int, string> DBElement = new Element <int, string>();
                    try
                    {
                        foreach (var Desc in KVP.Descendants())
                        {
                            if (Desc.Name.ToString() == "Name")
                            {
                                DBElement.NAME = Desc.Value.ToString();
                            }
                            if (Desc.Name.ToString() == "Description")
                            {
                                DBElement.DESCRIPTION = Desc.Value.ToString();
                            }
                            if (Desc.Name.ToString() == "Timestamp")
                            {
                                DateTime timestamp = DateTime.Parse(Desc.Value);
                                DBElement.TIMESTAMP = timestamp;
                            }
                            if (Desc.Name.ToString() == "Relations")
                            {
                                if (Desc.Descendants() == null)
                                {
                                    DBElement.RELATIONS = null;
                                }
                                List <int> Relations = new List <int>();
                                foreach (var Relation in Desc.Descendants())
                                {
                                    Relations.Add(int.Parse(Relation.Value));
                                }
                                DBElement.RELATIONS = Relations;
                            }
                            if (Desc.Name.ToString() == "Data")
                            {
                                DBElement.DATA = Desc.Value;
                            }
                        }
                    }
                    catch (Exception M)
                    {
                        Console.WriteLine(M.Message);
                    }

                    IntKeyDB.AddPair(DBKey, DBElement);
                }
            }
            return(IntKeyDB);
        }
        //String data base is created initially in case user wants to perform read actions first
        public void CreateStringDB()
        {
            Element <string, List <string> > EL1 = new Element <string, List <string> >();
            List <string> Data = new List <string>(); List <string> relations = new List <string>();

            Data.Add("Wish you were here"); relations.Add("Key3");
            EL1.NAME = "Pink Floyd"; EL1.DATA = Data; EL1.DESCRIPTION = "Rockband"; EL1.RELATIONS = relations; EL1.TIMESTAMP = DateTime.Now;
            StringKeyDB.AddPair("Key1", EL1);
            Data.Add("Beautiful day");
            EL1.NAME = "U2"; EL1.DATA = Data; EL1.DESCRIPTION = "Rockband"; EL1.RELATIONS = relations; EL1.TIMESTAMP = DateTime.Now;
            StringKeyDB.AddPair("Key2", EL1);
        }
示例#3
0
 // Code Analyzer shows that its complexity is 17 but it doesn't look like to me. Please comment if there is any scope of reducing the complexity
 public static string AddElementSL(this DatabaseDictionary <string, Element <string, List <string> > > Temp) //Method to add a random generated elment in a DB
 {
     try
     {
         string        Key    = Temp.SKeygenerator();
         Random        Random = new Random();
         List <string> Names  = new List <string> {
             "Megadeath", "Pink Floyd", "Porcupine Tree", "Bahramji", "RHCP"
         };
         List <List <string> > Relation = new List <List <string> > {
             new List <string> {
                 "Key1"
             }, new List <string> {
                 "Key2", "Key3"
             }, new List <string> {
                 "Key3", "Key1"
             }, new List <string> {
                 "Key4"
             }, new List <string> {
                 "Key4", "Key2"
             }
         };
         List <List <string> > Data = new List <List <string> > {
             new List <string> {
                 "Opeth"
             }, new List <string> {
                 "Animals"
             }, new List <string> {
                 "Sunset"
             }, new List <string> {
                 "Chillout"
             }, new List <string> {
                 "New Era"
             }
         };
         if (Key != "" || Key != null)
         {
             Element <string, List <string> > TempE = new Element <string, List <string> >();
             TempE.NAME        = Names[Random.Next(0, Names.Count)];
             TempE.DESCRIPTION = "Rockband";
             TempE.TIMESTAMP   = DateTime.Now;
             TempE.RELATIONS   = Relation[Random.Next(0, Relation.Count)];
             TempE.DATA        = Data[Random.Next(0, Data.Count)];
             Temp.AddPair(Key, TempE);
             Console.WriteLine("  New element added");
             return("New element added");
         }
         Console.WriteLine("  New element was not added");
         return("Element was not added");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(e.Message);
     }
 }
        public static void Main(string[] args)
        {
            Console.WriteLine("Testing Database Dictionary class" + "\n");
            DatabaseDictionary <int, Element <int, string> > d = new DatabaseDictionary <int, Element <int, string> >();
            Element <int, string> IKElement1 = new Element <int, string>();

            IKElement1.NAME = "Pink Floyd"; IKElement1.DESCRIPTION = "Rockband"; IKElement1.TIMESTAMP = DateTime.Now; IKElement1.RELATIONS = new List <int> {
                1, 2
            }; IKElement1.DATA = "Wish you were here";
            d.AddPair(1, IKElement1);
            //Above code is there to show how coding of adding an element in a database would look like.

            Console.WriteLine("Databases can't be tested in this project as most of the testing depends on ExtensionMethod which contain all extension methods.");
            Console.WriteLine("To avoid circular dependency, all tests are performed in DatabaseDictionaryTest project");
        }
示例#5
0
        static void Main(string[] args)
        {
            DatabaseDictionary <int, Element <int, string> > IntKeyDB = new DatabaseDictionary <int, Element <int, string> >();
            Element <int, string> IKElement1 = new Element <int, string>();

            IKElement1.NAME = "The Beatles"; IKElement1.DESCRIPTION = "Rockband"; IKElement1.TIMESTAMP = DateTime.Now; IKElement1.RELATIONS = new List <int> {
                5, 2
            }; IKElement1.DATA = "Revolver";
            Element <int, string> IKElement2 = new Element <int, string>();

            IKElement2.NAME = "Pink Floyd"; IKElement2.DESCRIPTION = "Rockband"; IKElement2.TIMESTAMP = DateTime.Now; IKElement2.RELATIONS = new List <int> {
                1, 2
            }; IKElement2.DATA = "Wish you were here";
            IntKeyDB.AddPair(1, IKElement2);
            IntKeyDB.AddPair(2, IKElement1);
            Console.Write("Following key or keys contain THE BEATLES as the NAME in their values (Elements)\nKey: ");
            Console.Write("\n\nFollowing key or keys contain WISH YOU WERE HERE as the DATA in their values (Elements)\nKey: ");
            foreach (int a in IntKeyDB.FindKeysbyData("Wish you were here"))
            {
                Console.Write("{0} ", a.ToString());
            }
            Console.Write("\n\nFollowing key or keys have been updated in the database today till now\nKey: ");
            Console.WriteLine();
        }