public static ICEFInfraWrapper CreateInfraWrapper(WrappingSupport need, WrappingAction action, bool isNew, object o, ObjectState?initState, IDictionary <string, object> props, IDictionary <string, Type> types) { // Goal is to provision the lowest overhead object based on need! ICEFInfraWrapper infrawrap = null; if (action != WrappingAction.NoneOrProvisionedAlready) { if ((o is INotifyPropertyChanged) || (need & WrappingSupport.Notifications) == 0) { if ((need & WrappingSupport.DataErrors) != 0) { infrawrap = new DynamicWithValuesBagErrors(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types); } else { if ((need & WrappingSupport.OriginalValues) != 0) { infrawrap = new DynamicWithValuesAndBag(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types); } else { infrawrap = new DynamicWithBag(o, props, types); } } } else { infrawrap = new DynamicWithAll(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types); } } return(infrawrap); }
private static void InternalNodeVisiter(ICEFInfraWrapper iw, Action <ICEFInfraWrapper> toRun, IDictionary <object, bool> visits) { if (visits.ContainsKey(iw)) { return; } visits[iw] = true; var av = (from a in iw.GetAllValues() where a.Value != null && !a.Value.GetType().IsValueType&& !a.Value.GetType().FullName.StartsWith("System.") select a).ToList(); var maxdop = Globals.EnableParallelPropertyParsing && Environment.ProcessorCount > 4 && av.Count() > Environment.ProcessorCount ? Environment.ProcessorCount >> 2 : 1; Parallel.ForEach(av, new ParallelOptions() { MaxDegreeOfParallelism = maxdop }, (kvp) => { var asEnum = kvp.Value as IEnumerable; if (asEnum != null) { var sValEnum = asEnum.GetEnumerator(); while (sValEnum.MoveNext()) { var iw2 = CEF.CurrentServiceScope.GetOrCreateInfra(sValEnum.Current, false); if (iw2 != null) { InternalNodeVisiter(iw2, toRun, visits); } } } else { // If it's a tracked object, recurse var iw2 = CEF.CurrentServiceScope.GetOrCreateInfra(kvp.Value, false); if (iw2 != null) { InternalNodeVisiter(iw2, toRun, visits); } } }); toRun.Invoke(iw); }
/// <summary> /// Infrastructure wrappers offer extended information about tracked objects, such as their "row state" (added, modified, etc.). /// </summary> /// <param name="o">Any object that's tracked within the current service scope.</param> /// <param name="canCreate">If false, the object must have an existing infrastructure wrapper or null is returned; if true, a new wrapper can be created.</param> /// <returns></returns> public static ICEFInfraWrapper AsInfraWrapped(this object o, bool canCreate = true) { ICEFInfraWrapper w = CEF.CurrentServiceScope.GetOrCreateInfra(o, canCreate); if (w == null && canCreate) { var t = CEF.CurrentServiceScope.IncludeObjectNonGeneric(o, null); if (t != null) { w = CEF.CurrentServiceScope.GetOrCreateInfra(t, canCreate); } if (w == null) { throw new CEFInvalidOperationException("Failed to identify wrapper object, current scope may be invalid."); } } return w; }
public ICEFInfraWrapper SavePreview(ServiceScope ss, ICEFInfraWrapper saving, ObjectState state, DBSaveSettings settings) { if (!IsLastUpdatedByDBAssigned && !string.IsNullOrEmpty(LastUpdatedByField)) { saving.SetValue(LastUpdatedByField, settings?.LastUpdatedBy ?? (ss.Settings.GetLastUpdatedBy ?? GetLastUpdatedBy).Invoke()); } if (!IsLastUpdatedDateDBAssigned && !string.IsNullOrEmpty(LastUpdatedDateField)) { saving.SetValue(LastUpdatedDateField, GetLastUpdatedDate.Invoke()); } if (state == ObjectState.Added) { if (!string.IsNullOrEmpty(IsDeletedField)) { saving.SetValue(IsDeletedField, false); } } return(saving); }
internal ValidationWrapper(ICEFInfraWrapper iw) { // If contained object implements IDataErrorInfo, support that "first" _source = iw.GetWrappedObject() as IDataErrorInfo; _iwsource = iw as IDataErrorInfo; }
public static void NodeVisiter(ICEFInfraWrapper iw, Action <ICEFInfraWrapper> toRun) { InternalNodeVisiter(iw, toRun, new ConcurrentDictionary <object, bool>(Globals.DefaultCollectionConcurrencyLevel, Globals.DefaultDictionaryCapacity)); }