Task Plugin not starting

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Ive created a new plugin in my application and the misc plugin contains 1 task.

Ive installed it, checked its enabled, and reduced the time to 60 seconds. I have also added logging.

Nothing happens, never gets used.

plugin code as follows:

    Plugin class
    

    public class MereSyncPlugin : BasePlugin, IMiscPlugin
    {
        private MereSyncObjectContext _context;
        private IScheduleTaskService _schedualTaskService;

        public MereSyncPlugin(MereSyncObjectContext context, IScheduleTaskService schedualTaskService)
        {
            _context = context;
            _schedualTaskService = schedualTaskService;
        }

        public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "";
            controllerName = "";
            routeValues = new RouteValueDictionary()
            {
                { "Namespaces", "Nop.plugin.Misc.MereSync.Controllers" },
                { "area", null }
            };  
        }

        public override void Install()
        {
            //TODO: add more
            _schedualTaskService.InsertTask(new Nop.Core.Domain.Tasks.ScheduleTask()
            {
                Enabled = true,
                Name = "Product Sync",
                Seconds = 3600,
                StopOnError = false,
                Type = "Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync"
            });
                
            //_context.Install();
            base.Install();
        }

        public override void Uninstall()
        {
            Nop.Core.Domain.Tasks.ScheduleTask task = _schedualTaskService.GetTaskByType("Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync");

            if (task != null)
                _schedualTaskService.DeleteTask(task);

            //_context.Uninstall();
            base.Uninstall();
        }
    }
    


    Object context class (although not set up at this point so commented out some parts)
    

    public class MereSyncObjectContext : DbContext, IDbContext
    {
        public bool ProxyCreationEnabled
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        public bool AutoDetectChangesEnabled
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        public MereSyncObjectContext(string nameOrConnectionString) : base(nameOrConnectionString)
        {

        }

        /*protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //TODO: insert ALL model MAPPINGS!!!!
            //modelBuilder.Configurations.Add(new insertnewmap());
            base.OnModelCreating(modelBuilder);
        }*/


        public string CreateDatabaseInstallationScript()
        {
            return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
        }

        public void Install()
        {
            Database.SetInitializer<MereSyncObjectContext>(null);
            Database.ExecuteSqlCommand(CreateDatabaseInstallationScript());
            SaveChanges();
        }

        public void Uninstall()
        {
            //this.DropPluginTable("MereSys_TableName");
        }

        IDbSet<TEntity> IDbContext.Set<TEntity>()
        {
            return base.Set<TEntity>();
        }

        public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters)
        {
            throw new NotImplementedException();
        }

        public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = default(int?), params object[] parameters)
        {
            throw new NotImplementedException();
        }

        public void Detach(object entity)
        {
            throw new NotImplementedException();
        }
    }
    


    Task class
    

    public class ProductSyncTask : ITask
    {
        private readonly ILogger _logger;
        public ProductSyncTask(ILogger logger)
        {
            this._logger = logger;
        }
        public async void Execute()
        {
            //TODO: Call My method, USE BEST PRACTICE, IoC DI
            //throw new NotImplementedException();
            _logger.InsertLog(Nop.Core.Domain.Logging.LogLevel.Information, "Start", "Product sync has started");
            ProductSyncService test = new ProductSyncService();
            await test.GetProductsAsync();
        }


    }
    


The rest fo the code isnt relevant as its just a service class etc. When i go to Nops logging, admin area > system > log  nothing shows up.  when i check to see if my task is enabled its true, but hasnt run. My plugin appears to be installed too.

What am i missing here?

Thanks!

UPDATE

A public action method 'null' was not found on controller 'Nop.Admin.Controllers.PluginController'.

System.Web.HttpException (0x80004005): A public action method 'null' was not found on controller 'Nop.Admin.Controllers.PluginController'. at System.Web.Mvc.Controller.HandleUnknownAction(String actionName) at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
7 years ago
Make sure Type = "Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync" is correct or not.

1st part is task with namespace
2nd part plugin namespace


check it by pressing run now from schedule task list in debug mode.

Note: clean build whole soln
7 years ago
Ran the task in debug mode, set up breakpoints on the class constructor to see if its ever hit.

No break point is hit.  Checked names, no issues. "Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync"

Am I missing anything vital?
7 years ago
[email protected] wrote:
Ran the task in debug mode, set up breakpoints on the class constructor to see if its ever hit.

No break point is hit.  Checked names, no issues. "Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync"

Am I missing anything vital?

Have you tried it without the async modifier on the task's Execute() method?
7 years ago
[email protected] wrote:
Ran the task in debug mode, set up breakpoints on the class constructor to see if its ever hit.

No break point is hit.  Checked names, no issues. "Nop.Plugin.Misc.MereSync.ProductSyncTask, Nop.Plugin.Misc.MereSync"

Am I missing anything vital?

Have you tried it without the async modifier on the task's Execute() method?
7 years ago
Yes that was my first thought.  But no still doesnt work. Its almost like the task never runs, I have a feeling though that im missing a vital part of code like 1 line. I have looked at some other examples but cant seem to find what the difference is
7 years ago
Ok I think ive found an issue, Went to event viewer and have seena  warning on my plugin saying "Plugin 'MereSync'. Could not load file or assembly Microsoft.Data.Edm, etc etc " " The located assembly's manifest definition does not match the assembly reference."

I think my module isnt actually being loaded correctly, the task is probably running fine, just cant fire the plugin code.

Any reason why im getting this message?
7 years ago
ok fixed the issue, deleted all files in presentation in my plugin, did a clean rebuild and set all refs to copy local false(always forget to do this). started site in debug, still not hitting my task :(
7 years ago
I have put this question on
http://stackoverflow.com/questions/41484284/nopcommerce-task-plugin-not-starting-task
too
7 years ago
Answer on stack
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.