Plugin for new task

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 年 前
Hi there!
I m trying to implement new task during plugin installation.

So its look like^

    public class ProductUpdatingServicePlugin : BasePlugin, IAdminMenuPlugin
    {
        private ProductUpdateLogRecordObjectContext _productUpdateLogRecordObjectContext;
        private IRepository<ProductUpdateLogRecord> _productUpdateRepository;
        public ProductUpdatingServiceSettings _productUpdatingServiceSettings { get; private set; }
        public ISettingService _settingService { get; private set; }
        public ScheduleTaskService _scheduleTaskService { get; private set; }

        public ProductUpdatingServicePlugin(
        ISettingService settingService,
        ProductUpdatingServiceSettings productUpdatingServiceSettings,
        ProductUpdateLogRecordObjectContext productUpdateLogRecordObjectContext,
        ScheduleTaskService scheduleTaskService,
        IRepository<ProductUpdateLogRecord> productUpdateRepository)
        {
            this._settingService = settingService;
            this._productUpdatingServiceSettings = productUpdatingServiceSettings;
            this._scheduleTaskService = scheduleTaskService;
            this._productUpdateLogRecordObjectContext = productUpdateLogRecordObjectContext;
            this._productUpdateRepository = productUpdateRepository;
        }
        public override void Install()
        {
            var settings = new ProductUpdatingServiceSettings()
            {
                ODBCName = "",
            };

            _settingService.SaveSetting(settings);

            _scheduleTaskService.InsertTask(new ScheduleTask
            {
                Enabled = true,
                Name = "Product sync log",
                Seconds = 3600,
                StopOnError = false,
                Type = "Nop.Plugin.Misc.ProductUpdatingService, Nop.Plugin.Misc.ProductUpdatingService.Tasks",
            });

            //locales
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName", "ODBC connection Name");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName.Hint", "Insert ODBC connection name");

            _productUpdateLogRecordObjectContext.Install();

            base.Install();
        }

        public override void Uninstall()
        {
            //locales
            this.DeletePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName");
            this.DeletePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName.Hint");

            ScheduleTask task = _scheduleTaskService.GetTaskByType("Nop.Plugin.Misc.ProductUpdatingService, Nop.Plugin.Misc.ProductUpdatingService.Tasks");

            if (task != null)
            {
                _scheduleTaskService.DeleteTask(task);
            }

            _productUpdateLogRecordObjectContext.Uninstall();
            base.Uninstall();
        }



but I receive an error.

An exception of type 'Autofac.Core.Registration.ComponentNotRegisteredException' occurred in Autofac.dll but was not handled in user code

Additional information: The requested service 'Nop.Services.Tasks.ScheduleTaskService' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.


Could u please explain to me how ш  can avoid it and get it works?
7 年 前
art_MOO wrote:
Hi there!
I m trying to implement new task during plugin installation.

So its look like^
...

Could u please explain to me how ш  can avoid it and get it works?


Hello,

At first glance you need to change this:

public ScheduleTaskService _scheduleTaskService { get; private set; }

to this:

public IScheduleTaskService _scheduleTaskService { get; private set; }

I haven't checked the rest of the code, but if everything is okay with it, yuo should not have any other problems.

Hope this helps!

Regards,
Hristian
7 年 前
Solved! Thanks a lot!
7 年 前
Ok but it's not work. That's the problem.
So right now I can see it, but I set up a breakpoint on executing method in Itask Class and I don't come to it when clock to Run now. Why it can be?
7 年 前
Ok never minds - solved - the error was in assembly name. I have to say that this product(Nopcommerce) is awesome. And support is also great!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.