This project is read-only.

Threading

Jul 12, 2008 at 8:59 PM
Edited Jul 13, 2008 at 12:56 AM
Hello All,


I am working on setting up my install of N2 to be able to take a Google news feed and turning  it in to News items. i am able to do so.

but i am trying to spin the process of updating the items off to a new Thread  get it to do so but when ever i call my n2query it  tells me that my  that i have no session or it was closed.


what do i need to pass to the new thread so that it can work with in the n2 system?


Thanks for all your help
Elizabeth

P.S. can you tell me what green items on the tree in edit mode means?
Public Sub UpdateNews(ByVal start As N2.ContentItem)

            Dim parameters() As Object = {start, HttpContext.Current,  N2.Context.Current}
            Dim pts As New ParameterizedThreadStart(AddressOf GetNews)
            Dim thread As New Thread(pts)
            thread.Name = "GetNews"
            thread.Priority = ThreadPriority.BelowNormal
            thread.Start(parameters)
        End Sub

        Public Shared Sub GetNews(ByVal data As Object)
            Dim parameters() As Object = CType(data, Object())
            Dim start As N2.ContentItem = CType(parameters(0),  N2.ContentItem)
            Dim context As HttpContext = CType(parameters(1), HttpContext)
            Dim test AsN2.Context = CType(parameters(2), N2.Context)
            Dim rss As GoogleRss
            Dim mCategorys As List(Of NewsCategory)
            Dim mArticals As List(Of Google_News_Artical)
            mCategorys = N2.Find.OfType(Of NewsCategory)(start.GetChildren(New TypeFilter(GetType(NewsCategory))))

            For Each Item As NewsCategory In mCategorys
                If Item.FeedUrl.Trim.Length > 0 Then
                    rss = GoogleRss.Load(New System.Uri(Item.FeedUrl))
                    For Each GoogleItem In rss.Channel.Items  mArticals=N2.Find.Items.Where.Type.Eq(GetType(Google_News_Artical)).And.Detail("Guid").Eq(GoogleItem.Guid.Text).MaxResults(1).Select(Of Google_News_Artical)()
                        If Not mArticals.Count > 0 Then
                            Dim mArtical As Google_News_Artical = N2.Context.Definitions.CreateInstance(Of Google_News_Artical)(start)
                            mArtical.Title = GoogleItem.Title
                            mArtical.Source = Regex.Match(GoogleItem.Description, "(?<=<font color=.*>).*(?=-</)").ToString
                            mArtical.Summary = Regex.Replace(Regex.Match(GoogleItem.Description, "(?<=</font><br><font size=.*>).*(?=</b></font>)").ToString, "<[^>]*>", String.Empty).ToString
                            mArtical.Text = mArtical.Summary
                            mArtical.StoryUrl = GoogleItem.Link
                            mArtical.StoryImage = Regex.Match(GoogleItem.Description, "(?<=<img src=).*(?= width=\d{2} height=\d{2} alt=.*>)").ToString
                            mArtical.Guid = GoogleItem.Guid.Text
      N2.Context.Persister.Save(mArtical)
                        End If
                    Next
                End If
            Next

        End Sub