Exemple #1
0
 private void RemoveParsedTitles(List <Uri> linksToTitles)
 {
     var parsedUrls       = Titles.Select(t => t.Url);
     var unicAndNotParsed = linksToTitles
                            .Where(link => !parsedUrls.Contains(link))
                            .Distinct()
                            .ToList();
 }
 private WikiPage[] GetPages()
 {
     if (Pages != null)
     {
         return(Pages);
     }
     if (Titles != null)
     {
         return(Titles.Select(t => new WikiPage(WikiSite, t)).ToArray());
     }
     throw new InvalidOperationException();
 }
Exemple #3
0
        public bool AddUniqueTitle(string title)
        {
            bool toAdd = !Titles.Select(x => x.Title).Any(x => string.Equals(title, x, StringComparison.OrdinalIgnoreCase));

            if (toAdd)
            {
                Titles.Add(new ShowTitle {
                    ShowId = Id, Title = title, IsPrimary = !Titles.Any()
                });
            }

            return(toAdd);
        }
Exemple #4
0
        /// <summary>
        /// Conversion from Entry to string seq seq
        /// Contrary function of LoadContentToFile()
        /// </summary>
        /// <returns></returns>
        private IEnumerable <IEnumerable <string> > SaveFileToContent()
        {
            var titles = Titles;

            if (_titleRules != null)
            {
                _titleRules(ref titles);
            }

            var content = new List <List <string> > {
                titles
            };

            foreach (var aEntry in Content)
            {
                var newEntry = aEntry;
                if (_entryRules != null)
                {
                    _entryRules(ref newEntry);
                }
                var newContentLine = new List <string>();
                foreach (var propName in Titles.Select(
                             title => (from prop in EntryType.GetProperties()
                                       from attr in prop.GetCustomAttributes(typeof(TitleName), false)
                                       where ((TitleName)attr).Name == title
                                       select prop.Name).FirstOrDefault()))
                {
                    if (propName != null)
                    {
                        var contentField = EntryType.GetProperty(propName).GetValue(newEntry, null);
                        newContentLine.Add(contentField.ToString());
                    }
                    else
                    {
                        newContentLine.Add("");
                    }
                }
                content.Add(newContentLine);
            }
            return(content);
        }
Exemple #5
0
        public static List <Models.Movie> GetDatabaseMovies(Titles results)
        {
            var netflixids = results.Select((m) => m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : ""));

            using (FilmTroveContext ftc = new FilmTroveContext())
            {
                ///1) find the matching records from the database
                var matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                ///2) find the records that don't have a match
                ///select the ids and get the netflix Ids that aren't in the FT database
                var ftnfids             = matchedmovies.Select(m => m.Netflix.Id);
                var netflixidsunmatched = netflixids.Where(m => !ftnfids.Contains(m));
                //Int32 count = 0;
                foreach (String nid in netflixidsunmatched)
                {
                    ///create FT database records for each of these with the movies basic information for now
                    FilmTrove.Models.Movie  newmovie     = ftc.Movies.Create();
                    FlixSharp.Holders.Title netflixmovie = results.Find(nid);
                    FillBasicTitle(newmovie, netflixmovie);


                    var             dbgenreslocal = ftc.Genres.Local.Where(g => netflixmovie.Genres.Contains(g.Name));
                    var             dbgenres      = ftc.Genres.Where(g => netflixmovie.Genres.Contains(g.Name));
                    HashSet <Genre> genres        = new HashSet <Genre>();
                    genres.AddRange(dbgenres);
                    genres.AddRange(dbgenreslocal);

                    var genrenames    = genres.Select(g => g.Name);
                    var missinggenres = netflixmovie.Genres.Where(g => !genrenames.Contains(g));
                    foreach (String genre in missinggenres)
                    {
                        Genre g = new Genre()
                        {
                            Name = genre
                        };
                        genres.Add(g);
                        ftc.Genres.Add(g);
                    }
                    //newmovie.Genres = netflixmovie.Genres;
                    foreach (Genre g in genres)
                    {
                        MovieGenre gi = ftc.GenreItems.Create();
                        gi.Genre = g;
                        gi.Movie = newmovie;
                        ftc.GenreItems.Add(gi);
                    }
                    ftc.Movies.Add(newmovie);
                }

                //try
                //{
                //count =
                ftc.SaveChanges();
                //}
                //catch (Exception ex)
                //{
                //    ///need to add some sort of logging?

                //}
                //if (count > 0)
                if (matchedmovies.Count() < results.Count())
                {
                    matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                }
                //else
                //    return matchedmovies.ToList();

                return(results.Select(m =>
                                      matchedmovies.First(f =>
                                                          f.Netflix.Id == (m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : "")))).ToList());
            }
        }
Exemple #6
0
        public static List<Models.Movie> GetDatabaseMovies(Titles results)
        {
            var netflixids = results.Select((m) => m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : ""));
            using (FilmTroveContext ftc = new FilmTroveContext())
            {

                ///1) find the matching records from the database
                var matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                ///2) find the records that don't have a match
                ///select the ids and get the netflix Ids that aren't in the FT database
                var ftnfids = matchedmovies.Select(m => m.Netflix.Id);
                var netflixidsunmatched = netflixids.Where(m => !ftnfids.Contains(m));
                //Int32 count = 0;
                foreach (String nid in netflixidsunmatched)
                {
                    ///create FT database records for each of these with the movies basic information for now
                    FilmTrove.Models.Movie newmovie = ftc.Movies.Create();
                    FlixSharp.Holders.Title netflixmovie = results.Find(nid);
                    FillBasicTitle(newmovie, netflixmovie);

                    var dbgenreslocal = ftc.Genres.Local.Where(g => netflixmovie.Genres.Contains(g.Name));
                    var dbgenres = ftc.Genres.Where(g => netflixmovie.Genres.Contains(g.Name));
                    HashSet<Genre> genres = new HashSet<Genre>();
                    genres.AddRange(dbgenres);
                    genres.AddRange(dbgenreslocal);

                    var genrenames = genres.Select(g => g.Name);
                    var missinggenres = netflixmovie.Genres.Where(g => !genrenames.Contains(g));
                    foreach (String genre in missinggenres)
                    {
                        Genre g = new Genre() { Name = genre };
                        genres.Add(g);
                        ftc.Genres.Add(g);
                    }
                    //newmovie.Genres = netflixmovie.Genres;
                    foreach (Genre g in genres)
                    {
                        MovieGenre gi = ftc.GenreItems.Create();
                        gi.Genre = g;
                        gi.Movie = newmovie;
                        ftc.GenreItems.Add(gi);
                    }
                    ftc.Movies.Add(newmovie);
                }

                //try
                //{
                    //count =
                ftc.SaveChanges();
                //}
                //catch (Exception ex)
                //{
                //    ///need to add some sort of logging?

                //}
                //if (count > 0)
                if (matchedmovies.Count() < results.Count())
                    matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                //else
                //    return matchedmovies.ToList();

                return results.Select(m =>
                    matchedmovies.First(f =>
                        f.Netflix.Id == (m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : "")))).ToList();
            }
        }
Exemple #7
0
        public void Export(IFileDialogService fileDialogService, string fileName, bool isDetailed, Encoding encoding = null)
        {
            if (fileDialogService is null)
            {
                throw new ArgumentNullException(nameof(fileDialogService));
            }

            var dialogSettings = new DialogSettings();

            dialogSettings.Title = "Сохранить";
            dialogSettings.DefaultFileExtention = ".csv";
            dialogSettings.FileName             = $"{fileName} {DateTime.Now:yyyy-MM-dd-HH-mm}.csv";

            var result = fileDialogService.RunSaveFileDialog(dialogSettings);

            if (!result.Successful)
            {
                return;
            }

            var writer = new StreamWriter(result.Path, false, encoding ?? Encoding.GetEncoding(1251));

            var csv = new CsvWriter(writer, CultureInfo.CurrentCulture);

            if (isDetailed)
            {
                var columnNames = Titles.Select(x => x.NomenclatureName).ToList();

                var headers = new[] { "Дата", "ТМЦ" }.Concat(columnNames).ToList();

                foreach (var header in headers)
                {
                    csv.WriteField(header);
                }

                csv.NextRecord();

                foreach (var row in ResultNodeList)
                {
                    csv.WriteField(row.MovementDocumentDate > DateTime.MinValue ? row.MovementDocumentDate.ToShortDateString() : string.Empty);
                    csv.WriteField(row.MovementDocumentName);

                    foreach (var column in row.NomenclatureColumns)
                    {
                        csv.WriteField(column.IsTotal? $"{ column.Amount:F2}" : $"{ column.Amount:F0}");
                    }

                    csv.NextRecord();
                }
            }
            else
            {
                var headers = new[] { "ТМЦ", "Период", "Цена", "Количество", "Сумма" };

                foreach (var header in headers)
                {
                    csv.WriteField(header);
                }

                csv.NextRecord();

                foreach (var row in ResultNodeList.SingleOrDefault().NomenclatureColumns)
                {
                    csv.WriteField(row.NomenclatureName);
                    csv.WriteField(row.DateRange);
                    csv.WriteField(row.IsTotal ? "" : row.PurchasePrice.ToString());
                    csv.WriteField(row.Amount);
                    csv.WriteField(row.Sum);
                    csv.NextRecord();
                }
            }

            writer.Close();
        }