public static SafeXmlReaderWriter Get(IScopeProvider scopeProvider, SystemLock xmlLock, XmlDocument xml, Action <XmlDocument> refresh, Action <XmlDocument, bool> apply, bool writer) { var scopeContext = scopeProvider.Context; // no real scope = just create a reader/writer instance if (scopeContext == null) { // obtain exclusive access to xml and create reader/writer var releaser = xmlLock.Lock(); return(new SafeXmlReaderWriter(releaser, xml, refresh, apply, writer, false)); } // get or create an enlisted reader/writer var rw = scopeContext.Enlist(EnlistKey, () => // creator { // obtain exclusive access to xml and create reader/writer var releaser = xmlLock.Lock(); return(new SafeXmlReaderWriter(releaser, xml, refresh, apply, writer, true)); }, (completed, item) => // action { item.DisposeForReal(completed); }, EnlistPriority); // ensure it's not already in-use - should never happen, just being super safe if (rw._using) { throw new InvalidOperationException("panic: used."); } rw._using = true; return(rw); }
public MainDomSemaphoreLock(ILogger logger) { var lockName = "UMBRACO-" + MainDom.GetMainDomId() + "-MAINDOM-LCK"; _systemLock = new SystemLock(lockName); var eventName = "UMBRACO-" + MainDom.GetMainDomId() + "-MAINDOM-EVT"; _signal = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); _logger = logger; }
public MainDomSemaphoreLock(ILogger <MainDomSemaphoreLock> logger, IHostingEnvironment hostingEnvironment) { var mainDomId = MainDom.GetMainDomId(hostingEnvironment); var lockName = "UMBRACO-" + mainDomId + "-MAINDOM-LCK"; _systemLock = new SystemLock(lockName); var eventName = "UMBRACO-" + mainDomId + "-MAINDOM-EVT"; _signal = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); _logger = logger; }
public MainDomSemaphoreLock(ILogger <MainDomSemaphoreLock> logger, IHostingEnvironment hostingEnvironment) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new PlatformNotSupportedException("MainDomSemaphoreLock is only supported on Windows."); } var mainDomId = MainDom.GetMainDomId(hostingEnvironment); var lockName = "UMBRACO-" + mainDomId + "-MAINDOM-LCK"; _systemLock = new SystemLock(lockName); var eventName = "UMBRACO-" + mainDomId + "-MAINDOM-EVT"; _signal = new EventWaitHandle(false, EventResetMode.AutoReset, eventName); _logger = logger; }