KevinJump / uSync-Legacy

uSync for Umbraco 4/6 - bits of the database to disk, and stuff like that
https://jumoo.co.uk/usync/
Mozilla Public License 2.0
75 stars 64 forks source link

File Watcher Imports doesn't work #10

Open KevinJump opened 8 years ago

KevinJump commented 8 years ago

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.

graham-w2 commented 8 years ago

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.

KevinJump commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

going to test this for the next release.