uSync-Legacy icon indicating copy to clipboard operation
uSync-Legacy copied to clipboard

File Watcher Imports doesn't work

Open KevinJump opened this issue 10 years ago • 4 comments

The File watcher import - (import when files change on the disk) isn't currently working.

setting <WatchForFileChanges>true</WatchForFileChanges> in uSyncBackOffice.Config, should cause uSync back office to perform an import shortly (8.128 seconds) after an *.config files are copied into the usync folder.

at the moment this fails:

Error during import: System.NullReferenceException: Object reference not set to an instance of an object.
   at Umbraco.Web.RequestLifespanMessagesFactory.Get()
   at Umbraco.Core.Services.MediaService.Umbraco.Core.Services.IMediaServiceOperations.Save(IMedia media, Int32 userId, Boolean raiseEvents)
   at Umbraco.Core.Services.MediaService.Save(IMedia media, Int32 userId, Boolean raiseEvents)
   at Jumoo.uSync.Core.Serializers.MediaSerializer.DeserializeCore(XElement node, Int32 parentId, Boolean forceUpdate)
   at Jumoo.uSync.Core.Serializers.ContentBaseSerializer`1.Deserialize(XElement node, Int32 parentId, Boolean forceUpdate)
   at Jumoo.uSync.Content.MediaHandler.Import(String file, Int32 parentId, Boolean force)
   at Jumoo.uSync.Content.BaseContentHandler`1.ImportFolder(String folder, Int32 parentId, Boolean force, Dictionary`2 updates)
   at Jumoo.uSync.Content.BaseContentHandler`1.ImportFolder(String folder, Int32 parentId, Boolean force, Dictionary`2 updates)
   at Jumoo.uSync.Content.BaseContentHandler`1.ImportFolder(String folder, Int32 parentId, Boolean force, Dictionary`2 updates)
   at Jumoo.uSync.Content.BaseContentHandler`1.ImportAll(String folder, Boolean force)
   at Jumoo.uSync.BackOffice.uSyncBackOfficeContext.ImportAll(String folder, Boolean force)
   at Jumoo.uSync.BackOffice.uSyncFileWatcher.ChangeTimerElapsed(Object sender, ElapsedEventArgs e)

this is likely caused by issues with context from within the file events.

KevinJump avatar Dec 16 '15 12:12 KevinJump

Yes seems to be because System.Web.HttpContext.Current == null in threads running from the FileSystemWatcher which is understandable.

Umbraco.Web.RequestLifespanMessagesFactory.Get() assumes that _ctxAccessor.Value != null but in this case it is null as UmbracoContext.Current only returns a value if the HttpContext exists. i.e. Umbraco assumes all changes happen within HttpContext.

Not sure if this can be fixed within uSync code. At the moment I've changed Umbraco.Web.RequestLifespanMessagesFactory.Get() to check httpContext and return "new EventMessages();" if null. Still testing this.

graham-w2 avatar Mar 23 '16 13:03 graham-w2

i think it might require that usync builds up the bootmanager as is done in the umbraco console app examples. bit convoluted and not that fast to be honest. - but it will provide you with the context needed to do any changes.

KevinJump avatar Mar 23 '16 14:03 KevinJump

Just tried this again (um 7.4.3) and it seems to be working - I need to check a number of things, but i think there is a move to reduce the need for HttpContext in the core, and this might have had an effect on this.

KevinJump avatar Aug 25 '16 09:08 KevinJump

going to test this for the next release.

KevinJump avatar Sep 18 '16 12:09 KevinJump