Esempio n. 1
0
        public void EqualityTest()
        {
            var A = new Contact("Steve", "Hamilton", "*****@*****.**", "Steve Limited", "(07)7533 2343");
            var B = new Contact("Steve", "Hamilton", "*****@*****.**", "Steve Limited", "(07)7533 2343");

            Assert.AreEqual(A, B);
        }
        public void TestMissingValues()
        {
            var contact = new Contact("Jim", "Does", "*****@*****.**", "Lollipops", "837773");
            var dataSet = new Dataset(new Site(4, "New Site", "Tim Jones", contact, contact, new GPSCoords(0, 0, "argis")));

            var sensor = new Sensor("Dummy Sensor", "Does stuff", 10, 0, "C", 5, dataSet);

            sensor.AddState(new SensorState(sensor, DateTime.Now));
            sensor.CurrentState.Values.Add(new DateTime(1990, 5, 1, 4, 0, 0), 15);
            sensor.CurrentState.Values.Add(new DateTime(1990, 5, 1, 5, 0, 0), 15);
            sensor.CurrentState.Values.Add(new DateTime(1991, 8, 2, 0, 0, 0), 15);

            dataSet.AddSensor(sensor);

            dataSet.DataInterval = 60;

            dataSet.HighestYearLoaded = 1;

            Assert.AreEqual(60, dataSet.DataInterval);

            var missingValues = missingValuesDetector.GetDetectedValues(sensor);

            for (var i = new DateTime(1990, 5, 1, 6, 0, 0); i < new DateTime(1991, 8, 2, 0, 0, 0); i = i.AddHours(1))
            {
                Assert.Contains(new ErroneousValue(i, missingValuesDetector, sensor), missingValues);
            }
        }
Esempio n. 3
0
        public void GetSetNextIDValid()
        {
            var A = new Contact("Steve", "Hamilton", "*****@*****.**", "Steve Limited", "(07)7533 2343");
            Contact.NextID = 1;

            Assert.AreEqual(Contact.NextID, 1);
            Assert.AreEqual(Contact.NextID, 2);

            Contact.NextID = 10;
            Assert.AreEqual(Contact.NextID, 10);
            Assert.AreEqual(Contact.NextID, 11);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new Site.
        /// </summary>
        /// <param name="iD">The unique ID field of the Site</param>
        /// <param name="name">The name of this site</param>
        /// <param name="owner">The name of the owner of the Site</param>
        /// <param name="primaryContact">The details of the primary contact</param>
        /// <param name="secondaryContact">The details of the secondary contact</param>
        /// <param name="gpsLocation">The GPS coordinates of the Site</param>
        public Site(int iD, string name, string owner, Contact primaryContact, Contact secondaryContact, GPSCoords gpsLocation)
        {
            if (iD < 0)
                throw new ArgumentException("ID number must a non-negative integer");
            if (String.IsNullOrEmpty(name))
                throw new ArgumentException("Site must not be empty");
            /*if(String.IsNullOrEmpty(owner))
                throw new ArgumentException("Owner must not be empty");
            if(primaryContact == null)
                throw new ArgumentException("Primary contact must not be null");
            if(gpsLocation == null)
                throw new ArgumentException("GPS Location must be supplied");*/

            _iD = iD;
            _name = name;
            _owner = owner;
            _primaryContact = primaryContact;
            _secondaryContact = secondaryContact;
            _gpsLocation = gpsLocation;
            Events = new List<Event>();
        }
Esempio n. 5
0
 public void InvalidEmailAddressNoDomain()
 {
     _contact = new Contact("Steve", "Hamilton", "noavalidemail", "Steve Limited", "(07)7533 2343");
 }
Esempio n. 6
0
 public void SetUp()
 {
     _contact = new Contact("Steve", "Hamilton", "*****@*****.**", "Steve Limited", "(07)7533 2343");
     _anotherContact = new Contact("Mike", "Rodgers", "*****@*****.**", "Rodgers Emporium", "(07)7553 2343");
 }
Esempio n. 7
0
 public void NullLastName()
 {
     _contact = new Contact("Steve", null, null, null, null);
 }
Esempio n. 8
0
        private void DeleteContact(Contact c)
        {
            if (!Common.Confirm("Confirm Delete", "Are you sure you want to delete this contact?")) return;

            if (c == null) return;
            var allContacts = AllContacts;
            allContacts.Remove(c);

            AllContacts = allContacts;

            Contact.ExportAll(AllContacts);

            Common.ShowMessageBox("Success", "Contact successfully removed.", false, false);
        }
 public void SetUp()
 {
     _sensor1 = new Sensor("Temperature", "C");
     _temperatureSensor = new Sensor("Temperature", "C");
     _temperatureSensor.ErrorThreshold = 4;
     _contact = new Contact("Bob", "Smith", "*****@*****.**", "Bob's Bakery", "1232222");
     _site = new Site(50, "Lake Rotorua", "Bob Smith", _contact, _contact, new GPSCoords(50, 50, "argis"));
     _dataset =
         new Dataset(_site, new List<Sensor> { { _sensor1 } });
 }
Esempio n. 10
0
 public void InvalidEmailAddressNoDomainWithAtSymbolTopDomainIsNothing()
 {
     _contact = new Contact("Steve", "Hamilton", "noavalidemail@foo.", "Steve Limited", "(07)7533 2343");
 }
Esempio n. 11
0
        public void btnSave()
        {
            if(Contact == null)
            {
                // New contact!
                try
                {
                    Contact c = new Contact(ContactTitle, ContactFirstName, ContactLastName, ContactEmail, ContactBusiness, ContactPhone);

                    AllContacts.Add(c);

                    EventLogger.LogInfo(null, GetType().ToString(), "New contact created. Contact name: "+ c.FirstName + " " + c.LastName);
                    Contact.ExportAll(AllContacts);

                    this.TryClose();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EventLogger.LogWarning(null, GetType().ToString(), "Attempted to create new contact, but failed. Details: " + e.Message);
                }
            }
            else
            {
                // Update the contact
                try
                {

                    AllContacts.Remove(Contact);

                    Contact.Title = ContactTitle;
                    Contact.FirstName = ContactFirstName;
                    Contact.LastName = ContactLastName;
                    Contact.Email = ContactEmail;
                    Contact.Business = ContactBusiness;
                    Contact.Phone = ContactPhone;

                    AllContacts.Add(Contact);
                    EventLogger.LogInfo(null, GetType().ToString(), "Contact saved. Contact name: " + Contact.FirstName + " " + Contact.FirstName);

                    // Updating the object itself, so just re-serialise
                    Contact.ExportAll(AllContacts);

                    MessageBox.Show("Contact successfully " + (_contact == null ? "created." : "updated."), Title,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.TryClose();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EventLogger.LogWarning(null, GetType().ToString(), "Attempted to save existing contact, but failed. Details: " + e.Message);
                }
            }
        }
Esempio n. 12
0
        public void SetUp()
        {
            _pc = new Contact("Kerry", "Arts", "*****@*****.**", "Waikato Uni", "0800 stuff");
            _sc = new Contact("Steven", "McTainsh", "*****@*****.**", "CMS", "0800 WAIKATO");
            _gps = new GPSCoords(37.5135426m, 6.21684m,"jayqon");
            _testSite = new Site(1, "Lake Rotorua", "Chris McBride", _pc, _sc, _gps);

            A = new Site(6, "A Site", "David Hamilton",
                             new Contact("David", "Hamilton", "*****@*****.**", "UoW", "1234567"),
                             new Contact("Stan", "Smith", "*****@*****.**", "CIA", "1212127"),
                             new GPSCoords(49, -2,"jayqon"));
            B = new Site(6, "A Site", "David Hamilton",
                             new Contact("David", "Hamilton", "*****@*****.**", "UoW", "1234567"),
                             new Contact("Stan", "Smith", "*****@*****.**", "CIA", "1212127"),
                             new GPSCoords(49, -2,"jayqon"));
        }
Esempio n. 13
0
 public void SecondayContactGetSetTest()
 {
     Assert.AreEqual(_sc, _testSite.SecondaryContact);
     _sc = new Contact("Michael", "Baumberger", "*****@*****.**", "Waikato Aero Club", "1235678");
     _testSite.SecondaryContact = _sc;
     Assert.AreEqual(_sc, _testSite.SecondaryContact);
 }
Esempio n. 14
0
 public void PrimaryContactGetSetTest()
 {
     Assert.AreEqual(_pc, _testSite.PrimaryContact);
     _pc = new Contact("Luke", "Barnett", "*****@*****.**", "Stuff", "02712345");
     _testSite.PrimaryContact = _pc;
     Assert.AreEqual(_pc, _testSite.PrimaryContact);
 }
Esempio n. 15
0
        private void EditContact(Contact c)
        {
            var editor =
                _container.GetInstance(typeof(ContactEditorViewModel), "ContactEditorViewModel") as
                ContactEditorViewModel;

            if (editor == null) return;

            editor.Contact = c;
            editor.AllContacts = AllContacts;

            _windowManager.ShowDialog(editor);
        }
Esempio n. 16
0
 public void InvalidEmailAddressNoDomainWithAtSymbolDomainJustADot()
 {
     _contact = new Contact("Steve", "Hamilton", "noavalidemail@.", "Steve Limited", "(07)7533 2343");
 }
Esempio n. 17
0
        public Dataset readMeta(Dataset input, string filename)
        {
            string siteOwner, siteName, siteCountry, siteGPSLat, siteGPSLong, siteGPSGrid, siteElevation, siteContactName, siteContactNumber, siteContactEmail, siteContactOrginisation;
            try
            {

                int iss;
                string numSensors, loopStr;
                StreamReader reader = new StreamReader(filename);
                reader.ReadLine(); // Throwing away asscoiated file
                siteName = CleanMetaIn(reader.ReadLine(), 11);
                siteOwner = CleanMetaIn(reader.ReadLine(), 7);
                siteGPSLat = CleanMetaIn(reader.ReadLine(), 19);
                siteGPSLong = CleanMetaIn(reader.ReadLine(), 19);
                siteGPSGrid = CleanMetaIn(reader.ReadLine(), 17);
                siteElevation = CleanMetaIn(reader.ReadLine(), 18);
                siteCountry = CleanMetaIn(reader.ReadLine(), 9);
                reader.ReadLine(); // Throwing away contact header

                siteContactName = CleanMetaIn(reader.ReadLine(), 6);
                siteContactOrginisation = CleanMetaIn(reader.ReadLine(), 14);
                siteContactNumber = CleanMetaIn(reader.ReadLine(), 7);
                siteContactEmail = CleanMetaIn(reader.ReadLine(), 7);
                numSensors = reader.ReadLine();

                if (String.IsNullOrWhiteSpace(siteContactName))
                {
                    siteContactName = ". .";
                }
                if (String.IsNullOrWhiteSpace(siteContactNumber))
                {
                    siteContactNumber = " ";
                }
                if (String.IsNullOrWhiteSpace(siteContactEmail))
                {
                    siteContactEmail = " ";
                }
                if (String.IsNullOrWhiteSpace(siteContactOrginisation))
                {
                    siteContactOrginisation = " ";
                }
                iss = Int32.Parse(CleanMetaIn(numSensors, 19));
                if (iss == input.Sensors.Count) // check to see if the number of sensors matches whats in the meta file
                {

                    string header = reader.ReadLine();
                    string[] arr4 = new string[iss + 1];
                    for (int i = 0; i < iss; i++)
                    {
                        header = reader.ReadLine();

                        int ndx = input.Sensors.FindIndex(delegate(Sensor toFind)
                        {
                            return toFind.Name == header;
                        }
                        );
                        loopStr = reader.ReadLine();
                        if (ndx >= 0)
                        {
                            do // Works out what meta data is attached to each sensor
                                //and adds it into the correct place
                            {

                                if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Desc")
                                {
                                    input.Sensors[ndx].Description = CleanMetaIn(loopStr, 13);
                                    loopStr = reader.ReadLine();
                                }
                                if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Seri")
                                {
                                    input.Sensors[ndx].CurrentMetaData.SerialNumber = CleanMetaIn(loopStr, 15);
                                    loopStr = reader.ReadLine();
                                }
                                if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Manu")
                                {
                                    input.Sensors[ndx].CurrentMetaData.Manufacturer = CleanMetaIn(loopStr, 14);
                                    loopStr = reader.ReadLine();
                                }
                                if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Date")
                                {
                                    input.Sensors[ndx].CurrentMetaData.DateOfInstallation = DateTime.Parse(CleanMetaIn(loopStr, 16));
                                    loopStr = reader.ReadLine();
                                }
                                if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Cali")
                                {
                                    if (loopStr.Substring(10, 2) == "n ")
                                    {

                                        input.Sensors[ndx].CurrentMetaData.IdealCalibrationFrequency = TimeSpan.FromDays(Double.Parse(CleanMetaIn(loopStr, 29)));
                                        loopStr = reader.ReadLine();
                                    }
                                    if (!string.IsNullOrEmpty(loopStr) && loopStr.Substring(0, 4) == "Cali" && loopStr.Substring(10, 2) == "n:")
                                    {
                                        var calibStr = CleanMetaIn(loopStr, 12);
                                        DateTime calibTime = new DateTime(int.Parse(calibStr.Substring(0, 4)), int.Parse(calibStr.Substring(5, 2)), int.Parse(calibStr.Substring(8, 2)));
                                        string[] first = calibStr.Substring(16).Split(' ');
                                        string[] preNum = first[0].Split('-');
                                        string[] postNum = first[2].Split('-');
                                        postNum[1].Remove(0, 6);
                                        input.Sensors[ndx].Calibrations.Add(new Calibration(calibTime, float.Parse(preNum[0].TrimStart('[')), float.Parse(preNum[1]), float.Parse(preNum[2].TrimEnd(']')), float.Parse(postNum[0].TrimStart('[')), float.Parse(postNum[1]), float.Parse(postNum[2].TrimEnd(']'))));
                                        loopStr = reader.ReadLine();
                                    }
                                }

                            } while (!string.IsNullOrEmpty(loopStr));
                        }
                    }

                }

                else
                {
                    Microsoft.Windows.Controls.MessageBox.Show("Could not load sensor data as meta file did not match actual number of sensors");
                    //Skip through the sensors until the notes
                    do
                    {
                        reader.ReadLine();
                    }
                    while (reader.Peek() != 'D');

                }

                string checkNext = reader.ReadLine();
                if (checkNext.Equals("Dataset Notes")) // Reasd
                {
                    if (input.Site.DataEditingNotes == null)
                        input.Site.DataEditingNotes = new Dictionary<DateTime, string>();
                    loopStr = reader.ReadLine();
                    while (!string.IsNullOrEmpty(loopStr))
                    {
                        input.Site.DataEditingNotes.Add(DateTime.Now, loopStr);
                        loopStr = reader.ReadLine();

                    }
                }

                checkNext = reader.ReadLine();
                if (checkNext.Equals("Site Notes")) // Rerads and add the site notes
                {
                    if (input.Site.SiteNotes == null)
                        input.Site.SiteNotes = " ";
                    loopStr = reader.ReadLine();
                    while (!string.IsNullOrEmpty(loopStr))
                    {
                        input.Site.SiteNotes = input.Site.SiteNotes + loopStr;
                        loopStr = reader.ReadLine();

                    }

                }

                var oldFile = input.SaveLocation;
                File.Delete(oldFile);
                var names = siteContactName.Split(' ');

                Contact siteContact = new Contact(names[0], names[1], siteContactEmail, siteContactOrginisation, siteContactNumber, 12);
                OwnerHelper.Add(siteOwner);
                ObservableCollection<Contact> contactList = Contact.ImportAll();
                if (!contactList.Contains(siteContact))
                {
                    contactList.Add(siteContact);
                    Contact.ExportAll(contactList);
                }
                input.Site.PrimaryContact = siteContact;
                input.Site.GpsLocation = new GPSCoords(decimal.Parse(siteGPSLat), decimal.Parse(siteGPSLong), siteGPSGrid);
                input.Site.Name = siteName;
                input.Site.Elevation = float.Parse(siteElevation);
                input.Site.Owner = siteOwner;
                input.Site.CountryName = siteCountry;

            }
            catch (Exception excep)
            {
                System.Windows.MessageBox.Show("There was an error importing the meta file, please make sure that it is correctly formated and all parts are filled in" );
            }
            return input;
        }
Esempio n. 18
0
 public void NullEmail()
 {
     _contact = new Contact("Steve", "Hamilton", null, null, null);
 }
Esempio n. 19
0
 public void Setup()
 {
     Contact.NextID = 1;
     _contactOne = new Contact("Kerry", "Arts", "*****@*****.**", "Lalala", "123456789");
     _contactTwo = new Contact("Leroy", "Jenkins", "*****@*****.**", "AwesomeCompany", "022 314 1337");
 }
Esempio n. 20
0
 public void NullFirstName()
 {
     _contact = new Contact(null,"Hamilton", null, null, null);
 }