コード例 #1
0
ファイル: PlanetTus.cs プロジェクト: markogrbic/kinoNET-si
        public override List<Movie> Parse(string xml, string city, DateTime date)
        {
            string _city = "Planet Tuš " + city;

            List<Movie> movies = new List<Movie>();

            List<ShowTime> showTimeList;
            DateTime xmlDate = new DateTime();
            string dateFormat = "yyyy-MM-ddHH:mm";

            XDocument doc = XDocument.Parse(xml);

            //get all days
            List<XElement> dayListElement = (from e in doc.Descendants("dan") select e).ToList();

            //movieList = new List<Movie>();

            foreach (XElement dayElement in dayListElement)
            {
                xmlDate = DateTime.Parse(dayElement.Attribute("datum").Value);

                if (xmlDate.Date == date.Date)
                {
                    //get all spored
                    List<XElement> sporedList = (from e in dayElement.Descendants("spored") select e).ToList();

                    foreach (XElement sporedElement in sporedList)
                    {

                        if (sporedElement.Attribute("kino").Value.Equals(_city))
                        {
                            //get all films
                            List<XElement> filmList = (from e in sporedElement.Descendants("film") select e).ToList();

                            foreach (XElement filmElement in filmList)
                            {
                                Movie movie = new Movie();
                                try
                                {
                                    movie.MovieId = filmElement.Attribute("id").Value;
                                    movie.Title = filmElement.Element("naslov_si").Value;
                                    movie.OriginalTitle = filmElement.Element("naslov_en").Value;
                                    movie.Genre = filmElement.Element("zvrst").Value;
                                    movie.PosterUrl = filmElement.Element("cover").Value;
                                }
                                catch (Exception)
                                {
                                    continue;
                                }

                                //get all showtimes for a movie element as List of XElement-s
                                List<XElement> showTimeListElements = (from e in filmElement.Descendants("ura") select e).ToList();

                                showTimeList = new List<ShowTime>();

                                foreach (XElement showTimeElement in showTimeListElements)
                                {
                                    ShowTime st = new ShowTime();
                                    string dateTimeString = null;
                                    dateTimeString += dayElement.Attribute("datum").Value;
                                    dateTimeString += showTimeElement.Value;
                                    st.Date = DateTime.ParseExact(dateTimeString, dateFormat, null);
                                    st.Theater = "Dvorana " + showTimeElement.Attribute("theatre").Value;

                                    showTimeList.Add(st);
                                }
                                string rs = null;
                                foreach (ShowTime st in showTimeList)
                                {
                                    rs += st.Date.ToString("HH:mm") + ", ";
                                }

                                //removes last 2 characters ', ' from the string
                                rs = rs.Remove(rs.Length - 2, 2);
                                movie.Showtimes = rs;

                                movies.Add(movie);
                            }

                            break;
                        }
                    }

                    break;
                }
            }

            return movies;
        }
コード例 #2
0
ファイル: Kolosej.cs プロジェクト: markogrbic/kinoNET-si
        public override List<Movie> Parse(string xml, string city, DateTime dt)
        {
            List<Movie> movies = new List<Movie>();

            bool movieShowTimeExists;
            List<ShowTime> showTimeList;
            string dateFormat = "yyyy-MM-ddHH:mm:ss";

            XDocument doc = XDocument.Parse(xml);

            //get all movies
            List<XElement> movieListElement = (from e in doc.Descendants("movie") select e).ToList();

            foreach (XElement movieElement in movieListElement)
            {
                movieShowTimeExists = false;

                Movie movie = new Movie();
                movie.MovieId = movieElement.Attribute("id").Value;
                movie.Title = movieElement.Element("title").Value;
                movie.OriginalTitle = movieElement.Element("original_title").Value;
                movie.Genre = movieElement.Element("genre").Value;
                movie.PosterUrl = movieElement.Element("poster").Value;
                //movie.Year = movieElement.Element("year").Value;
                //movie.Duration = Convert.ToInt32(movieElement.Element("duration").Value);

                //get all showtimes for a specific movie
                List<XElement> showTimeListElement = (from e in movieElement.Descendants("show") select e).ToList();

                showTimeList = new List<ShowTime>();

                foreach (XElement showtimeElement in showTimeListElement)
                {
                    if (showtimeElement.Element("city").Value.Equals(city))
                    {
                        ShowTime st = new ShowTime();

                        st.ShowTimeId = showtimeElement.Attribute("id").Value;
                        string dateTimeString = null;
                        dateTimeString += showtimeElement.Element("date").Value;
                        dateTimeString += showtimeElement.Element("time").Value;
                        st.Date = DateTime.ParseExact(dateTimeString, dateFormat, null);
                        st.City = showtimeElement.Element("city").Value;
                        st.Center = showtimeElement.Element("center").Value;
                        st.Theater = showtimeElement.Element("theater").Value;

                        if (st.Date.Date == dt.Date)
                        {
                            movieShowTimeExists = true;
                            showTimeList.Add(st);
                        }
                    }
                }

                if (movieShowTimeExists == true)
                {
                    //chech if the 1st showtime in the list is actually the one that should be last (between 00:00:00 and 05:00:00)
                    TimeSpan startTime = new TimeSpan(00, 00, 00);
                    TimeSpan endTime = new TimeSpan(05, 00, 00);
                    if (showTimeList.ElementAt(0).Date.TimeOfDay >= startTime && showTimeList.ElementAt(0).Date.TimeOfDay < endTime)
                    {
                        ShowTime stReplaceToLastSpot = new ShowTime();
                        stReplaceToLastSpot = showTimeList.ElementAt(0);
                        showTimeList.RemoveAt(0);

                        stReplaceToLastSpot.Date = stReplaceToLastSpot.Date.AddDays(1);
                        showTimeList.Add(stReplaceToLastSpot);
                    }

                    string rs = null;
                    foreach (ShowTime st in showTimeList)
                    {
                        rs += st.Date.ToString("HH:mm") + ", ";
                    }

                    //removes last 2 characters ', ' from the string
                    rs = rs.Remove(rs.Length - 2, 2);
                    movie.Showtimes = rs;

                    movies.Add(movie);
                }
            }

            return movies;
        }