Ejemplo n.º 1
0
        public void Make_All_Reviews()
        {
            ReviewPage.GoTo();
            Assert.IsTrue(ReviewPage.IsAt, "Wasn't at Review page");

            ReviewPage.MakeReview("").Review("True").CheckAllFinal();
        }
Ejemplo n.º 2
0
        private void InitWithPage(MNPage p)
        {
            tabControl1.SelectedTab = tabPage;

            if (p_Book.Pages.ContainsKey(p.Id))
            {
                p_Page = p_Book.Pages[p.Id];
            }
            else
            {
                p_Page             = new ReviewPage();
                p_Book.Pages[p.Id] = p_Page;
                p_Page.PageTitle   = p.TextBRaw;
                p_Page.PageHelp    = p.MessageTextRaw;
            }

            richTextBox1.Text  = p_Page.PageTitle;
            richTextBox2.Text  = p_Page.PageHelp;
            richTextBox3.Text  = p_Page.PageNotes;
            textItemText.Text  = "";
            textItemNotes.Text = "";

            p_PageOrig = p;
            p_ItemOrig = null;

            UpdatePageHelpColor();
            UpdatePageTitleColor();
        }
        public ReviewTest()
        {
            var loginPage = new LoginPage(baseUrl, ngDriver);

            loginPage.Login(AdminEmail, AdminPassword);
            reviewPage = new ReviewPage("http://devata.abbyyusa.com/validate/preview/590b42098b32a97b727e834b", ngDriver);
            //reviewPage = new ReviewPage("http://66.6.124.181/validate/preview/59079263bc18712c074ac85d", ngDriver);
        }
Ejemplo n.º 4
0
        public void Can_Make_Final_Review()
        {
            string theme  = TestContext.DataRow["theme"].ToString();
            string review = TestContext.DataRow["review"].ToString();

            ReviewPage.GoTo();
            Assert.IsTrue(ReviewPage.IsAt, "Wasn't at Review page");

            ReviewPage.MakeReview(theme).Review(review).SaveFinal();

            ReviewPage.MakeReview(theme).Review(review).CheckFinal();
        }
Ejemplo n.º 5
0
        public void Can_Set_Score()
        {
            string theme  = TestContext.DataRow["theme"].ToString();
            string review = TestContext.DataRow["review"].ToString();
            string mark   = TestContext.DataRow["mark"].ToString();

            ReviewPage.GoTo();
            Assert.IsTrue(ReviewPage.IsAt, "Wasn't at Review page");

            ReviewPage.MakeReview(theme).Review(review).SetMark(mark);
            ReviewPage.MakeReview(theme).Review(review).CheckMark(mark);
        }
Ejemplo n.º 6
0
        private void CriticsList_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var mi = (MovieReviewItem)MovieReviewItems.SelectedItem;

            if (mi != null)
            {
                if (mi.Link != null)
                {
                    ReviewPage.Navigate(new Uri(mi.Link));
                }
            }
        }
Ejemplo n.º 7
0
        public void Visual_Compare_HTML()
        {
            string theme      = TestContext.DataRow["theme"].ToString();
            string actual     = TestContext.DataRow["actual"].ToString();
            string expected   = TestContext.DataRow["expected"].ToString();
            string result     = TestContext.DataRow["result"].ToString();
            string workingDir = TestContext.DataRow["workingDir"].ToString();
            string refPath    = TestContext.DataRow["refPath"].ToString();

            ReviewPage.GoTo();
            ReviewPage.MakeReview(theme)
            .MakeScreenshot(actual, expected, result, workingDir, refPath);
        }
Ejemplo n.º 8
0
 public GoCityStepDefinitions(IObjectContainer objectContainer)
 {
     this._scenarioContext    = objectContainer.Resolve <ScenarioContext>();
     this.driver              = objectContainer.Resolve <IWebDriver>();
     this.homePage            = objectContainer.Resolve <HomePage>();
     this.helpers             = objectContainer.Resolve <Helpers>();
     this.howItWorksPage      = objectContainer.Resolve <HowItWorksPage>();
     this.helpPage            = objectContainer.Resolve <HelpPage>();
     this.covid19Page         = objectContainer.Resolve <Covid19Page>();
     this.cityPassPage        = objectContainer.Resolve <CityPassPage>();
     this.bangkokAllinclusive = objectContainer.Resolve <BangkokAllinclusive>();
     this.reviewPage          = objectContainer.Resolve <ReviewPage>();
     this.paymentPage         = objectContainer.Resolve <PaymentPage>();
 }
Ejemplo n.º 9
0
        public void Base_UI_Elements_Inspection()
        {
            Assert.IsTrue(DashboardPage.IsAt, "Wrong DashboardPage label.");

            PickThemesPage.GoTo();
            Assert.IsTrue(PickThemesPage.IsAt, "Wrong PickThemesPage label.");

            UploadDocsPage.GoTo();
            Assert.IsTrue(UploadDocsPage.IsAt, "Wrong UploadDocsPage label.");

            ReviewPage.GoTo();
            Assert.IsTrue(ReviewPage.IsAt, "Wrong ReviewPage label.");

            Navigation.Logout.Select();
            Assert.IsTrue(LoginPage.IsAt, "Wrong LoginScreen label.");
        }
Ejemplo n.º 10
0
        public async Task <bool> Process(BaseController baseController, Func <string, Task> callback)
        {
            var comment = baseController as Comment;

            if (comment == null || !comment.Body.StartsWith("!wikify") || comment.Depth != 0)
            {
                return(false);
            }

            if (!_service.Subreddit.Moderators.Any(m => m.Name.Equals(comment.Author)))
            {
                return(false);
            }

            var result = await _service.SelfCommentDatabase.GetAny(nameof(SelfComment.ParentId), comment.Id);

            if (result != null)
            {
                return(false);
            }

            if (!DryRun)
            {
                var commandParts = Regex.Split(comment.Body, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
                if (commandParts.Length == 3)
                {
                    if (commandParts[1] == "review")
                    {
                        var knifeName  = commandParts[2].Trim('"');
                        var post       = _service.Subreddit.Post(comment.ParentFullname).Info();
                        var rewiewPage = new ReviewPage(_logger, _service);
                        rewiewPage.AddReviewLinkToReviewPage(knifeName, post.Author, post.Title, $"{_urlRoute}{post.Listing.Permalink}");

                        var replyComment = comment
                                           .Reply("Added to the wiki: https://www.reddit.com/r/chefknives/wiki/reviews")
                                           .Distinguish("yes");

                        _service.SelfCommentDatabase.Upsert(replyComment.ToSelfComment(comment.Id, RedditThingType.Comment, comment.Listing.AuthorFlairTemplateId));
                    }
                }
            }

            _logger.Information($"[{nameof(WikifyCommentHandler)}]: Commented on command: {comment.Body}");

            return(true);
        }
Ejemplo n.º 11
0
        private string GetFilterAnswer(Dictionary <string, string> questionAndAnswer)
        {
            TypeField type = new TypeField();

            ReviewPage.TypeAnsQuestionFilter(questionAndAnswer["q"], currentCard, ref type);
            var answer = Sound.ExpandSounds(questionAndAnswer["a"]);

            answer = LaTeX.MungeQA(answer, collection);
            if (String.IsNullOrWhiteSpace(type.CorrectAnswer))
            {
                answer = ReviewPage.TypeAnswerRegex.Replace(answer, "");
            }
            else
            {
                answer = ReviewPage.TypeAnswerRegex.Replace(answer, type.CorrectAnswer);
            }
            return(answer);
        }
Ejemplo n.º 12
0
        public void Can_Make_Review()
        {
            string theme        = TestContext.DataRow["theme"].ToString();
            string review       = TestContext.DataRow["review"].ToString();
            string element_type = TestContext.DataRow["element_type"].ToString();
            string element_text = TestContext.DataRow["element_text"].ToString();

            ReviewPage.GoTo();
            Assert.IsTrue(ReviewPage.IsAt, "Wasn't at Review page");

            ReviewPage.MakeReview(theme).Review(review).ElementType(element_type).ElementText(element_text).Save();

            Assert.IsTrue(ReviewPage.IsAt, "Wasn't at Review page");

            ReviewPage.MakeReview(theme).Review(review).ElementType(element_type).ElementText(element_text).Check();

            ReviewPage.MakeReview(theme).ElementType(element_type).ElementText(element_text).Delete();
        }
Ejemplo n.º 13
0
        private void StartDocumentReview(MNDocument doc, string filePath)
        {
            Document    = doc;
            doc.Reviews = p_Book;
            ClearUI();

            labelBookTitle.Text     = Document.Book.BookTitle;
            tabControl1.SelectedTab = tabBook;

            string folder = Properties.Settings.Default.ReviewsDirectory;

            if (Directory.Exists(folder))
            {
                string path = Path.Combine(folder, Path.GetFileNameWithoutExtension(Document.Book.FilePath) + ".smr");
                LoadData(path);
            }

            p_PageOrig = null;
            p_ItemOrig = null;
            p_Page     = new ReviewPage();
            p_Item     = new ReviewItem();
        }
Ejemplo n.º 14
0
 private void MakesureCleanState()
 {
     mainPage.Collection.ClearUndo();
     ReviewPage.ClearReviewUndo();
 }
        //---
        private void Insert_Or_Update_ReviewPage_Review_Interaction(ReviewPage reviewPage, List <Review> reviews)
        {
            try
            {
                using (DataDbContext context = new DataDbContext())
                {
                    //var reviewPage_ = context.ReviewPages.Find().ReviewPageId
                }

                var sourceName = "FaceBook";
                var callMethod = "Api";
                var accountId  = "105294769132327896230";
                var locationId = "14880430448251263796";
                var externalId = "2366450684051732373";


                var reviewPageComp = string.Concat(sourceName, callMethod);
                reviewPageComp = string.Concat(reviewPageComp, accountId);
                reviewPageComp = string.Concat(reviewPageComp, locationId);
                reviewPageComp = string.Concat(reviewPageComp, externalId);

                // Insert seed data into the database using one instance of the context
                using (DataDbContext context = new DataDbContext())
                {
                    DAC.LPM.SQLServer.ReviewPage _reviewPage = new DAC.LPM.SQLServer.ReviewPage
                    {
                        SourceName    = sourceName,
                        CallMethod    = callMethod,
                        AccountId     = accountId,
                        LocationId    = locationId,
                        ExternalId    = externalId,
                        AverageRating = 0.0M,
                        //Created = DateTime.Today,
                        Updated     = DateTime.Today,
                        LastUpdated = DateTime.Today,

                        Reviews = new List <DAC.LPM.SQLServer.Review>
                        {
                            new DAC.LPM.SQLServer.Review
                            {
                                ParsedId         = "ParsedId",
                                AuthorName       = "AuthorName",
                                AuthorProfileUrl = "AuthorProfileUrl",
                                AuthorIconUrl    = "AuthorIconUrl",
                                AuthorExternalId = "AuthorExternalId",
                                ReviewPageId_FK  = reviewPageComp,
                                Content          = "Content for review",
                                //ContentLength = 20,
                                Rating      = 1,
                                Created     = DateTime.Today.ToString(),
                                Updated     = DateTime.Today.ToString(),
                                LastUpdated = DateTime.Today,

                                Interactions = new List <Interaction>
                                {
                                    new Interaction
                                    {
                                        InteractionType  = "InteractionType",
                                        ParentType       = "ParentType",
                                        AuthorName       = "AuthorName",
                                        AuthorProfileUrl = "AuthorProfileUrl",
                                        AuthorIconUrl    = "AuthorIconUrl",
                                        AuthorExternalId = "AuthorExternalId",
                                        Content          = DateTime.Today.ToString(),
                                        //ContentLength = 20,
                                        Created     = DateTime.Today.ToString(),
                                        CreatedTime = DateTime.Today,
                                        LastUpdated = DateTime.Today
                                    }
                                }
                            }
                        }
                    };

                    context.ReviewPages.Add(_reviewPage);
                    context.SaveChanges();
                }



                using (DataDbContext context = new DataDbContext())
                {
                    var service = new SQLServerServices(context);
                    var result  = service.Find("FaceBook");


                    //Assert.AreEqual("ReviewPage SourceName Test", context.ReviewPages.Find().SourceName);
                    //Assert.Equals("ReviewPage SourceName Test", context.ReviewPages.First().SourceName);
                    //Assert.AreEqual("Review AuthorName", context.Reviews.First().AuthorName);
                    //Assert.AreEqual("SQLServerTests ReviewPage SourceName Test", result.First().SourceName);

                    //--- Assert.AreEqual(2, result.Count());

                    logger.Debug($"Total # of Reviews ({result.Count()}) ");
                }
            }
            catch (Exception ex)
            {
                logger.Error(
                    $"Exception Error: {ex.Message} Details: {ex.StackTrace} InnerException: {ex.InnerException}");
                throw ex;
            }
            finally
            {
                //  context.Database.CloseConnection();
            }
        }
Ejemplo n.º 16
0
        public static async Task Main(string[] args)
        {
            var initialConfiguration = new ConfigurationBuilder()
                                       .AddJsonFile("appsettings.json", false, false)
                                       .Build();

            var ChefKnivesSettingsFile = Environment.ExpandEnvironmentVariables(initialConfiguration["ChefKnivesSettingsFile"]);
            var compoundConfiguration  = new ConfigurationBuilder()
                                         .AddJsonFile("appsettings.json", false, true);

            if (!string.IsNullOrEmpty(ChefKnivesSettingsFile))
            {
                compoundConfiguration.AddJsonFile(ChefKnivesSettingsFile, true, false);
            }

            _configuration = compoundConfiguration.Build();

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File("Logs/.log", rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            if (args.Any(a => a.Equals("--seedchefknives")))
            {
                Console.WriteLine("Action: Seed for chefknives. Press any key to continue...");
                Console.ReadLine();
                await SeedFor("chefknives");
            }
            else if (args.Any(a => a.Equals("--testchefknivesbot")))
            {
                Console.WriteLine("Running ChefKnivesBot on r/zapatodefuego.");
                Console.WriteLine("Press any key to exit...");

                var service = new TestSubredditBotInitializer().Start(Log.Logger, _configuration, false);
                InitializeTestServiceFunctions(Log.Logger, service, false);

                Console.ReadKey();
                service.Dispose();
            }
            else if (args.Any(a => a.Equals("--chefkniveswiki")))
            {
                Console.WriteLine("Executing wiki functions");
                var service = new TestSubredditBotInitializer().Start(Log.Logger, _configuration, false);

                var reviewPage = new ReviewPage(Log.Logger, service);
                reviewPage.AddReviewLinkToReviewPage("A", "zapatodefuego", "test entry 0", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("B", "zapatodefuego", "test entry 1", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("C", "zapatodefuego", "test entry 2", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("X", "zapatodefuego", "test entry 3", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("Y", "zapatodefuego", "test entry 4", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("Z", "zapatodefuego", "test entry 5", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");

                reviewPage.AddReviewLinkToReviewPage("A", "zapatodefuego", "test entry 10", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("B", "zapatodefuego", "test entry 11", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("C", "zapatodefuego", "test entry 12", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("X", "zapatodefuego", "test entry 13", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("Y", "zapatodefuego", "test entry 14", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
                reviewPage.AddReviewLinkToReviewPage("Z", "zapatodefuego", "test entry 15", "https://www.reddit.com/r/chefknives/wiki/edit/reviews");
            }
            else if (args.Any(a => a.Equals("--reprocessmongo")))
            {
                var mongoClient = new MongoClient(_configuration["ConnectionString"]);
                var collection  = mongoClient.GetDatabase("chefknives").GetCollection <BsonDocument>("comments");
                //var redditComments = collection.Find(Builders<BsonDocument>.Filter.Eq("_t", "RedditComment")).ToList();
                //foreach (var redditComment in redditComments)
                //{
                //    var comment = BsonSerializer.Deserialize<Comment>(redditComment);
                //    var bson = comment.ToBsonDocument();
                //    bson.InsertAt(1, new BsonElement("_t", "Comment"));
                //    collection.ReplaceOne(
                //        filter: new BsonDocument("_id", comment.Id),
                //        options: new ReplaceOptions { IsUpsert = true },
                //        replacement: bson);
                //}

                //var bsonResults = collection.AsQueryable();
                //foreach (var r in bsonResults)
                //{
                //    var s = r.GetValue("Author");
                //    var ss = s.AsString.ToLower();
                //}
            }
            else if (args.Any(a => a.Equals("--wordcloud")))
            {
                var mongoClient = new MongoClient(_configuration["ConnectionString"]);
                var collection  = mongoClient.GetDatabase("chefknives").GetCollection <BsonDocument>("posts");
                var makerPosts  = collection
                                  .Find(Builders <BsonDocument>
                                        .Filter.Eq("Flair", "Maker Post"))
                                  .ToList()
                                  .Select(b => BsonSerializer.Deserialize <Post>(b));

                var cloud = new Dictionary <string, int>();
                foreach (var makerPost in makerPosts)
                {
                    var words = makerPost.Title.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();

                    words.ForEach(w =>
                    {
                        var word = w.ToLower().Trim();
                        if (cloud.TryGetValue(word, out int value))
                        {
                            cloud[word]++;
                        }
                        else
                        {
                            cloud.Add(word, 1);
                        }
                    });
                }

                var builder = new StringBuilder();
                foreach (var kvp in from entry in cloud orderby entry.Value descending select entry)
                {
                    builder.AppendLine($"{kvp.Key} {kvp.Value}");
                }

                File.WriteAllText("out.txt", builder.ToString());
            }
        }
        //--- 1
        #region Implement Interface Method
        public bool  Save(ReviewPage reviewPage, List <Review> reviews, int expectedReviewCount = -1)
        {
            //--return UpsertReviewPageSet(reviewPage, reviews);
            #region SQL

            try
            {
                // Insert seed data into the database using one instance of the context
                using (DataDbContext context = new DataDbContext())
                {
                    var sourceName = !String.IsNullOrEmpty(reviewPage.SourceName) ? reviewPage.SourceName : string.Empty;
                    var callMethod = !String.IsNullOrEmpty(reviewPage.CallMethod) ? reviewPage.CallMethod : string.Empty;
                    var accountId  = !String.IsNullOrEmpty(reviewPage.AccountId) ? reviewPage.AccountId : string.Empty;
                    var locationId = !String.IsNullOrEmpty(reviewPage.LocationId) ? reviewPage.LocationId : string.Empty;
                    var externalId = !String.IsNullOrEmpty(reviewPage.ExternalId) ? reviewPage.ExternalId : string.Empty;
                    var created    = (reviewPage.Created != null) ? reviewPage.Created : DateTime.Now.ToUniversalTime();

                    var reviewPageComp = string.Concat(sourceName, callMethod);
                    reviewPageComp = string.Concat(reviewPageComp, accountId);
                    reviewPageComp = string.Concat(reviewPageComp, locationId);
                    reviewPageComp = string.Concat(reviewPageComp, externalId);


                    //--- Create a lists  of all from Review.
                    foreach (Review review in reviews)
                    {
                        //if (review.Comments != null)
                        //{
                        //foreach (Comment comment in review.Comments)
                        //{
                        //_interactions.Add(new DAC.LPM.SQLServer.Interaction()
                        //{
                        //    InteractionType = "Comment.."
                        ////ParentId = ,
                        //ParentType = "Review..",
                        //AuthorName = comment.Author.Name,
                        //AuthorProfileUrl = comment.Author.ProfileUrl,
                        //AuthorIconUrl = comment.Author.IconUrl,
                        //AuthorExternalId = "AuthorExternalId",
                        //Content = comment.Content,
                        //Created = comment.Created,
                        //    CreatedTime = comment.CreatedTime
                        //});
                        //}
                        //}
                        //else if (review.Response != null)
                        //{
                        //foreach (Response response in review.Response)
                        //{
                        //    _interactions.Add(new DAC.LPM.SQLServer.Interaction()
                        //    {
                        //        InteractionType = "Response.."
                        //        //ParentId = ,
                        //ParentType = "Review.."
                        //        AuthorName = comment.Author.Name,
                        //        AuthorProfileUrl = comment.Author.ProfileUrl,
                        //        AuthorIconUrl = comment.Author.IconUrl,
                        //        AuthorExternalId = "AuthorExternalId",
                        //        Content = comment.Content,
                        //        Created = comment.Created,
                        //        //        CreatedTime = comment.CreatedTime
                        //    });
                        //}
                        if (review.Comments != null)
                        {
                            foreach (Comment comment in review.Comments)
                            {
                                _interactions.Add(new DAC.LPM.SQLServer.Interaction()
                                {
                                    InteractionType = "Comment..",
                                    //ParentId = ,
                                    ParentType       = "Review..",
                                    AuthorName       = comment.Author.Name,
                                    AuthorProfileUrl = comment.Author.ProfileUrl,
                                    AuthorIconUrl    = comment.Author.IconUrl,
                                    //AuthorExternalId = comment.Author.ExternalId,
                                    Content = comment.Content,
                                    //ContentLength = 20,
                                    Created = comment.Created
                                              //CreatedTime = comment.CreatedTime
                                });
                            }
                        }
                        //else if (review.Response != null)
                        //{
                        //    foreach (Response response in review.Response)
                        //    {
                        //        _interactions.Add(new DAC.LPM.SQLServer.Interaction()
                        //        {
                        //            InteractionType = "Response.."
                        //            //ParentId = ,
                        //            ParentType = "Review.."
                        //            AuthorName = comment.Author.Name,
                        //            AuthorProfileUrl = comment.Author.ProfileUrl,
                        //            AuthorIconUrl = comment.Author.IconUrl,
                        //            AuthorExternalId = comment.Author.ExternalId,
                        //            Content = comment.Content,
                        //            Created = comment.Created,
                        //            //        CreatedTime = comment.CreatedTime
                        //        });
                        //    }
                        //}


                        _reviews.Add(new DAC.LPM.SQLServer.Review()
                        {
                            //ParsedId = review.ParsedId,
                            //AuthorName = review.Author.Name,
                            //AuthorProfileUrl = review.Author.ProfileUrl,
                            //AuthorIconUrl = review.Author.IconUrl,
                            //AuthorExternalId = "AuthorExternalId..",
                            //ReviewPageId_FK = reviewPageComp,
                            //Content = review.Content,
                            //Rating = review.Rating,
                            //Created = review.Created,
                            //Updated = review.Updated,
                            //LastUpdated = DateTime.Now.ToUniversalTime(),

                            ParsedId         = review.ParsedId,
                            AuthorName       = review.Author.Name,
                            AuthorProfileUrl = review.Author.ProfileUrl,
                            AuthorIconUrl    = review.Author.IconUrl,
                            //AuthorExternalId = review.Author.ExternalId,
                            ReviewPageId_FK = reviewPageComp,
                            Content         = review.Content,
                            Rating          = 1,
                            Created         = DateTime.Today.ToString(),
                            Updated         = review.Updated,
                            LastUpdated     = DateTime.Today,
                            Interactions    = _interactions
                        });
                    }

                    DAC.LPM.SQLServer.ReviewPage __reviewPage = new DAC.LPM.SQLServer.ReviewPage
                    {
                        SourceName    = sourceName,
                        CallMethod    = callMethod,
                        AccountId     = accountId,
                        LocationId    = locationId,
                        ExternalId    = externalId,
                        AverageRating = 4.1M,
                        Created       = DateTime.Today,
                        Updated       = DateTime.Today,
                        LastUpdated   = DateTime.Today,
                        Reviews       = _reviews
                    };

                    context.ReviewPages.Add(__reviewPage);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                //---logger.Error($"Exception Error: {ex.Message} Details: {ex.StackTrace} InnerException: {ex.InnerException}");
                return(false);

                throw ex;
            }

            #endregion

            return(true);
        }
Ejemplo n.º 18
0
        private void UpsertReviewPageSet(ReviewPage reviewPage, List <Review> reviews)
        {
            SetUpMongoConnection();
            var policy = Policy.Handle <Exception>().Retry(3);

            var reviewPageFilter = Builders <BsonDocument> .Filter.Eq("Id", reviewPage.Id);

            var reviewPageCollection = MongoDBAccess.GetCollection(
                MONGO_COLLECTION_REVIEWPAGE, MONGO_DATABASE);
            var reviewBsonDocument = reviewPageCollection.
                                     Find(reviewPageFilter).Limit(1).FirstOrDefault();

            policy.Execute(
                () => reviewPageCollection.ReplaceOne(reviewPageFilter,
                                                      new BsonDocument
            {
                { "SourceName", (!String.IsNullOrEmpty(reviewPage.SourceName))?reviewPage.SourceName:string.Empty },
                { "CallMethod", (!String.IsNullOrEmpty(reviewPage.CallMethod))?reviewPage.CallMethod:string.Empty },
                { "AccountId", (!String.IsNullOrEmpty(reviewPage.AccountId))?reviewPage.AccountId:string.Empty },
                { "LocationId", (!String.IsNullOrEmpty(reviewPage.LocationId))?reviewPage.LocationId:string.Empty },
                { "ExternalId", (!String.IsNullOrEmpty(reviewPage.ExternalId))?reviewPage.ExternalId:string.Empty },
                { "Metadata", ObjectToBsonDocument(reviewPage.Metadata) },
                { "Created", (reviewBsonDocument != null) ?
                  reviewBsonDocument.GetValue("Created", null).ToUniversalTime() :
                  DateTime.Now.ToUniversalTime() },
                { "Updated", DateTime.Now.ToUniversalTime() },
                { "Id", reviewPage.Id }
            },
                                                      new UpdateOptions {
                IsUpsert = true
            }));

            var reviewWriteModel = new List <WriteModel <BsonDocument> >();
            var reviewCollection = MongoDBAccess.GetCollection(
                MONGO_COLLECTION_REVIEW, MONGO_DATABASE);
            var commentWriteModel = new List <WriteModel <BsonDocument> >();
            var commentCollection = MongoDBAccess.GetCollection(
                MONGO_COLLECTION_COMMENT, MONGO_DATABASE);

            reviewWriteModel.Add(new DeleteManyModel <BsonDocument>(
                                     Builders <BsonDocument> .Filter.Eq("ReviewPageId", reviewPage.Id)));

            foreach (Review review in reviews)
            {
                BsonDocument reviewBson = new BsonDocument();
                this.AddBsonDocument("Id", review.Id, reviewBson);
                this.AddBsonDocument("ParsedId", review.ParsedId, reviewBson);
                this.AddBsonDocument("ReviewPageId", review.ReviewPageId, reviewBson);
                this.AddBsonDocument("Author", ObjectToBsonDocument(review.Author), reviewBson);
                this.AddBsonDocument("Rating", review.Rating, reviewBson);
                this.AddBsonDocument("Content", review.Content, reviewBson);
                this.AddBsonDocument("Created", review.Created, reviewBson);
                this.AddBsonDocument("Updated", review.Updated, reviewBson);

                this.AddBsonDocument("Children", IEnumerableToBsonArray(review.Children), reviewBson);
                this.AddBsonDocument("Metadata", ObjectToBsonDocument(review.Metadata), reviewBson);
                this.AddBsonDocument("Response", ObjectToBsonDocument(review.Response), reviewBson);


                reviewWriteModel.Add(new InsertOneModel <BsonDocument>(
                                         reviewBson));



                commentWriteModel.Add(new DeleteManyModel <BsonDocument>(
                                          Builders <BsonDocument> .Filter.Eq("ReviewId", review.Id)));
                if (review.Comments != null)
                {
                    foreach (Comment comment in review.Comments)
                    {
                        commentWriteModel.Add(new InsertOneModel <BsonDocument>(
                                                  new BsonDocument
                        {
                            { "Id", comment.Id },
                            { "ReviewId", comment.ReviewId },
                            { "Author", ObjectToBsonDocument(comment.Author) },
                            { "Content", comment.Content },
                            { "Created", comment.Created },
                            { "Replies", IEnumerableToBsonArray(comment.Replies) }
                        }));
                    }
                }
            }
            if (reviewWriteModel.Count > 0)
            {
                policy.Execute(
                    () => reviewCollection.BulkWrite(reviewWriteModel,
                                                     new BulkWriteOptions {
                    IsOrdered = false
                }));
            }

            if (commentWriteModel.Count > 0)
            {
                policy.Execute(
                    () => commentCollection.BulkWrite(commentWriteModel,
                                                      new BulkWriteOptions {
                    IsOrdered = true
                }));
            }
        }
Ejemplo n.º 19
0
 public void Save(ReviewPage reviewPage, List <Review> reviews, int expectedReviewCount = -1)
 {
     UpsertReviewPageSet(reviewPage, reviews);
 }