//public void SetHolder(System.Collections.Hashtable msgDict) //{ // Type t = this.GetType(); // //ValueMap<string, RepresentedModelValue> model = new RepresentedModel(t).schema; // ValueMap<string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); // //foreach (KeyValuePair<string, object> v in msgDict) // //{ // // int descIndex = model.IndexOf(v.Key); // // if (descIndex >= 0) // // { // // //PropertyInfo pi = t.GetProperty(v.Key); // // //if (pi == null) // // // continue; // // PropertyInfo pi = model.val2[descIndex].propertyDescriptor; // // Type pt = pi.PropertyType; // // bool nullable = false; // // Type ptn = Nullable.GetUnderlyingType(pt); // // if (nullable = ptn != null) // // pt = ptn; // // if (v.Value == null && !nullable) // // { // // if (pt.BaseType != typeof(object)) // // throw new Exception("value does not accept nullable types, key: " + v.Key); // // else continue; // // } // // else if (!nullable && pt != v.Value.GetType()) // // throw new Exception("unknown type for key: " + v.Key); // // pi.SetValue(this, v.Value, null); // // } // //} // for (int idx = 0; idx < model.val1.Count; idx++) // { // string key = model.val1[idx]; // object val; // //if (msgDict.TryGetValue(key, out val)) // if (msgDict.ContainsKey(key)) // { // val = msgDict[key]; // //PropertyInfo pi = t.GetProperty(v.Key); // //if (pi == null) // // continue; // PropertyInfo pi = model.val2[idx].propertyDescriptor; // Type pt = pi.PropertyType; // bool nullable = false; // Type ptn = Nullable.GetUnderlyingType(pt); // if (nullable = ptn != null) // pt = ptn; // if (val == null && !nullable) // { // if (pt.BaseType != typeof(object)) // throw new Exception("value does not accept nullable types, key: " + key); // else continue; // } // else if (!nullable && pt != val.GetType()) // throw new Exception("unknown type for key: " + key); // //pi.SetValue(this, val, null); // model.val2[idx].PropValueSet(this, val); // } // } // Holder = new System.Collections.Hashtable(msgDict); //} //void ReverseSetProps() //{ // if (Holder == null) // return; // Type t = this.GetType(); // ValueMap<string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); // foreach (KeyValuePair<string, object> v in Holder) // { // //PropertyInfo pi = t.GetProperty(v.Key); // //if (pi == null) // // continue; // int propDescIndex = model.IndexOf(v.Key); // if (propDescIndex >= 0) // { // PropertyInfo pi = model.val2[propDescIndex].propertyDescriptor; // pi.SetValue(this, v.Value, null); // } // } //} void SetProps() { if (Holder == null) { //Holder = new System.Collections.Hashtable(); Holder = new Dictionary <string, object>(); } Type t = this.GetType(); //ValueMap<string, RepresentedModelValue> model = new RepresentedModel(t).schema; ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); for (int i = 0; i < model.val1.Count; i++) { /*string k = model.val1[i]; * PropertyInfo pi = model.val2[i].propertyDescriptor; //t.GetProperty(k); * object val = pi.GetValue(this, null); * * if (Holder.ContainsKey(k)) * Holder[k] = val; * else * Holder.Add(k, val);*/ Holder[model.val1[i]] = model.val2[i].PropValue(this); } }
public RepresentedModel GetModel() { Type t = this.GetType(); RepresentedModel model = new RepresentedModel(t); return(model); }
public static bool CheckWithSelector(System.Collections.Hashtable other, TQItemSelector selector) { object DVAL; bool nullable; foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters) { if (other.ContainsKey(rule.Key)) { DVAL = other[rule.Key]; if (rule.Value.ValueSet == TQItemSelectorSet.Equals) { if (((IComparable)rule.Value.Value) .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) != 0) { return(false); } } else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals) { if (((IComparable)rule.Value.Value) .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) == 0) { return(false); } } } else { return(false); } } return(true); }
void SetProps() { if (Holder == null) { Holder = new Dictionary <string, object>(); } Type t = this.GetType(); //ValueMap<string, RepresentedModelValue> model = new RepresentedModel(t).schema; ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); for (int i = 0; i < model.val1.Count; i++) { string k = model.val1[i]; PropertyInfo pi = model.val2[i].propertyDescriptor; //t.GetProperty(k); object val = pi.GetValue(this, null); if (Holder.ContainsKey(k)) { Holder[k] = val; } else { Holder.Add(k, val); } } }
public static bool CheckWithSelector(Dictionary <string, object> other, TQItemSelector selector) { object DVAL; bool nullable; foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters) { if (other.TryGetValue(rule.Key, out DVAL)) { if (rule.Value.ValueSet == TQItemSelectorSet.Equals) { if (((IComparable)rule.Value.Value) .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) != 0) { return(false); } } else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals) { if (((IComparable)rule.Value.Value) .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) == 0) { return(false); } } } else { return(false); } } return(true); }
public void InitialiseFromModel(RepresentedModel model, QueueConnectionParameters connection) { this.model = model; this.connection = connection; SetSelector(TQItemSelector.DefaultFifoSelector); MongoQueueParams mongoparams = connection.specParams as MongoQueueParams; try { OpenConnection(mongoparams); } catch (Exception e) { throw new QueueConnectionException("can't open connection to: " + mongoparams.ConnectionString, e); } }
public void SetHolder(Dictionary <string, object> msgDict) { Type t = this.GetType(); //ValueMap<string, RepresentedModelValue> model = new RepresentedModel(t).schema; ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); foreach (KeyValuePair <string, object> v in msgDict) { int descIndex = model.IndexOf(v.Key); if (descIndex >= 0) { //PropertyInfo pi = t.GetProperty(v.Key); //if (pi == null) // continue; PropertyInfo pi = model.val2[descIndex].propertyDescriptor; Type pt = pi.PropertyType; bool nullable = false; Type ptn = Nullable.GetUnderlyingType(pt); if (nullable = ptn != null) { pt = ptn; } if (v.Value == null && !nullable) { if (pt.BaseType != typeof(object)) { throw new Exception("value does not accept nullable types, key: " + v.Key); } else { continue; } } else if (!nullable && pt != v.Value.GetType()) { throw new Exception("unknown type for key: " + v.Key); } pi.SetValue(this, v.Value, null); } } Holder = new Dictionary <string, object>(msgDict); }
public void SetHolder(Dictionary <string, object> msgDict) { Type t = this.GetType(); ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); for (int idx = 0; idx < model.val1.Count; idx++) { string key = model.val1[idx]; object val; if (msgDict.TryGetValue(key, out val)) { PropertyInfo pi = model.val2[idx].propertyDescriptor; Type pt = pi.PropertyType; bool nullable = false; Type ptn = Nullable.GetUnderlyingType(pt); if (nullable = ptn != null) { pt = ptn; } if (val == null && !nullable) { if (pt.BaseType != typeof(object)) { throw new Exception("value does not accept nullable types, key: " + key); } else { continue; } } else if (!nullable && pt != val.GetType()) { throw new Exception("unknown type for key: " + key); } //pi.SetValue(this, val, null); model.val2[idx].PropValueSet(this, val); } } Holder = new Dictionary <string, object>(msgDict); //Holder = new System.Collections.Hashtable(msgDict); }
void ReverseSetProps() { if (Holder == null) { return; } Type t = this.GetType(); ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); foreach (KeyValuePair <string, object> v in Holder) { //PropertyInfo pi = t.GetProperty(v.Key); //if (pi == null) // continue; int propDescIndex = model.IndexOf(v.Key); if (propDescIndex >= 0) { PropertyInfo pi = model.val2[propDescIndex].propertyDescriptor; pi.SetValue(this, v.Value, null); } } }
/// <summary> /// Get dictionary holder without inherited properties, but with MType /// </summary> /// <returns></returns> public Dictionary <string, object> GetSendEnvelope() { Dictionary <string, object> di = new Dictionary <string, object>(); Type t = this.GetType(); ValueMap <string, RepresentedModelValue> model = RepresentedModel.FindScheme(t); di.Add("MType", this.MType); for (int i = 0; i < model.val1.Count; i++) { string k = model.val1[i]; RepresentedModelValue v = model.val2[i]; if (!v.Inherited) { PropertyInfo pi = model.val2[i].propertyDescriptor; object val = pi.GetValue(this, null); di.Add(k, val); } } return(di); }
public RepresentedModel GetModel() { Type t = this.GetType(); RepresentedModel model = new RepresentedModel(t); return model; }
public void InitialiseFromModel(RepresentedModel model, QueueConnectionParameters connection) { this.m = model; }
public MemQueue(RepresentedModel model, QueueConnectionParameters connection) { this.InitialiseFromModel(model, connection); Name = connection.Name; }
/// <summary> /// This will check for all required keys in dictionary and /// CHECK Equal or NotEqual valued parameters by selector /// </summary> /// <param name="selector"></param> /// <returns></returns> public static InternalCheckDictionary MakeCheckerDictionary(TQItemSelector selector) { Type KeyType = typeof(Dictionary <string, object>); ParameterExpression one = Expression.Parameter(KeyType); List <Expression> body = new List <Expression>(); MethodInfo tryGetValue = KeyType.GetMethod("TryGetValue", new Type[] { typeof(string), typeof(object).MakeByRefType() });// string, out object MethodInfo conv = typeof(RepresentedModel).GetMethod("Convert"); LabelTarget returnTarget = Expression.Label(typeof(bool)); ParameterExpression varOut = Expression.Variable(typeof(object), "outObject"); bool nullable; foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters) { Expression callOut = Expression.Call(one, tryGetValue, Expression.Constant(rule.Key), varOut); Expression cond = Expression.IfThen(Expression.Not(callOut), Expression.Return(returnTarget, Expression.Constant(false))); body.Add(cond); if (rule.Value.ValueSet == TQItemSelectorSet.Ascending || rule.Value.ValueSet == TQItemSelectorSet.Descending) { continue; } Expression cmpVal = Expression.Constant(rule.Value.Value); MethodInfo internalCMP = rule.Value.Value.GetType().GetMethod("CompareTo", new Type[] { typeof(object) }); Expression ICMP = Expression.Call(cmpVal, internalCMP, Expression.Call(null, conv, varOut, Expression.Constant(RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable)))); Expression isEq = null; if (rule.Value.ValueSet == TQItemSelectorSet.Equals) { isEq = Expression.NotEqual(ICMP, Expression.Constant(0)); } else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals) { isEq = Expression.Equal(ICMP, Expression.Constant(0)); } Expression cond2 = Expression.IfThen(isEq, Expression.Return(returnTarget, Expression.Constant(false))); body.Add(cond2); } LabelExpression returnDef = Expression.Label(returnTarget, Expression.Constant(true)); body.Add(returnDef); Expression expression_body = Expression.Block(new[] { varOut }, body); return((InternalCheckDictionary)Expression.Lambda(typeof(InternalCheckDictionary), expression_body, one).Compile()); }