IList <int> IOperationServiceInternal.GetOperationIds(int maxAge, bool onlyNonAcknowledged, int limitAmount) { List <int> operations = new List <int>(); using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { foreach (OperationData data in entities.Operations.OrderByDescending(o => o.TimestampIncome)) { // If we only want non-acknowledged ones if (onlyNonAcknowledged && data.IsAcknowledged) { continue; } // If we shall ignore the age, or obey the maximum age... if (maxAge > 0 && (DateTime.Now - data.TimestampIncome).TotalMinutes > maxAge) { continue; } operations.Add(data.Id); // If we need to limit operations if (limitAmount > 0 && operations.Count >= limitAmount) { break; } } } return(operations); }
void IDispositioningServiceInternal.Dispatch(int operationId, string emkResourceId) { lock (SyncRoot) { using (var entities = EntityFrameworkHelper.CreateContext <DispositioningEntities>(EdmxPath)) { bool exists = entities.DispResources.Any(_ => _.Operation_Id == operationId && _.EmkResourceId == emkResourceId); if (exists) { throw new InvalidOperationException(Properties.Resources.DispatchNotPossibleEntryAlreadyExists); } DispResourceData data = new DispResourceData(); data.Operation_Id = operationId; data.EmkResourceId = emkResourceId; data.Timestamp = DateTime.Now; entities.DispResources.AddObject(data); entities.SaveChanges(); } } DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Dispatch); OnDispositionEventArgs(args); }
public override void OnStart() { base.OnStart(); using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { } }
string[] IDispositioningServiceInternal.GetDispatchedResources(int operationId) { lock (SyncRoot) { using (var entities = EntityFrameworkHelper.CreateContext <DispositioningEntities>(EdmxPath)) { return(entities.DispResources.Where(_ => _.Operation_Id == operationId).Select(_ => _.EmkResourceId).ToArray()); } } }
bool IOperationServiceInternal.ExistsOperation(string operationNumber) { if (string.IsNullOrWhiteSpace(operationNumber)) { return(false); } using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { return(entities.Operations.Any(item => item.OperationNumber == operationNumber)); } }
Operation IOperationServiceInternal.StoreOperation(Operation operation) { using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { OperationData data = new OperationData(operation); entities.Operations.AddObject(data); entities.SaveChanges(); operation.Id = data.Id; return(operation); } }
private static void ApplySettingValue(string identifier, string name, SettingItem item) { using (SettingsEntities entities = EntityFrameworkHelper.CreateContext <SettingsEntities>(EdmxPath)) { UserSettingData userData = entities.GetUserSettingData(identifier, name); if (userData != null) { item.ApplyUserValue(userData.Value); } } }
private static void ImportUserSettings(XDocument doc) { using (MigrationSettingsEntities entities = EntityFrameworkHelper.CreateContext <MigrationSettingsEntities>("Data.SettingsEntities")) { foreach (XElement section in doc.Root.Elements("Section")) { string identifier = section.Attribute("Identifier").Value; foreach (XElement setting in section.Elements("UserSetting")) { try { string name = setting.Attribute("Name").Value; bool isNew = true; UserSettingData data = entities.UserSettings.FirstOrDefault(item => item.Identifier == identifier && item.Name == name); if (data == null) { data = new UserSettingData(); } else { isNew = false; Logger.Instance.LogFormat(LogType.Warning, null, Resources.OverwritingExistingItem, identifier, name); } data.Identifier = identifier; data.Name = name; data.Value = setting.Value; XAttribute isNull = setting.Attribute("IsNull"); if (isNull != null && isNull.Value.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { data.Value = null; } if (isNew) { entities.UserSettings.AddObject(data); } Logger.Instance.LogFormat(LogType.Info, null, Resources.SettingWritten, data.Identifier, data.Name); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, null, Resources.SettingWriteError); Logger.Instance.LogException(null, ex); } } } entities.SaveChanges(); } }
Operation IOperationServiceInternal.GetOperationById(int operationId) { List <Operation> operations = new List <Operation>(); using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { OperationData data = entities.Operations.FirstOrDefault(d => d.Id == operationId); if (data == null) { return(null); } return(data.ToOperation()); } }
private static bool CheckDatabaseReachable() { using (SystemEntities entities = EntityFrameworkHelper.CreateContext <SystemEntities>(EdmxPath)) { try { entities.Connection.Open(); return(true); } catch (Exception) { // Intentionally left blank --> database not reachable or other error. } } return(false); }
void IOperationServiceInternal.AcknowledgeOperation(int operationId) { using (OperationManagementEntities entities = EntityFrameworkHelper.CreateContext <OperationManagementEntities>(EdmxPath)) { OperationData data = entities.Operations.FirstOrDefault(d => d.Id == operationId); if (data == null || data.IsAcknowledged) { return; } data.IsAcknowledged = true; entities.SaveChanges(); } var copy = OperationAcknowledged; if (copy != null) { copy(operationId); } }
void IDispositioningServiceInternal.Recall(int operationId, string emkResourceId) { lock (SyncRoot) { using (var entities = EntityFrameworkHelper.CreateContext <DispositioningEntities>(EdmxPath)) { DispResourceData exists = entities.DispResources.SingleOrDefault(_ => _.Operation_Id == operationId && _.EmkResourceId == emkResourceId); if (exists == null) { throw new InvalidOperationException(Properties.Resources.RecallNotPossibleEntryDoesNotExist); } entities.DispResources.DeleteObject(exists); entities.SaveChanges(); } } DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Recall); OnDispositionEventArgs(args); }
private IList <SettingKey> SaveSettings(IEnumerable <KeyValuePair <SettingKey, SettingItem> > values) { List <SettingKey> keys = new List <SettingKey>(); using (SettingsEntities entities = EntityFrameworkHelper.CreateContext <SettingsEntities>(EdmxPath)) { foreach (var pair in values) { SettingKey key = pair.Key; IProxyType <string> value = pair.Value; try { if (AddOrUpdateSetting(entities, key, value)) { keys.Add(key); } } catch (ConstraintException ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingAddOrUpdateConstraintError, key); Logger.Instance.LogException(this, ex); } catch (DataException ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingAddOrUpdateError, key); Logger.Instance.LogException(this, ex); } } if (keys.Count > 0) { entities.SaveChanges(); } } return(keys); }