Exemple #1
0
        public static Journal asd( )
        {
            var assembly = Assembly.GetExecutingAssembly( );
            var stream   = assembly.GetManifestResourceStream(@"Our4LegendData.xml");

            if (stream == null)
            {
                throw new Exception( );
            }
            var Reader = new StreamReader(stream);

            var Doc = XDocument.Parse(Reader.ReadToEnd( ));

            var journal = (from Jou in Doc.Descendants("Journal")
                           select new Journal
            {
                Name = ( string )Jou.Attribute("Name"),

                ListOfIssue = from Iss in Jou.Descendants("Issue")
                              select new Issue
                {
                    Number = ( long )Iss.Attribute("Number"),
                    PublishTime = Convert.ToDateTime(Iss.Attribute("PublishTime")),
                    Price = ( decimal )Iss.Attribute("Price"),
                    ListOfArticle = from Art in Iss.Descendants("Article")
                                    select new Article
                    {
                        Title = ( string )Art.Attribute("Title"),
                        Text = ( string )Art.Attribute("Text"),
                        ListOfAuthor = from Aut in Art.Descendants("Author")
                                       select new Author
                        {
                            FirstName = ( string )Aut.Attribute("FirstName"),
                            FamilyName = ( string )Aut.Attribute("FamilyName"),
                            EmailAddress = ( string )Aut.Attribute("EmailAddress")
                        }
                    }
                }
            }).FirstOrDefault( );

            return(journal);
        }
        public static Journal GetJournal(IRandomAccessStream stream)
        {
            if (stream == null)
            {
                return(null);
            }
            else
            {
                var Reader = new StreamReader(stream.AsStream());

                var Doc = XDocument.Parse(Reader.ReadToEnd());

                Journal journal;
                try
                {
                    journal = (from Jou in Doc.Descendants("Journal")
                               select new Journal
                    {
                        Name = ( string )Jou.Attribute("Name"),
                        ListOfAuthor = from Aut in Jou.Descendants("Author")
                                       select new Author
                        {
                            FirstName = ( string )Aut.Attribute("FirstName"),
                            FamilyName = ( string )Aut.Attribute("FamilyName"),
                            EmailAddress = ( string )Aut.Attribute("EmailAddress"),
                            Introduction = ( string )Aut.Attribute("Introduction")
                        },
                        ListOfIssue = from Iss in Jou.Descendants("Issue")
                                      select new Issue
                        {
                            Number = ( long )Iss.Attribute("Number"),
                            PublishTime = Convert.ToDateTime(( string )Iss.Attribute("PublishTime")),
                            Price = ( decimal )Iss.Attribute("Price"),
                            ListOfArticle = from Art in Iss.Descendants("Article")
                                            select new Article
                            {
                                Title = ( string )Art.Attribute("Title"),
                                TextLine = from Lin in Art.Descendants("Text").FirstOrDefault().Descendants("Line")
                                           select(string) Lin.Attribute("Run"),
                                ListOfAuthorName = from Aut in Art.Descendants("AuthorName")
                                                   select(string) Aut.Attribute("FirstName") + " " + ( string )Aut.Attribute("FamilyName"),
                            }
                        }
                    }).First();
                }
                catch (System.Exception)
                {
                    return(null);
                }
                foreach (var Aut in journal.ListOfAuthor)
                {
                    foreach (var Iss in journal.ListOfIssue)
                    {
                        foreach (var Art in Iss.ListOfArticle)
                        {
                            foreach (var aut in Art.ListOfAuthor)
                            {
                                if (Aut == aut)
                                {
                                    Aut.ArticleHaveContribute.Add(Art);
                                }
                            }
                        }
                    }
                }
                return(journal);
            }
        }