private static void UpdateFilesystemKey(Model.ServiceLock item) { IPersistentStore store = PersistentStoreRegistry.GetDefaultStore(); using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush)) { ServiceLockUpdateColumns columns = new ServiceLockUpdateColumns(); columns.FilesystemKey = item.FilesystemKey; IServiceLockEntityBroker broker = ctx.GetBroker <IServiceLockEntityBroker>(); broker.Update(item.Key, columns); ctx.Commit(); } }
/// <summary> /// Update a service in the database. /// </summary> /// <param name="key"></param> /// <returns><b>true</b> if the record is updated successfully. <b>false</b> otherwise.</returns> /// <param name="enabled"></param> /// <param name="scheduledDateTime"></param> public bool UpdateServiceLock(ServerEntityKey key, bool enabled, DateTime scheduledDateTime) { Platform.Log(LogLevel.Info, "User updating service Key={0}", key.Key); ServiceLockUpdateColumns columns = new ServiceLockUpdateColumns(); columns.Enabled = enabled; columns.ScheduledTime = scheduledDateTime; bool ok = _adapter.Update(key, columns); Platform.Log(LogLevel.Info, "ServiceLock Key={0} {1}", key.Key, ok ? "updated by user" : " failed to update"); return(ok); }
static public ServiceLock Insert(IUpdateContext update, ServiceLock entity) { var broker = update.GetBroker <IServiceLockEntityBroker>(); var updateColumns = new ServiceLockUpdateColumns(); updateColumns.ServiceLockTypeEnum = entity.ServiceLockTypeEnum; updateColumns.Lock = entity.Lock; updateColumns.ScheduledTime = entity.ScheduledTime; updateColumns.Enabled = entity.Enabled; updateColumns.State = entity.State; updateColumns.FilesystemKey = entity.FilesystemKey; updateColumns.ProcessorId = entity.ProcessorId; ServiceLock newEntity = broker.Insert(updateColumns); return(newEntity); }
/// <summary> /// Updates the 'State' of the filesystem associated with the 'FilesystemDelete' <see cref="ServiceLock"/> item /// </summary> /// <param name="item"></param> /// <param name="fs"></param> private static void UpdateState(Model.ServiceLock item, ServerFilesystemInfo fs) { FilesystemState state = null; if (item.State != null && item.State.DocumentElement != null) { //load from datatabase state = XmlUtils.Deserialize <FilesystemState>(item.State.DocumentElement); } if (state == null) { state = new FilesystemState(); } if (fs.AboveHighWatermark) { // we don't want to generate alert if the filesystem is offline or not accessible. if (fs.Online && (fs.Readable || fs.Writeable)) { TimeSpan ALERT_INTERVAL = TimeSpan.FromMinutes(ServiceLockSettings.Default.HighWatermarkAlertInterval); if (state.AboveHighWatermarkTimestamp == null) { state.AboveHighWatermarkTimestamp = Platform.Time; } TimeSpan elapse = (state.LastHighWatermarkAlertTimestamp != null) ? Platform.Time - state.LastHighWatermarkAlertTimestamp.Value : Platform.Time - state.AboveHighWatermarkTimestamp.Value; if (elapse.Duration() >= ALERT_INTERVAL) { ServerPlatform.Alert(AlertCategory.System, AlertLevel.Warning, "Filesystem", AlertTypeCodes.LowResources, null, TimeSpan.Zero, SR.AlertFilesystemAboveHW, fs.Filesystem.Description, TimeSpanFormatter.Format(Platform.Time - state.AboveHighWatermarkTimestamp.Value, true)); state.LastHighWatermarkAlertTimestamp = Platform.Time; } } else { state.AboveHighWatermarkTimestamp = null; state.LastHighWatermarkAlertTimestamp = null; } } else { state.AboveHighWatermarkTimestamp = null; state.LastHighWatermarkAlertTimestamp = null; } XmlDocument stateXml = new XmlDocument(); stateXml.AppendChild(stateXml.ImportNode(XmlUtils.Serialize(state), true)); IPersistentStore store = PersistentStoreRegistry.GetDefaultStore(); using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush)) { ServiceLockUpdateColumns columns = new ServiceLockUpdateColumns(); columns.State = stateXml; IServiceLockEntityBroker broker = ctx.GetBroker <IServiceLockEntityBroker>(); broker.Update(item.GetKey(), columns); ctx.Commit(); } }