Esempio n. 1
0
        private PostCollection GetChildrenByPostID()
        {
            PostCollection posts;
            PostCollection threaded    = new PostCollection();
            Stack          threadStack = new Stack();

            // Get posts for the post id
            posts = Posts.GetThreadByPostID(PostID);

            // Push the PostID on to the stack
            threadStack.Push(PostID);


            foreach (Post post in posts)
            {
                if (post.PostID != (int)threadStack.Peek())
                {
                    if (threadStack.Contains((int)post.ParentID))
                    {
                        threadStack.Push(post.PostID);
                        threaded.Add(post);
                    }
                }
                else
                {
                    threaded.Add(post);
                }
            }

            return(threaded);
        }
Esempio n. 2
0
        private void GetPostsForRevision(XmlTextWriter writer)
        {
            string v = Request.QueryString["revision"];
            string p = Request.QueryString["id"];

            if (string.IsNullOrEmpty(p))
            {
                throw new RESTConflict("The Post Id (id) querystring value is missing");
            }

            int postid = Int32.Parse(p);

            int version = (Int32.Parse(v ?? "-1"));

            Query q = VersionStore.CreateQuery();

            q.AndWhere(VersionStore.Columns.ItemId, postid);
            q.AndWhere(VersionStore.Columns.Type, "post/xml");
            if (version > 0)
            {
                q.AndWhere(VersionStore.Columns.Version, version);
            }

            VersionStoreCollection vsc   = VersionStoreCollection.FetchByQuery(q);
            PostCollection         posts = new PostCollection();

            posts.Add(new Post(postid));

            foreach (VersionStore vs in vsc)
            {
                posts.Add(ObjectManager.ConvertToObject <Post>(vs.Data));
            }

            posts.Sort(delegate(Post p1, Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); });

            writer.WriteStartElement("posts");
            writer.WriteAttributeString("pageIndex", "1");
            writer.WriteAttributeString("pageSize", posts.Count.ToString());
            writer.WriteAttributeString("totalPosts", posts.Count.ToString());
            foreach (Post post in posts)
            {
                if (version <= 0 || post.Version == version)
                {
                    ConvertPostToXML(post, writer);
                }
            }

            writer.WriteEndElement();
        }
        private PostCollection Build(JObject jObject, JsonSerializer serializer)
        {
            PostCollection result = new PostCollection();

            JToken current;

            if ((current = jObject["total_posts"]) != null)
            {
                result.TotalPosts = (long)current;
            }
            if ((current = jObject["blog"]) != null)
            {
                result.Blog = serializer.Deserialize <BlogInfo>(jObject.CreateReader());
            }
            if ((current = jObject["posts"]) != null)
            {
                var posts = serializer.Deserialize <List <Post> >(current.CreateReader());
                foreach (var item in posts)
                {
                    result.Add(item);
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Does cleanup work when worker is complete.
        /// </summary>
        /// <param name="sender">
        /// RunWorkerCompleted event.
        /// </param>
        /// <param name="e">RunWorkerCompleted event arguments.</param>
        /// <history>
        /// Sean Patterson    11/1/2010   [Created]
        /// </history>
        private void allPostsWorker_RunWorkerCompleted
            (object sender, RunWorkerCompletedEventArgs e)
        {
            WorkerArgs    myArgs       = (WorkerArgs)e.Result;
            StringBuilder ProgressText = new StringBuilder();

            ProgressText.AppendLine(txtStatus.Text);

            if (e.Cancelled)
            {
                UpdateStatusText("Process cancelled.");
                UpdateStatusBar("Process cancelled.");
            }
            else if (e.Error != null)
            {
                UpdateStatusText("Error with process. Process halted.");
                UpdateStatusBar("Process halted.");
            }
            else
            {
                // Use an observable collection to properly bind/update the
                // ListView
                PostCollection.Clear();

                if ((App.sourceBlog.blogPosts.Count) > 0 || (App.sourceBlog.blogData != null))
                {
                    if (App.sourceBlog.blogPosts.Count > 0)
                    {
                        foreach (Post postItem in App.sourceBlog.blogPosts)
                        {
                            PostData myPost = new PostData(postItem);
                            PostCollection.Add(myPost);
                        }

                        btnMigrate.IsEnabled        = true;
                        btnSelectAllPosts.IsEnabled = true;
                    }
                    else
                    {
                        for (int i = 0; i <= App.sourceBlog.blogData.posts.Length - 1; i++)
                        {
                            PostData myPost = new PostData(App.sourceBlog.blogData.posts[i]);
                            PostCollection.Add(myPost);
                        }

                        btnMigrate.IsEnabled        = true;
                        btnSelectAllPosts.IsEnabled = true;
                    }
                }

                lsvAllPosts.ItemsSource = PostCollection;
                lblEntriesCount.Content = "[" + PostCollection.Count + " Total]";

                UpdateStatusText("Process complete.");
                UpdateStatusBar("Process complete.");
            }
        }
Esempio n. 5
0
        protected override void Establish_context()
        {
            _posts         = new PostCollection();
            _originalPosts = new PostCollection();

            for (int i = 0; i < PostSetsToGenerate; i++)
            {
                // Create set of four posts on a given date (CreatedOn), two with the same event data, two without event dates at all.
                _posts.Add(CreatePost(String.Format("A (Has date) {0}", i),
                                      DateTime.Now.Date.Add(TimeSpan.FromDays(i)),
                                      DateTime.Now.Date.Add(TimeSpan.FromDays(i))));
                _posts.Add(CreatePost(String.Format("B (Has date) {0}", i),
                                      DateTime.Now.Date.Add(TimeSpan.FromDays(i)),
                                      DateTime.Now.Date.Add(TimeSpan.FromDays(i))));
                _posts.Add(CreatePost(String.Format("A (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null));
                _posts.Add(CreatePost(String.Format("B (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null));
            }

            _originalPosts.AddRange(_posts);
        }
Esempio n. 6
0
    private void BindData(PageWidget widget)
    {
        txtTitle.Text = widget.Title;

        Query q = Post.CreateQuery();

        q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
        q.AndWhere(Post.Columns.IsDeleted, false);
        q.AndWhere(Post.Columns.Status, 1);

        PostCollection pc = new PostCollection();

        pc.LoadAndCloseReader(q.ExecuteReader());

        PostCollection pcInUse    = new PostCollection();
        PostCollection pcNotInUse = new PostCollection();

        foreach (int i in widget.PostIds)
        {
            bool found = false;
            foreach (Post p in pc)
            {
                if (i == p.Id)
                {
                    pcInUse.Add(p);
                    found = true;
                }
            }

            if (found)
            {
                pc.Remove(pcInUse[pcInUse.Count - 1]);
            }
        }

        the_Posts.DataSource = pc;
        the_Posts.DataBind();

        existing_items.Items.Clear();
        foreach (Post p in pcInUse)
        {
            existing_items.Items.Add(new OrderedListItem(string.Format(ItemFormat, p.Name, p.Id), p.Name,
                                                         p.Id.ToString()));
        }
    }
        public void AddPostTest()
        {
            // Arrange
            PostStruct postStruct = new PostStruct(1, "C:\\Users\\guita\\Documents\\School\\Eindhoven\\Semester2Herkansing\\Iteratie 4\\KillerAppMemePlatform2\\KillerAppMemePlatform1\\UploadedFilesBestSong.PNG - post.png", "Title", 1, 0, 1);

            Post testPost = new Post(postStruct);

            // Act
            PostCollection postCollection = new PostCollection();

            postCollection.Add(postStruct);

            List <IPost> post = postCollection.GetAllPosts();

            post.Reverse();

            IPost lastAdded = post[0];

            // Assert
            Assert.AreEqual(lastAdded.PostId, testPost.PostId);
        }
Esempio n. 8
0
 public FakeBloggersPointService()
 {
     _posts.Add(_post);
     _comments.Add(_comment);
     _authors.Add(_author);
 }
Esempio n. 9
0
        static void Main(string[] args)
        {
            int score = 0;

            Console.Write("TEST1: Ist die Post Klasse abstrakt? ");
            score += AssertTrue(() => typeof(Post).IsAbstract);

            Console.Write("TEST2: Kann ein TextPost angelegt werden? ");
            DateTime time = DateTime.Now.AddMinutes(-10);
            TextPost tp1  = new TextPost("Mein Titel");
            TextPost tp2  = new TextPost("Mein 2. Titel", time);

            score += AssertTrue(() => tp1.Title == "Mein Titel" && tp2.Created == time);

            Console.Write("TEST3: Kann ein ImagePost angelegt werden? ");
            ImagePost ip1 = new ImagePost("Mein Titel");
            ImagePost ip2 = new ImagePost("Mein Titel", time);

            score += AssertTrue(() => ip1.Title == "Mein Titel" && ip2.Created == time);

            Console.Write("TEST4: Stimmt die Länge des Postings? ");
            TextPost tp3 = new TextPost("Mein Titel", time);
            TextPost tp4 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp3.Length == 0 && tp4.Length == 7);

            Console.Write("TEST5: Stimmt das HTML Property von TextPost? ");
            Post tp5 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp5.Html == "<p>Content</p>");

            Console.Write("TEST6: Stimmt das HTML Property von ImagePost? ");
            Post ip3 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip3.Html == "<img src=\"http://image.png\">");

            Console.Write("TEST7: Stimmt die ToString Repräsentation von Post? ");
            object ip4 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip4.ToString() == "<img src=\"http://image.png\">");

            Console.Write("TEST8: Ist das Length Property von TextPost readonly? ");
            PropertyInfo info = typeof(TextPost).GetMember("Length")[0] as PropertyInfo;

            score += AssertTrue(() => info.CanWrite == false);

            Console.Write("TEST9: Ist das Title Property von Post readonly? ");
            PropertyInfo info2 = typeof(Post).GetMember("Title")[0] as PropertyInfo;

            score += AssertTrue(() => info2.CanWrite == false);

            Console.Write("TEST10: Funktioniert die PostCollection? ");
            TextPost tp6 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };
            ImagePost ip5 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };
            PostCollection pc1 = new PostCollection();

            pc1.Add(tp6);
            pc1.Add(ip5);
            score += AssertTrue(() => pc1.Count == 2);

            Console.Write("TEST11: Funktioniert CalcRating mit Lambdas? ");
            TextPost tp7 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip6 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc2 = new PostCollection();

            pc2.Add(tp7);
            pc2.Add(ip6);
            score += AssertTrue(() => pc2.CalcRating(p => p.Rating > 0 ? p.Rating : 0) == 10);

            Console.Write("TEST12: Funktioniert ProcessPosts mit Lambdas? ");
            TextPost tp8 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip7 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc3 = new PostCollection();

            pc3.Add(tp8);
            pc3.Add(ip7);
            int ratingSum = 0;

            pc3.ProcessPosts(p => ratingSum += p.Rating);
            score += AssertTrue(() => ratingSum == 9);

            double percent = score / 12.0;
            int    note    = percent > 0.875 ? 1 : percent > 0.75 ? 2 : percent > 0.625 ? 3 : percent > 0.5 ? 4 : 5;

            Console.WriteLine($"{score} von 12 Punkten erreicht. Note: {note}.");
            Console.ReadLine();
        }
Esempio n. 10
0
        private void GetPostsForRevision(XmlTextWriter writer)
        {
            string v = Request.QueryString["revision"];
            string p = Request.QueryString["id"];

            if (string.IsNullOrEmpty(p))
                throw new RESTConflict("The Post Id (id) querystring value is missing");

            int postid = Int32.Parse(p);

            int version = (Int32.Parse(v ?? "-1"));

            Query q = VersionStore.CreateQuery();
            q.AndWhere(VersionStore.Columns.ItemId, postid);
            q.AndWhere(VersionStore.Columns.Type, "post/xml");
            if (version > 0)
                q.AndWhere(VersionStore.Columns.Version, version);

            VersionStoreCollection vsc = VersionStoreCollection.FetchByQuery(q);
            PostCollection posts = new PostCollection();
            posts.Add(new Post(postid));

            foreach (VersionStore vs in vsc)
            {
                posts.Add(ObjectManager.ConvertToObject<Post>(vs.Data));
            }

            posts.Sort(delegate(Post p1, Post p2) { return Comparer<int>.Default.Compare(p2.Version, p1.Version); });

            writer.WriteStartElement("posts");
            writer.WriteAttributeString("pageIndex", "1");
            writer.WriteAttributeString("pageSize", posts.Count.ToString());
            writer.WriteAttributeString("totalPosts", posts.Count.ToString());
            foreach (Post post in posts)
            {
                if (version <= 0 || post.Version == version)
                    ConvertPostToXML(post, writer);
            }

            writer.WriteEndElement();
        }