コード例 #1
0
        public DatabasePresentationWindow()
        {
            InitializeComponent();
            using (DatabaseContext siContext = new DatabaseContext())
            {
                var query = (from Product in siContext.Product
                            select  Product).ToList();
                List<Product> comments = new List<Product>();

                foreach (var comment in query)
                {
                    comments.Add(comment);
                }
                productsDb.ItemsSource = comments.ToList();
            }
            using (DatabaseContext siContext = new DatabaseContext())
            {
                var query = (from Product in siContext.Product
                             select Product.Comments).ToList();
                List<CommentDb> comments = new List<CommentDb>();

                foreach (var comment in query)
                {
                    if (comment.Count > 0)
                    {
                        foreach (var com in comment)
                        {
                            com.Comment = Regex.Replace(com.Comment, @"<[^>]+>|&nbsp;", "").Trim();
                            comments.Add(com);
                        }
                    }
                }
                commentData.ItemsSource = comments.ToList();
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: ziomal9191/uekHD
 private void buttonClearDb(object sender, RoutedEventArgs e)
 {
     DatabaseContext context = new DatabaseContext();
     context.Comments.RemoveRange(context.Comments);
     context.Product.RemoveRange(context.Product);
     context.SaveChanges();
 }
コード例 #3
0
ファイル: SkapiecWebCrawler.cs プロジェクト: ziomal9191/uekHD
        /// <summary>
        /// Dla serwisu skapiec.pl pobiera całą zawartość z komentarzami
        /// </summary>
        /// <param name="statistic"></param>
        /// <param name="product"></param>
        /// <returns></returns>
        public Product getPagesContent(IStatisctics statistic, Product product)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            client.Encoding = Encoding.UTF8;
            ILinkProvider provider = new SkapiecLinkProvider(m_downloadString);
            using (var db = new DatabaseContext())
            {

                string link = "";
                while ((link = provider.getLink()) != "")
                {
                    statistic.addDowlodedPage(link);
                    string pageContent = client.DownloadString(link);
                    pagesContent.Add(pageContent);
                }
                return product;
            }
        }
コード例 #4
0
        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            using (DatabaseContext siContext = new DatabaseContext())
            {
                var query = (from Product in siContext.Product
                             select Product.Comments).ToList();
                List<CommentDb> comments = new List<CommentDb>();

                foreach (var comment in query)
                {
                    if (comment.Count > 0)
                    {
                        foreach (var com in comment)
                        {
                            com.Comment = Regex.Replace(com.Comment, @"<[^>]+>|&nbsp;", "").Trim();
                            comments.Add(com);
                        }
                    }
                }
                commentData.ItemsSource = comments.ToList();
            }
        }
コード例 #5
0
        private void productSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            using (DatabaseContext siContext = new DatabaseContext())
            {
                if (productsDb.SelectedItem is Product)
                {

                var item = (Product)productsDb.SelectedItem;
                   var getProduct = from Product in siContext.Product where Product.Model.Equals(item.Model) select Product.Comments;
                    List<CommentDb> comments = new List<CommentDb>();

                    foreach (var comment in getProduct)
                    {
                        if (comment.Count > 0)
                        {
                            foreach (var com in comment)
                            {
                                com.Comment = Regex.Replace(com.Comment, @"<[^>]+>|&nbsp;", "").Trim();
                                comments.Add(com);
                            }
                        }
                    }
                    commentData.ItemsSource = comments.ToList();
                }
                else
                {
                    commentData.ItemsSource = new List<Product>();

                }
            }
        }
コード例 #6
0
ファイル: HttpCommentGeter.cs プロジェクト: ziomal9191/uekHD
        /// <summary>
        /// Funcja dodająca proddukt do bd, wraz ze sprawdzaniem czy dany komentarz dla danego produktu istnieje
        /// </summary>
        /// <param name="product"></param>
        /// <param name="statistic"></param>
        private void addProductToDatabase(Product product, IStatisctics statistic)
        {
            try
            {
                using (var db = new DatabaseContext())
                {
                    IQueryable<Product> productsInDb = from p in db.Product
                                                       where
                         p.Brand.Equals(product.Brand) &&
                         p.Model.Equals(product.Model) &&
                         p.Type.Equals(product.Type)
                                                       select p;// select db.Product;//and p.Model.E;

                    if (productsInDb != null)
                    {
                        foreach (Product productInDb in productsInDb)
                        {
                            DateTime time = DateTime.Now;

                            foreach (CommentDb dowloadedProd in product.Comments)
                            {
                                bool contains = productInDb.Comments.Any(x => {
                                    bool returnValue = true;
                                    if (dowloadedProd.Advantages != null && x.Advantages != null)
                                        returnValue &= dowloadedProd.Advantages.Equals(x.Advantages);
                                    if (dowloadedProd.Disadvantages != null && x.Disadvantages != null)
                                        returnValue &= dowloadedProd.Disadvantages.Equals(x.Disadvantages);
                                    if (dowloadedProd.Comment != null && x.Comment != null)
                                        returnValue &= dowloadedProd.Comment.Equals(x.Comment);
                                    if (dowloadedProd.Date != null && x.Date != null)
                                        returnValue &= dowloadedProd.Date.Equals(x.Date);
                                    returnValue &= dowloadedProd.Recommend.Equals(x.Recommend);
                                    returnValue &= dowloadedProd.Stars.Equals(x.Stars);
                                    returnValue &= dowloadedProd.Usability.Equals(x.Usability);
                                    returnValue &= dowloadedProd.UsabilityVotes.Equals(x.UsabilityVotes);
                                    returnValue &= dowloadedProd.Author.Equals(x.Author);
                                    return returnValue;
                                });
                                if (contains) { }
                                else
                                {
                                    dowloadedProd.LoadDate = time;
                                    statistic.addAddedComment(dowloadedProd.Comment);

                                    productInDb.Comments.Add(dowloadedProd);
                                }
                            }
                        }
                        if (productsInDb.Count() == 0)
                        {
                            DateTime time = DateTime.Now;
                            foreach (CommentDb com in product.Comments)
                            {
                                com.LoadDate = time;
                                statistic.addAddedComment(com.Comment);
                            }

                            db.Product.Add(product);
                        }

                    }
                    else
                    {
                        DateTime time = DateTime.Now;
                        foreach (CommentDb com in product.Comments)
                        {
                                com.LoadDate = time;
                                statistic.addAddedComment(com.Comment);
                        }
                        db.Product.Add(product);
                    }
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new System.Data.Entity.Validation.DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: ziomal9191/uekHD
        private void buttonSaveToFile(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
            dialog.FileName = "Document"; // Default file name
            dialog.DefaultExt = ".xml"; // Default file extension
            dialog.Filter = "Xml documents (.xml)|*.xml"; // Filter files by extension
            if (dialog.ShowDialog(this) == true)
            {
                using (DatabaseContext siContext = new DatabaseContext())
                {
                    List<Product> query = (from Product in siContext.Product
                                           select Product).ToList();
                    using (var writer = System.Xml.XmlWriter.Create(dialog.FileName))
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("InfoDb");
                        foreach (Product product in query)
                        {
                            writer.WriteStartElement("Product");
                            writer.WriteElementString("ProductId", product.ProductId.ToString());
                            writer.WriteElementString("Type", product.Type);
                            writer.WriteElementString("Brand", product.Brand);
                            writer.WriteElementString("Model", product.Model);
                            foreach (CommentDb comment in product.Comments)
                            {
                                writer.WriteStartElement("CommentBlock");
                                writer.WriteElementString("CommentDbID", comment.CommentDbID.ToString());
                                writer.WriteElementString("Comment", comment.Comment);
                                writer.WriteElementString("Stars", comment.Stars.ToString());
                                writer.WriteElementString("Advantages", comment.Advantages);
                                writer.WriteElementString("Disadvantages", comment.Disadvantages);
                                writer.WriteElementString("Author", comment.Author);
                                writer.WriteElementString("Date", comment.Date.ToString());
                                writer.WriteElementString("Recomend", comment.Recommend.ToString());
                                writer.WriteElementString("Usability", comment.Usability.ToString());
                                writer.WriteElementString("UsabilityVotes", comment.UsabilityVotes.ToString());
                                writer.WriteElementString("PortalName", comment.PortalName);
                                writer.WriteEndElement();

                            }
                            writer.WriteEndElement();
                        }
                    }
                }
            }
        }