/// <summary>
        /// Set a <see cref="ServiceLock"/> entry to pending.
        /// </summary>
        /// <param name="item">The <see cref="ServiceLock"/> entry to set.</param>
        /// <param name="scheduledTime"></param>
        /// <param name="enabled">Bool telling if the ServiceLock entry should be enabled after unlock.</param>
        protected static void UnlockServiceLock(Model.ServiceLock item, bool enabled, DateTime scheduledTime)
        {
            using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                // Update the WorkQueue item status and times.
                IUpdateServiceLock update = updateContext.GetBroker<IUpdateServiceLock>();

                ServiceLockUpdateParameters parms = new ServiceLockUpdateParameters
                                                    	{
                                                    		ServiceLockKey = item.GetKey(),
                                                    		Lock = false,
                                                    		ScheduledTime = scheduledTime,
                                                    		ProcessorId = item.ProcessorId,
                                                    		Enabled = enabled
                                                    	};

            	if (false == update.Execute(parms))
                {
                    Platform.Log(LogLevel.Error, "Unable to update StudyLock GUID Status: {0}",
                                 item.GetKey().ToString());
                }

                updateContext.Commit();
            }
        }
예제 #2
0
        /// <summary>
        /// Reset the Lock for a specific <see cref="Model.ServiceLock"/> row.
        /// </summary>
        /// <param name="item">The row to reset the lock for.</param>
        private void ResetServiceLock(Model.ServiceLock item)
        {
            // keep trying just in case of db error
            while(true)
            {
                try
                {
                    using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
                    {
                        // Update the ServiceLock item status and times.
                        IUpdateServiceLock update = updateContext.GetBroker<IUpdateServiceLock>();

                        ServiceLockUpdateParameters parms = new ServiceLockUpdateParameters();
                        parms.ServiceLockKey = item.GetKey();
                        parms.Lock = false;
                        parms.ScheduledTime = Platform.Time.AddMinutes(10);
                        parms.ProcessorId = item.ProcessorId;

                        if (false == update.Execute(parms))
                        {
                            Platform.Log(LogLevel.Error, "Unable to update ServiceLock GUID Status: {0}",
                                         item.GetKey().ToString());
                        }

                        updateContext.Commit();
                    }

                    break;
                }
                catch(Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex, "Exception has occured when trying to reset the entry. Retry later");
                    _terminationEvent.WaitOne(2000, false);
                }
            }
            
        }