public static ArrayList GetEventsList()
        {
            CreateEventsXml();
            lock (ContactsDirLock)
            {
                lock (EventsDirLock)
                {
                    eventsList = new ArrayList();

                    XDocument doc = XDocument.Load(EventsDir);
                    IEnumerable <XElement> enumEvents = doc.Elements("Events").Elements();


                    DateTime dateStart;
                    DateTime dateEnd;
                    bool     appointment;
                    bool     recurring;
                    //ArrayList recurringType;
                    Contact person;
                    int     cId;
                    string  cName, cSName, cAddr1, cAddr2, cLoc;
                    int     eId = 0;

                    foreach (var xmlEvents in enumEvents)
                    {
                        CalEvent ev = new CalEvent();

                        ev.SetId(eId);
                        eId++;
                        String format = (xmlEvents.Element("dateStart").Value);
                        dateStart = Convert.ToDateTime(format);
                        format    = (xmlEvents.Element("dateEnd").Value);
                        dateEnd   = Convert.ToDateTime(format);
                        ev.SetStartDate(dateStart);
                        ev.SetEndDate(dateEnd);

                        //dateStart = XmlConvert.ToDateTime(xmlEvents.Element("dateStart").Value);
                        Console.WriteLine(dateStart.ToString());
                        //dateStart = new DateTime((xmlEvents.Element("dateStart").Value).ToString());
                        //ev.SetStartDate(xmlEvents.Element("dateStart").Value);
                        //ev.SetEndDate(xmlEvents.Element("dateEnd").Value);
                        ev.SetTitle(xmlEvents.Element("title").Value);
                        if ((xmlEvents.Element("appointment").Value) == "False")
                        {
                            appointment = false;
                        }
                        else
                        {
                            appointment = true;
                        }
                        ev.SetAppointment(appointment);

                        if ((xmlEvents.Element("recurring").Value) == "False")
                        {
                            recurring = false;
                        }
                        else
                        {
                            recurring = true;
                        }
                        ev.SetRecurring(recurring);
                        //MessageBox.Show(recurring.ToString());
                        //MessageBox.Show(ev.IsRecurring().ToString());

                        //MessageBox.Show(xmlEvents.Element("recurringType").Value);
                        if (recurring)
                        {
                            string   recLong = xmlEvents.Element("recurringType").Value;
                            string[] recType = recLong.Split(',');
                            ev.SetRecurringType(recType);
                        }
                        else if (xmlEvents.Element("recurringType").Value == "NIL")
                        {
                            ev.SetRecurringType("NIL");
                        }
                        else if (ev.IsRecurring() && ev.GetRecurringTypeString().Contains("Weekly"))
                        {
                            ev.SetRecurring(true);
                            ev.SetRecurringType("Weekly");
                        }

                        else
                        {
                            MessageBox.Show("Something is wrong with recType: XmlControl.GetEventsList()");
                        }
                        //MessageBox.Show(ev.ToString());

                        cId    = int.Parse(xmlEvents.Element("person").Element("id").Value);
                        cName  = (xmlEvents.Element("person").Element("name").Value);
                        cSName = (xmlEvents.Element("person").Element("surname").Value);
                        cAddr1 = (xmlEvents.Element("person").Element("address1").Value);
                        cAddr2 = (xmlEvents.Element("person").Element("address2").Value);
                        cLoc   = (xmlEvents.Element("person").Element("postcode").Value);
                        Contact contact = new Contact(cName, cSName, cAddr1, cAddr2, cLoc);
                        contact.SetId(cId);

                        person = contact;
                        ev.SetContact(person);

                        ev.SetLocation(xmlEvents.Element("postcode").Value);
                        eventsList.Add(ev);
                    }
                }
            }

            return(eventsList);
        }
        private static void AddEventThread(CalEvent cEvent)
        {
            lock (EventsDirLock)
            {
                lock (ContactsDirLock)
                {
                    CreateEventsXml();
                    cEvent.InitNullValues();
                    string concatenated = string.Join(",",
                                                      cEvent.GetRecurringType().Select(x => x.ToString()).ToArray());

                    XDocument doc;
                    doc = XDocument.Load(EventsDir);
                    string person;
                    if (cEvent.IsAppointment())
                    {
                        person = cEvent.GetContact().ToString();
                    }
                    else
                    {
                        person = "NIL";
                    }

                    //int cId = GetContactId(cEvent.GetContact());
                    //MessageBox.Show(cEvent.ToString() + "xmlAddEvent");
                    doc.Element("Events").Add(new XElement("event",
                                                           new XElement("dateStart", new XText(cEvent.GetStartDate().ToString())),
                                                           new XElement("dateEnd", new XText(cEvent.GetEndDate().ToString())),
                                                           new XElement("title", new XText(cEvent.GetTitle())),
                                                           new XElement("appointment", new XText(cEvent.IsAppointment().ToString())),
                                                           new XElement("recurring", new XText(cEvent.IsRecurring().ToString())),
                                                           new XElement("recurringType", new XText(concatenated)),
                                                           new XElement("person",
                                                                        new XElement("id", new XText(cEvent.GetContact().GetId().ToString())),
                                                                        new XElement("name", new XText(cEvent.GetContact().FName)),
                                                                        new XElement("surname", new XText(cEvent.GetContact().SName)),
                                                                        new XElement("address1", new XText(cEvent.GetContact().Address1)),
                                                                        new XElement("address2", new XText(cEvent.GetContact().Address2)),
                                                                        new XElement("postcode", new XText(cEvent.GetContact().Postcode))),
                                                           new XElement("postcode", new XText(cEvent.GetLocation().ToString()))
                                                           ));
                    doc.Save(EventsDir);
                }
            }
        }