/// <summary>
        /// Writes the data for this export to the file specified.
        /// </summary>
        /// <param name="filename">The file to write to.</param>
        /// <param name="geographyProvider">The geography data provider.</param>
        /// <param name="booksReadProvider">The books data provider.</param>
        /// <param name="errorMessage">The error message if unsuccessful.</param>
        /// <returns>True if written successfully, false otherwise.</returns>
        public bool WriteToFile(
            string filename,
            IGeographyProvider geographyProvider,
            IBooksReadProvider booksReadProvider,
            out string errorMessage)
        {
            errorMessage        = string.Empty;
            _selectedMonthTally = booksReadProvider.SelectedMonthTally;
            _reportsTallies     = booksReadProvider.ReportsTallies;

            try
            {
                // Set up the file content.
                string title;
                string content;
                GetMonthlyReportTitleAndContent(out title, out content);

                // Write out the content
                TextWriter textWriter = new StreamWriter(filename, false, Encoding.Default); //overwrite original file
                textWriter.Write(content);

                // Tidy up
                textWriter.Close();
            }
            catch (Exception e)
            {
                errorMessage = e.ToString();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the data for this export to the file specified.
        /// </summary>
        /// <param name="filename">The file to write to.</param>
        /// <param name="geographyProvider">The geography data provider.</param>
        /// <param name="booksReadProvider">The books data provider.</param>
        /// <param name="errorMessage">The error message if unsuccessful.</param>
        /// <returns>True if written successfully, false otherwise.</returns>
        public bool WriteToFile(
            string filename,
            IGeographyProvider geographyProvider,
            IBooksReadProvider booksReadProvider,
            out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                // Set up the nations file.
                NationsFile nationsFile = new NationsFile();
                foreach (Nation nation in geographyProvider.Nations.OrderBy(x => x.Name))
                {
                    nationsFile.Nations.Add(nation);
                }

                // Serialize the XML
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(NationsFile));
                TextWriter    textWriter    = new StreamWriter(filename, false, Encoding.Default); //overwrite original file
                xmlSerializer.Serialize(textWriter, nationsFile);

                // Tidy up
                textWriter.Close();
            }
            catch (Exception e)
            {
                errorMessage = e.ToString();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the data for this export to the file specified.
        /// </summary>
        /// <param name="filename">The file to write to.</param>
        /// <param name="geographyProvider">The geography data provider.</param>
        /// <param name="booksReadProvider">The books data provider.</param>
        /// <param name="errorMessage">The error message if unsuccessful.</param>
        /// <returns>True if written successfully, false otherwise.</returns>
        public bool WriteToFile(
            string filename,
            IGeographyProvider geographyProvider,
            IBooksReadProvider booksReadProvider,
            out string errorMessage)
        {
            errorMessage = string.Empty;

            try
            {
                StreamWriter sw = new StreamWriter(filename, false, Encoding.Default); //overwrite original file

                // write the header
                sw.WriteLine(
                    "Date,DD/MM/YYYY,Author,Title,Pages,Note,Nationality,Original Language,Book,Comic,Audio,Image,Tags"
                    );

                // write the records
                CsvWriter csv = new CsvWriter(sw);
                foreach (BookRead book in booksReadProvider.BooksRead)
                {
                    csv.WriteField(book.DateString);
                    csv.WriteField(book.Date.ToString("d/M/yyyy"));
                    csv.WriteField(book.Author);
                    csv.WriteField(book.Title);
                    csv.WriteField(book.Pages > 0 ? book.Pages.ToString() : "");
                    csv.WriteField(book.Note);
                    csv.WriteField(book.Nationality);
                    csv.WriteField(book.OriginalLanguage);
                    csv.WriteField(book.Format == BookFormat.Book ? "x" : "");
                    csv.WriteField(book.Format == BookFormat.Comic ? "x" : "");
                    csv.WriteField(book.Format == BookFormat.Audio ? "x" : "");
                    csv.WriteField(book.ImageUrl);
                    csv.WriteField(book.DisplayTags);
                    csv.NextRecord();
                }

                // tidy up
                sw.Close();
            }
            catch (Exception e)
            {
                errorMessage = e.ToString();
                return(false);
            }

            return(true);
        }
        public static Dictionary <int, List <MonthOfYearTally> > GetBookListsByMonthOfYear(IBooksReadProvider booksReadProvider)
        {
            // get the books foreach year
            Dictionary <int, List <BookRead> > bookListsByYear = new Dictionary <int, List <BookRead> >();

            foreach (BookRead book in booksReadProvider.BooksRead)
            {
                int bookReadYear = book.Date.Year;
                if (bookListsByYear.ContainsKey(bookReadYear))
                {
                    bookListsByYear[bookReadYear].Add(book);
                }
                else
                {
                    bookListsByYear.Add(bookReadYear, new List <BookRead> {
                        book
                    });
                }
            }

            // for each year get the lists of books read each day
            Dictionary <int, Dictionary <int, List <BookRead> > > bookTotalsByMonthAndYear = new Dictionary <int, Dictionary <int, List <BookRead> > >();

            foreach (int year in bookListsByYear.Keys)
            {
                Dictionary <int, List <BookRead> > booksByMonthOfYear = new Dictionary <int, List <BookRead> >();
                foreach (BookRead book in bookListsByYear[year])
                {
                    int bookReadMonthOfYear = book.Date.Month;
                    if (booksByMonthOfYear.ContainsKey(bookReadMonthOfYear))
                    {
                        booksByMonthOfYear[bookReadMonthOfYear].Add(book);
                    }
                    else
                    {
                        booksByMonthOfYear.Add(bookReadMonthOfYear, new List <BookRead> {
                            book
                        });
                    }
                }

                bookTotalsByMonthAndYear.Add(year, booksByMonthOfYear);
            }

            // from these get the daily tallies for each year
            Dictionary <int, List <MonthOfYearTally> > bookListsByMonthAndYear = new Dictionary <int, List <MonthOfYearTally> >();

            foreach (int year in bookTotalsByMonthAndYear.Keys)
            {
                Dictionary <int, List <BookRead> > booksByMonthOfYear = bookTotalsByMonthAndYear[year];
                List <MonthOfYearTally>            monthOfYearTallies = new List <MonthOfYearTally>();

                foreach (int monthOfYear in booksByMonthOfYear.Keys.ToList().OrderBy(x => x))
                {
                    List <BookRead>  booksforMonth = booksByMonthOfYear[monthOfYear];
                    MonthOfYearTally tally         = new MonthOfYearTally
                    {
                        MonthOfYear        = monthOfYear,
                        BooksReadThisMonth = booksforMonth.Count,
                        PagesReadThisMonth = booksforMonth.Sum(x => x.Pages)
                    };

                    monthOfYearTallies.Add(tally);
                }

                bookListsByMonthAndYear.Add(year, monthOfYearTallies);
            }

            return(bookListsByMonthAndYear);
        }
        public static List <KeyValuePair <string, int> > SortedSortedBooksReadByCountryTotals(IBooksReadProvider booksReadProvider)
        {
            BooksDelta currentResults = booksReadProvider.BookDeltas.Last();

            List <KeyValuePair <string, int> > countryTotals = new List <KeyValuePair <string, int> >();

            // Country, ttl books, ttl books %, ttl pages, ttl pages%
            //Tuple<string, UInt32, double, UInt32, double>
            int    ttlOtherBooks      = 0;
            double ttlOtherPercentage = 0;

            foreach (Tuple <string, uint, double, uint, double> country in currentResults.OverallTally.CountryTotals)
            {
                string countryName       = country.Item1;
                int    ttlBooks          = (int)country.Item2;
                double countryPercentage = country.Item3;
                if (countryPercentage > 1.0)
                {
                    countryTotals.Add(new KeyValuePair <string, int>(countryName, ttlBooks));
                }
                else
                {
                    ttlOtherPercentage += countryPercentage;
                    ttlOtherBooks      += ttlBooks;
                }
            }

            List <KeyValuePair <string, int> > sortedCountryTotals = countryTotals.OrderByDescending(x => x.Value).ToList();

            if (ttlOtherPercentage > 1.0)
            {
                sortedCountryTotals.Add(new KeyValuePair <string, int>("Other", ttlOtherBooks));
            }
            return(sortedCountryTotals);
        }
Ejemplo n.º 6
0
 public BaseDiagramViewModel(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     GeographyProvider = geographyProvider;
     BooksReadProvider = booksReadProvider;
 }
 public PagesByCountryDiagramViewModel(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
     : base(geographyProvider, booksReadProvider)
 {
 }
 /// <summary>
 /// Sets up the providers then gets plot model to be displayed.
 /// </summary>
 /// <param name="geographyProvider">The geography data source.</param>
 /// <param name="booksReadProvider">The books data source.</param>
 /// <returns>The user view item model.</returns>
 public PlotModel SetupPlot(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     GeographyProvider = geographyProvider;
     BooksReadProvider = booksReadProvider;
     return(SetupPlot());
 }
 public BooksReadByCountryViewModel(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
     : base(geographyProvider, booksReadProvider)
 {
 }
Ejemplo n.º 10
0
 public void UpdateData(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     GeographyProvider = geographyProvider;
     BooksReadProvider = booksReadProvider;
     Model             = _plotGenerator.SetupPlot(geographyProvider, booksReadProvider);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Sets up the providers then gets plot model to be displayed.
 /// </summary>
 /// <param name="geographyProvider">The geography data source.</param>
 /// <param name="booksReadProvider">The books data source.</param>
 /// <returns>The user view item model.</returns>
 public void SetupPlot(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     GeographyProvider = geographyProvider;
     BooksReadProvider = booksReadProvider;
     SetupSeries();
 }
 /// <summary>
 /// Sets up the providers then gets editor to be displayed.
 /// </summary>
 /// <param name="geographyProvider">The geography data source.</param>
 /// <param name="booksReadProvider">The books data source.</param>
 public void SetupEditor(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     GeographyProvider = geographyProvider;
     BooksReadProvider = booksReadProvider;
     SetupEditor();
 }
Ejemplo n.º 13
0
 public void Update(IGeographyProvider geographyProvider, IBooksReadProvider booksReadProvider)
 {
     _plotPairViewModel.UpdateData(geographyProvider, booksReadProvider);
     OnPropertyChanged(() => ViewController);
     OnPropertyChanged(() => Model);
 }