Developer forum

Forum » Development » NewsV2 ( News.Notifications.ItemSaved)

NewsV2 ( News.Notifications.ItemSaved)

George Nelzo Pereira
Reply

Hi people,

I'm trying make some changes for every new news.
I'm using the same code what Imar was post.

When I change the code:

 

//news.Item.NewsAuthor = "me";
//news.Item.Save();

to (just uncomment)

news.Item.NewsAuthor = "George";
news.Item.Save();
 
They save and restart the application.
If I'm debugging, looks like a looping in the notifications, they try saving a lot.
I tryid get a new version, create a new aplication... but still the same error. :(
 
Someone have any ideas?
 
That the error (event wiewer)
 
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: nlssorting.dll, version: 4.0.30319.296, time stamp: 0x504835c7
Exception code: 0xc00000fd
Fault offset: 0x0000000000002296
Faulting process id: 0x17fc
Faulting application start time: 0x01cdcca27d05b003
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\nlssorting.dll
 
-------------
 
Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0
 
Problem signature:
P1: w3wp.exe
P2: 7.5.7601.17514
P3: 4ce7afa2
P4: nlssorting.dll
P5: 4.0.30319.296
P6: 504835c7
P7: c00000fd
P8: 0000000000002296
P9: 
P10: 
 
Attached files:
 
These files may be available here:
 
Analysis symbol: 
Rechecking for solution: 0
Report Id: d96d68ee-3895-11e2-9c49-2c41382bcdf0
 


Replies

 
Pavel Volgarev
Reply
This post has been marked as an answer

Hi George,

The notification is fired from within the "Save" method of the news item so that's why you get an infinite loop. I've added an "ItemSaving" notification that is fired right before the record is committed to the database. Use it like this:

[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.NewsV2.ItemSaving)]
public class NewsV2ItemSavingObserver : Dynamicweb.Extensibility.NotificationSubscriber
{
    public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
    {
        Dynamicweb.NewsV2.Extensibility.NewsItemNotificationArgs news = (Dynamicweb.NewsV2.Extensibility.NewsItemNotificationArgs)args;
        
        news.Item.NewsAuthor = "me";

        // No need to call "Save"
    }
}

The notification will be available in Dynamicweb 8.2 (to be released very soon). Alternatively you can cast the item instance to "Dynamicweb.Modules.Common.DbObject" and call "Save" method on it:

(news.Item as Dynamicweb.Modules.Common.DbObject).Save();

-- Pavel

 

 

Votes for this answer: 1
 
George Nelzo Pereira
Reply

Hi Pavel, thanks for your reply.

yep... for now... if  I don't use .save, I cannot keep my informations on DB.

In your code you use : Dynamicweb.Notifications.NewsV2.ItemSaving
And Imar code use: Dynamicweb.Modules.News.Notifications.ItemSaved

That's (likes your code) will see on 8.2, correct?

I've tryid you suggestion (with casting) but keep in looping...
I will wait for 8.2. :(

Thank you so much.

 
Pavel Volgarev
Reply
This post has been marked as an answer

Hi George,

 

Okay, my bad. Apparently you can't do that trick with casting to a base class. But regarding the "ItemSaving" notification - yes, that's an upcoming feature.

 

-- Pavel

Votes for this answer: 1

 

You must be logged in to post in the forum