Esempio n. 1
0
        /// <summary>
        /// Save the beastie file.
        /// </summary>
        /// <param name="beastieFile">serialisable object to save</param>
        public void Save(Beastie beastieFile)
        {
            if (string.IsNullOrWhiteSpace(beastieFile.Name))
            {
                this.logger.WriteLine(
                    $"Error saving beastie file, filename is null or empty");
                return;
            }

            string path = $"{DataPath.BeastieDataPath}";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                XmlFileIo.WriteXml(
                    beastieFile,
                    $"{path}\\{beastieFile.Name}.xml");
            }
            catch (Exception ex)
            {
                this.logger.WriteLine(
                    $"Error saving {beastieFile.Name}: {ex}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load a model to edit.
        /// </summary>
        /// <param name="path">path of the file to load</param>
        public void Load(string path)
        {
            this.Observations.Reset();

            try
            {
                string filename = Path.GetFileName(path);
                string year     = Path.GetFileName(Path.GetDirectoryName(path));

                RawObservations observations =
                    XmlFileIo.ReadXml <RawObservations>(
                        path);

                this.Observations.LoadObservations(
                    observations,
                    filename,
                    year);
            }
            catch (Exception ex)
            {
                string           errorDescription = $"Error loading {this.Observations.Filename}";
                AppStatusMessage message          =
                    new AppStatusMessage(
                        errorDescription);
                Messenger.Default.Send(message);

                this.logger.WriteLine(
                    $"Event Entry Save : {errorDescription}: {ex}");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deserialise the <see cref="ClassDetails"/> from the <paramref name="filename"/>.
        /// </summary>
        /// <param name="filename">name of the file to read</param>
        /// <returns>deserialised file</returns>
        public ClassDetails Read(string filename)
        {
            string       myPath  = BasePathReader.GetBasePath() + StaticResources.classDetailsPath + filename + XmlExtensionLabel;
            ClassDetails results =
                XmlFileIo.ReadXml <ClassDetails>(
                    myPath);

            return(results);
        }
Esempio n. 4
0
        /// <summary>
        /// Serialise the <see cref="ClassDetails"/> to <parmref name="filename"/>.
        /// </summary>
        /// <param name="file">file to serialise</param>
        /// <param name="filename">location to save the file to</param>
        public void Write(
            ClassDetails file,
            string filename)
        {
            string myPath = BasePathReader.GetBasePath() + StaticResources.classDetailsPath + filename + XmlExtensionLabel;

            XmlFileIo.WriteXml <ClassDetails>(
                file,
                myPath);
        }
Esempio n. 5
0
        /// <summary>
        /// Save the points table
        /// </summary>
        /// <param name="seasonName">season name</param>
        /// <param name="eventName">event name</param>
        /// <param name="resultsTable">points table</param>
        public bool SaveResultsTable(
            string seasonName,
            string eventName,
            List <IResultsTableEntry> resultsTable)
        {
            bool success = true;

            try
            {
                ResultsTableRoot rootElement = new ResultsTableRoot();

                XDocument writer = new XDocument(
                    new XDeclaration("1.0", "uft-8", "yes"),
                    new XComment("Results Table XML"));

                foreach (ResultsTableEntry entry in resultsTable)
                {
                    Row entryElement =
                        new Row(
                            entry.Key,
                            entry.Name,
                            entry.Club,
                            entry.Handicap.ToString(),
                            entry.Notes,
                            entry.ExtraInfo,
                            entry.Order,
                            entry.PB,
                            entry.SB,
                            entry.Points.ToString(),
                            entry.HarmonyPoints,
                            entry.RaceNumber,
                            entry.RunningOrder,
                            entry.Time.ToString(),
                            entry.Sex);

                    rootElement.Add(entryElement);
                }

                string fileName =
                    ResultsTableReader.GetPath(
                        seasonName,
                        eventName);
                XmlFileIo.WriteXml <ResultsTableRoot>(
                    rootElement,
                    fileName);
            }

            catch (XmlException ex)
            {
                this.logger.WriteLog($"Error writing results table file: {ex.XmlMessage}");
                success = false;
            }

            return(success);
        }
Esempio n. 6
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ConsistencyViewModel"/> class.
        /// </summary>
        public ConsistencyViewModel()
        {
            string basePath = DataPath.RawDataPath;

            this.LocationCollection  = new ComponentCounterCollectionViewModel("Locations");
            this.LengthCollection    = new ComponentCounterCollectionViewModel("Length");
            this.IntensityCollection = new ComponentCounterCollectionViewModel("Intensity");
            this.TimeOfDayCollection = new ComponentCounterCollectionViewModel("TimeOfDay");
            this.WeatherCollection   = new ComponentCounterCollectionViewModel("Weather");
            this.HabitatCollection   = new ComponentCounterCollectionViewModel("Habitat");
            this.KindCollection      = new ComponentCounterCollectionViewModel("Kind");

            string[] subdirectoryEntries = Directory.GetDirectories(basePath);

            try
            {
                foreach (string directory in subdirectoryEntries)
                {
                    string[] files = Directory.GetFiles(directory);

                    foreach (string file in files)
                    {
                        RawObservationsString cars = XmlFileIo.ReadXml <RawObservationsString>(file);

                        this.LocationCollection.AddOne(cars.Location);
                        this.LengthCollection.AddOne(cars.Length);
                        this.IntensityCollection.AddOne(cars.Intensity);
                        this.TimeOfDayCollection.AddOne(cars.TimeOfDay);
                        this.WeatherCollection.AddOne(cars.Weather);

                        foreach (string habitat in cars.Habitats.Habitat)
                        {
                            this.HabitatCollection.AddOne(habitat);
                        }

                        foreach (string kind in cars.Species.Kind)
                        {
                            this.KindCollection.AddOne(kind);
                        }

                        foreach (string kind in cars.Heard.Kind)
                        {
                            this.KindCollection.AddOne(kind);
                        }
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Save the current model.
        /// </summary>
        /// <returns>success flag</returns>
        public bool Save()
        {
            if (string.IsNullOrWhiteSpace(this.Observations.GetLocation()))
            {
                string faultString = "Can't save, no location provided.";

                logger.WriteLine($"Event Entry Save: {faultString}");

                AppStatusMessage message =
                    new AppStatusMessage(
                        faultString);
                Messenger.Default.Send(message);

                return(false);
            }

            string path = $"{DataPath.RawDataPath}\\{this.Observations.Year}";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                XmlFileIo.WriteXml(
                    this.Observations.GetObservations(),
                    $"{path}\\{this.Observations.Filename}");
            }
            catch (Exception ex)
            {
                string           errorDescription = $"Error saving {this.Observations.Filename}";
                AppStatusMessage message          =
                    new AppStatusMessage(
                        errorDescription);
                Messenger.Default.Send(message);

                this.logger.WriteLine(
                    $"Event Entry Save : {errorDescription}: {ex}");
            }

            this.Observations.Reset();

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Select a new page for the view.
        /// </summary>
        /// <param name="newPageName">
        /// Name of the page to display.
        /// </param>
        private void NewPage(string newPageName)
        {
            this.SetMonth(newPageName);

            List <string> eventPaths = this.FindEventPaths();

            this.Events.Clear();

            foreach (string eventPath in eventPaths)
            {
                try
                {
                    RawObservations observations =
                        XmlFileIo.ReadXml <RawObservations>(
                            eventPath);

                    ICalendarItem calendarItem =
                        new CalendarItem(
                            observations.Date.Substring(0, 2),
                            observations.Location,
                            observations.Intensity,
                            eventPath,
                            this.openEventCommand);

                    this.Events.Add(calendarItem);
                }
                catch (Exception ex)
                {
                    string           errorDescription = $"Error loading {eventPath}";
                    AppStatusMessage message          =
                        new AppStatusMessage(
                            errorDescription);
                    Messenger.Default.Send(message);

                    this.logger.WriteLine(
                        $"Calendar view model : {errorDescription}: {ex}");
                }
            }

            this.RaisePropertyChangedEvent(nameof(this.Events));
        }
Esempio n. 9
0
        /// <summary>
        /// Load a file and store it in the Data Manager
        /// </summary>
        /// <param name="path">path of the file to load</param>
        private void LoadFile(string path)
        {
            try
            {
                Beastie beastie =
                    XmlFileIo.ReadXml <Beastie>(
                        path);

                this.dataManager.AddBeastie(beastie);
            }
            catch (Exception ex)
            {
                AppStatusMessage message =
                    new AppStatusMessage(
                        $"Error loading {path}");
                Messenger.Default.Send(message);

                this.logger.WriteLine(
                    $"Error loading {path}: {ex}");
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Initialises a new instance of the <see cref="EventEntry"/> class.
        /// </summary>
        /// <param name="dataFileFactory">Data file factory</param>
        /// <param name="logger">the logger</param>
        public EventEntry(
            IBeastieDataFileFactory dataFileFactory,
            IAsLogger logger)
        {
            this.Observations = new ObservationManager();
            this.logger       = logger;
            this.rawPageData  =
                XmlFileIo.ReadXml <BeastiePages>(
                    $"{DataPath.BasePath}\\TestDataEntry.xml");

            // Ensure that all data files exist.
            List <string> beastieNames = new List <string>();

            foreach (Page page in this.rawPageData.Pages)
            {
                beastieNames.AddRange(page.Beasties);
            }

            dataFileFactory.CheckFiles(
                beastieNames);
        }
Esempio n. 11
0
        /// <summary>
        /// Reads the athlete season details xml from file and decodes it.
        /// </summary>
        /// <param name="seasonName">season name</param>
        /// <param name="eventName">event name</param>
        /// <param name="date">event date</param>
        /// <returns>decoded athlete's details</returns>
        public IEventResults LoadResultsTable(
            string seasonName,
            string eventName,
            DateType date)
        {
            IEventResults    resultsTable = new EventResults();
            ResultsTableRoot deserialisedResultTable;
            string           resultsPath =
                ResultsTableReader.GetPath(
                    seasonName,
                    eventName);

            try
            {
                deserialisedResultTable =
                    XmlFileIo.ReadXml <ResultsTableRoot>(
                        resultsPath);
            }
            catch (XmlException ex)
            {
                this.logger.WriteLog(
                    $"Error reading the results table; {ex.XmlMessage}");

                return(resultsTable);
            }

            foreach (Row row in deserialisedResultTable)
            {
                RaceTimeType time =
                    new RaceTimeType(
                        row.Time);
                RaceTimeType handicap =
                    new RaceTimeType(
                        row.Handicap);
                CommonPoints points =
                    new CommonPoints(
                        row.Points,
                        date);
                int position = resultsTable.Entries.Count + 1;

                ResultsTableEntry rowEntry =
                    new ResultsTableEntry(
                        row.Key,
                        row.Name,
                        time,
                        row.Order,
                        row.RunningOrder,
                        handicap,
                        row.Club,
                        row.Sex,
                        row.Number,
                        points,
                        row.HarmonyPoints,
                        row.IsPersonalBest,
                        row.IsYearBest,
                        row.Notes,
                        row.ExtraInformation,
                        position);
                resultsTable.AddEntry(rowEntry);
            }

            return(resultsTable);
        }
Esempio n. 12
0
        /// <summary>
        /// Open the event specified by the path.
        /// </summary>
        /// <param name="path">
        /// The path to the raw data for the event to be opened.
        /// </param>
        public void OpenEvent(string path)
        {
            RawObservations observations =
                XmlFileIo.ReadXml <RawObservations>(
                    path);

            if (observations == null)
            {
                return;
            }

            this.Location  = observations.Location;
            this.Date      = observations.Date;
            this.Notes     = observations.Notes;
            this.Length    = observations.Length.ToString();
            this.Intensity = observations.Intensity;
            this.TimeOfDay = observations.TimeOfDay.ToString();
            this.Weather   = observations.Weather.ToString();

            this.Habitats.Clear();

            foreach (ObservationHabitat habitat in observations.Habitats.Habitats)
            {
                this.Habitats.Add(habitat.ToString());
            }

            this.Beasties.Clear();

            foreach (string beastie in observations.Species.Kind)
            {
                Beastie modelBeastie = this.getBeastie(beastie);

                IBeastieReportIconViewModel beastieIcon =
                    new BeastieReportIconViewModel(
                        modelBeastie.DisplayName,
                        modelBeastie?.LatinName ?? string.Empty,
                        modelBeastie?.Image ?? string.Empty,
                        modelBeastie?.Presence ?? (Presence)(-1));

                this.Beasties.Add(beastieIcon);
            }

            foreach (string beastie in observations.Heard.Kind)
            {
                Beastie modelBeastie = this.getBeastie(beastie);

                IBeastieReportIconViewModel beastieIcon =
                    new BeastieReportIconViewModel(
                        modelBeastie.DisplayName,
                        modelBeastie?.LatinName ?? string.Empty,
                        modelBeastie?.Image ?? string.Empty,
                        modelBeastie?.Presence ?? (Presence)(-1));

                this.Beasties.Add(beastieIcon);
            }

            this.RaisePropertyChangedEvent(nameof(this.Location));
            this.RaisePropertyChangedEvent(nameof(this.Date));
            this.RaisePropertyChangedEvent(nameof(this.Notes));
            this.RaisePropertyChangedEvent(nameof(this.Length));
            this.RaisePropertyChangedEvent(nameof(this.Intensity));
            this.RaisePropertyChangedEvent(nameof(this.TimeOfDay));
            this.RaisePropertyChangedEvent(nameof(this.Weather));
            this.RaisePropertyChangedEvent(nameof(this.Habitats));
            this.RaisePropertyChangedEvent(nameof(this.Beasties));
        }