public bool?Evaluate(T context) { LogicOfTo <T, bool?> logic = (LogicOfTo <T, bool?>) this.Decorated; Condition.Requires(logic).IsNotNull(); var rv = logic.Perform(context) as LogicOfTo <T, bool?>; //note we don't bias the logic return(rv.Result); }
private void PerformOperation(IStore requestStore, IStore responseStore) { Condition.Requires(requestStore).IsNotNull(); Condition.Requires(responseStore).IsNotNull(); var req = requestStore.Get <OperationArg>(this.Id); TArg reqObj = (TArg)req.Data; try { LogicOfTo <TArg, TResult> logic = (LogicOfTo <TArg, TResult>) this.OperationLogic; var respLogic = logic.Perform(reqObj) as LogicOfTo <TArg, TResult>; responseStore.SaveItem(OperationResult.New(this.Id, respLogic.Result)); } catch (Exception ex) { responseStore.SaveItem(OperationError.New(this.Id, ex)); } }
public virtual List <IHasId> Search(LogicOfTo <IHasId, bool> filter) { Condition.Requires(filter).IsNotNull(); List <IHasId> returnValue = new List <IHasId>(); //#if DEBUG // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search starts", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName)); //#endif //lock and retrieve the values List <IHasId> vals = new List <IHasId>(); lock (this._stateLock) { vals.AddRange(this.Dictionary.Values); } vals.WithEach(x => { //if the item is the wrong type, skip it LogicOfTo <IHasId, bool> logic = filter.Perform(x) as LogicOfTo <IHasId, bool>; if (logic.Result) { returnValue.Add(x); } }); //#if DEBUG // returnValue.WithEach(x => // { // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search returns {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.GetStoredObjectId().ToString())); // }); // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search ends", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName)); //#endif return(returnValue); }
/// <summary> /// filters out non-type items, and those that don't pass the explicit filter /// </summary> public static List <IHasId> SearchOf(this ISearchableStore store, Type type, LogicOfTo <IHasId, bool> filter) { if (store == null) { return(null); } LogicOfTo <IHasId, bool> filter2 = new LogicOfTo <IHasId, bool>((item) => { if (!type.IsAssignableFrom(item.GetType())) { return(false); } LogicOfTo <IHasId, bool> logic = filter.Perform(item) as LogicOfTo <IHasId, bool>; return(logic.Result); }); var list = store.Search(filter2); return(list); }
public virtual List<IHasId> Search(LogicOfTo<IHasId, bool> filter) { Condition.Requires(filter).IsNotNull(); List<IHasId> returnValue = new List<IHasId>(); //#if DEBUG // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search starts", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName)); //#endif //lock and retrieve the values List<IHasId> vals = new List<IHasId>(); lock (this._stateLock) { vals.AddRange(this.Dictionary.Values); } vals.WithEach(x => { //if the item is the wrong type, skip it LogicOfTo<IHasId, bool> logic = filter.Perform(x) as LogicOfTo<IHasId, bool>; if(logic.Result) { returnValue.Add(x); } }); //#if DEBUG // returnValue.WithEach(x => // { // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search returns {3}", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName, x.GetStoredObjectId().ToString())); // }); // Debug.WriteLine(string.Format("Id:{0} Thread:{1} Type:{2} Store search ends", (this as IHasId).With(o => o.Id).With(o => o.ToString()), Thread.CurrentThread.ManagedThreadId, this.GetType().FullName)); //#endif return returnValue; }
/// <summary> /// filters out non-T items, and those that don't pass the explicit filter /// </summary> /// <typeparam name="T"></typeparam> /// <param name="store"></param> /// <param name="filter"></param> /// <returns></returns> public static List <T> SearchOf <T>(this ISearchableStore store, LogicOfTo <T, bool> filter) where T : IHasId { if (store == null) { return(null); } LogicOfTo <IHasId, bool> filter2 = new LogicOfTo <IHasId, bool>((item) => { if (!(item is T)) { return(false); } T t = (T)item; LogicOfTo <T, bool> logic = filter.Perform(t) as LogicOfTo <T, bool>; return(logic.Result); }); var list = store.Search(filter2); return(list.ConvertListTo <T, IHasId>()); }