Automatic import products through the scheduler

Apr 20, 2010 at 10:08 AM
Edited Apr 20, 2010 at 10:12 AM

1. I want to make an automatic import of products through the scheduler. To do this, I created a dll file named Dorofei.SchedulerDLL.dll.   And copy to site bin folder.

2. Create the new shedule Dorofei.Modules.NB_Store.AutoImportXML, Dorofei.SchedulerDLL, but the products are not imported. ((

What am I doing wrong?


ps: File (Portals\0\ImportProducts.xml) updated automatic from the another prorgam.

ps: Code the dll:

Imports System.Reflection
Imports DotNetNuke.Services.Scheduling
Imports DotNetNuke.Services.Exceptions
Imports NEvoWeb.Modules.NB_Store.SharedFunctions
Imports System.IO
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities
Imports DotNetNuke.UI.Skins
Imports DotNetNuke.Entities.Tabs
Imports NEvoWeb.Modules.NB_Store

Namespace Dorofei.Modules.NB_Store
    Public Class AutoImportXML
        Inherits DotNetNuke.Services.Scheduling.SchedulerClient

        Public Sub New(ByVal objScheduleHistoryItem As DotNetNuke.Services.Scheduling.ScheduleHistoryItem)
            MyBase.new()
            Me.ScheduleHistoryItem = objScheduleHistoryItem
        End Sub

        Public Overrides Sub DoWork()
            Try

                'notification that the event is progressing
                'Me.Progressing()    'OPTIONAL

                Dim PS As New PortalSettings
                Dim imp As New Import
                Dim strMsg As String = ""
                Dim ImportFile As String = PS.HomeDirectoryMapPath & "ImportProducts.xml"

                strMsg = imp.ImportProducts(PS, ImportFile, True, True)

                Me.ScheduleHistoryItem.AddLogNote("Все данные успешно загружены. Вот инфо: " + strMsg)

                'update the result to success since no exception was thrown
                Me.ScheduleHistoryItem.Succeeded = True
                'Me.ScheduleHistoryItem.AddLogNote("Store Clean Up Carts Completed.")

            Catch exc As Exception
                Me.ScheduleHistoryItem.Succeeded = False
                Me.ScheduleHistoryItem.AddLogNote("Ошибка. Товары не импортированы." + exc.ToString)
                Me.ScheduleHistoryItem.Succeeded = False

                'notification that we have errored
                Me.Errored(exc)

                'log the exception
                LogException(exc)
            End Try
        End Sub

   End Class

End Namespace

 

 

Coordinator
Apr 20, 2010 at 10:34 AM
Hi, As long as your using DNN5 then this looks OK. (DNN4 doesn;t create the portalsettings when you create a new object, I think DNN5 does, but I've only been told this has been fixed in DNN5!) The only other thing I can think is the xml is incorrect in some way....have you tried debugging the import class? Regards, Dave.
Apr 21, 2010 at 10:00 AM

I was like this problem:

I see the item in the Schedule Item list. But if I check the history of the item, no rows are shown.  Also, in 'View Schedule Status', my task is listed but 273,3518959  is filled in in the column Overdue(seconds) and nothing is filled in  in the column Time remaining (seconds).

I am found this problem. It turns out that my class was named for another.

Now I get a message in history:

Все данные успешно загружены. Вот инфо: System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.Services.Localization.Localization.GetEnabledLocales() at NEvoWeb.Modules.NB_Store.Import.ImportProducts(PortalSettings PS, String ImportFile, Boolean UpdateExistingProductsFlg, Boolean CreateCategoriesFlg)



Coordinator
Apr 21, 2010 at 10:21 AM

Hi,

I think this may be because dnn is trying to get the current portal in order to go through languages

-------------------------------------------------

Dim objPortalSettings As PortalSettings = PortalController.GetCurrentPortalSettings()

--------------------------------------------

However I think the scheduler runs independant of portals....which means it's never going to find the current one!!

The only solution I can think of is to change the import class hard code the langauges you wish to process...

in the import.vb you need to change

--------------------------------------------

Dim supportedLanguages As LocaleCollection = DotNetNuke.Services.Localization.Localization.GetEnabledLocales()

--------------------------------------------

to remove the "...getenabledlocales" and then later in the code populate the supportlanguages collection with your required languages.

 

A more elegant solution maybe to pass in the langauge collection as an optional parameter and then use this, obvously if the langauge collection sis not passed in then the getenabledlangaues function is used.

If you do go for the second option, then if you pass me the code I can look at integrating it into the next release of NB_Store.

Regards,

Dave.

 

Apr 24, 2010 at 9:24 AM
Edited Apr 24, 2010 at 9:34 AM
Now everything works))
Apr 24, 2010 at 9:31 AM
Hi, I am replace text:
Dim supportedLanguages As LocaleCollection = DotNetNuke.Services.Localization.Localization.GetEnabledLocales()
to:
Dim supportedLanguages As New List(Of String)(DotNetNuke.Services.Localization.Localization.GetLocales(0).Keys)
note: Here is PortalID = 0
I replaced it not only in import.vb, but in many other files. And build NEvoweb.DNN.Modules.NB_Store.dll.
And also rewrote the code scheduler:
Imports System.Reflection
Imports DotNetNuke.Services.Scheduling
Imports DotNetNuke.Services.Exceptions
Imports NEvoWeb.Modules.NB_Store.SharedFunctions
Imports System.IO
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities
Imports DotNetNuke.UI.Skins
Imports DotNetNuke.Entities.Tabs
Imports NEvoWeb.Modules.NB_Store

Namespace Dorofei.Modules.NB_Store
    Public Class AutoImportXML
        Inherits DotNetNuke.Services.Scheduling.SchedulerClient

        Public Sub New(ByVal objScheduleHistoryItem As DotNetNuke.Services.Scheduling.ScheduleHistoryItem)
            MyBase.new()
            Me.ScheduleHistoryItem = objScheduleHistoryItem
        End Sub

        Public Overrides Sub DoWork()
            Try

                'notification that the event is progressing
                'Me.Progressing()    'OPTIONAL

                Dim PS As New PortalSettings
                Dim imp As New Import
                Dim strMsg As String = ""
                Dim ImportFile As String = DotNetNuke.Common.Globals.ApplicationMapPath & "\Portals\0\ImportProducts.xml" '!!!PortalID 
                PS.PortalId = 0
                strMsg = imp.ImportProducts(PS, ImportFile, True, True)

                Me.ScheduleHistoryItem.AddLogNote("Все данные успешно загружены. Вот инфо: " + strMsg)

                'update the result to success since no exception was thrown
                Me.ScheduleHistoryItem.Succeeded = True
                'Me.ScheduleHistoryItem.AddLogNote("Store Clean Up Carts Completed.")

            Catch exc As Exception
                Me.ScheduleHistoryItem.Succeeded = False
                Me.ScheduleHistoryItem.AddLogNote("Ошибка. Товары не импортированы." + exc.ToString)
                Me.ScheduleHistoryItem.Succeeded = False

                'notification that we have errored
                Me.Errored(exc)

                'log the exception
                LogException(exc)
            End Try
        End Sub

   End Class

End Namespace

 

 

Editor
Jun 30, 2014 at 10:47 AM
Was looking to reuse this, I wondered if this is still valid for the current release, Along side dnn6.1.x?
Editor
Jul 14, 2014 at 7:16 PM
Could this code be used for a sort of "Drop shipping" functionality?

Regards,

Geoff