/// <summary> /// Merge the actual database values with the object from Core Change Tracker. /// </summary> /// <param name="ctx">Database context instance.</param> /// <param name="modalEntity">The instance returned from the action.</param> /// <param name="formKeys">List of user informed fields.</param> /// <returns>Returns the merged entity.</returns> public static object Merge(this CoreDbContext ctx, IKeyed modalEntity, IEnumerable <string> formKeys) { var type = modalEntity.GetType(); var dbEntity = ctx.Entry(ctx.Find(type, modalEntity.ID)); var changedProperties = formKeys.Where(x => type.GetProperty(x) != null).ToDictionary(k => k, v => type.GetProperty(v).GetValue(modalEntity)); if (changedProperties != null && changedProperties.Count() > 0) { dbEntity.CurrentValues.SetValues(changedProperties.ToDictionary(k => k.Key, v => v.Value)); } if (changedProperties.Count(x => dbEntity.Properties.Count(y => y.Metadata.Name == x.Key) == 0) > 0) { //Set value for unmapped properties in DB var unmappedProperties = changedProperties.Where(x => dbEntity.Properties.Count(y => y.Metadata.Name == x.Key) == 0); foreach (var property in unmappedProperties) { var prop = dbEntity.Entity.GetType().GetProperty(property.Key); if (prop.SetMethod != null) //Checks if it has set method { prop.SetValue(dbEntity.Entity, property.Value); } } } return(dbEntity.Entity); }
internal void DomainCollectionTests(Messenger m, IKeyed <int, PersonDO> collection) { GIVEN["a collection and a Messenger"] = () => collection = collection.Create(m = CreateMesseneger(), x => x.ID, x => { x.Apply <PersonAdded>((e, c) => c.Add(e)); x.Apply <PersonChanged>((e, c) => c.Set(e.ID, e)); x.Apply <PersonRemoved>((e, c) => c.Remove(e.ID)); }); WHEN["sending an add event"] = () => m.ApplyChange(new PersonAdded { ID = 1, Name = "N1" }); THEN["the item is added"] = () => collection.Should().BeEquivalentTo(new PersonDO { ID = 1, Name = "N1" }); WHEN["sending a set event"] = () => m.ApplyChange(new PersonChanged { ID = 1, Name = "N2" }); THEN["the item is replaced"] = () => collection.Should().BeEquivalentTo(new PersonDO { ID = 1, Name = "N2" }); WHEN["sending a remove event"] = () => m.ApplyChange(new PersonRemoved { ID = 1 }); THEN["the item is added"] = () => collection.Should().BeEquivalentTo(); }
/// <summary> /// Logs to Console when at-level, and all messages to error log, including device key /// </summary> public static void Console(uint level, IKeyed dev, string format, params object[] items) { if (Level >= level) { Console(level, "[{0}] {1}", dev.Key, string.Format(format, items)); } }
//static void DoDeviceCommand(string command) //{ // Debug.Console(0, "Not yet implemented. Stay tuned"); //} public static void AddDevice(IKeyed newDev) { try { if (!DeviceCriticalSection.TryEnter()) { Debug.Console(0, Debug.ErrorLogLevel.Error, "Currently unable to add devices to Device Manager. Please try again"); return; } // Check for device with same key //var existingDevice = _Devices.FirstOrDefault(d => d.Key.Equals(newDev.Key, StringComparison.OrdinalIgnoreCase)); ////// If it exists, remove or warn?? //if (existingDevice != null) if (!AddDeviceEnabled) { Debug.Console(0, Debug.ErrorLogLevel.Error, "All devices have been activated. Adding new devices is not allowed."); return; } if (Devices.ContainsKey(newDev.Key)) { Debug.Console(0, newDev, "WARNING: A device with this key already exists. Not added to manager"); return; } Devices.Add(newDev.Key, newDev); //if (!(_Devices.Contains(newDev))) // _Devices.Add(newDev); } finally { DeviceCriticalSection.Leave(); } }
public static void RemoveDevice(IKeyed newDev) { try { DeviceCriticalSection.Enter(); if (newDev == null) { return; } if (Devices.ContainsKey(newDev.Key)) { Devices.Remove(newDev.Key); } //if (_Devices.Contains(newDev)) // _Devices.Remove(newDev); else { Debug.Console(0, "Device manager: Device '{0}' does not exist in manager. Cannot remove", newDev.Key); } } finally { DeviceCriticalSection.Leave(); } }
public LoadRequest(ResourceType type, IKeyed holder, AttachmentKey key, ResourceDomain domain, IResult result) { Type = type; _holder = new WeakReference <IKeyed>(holder); Key = key; Domain = domain; Result = result; }
public AsyncResult <T> LoadResource <T>(ResourceType <T> type, IKeyed holder, AttachmentKey key, ResourceDomain domain) { var result = new AsyncResult <T>(); var request = new LoadRequest(type, holder, key, domain, result); _loadRequests.Enqueue(request); return(result); }
/// <summary> /// Get case insensitive hashcode for key /// </summary> public int GetHashCode(IKeyed keyed) { if (keyed == null) { return(0); // per BCL convention } return(GetHashCode(keyed.Key)); }
/// <summary> /// Logs to both console and the custom user log (not the built-in error log). If appdebug level is set at /// or above the level provided, then the output will be written to both console and the log. Otherwise /// it will only be written to the log. /// </summary> /// <param name="level"></param> /// <param name="dev"></param> /// <param name="format">String.format string</param> /// <param name="items">Parameters for substitution in the format string.</param> public static void ConsoleWithLog(uint level, IKeyed dev, string format, params object[] items) { var str = string.Format(format, items); if (Level >= level) { ConsoleWithLog(level, "[{0}] {1}", dev.Key, str); } }
public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel, string format, params object[] items) { if (SaveData.Level >= level) { var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items)); Console(level, str); LogError(errorLogLevel, str); } }
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel, string format, params object[] items) { var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items)); LogError(errorLogLevel, str); if (Level >= level) { Console(level, str); } }
/// <summary> /// Compare keyed operands /// </summary> public bool Equals(IKeyed x, IKeyed y) { if (x == null && y == null) { return(true); } else if (x == null || y == null) { return(false); } return(Equals(x.Key, y.Key)); }
//static void DoDeviceCommand(string command) //{ // Debug.Console(0, "Not yet implemented. Stay tuned"); //} public static void AddDevice(IKeyed newDev) { // Check for device with same key //var existingDevice = _Devices.FirstOrDefault(d => d.Key.Equals(newDev.Key, StringComparison.OrdinalIgnoreCase)); ////// If it exists, remove or warn?? //if (existingDevice != null) if (Devices.ContainsKey(newDev.Key)) { Debug.Console(0, newDev, "WARNING: A device with this key already exists. Not added to manager"); return; } Devices.Add(newDev.Key, newDev); //if (!(_Devices.Contains(newDev))) // _Devices.Add(newDev); }
/// <summary> /// Poll is a provided action instead of string /// </summary> /// <param name="parent"></param> /// <param name="client"></param> /// <param name="pollTime"></param> /// <param name="warningTime"></param> /// <param name="errorTime"></param> /// <param name="pollBytes"></param> public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime, long warningTime, long errorTime, Action pollAction) : base(parent, warningTime, errorTime) { if (pollTime > warningTime || pollTime > errorTime) { throw new ArgumentException("pollTime must be less than warning or errorTime"); } //if (pollTime < 5000) // throw new ArgumentException("pollTime cannot be less than 5000 ms"); Client = client; PollTime = pollTime; PollAction = pollAction; }
public static IKeyed <TKey, TItem> Create <TKey, TItem>( this IKeyed <TKey, TItem>?template, Messenger messenger, Func <TItem, TKey> keySelector, Action <Configurator <IKeyedCollectionMutator <TKey, TItem> > > config ) where TKey : notnull { var collection = new KeyedCollection <TKey, TItem>(keySelector); var configurator = new Configurator <IKeyedCollectionMutator <TKey, TItem> >( messenger, new KeyedCollectionMutator <TKey, TItem>(collection)); config(configurator); return(collection); }
public static void RemoveDevice(IKeyed newDev) { if (newDev == null) { return; } if (Devices.ContainsKey(newDev.Key)) { Devices.Remove(newDev.Key); } //if (_Devices.Contains(newDev)) // _Devices.Remove(newDev); else { Debug.Console(0, "Device manager: Device '{0}' does not exist in manager. Cannot remove", newDev.Key); } }
public StatusMonitorBase(IKeyed parent, long warningTime, long errorTime) { Parent = parent; if (warningTime > errorTime) { throw new ArgumentException("warningTime must be less than errorTime"); } if (warningTime < 5000 || errorTime < 5000) { throw new ArgumentException("time values cannot be less that 5000 ms"); } IsOnlineFeedback = new BoolFeedback(() => { return(IsOnline); }); Status = MonitorStatus.StatusUnknown; WarningTime = warningTime; ErrorTime = errorTime; }
public static void RegisterKeyed <TInterface, TConcrete, TKey>(this IUnityContainer container, TKey key) where TConcrete : TInterface { IKeyed <TKey, TInterface> existing = null; var isRegistered = container.IsRegistered <IKeyed <TKey, TInterface> >(); if (isRegistered) { existing = container.Resolve <IKeyed <TKey, TInterface> >(); } if (existing == null) { existing = new Keyed <TKey, TInterface>(); container.RegisterInstance(existing); } ((Keyed <TKey, TInterface>)existing).Add <TConcrete>(key, container); }
public virtual Variable Get(Key key, Logger log = null) { if (key.AtEnd) { return(this); } if (!IsSet) { Logger.LogF(log, Logger.Level.Error, StringsScripting.Formatted_IKeyedGet_Variable_Unset, key); return(null); } IKeyed value = Value as IKeyed; if (value == null) { Logger.LogF(log, Logger.Level.Error, StringsScripting.Formatted_Variable_not_found, key); return(null); } return(value.Get(key, log)); }
public bool Equals(IKeyed other) { return(other?.Key == Key); }
public int GetHashCode(IKeyed obj) { return(obj.Key.GetHashCode()); }
public int CompareTo(IKeyed other) { return(string.CompareOrdinal(Key, other?.Key)); }
private static CrestronGenericBaseDevice GetDmRmcControllerForCpu3Chassis(string key, string name, string typeName, Switch chassis, uint num, IKeyed parentDev) { Func <string, string, DMOutput, CrestronGenericBaseDevice> cpu3Handler; if (ChassisCpu3Dict.TryGetValue(typeName.ToLower(), out cpu3Handler)) { return(cpu3Handler(key, name, chassis.Outputs[num])); } Debug.Console(0, "Cannot create DM-RMC of type '{0}' with parent device {1}", typeName, parentDev.Key); return(null); }
public StatusMonitorCollection(IKeyed parent) { Parent = parent; }
/// <summary> /// Build the monitor from a config object /// </summary> public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, CommunicationMonitorConfig props) : this(parent, client, props.PollInterval, props.TimeToWarning, props.TimeToError, props.PollString) { }
public Factory(IKeyed <FactoryType, IHandler> handlers) { _handlers = handlers; }
public CrestronGenericBaseCommunicationMonitor(IKeyed parent, GenericBase device, long warningTime, long errorTime) : base(parent, warningTime, errorTime) { Device = device; }
public bool Equals(IKeyed x, IKeyed y) { return((x != null && y != null) && x.Key == y.Key); }
public static TValue GetValueWithDefault <TKey, TValue>(this IKeyed <TKey, TValue> dictionary, TKey key, TValue defaultValue) where TKey : notnull { return(dictionary.TryGetValue(key, out TValue value) ? value : defaultValue); }
public KeyFlavour(IKeyed keyFlavourable) : this(keyFlavourable.GetType()) { }