public FMAbstractAttribute(FMObject aThisObject, string aType, string aName) { Subscribers = new Dictionary <FMAttribute_derived, int>(); thisObject = aThisObject; type = aType; name = aName; }
Object GetMemberOrConst(string aMember, FMObject aCtxObject) { if (aCtxObject != null && aCtxObject.attributes.ContainsKey(aMember)) { return(aCtxObject.attributes[aMember].FMValue); } else if ((aMember[0] == '\'') && (aMember[aMember.Length - 1] == '\'')) { return(aMember.Substring(1, aMember.Length - 2)); } else if (aMember.ToLower() == "true") { return(true); } else if (aMember.ToLower() == "false") { return(false); } else if (char.IsNumber(aMember[0])) { if (aMember.IndexOf('.') > 0) { return(decimal.Parse(aMember)); } else { return(int.Parse(aMember)); } } else { throw new Exception("Cannot evaluate member or constant " + aMember); } }
public FMAttribute_derived(FMObject aThisObject, string aType, string aName, string aExpression) : base(aThisObject, aType, aName) { Subscriptions = new List <FMAbstractAttribute>(); ObjectSubscriptions = new List <FMObject>(); ObjectSpaceSubscriptions = new List <FMObjectSpace>(); this.fMExpression = aExpression; }
public static ObjectForm OpenObject(FMObject aRootObject) { ObjectForm vFrm = new ObjectForm(); vFrm.rootObject = aRootObject; vFrm.rootObject_PropertyChanged(null, null); vFrm.Show(); return vFrm; }
public void Subscribe(FMObject.FMAttribute_derived aSubscriber) { if (!InstanceSubscribers.ContainsKey(aSubscriber)) { InstanceSubscribers.Add(aSubscriber, 0); this.AllObjectsCollectionChanged += aSubscriber.ObservedItemChanged; aSubscriber.ObjectSpaceSubscriptions.Add(this); } }
public void UnSubscribe(FMObject.FMAttribute_derived aSubscriber) { if (InstanceSubscribers.ContainsKey(aSubscriber)) { InstanceSubscribers.Remove(aSubscriber); this.AllObjectsCollectionChanged -= aSubscriber.ObservedItemChanged; aSubscriber.ObjectSpaceSubscriptions.Remove(this); } }
void LoadObjectByObjectDetails(ObjectDetails vObjectDetails) { FMObject vLoadedObject = new FMObject(objectSpace, vObjectDetails.ObjectGUID); vLoadedObject.FMClass = vObjectDetails.ClassName; foreach (AttributeDetails AD in vObjectDetails.Attributes) { vLoadedObject.CreateAttribute(AD.Type, AD.Attribute, AD.Value); } foreach (DerivedAttributeDetails DAD in vObjectDetails.DerivedAttributes) { vLoadedObject.CreateDerivedAttribute(DAD.Type, DAD.Attribute, DAD.Query); } }
Object GetMemberOrConst(string aMember, FMObject aCtxObject) { if (aCtxObject != null && aCtxObject.attributes.ContainsKey(aMember)) return aCtxObject.attributes[aMember].FMValue; else if ((aMember[0] == '\'') && (aMember[aMember.Length - 1] == '\'')) return aMember.Substring(1, aMember.Length - 2); else if (aMember.ToLower() == "true") return true; else if (aMember.ToLower() == "false") return false; else if (char.IsNumber(aMember[0])) { if (aMember.IndexOf('.') > 0) return decimal.Parse(aMember); else return int.Parse(aMember); } else throw new Exception("Cannot evaluate member or constant " + aMember); }
private string fMExpression; // Write only on creation #endregion Fields #region Constructors public FMAttribute_derived(FMObject aThisObject, string aType, string aName, string aExpression) : base(aThisObject, aType, aName) { Subscriptions = new List<FMAbstractAttribute>(); ObjectSubscriptions = new List<FMObject>(); ObjectSpaceSubscriptions = new List<FMObjectSpace>(); this.fMExpression = aExpression; }
public FMAttribute(FMObject aThisObject, string aType, string aName, Object aValue) : base(aThisObject, aType, aName) { this.fMValue = aValue; }
public FMAbstractAttribute(FMObject aThisObject, string aType, string aName) { Subscribers = new Dictionary<FMAttribute_derived, int>(); thisObject = aThisObject; type = aType; name = aName; }
void PersistObject(FMObject aObject) { try { fDBConnection.Open(); #region Begin transaction SqlCommand vSQLCMD = new SqlCommand("Begin transaction", fDBConnection); vSQLCMD.ExecuteNonQuery(); #endregion string vSQL = ""; bool vOjectInDB = EvaluateSQL("select ObjectGUID from FMObject where ObjectGUID = '" + aObject.ObjectGUID + "'").Rows.Count > 0; if (vOjectInDB) { vSQL = "update FMObject set classname = '" + aObject.FMClass + "' where ObjectGUID = '" + aObject.ObjectGUID + "'"; } else { vSQL = "insert into FMObject values ('" + aObject.ObjectGUID + "', '" + aObject.FMClass + "')"; } new SqlCommand(vSQL, fDBConnection).ExecuteNonQuery(); foreach (KeyValuePair <String, FMObject.FMAbstractAttribute> KVP in aObject.attributes) { vSQL = ""; if (KVP.Value is FMObject.FMAttribute_derived) { FMObject.FMAttribute_derived vDerAttr = KVP.Value as FMObject.FMAttribute_derived; if (AttributeExistsInPS(vDerAttr)) { vSQL = "update " + GetTableForAttributeType(vDerAttr) + " set query = '" + vDerAttr.Expression + "' where attribute = '" + vDerAttr.name + "' and objectguid = '" + aObject.ObjectGUID + "' and Type = '" + vDerAttr.Type + "'"; } else { vSQL = "insert into " + GetTableForAttributeType(vDerAttr) + " values ('" + vDerAttr.Expression + "', '" + vDerAttr.name + "', '" + aObject.ObjectGUID + "', '" + vDerAttr.Type + "')"; } } else { FMObject.FMAttribute vAttr = KVP.Value as FMObject.FMAttribute; string vSQLValue = ""; switch (KVP.Value.Type) { case "Int32": case "Decimal": vSQLValue = vAttr.FMValue.ToString(); break; case "String": vSQLValue = "'" + vAttr.FMValue.ToString() + "'"; break; case "DateTime": vSQLValue = ((DateTime)vAttr.FMValue).ToString("yyyy-MM-dd HH:mm:ss"); break; case "Boolean": vSQLValue = (Boolean)vAttr.FMValue? "1" : "0"; break; } if (AttributeExistsInPS(vAttr)) { vSQL = "update " + GetTableForAttributeType(vAttr) + " set value = " + vSQLValue + " where attribute = '" + vAttr.name + "' and objectguid = '" + aObject.ObjectGUID + "'"; } else { vSQL = "insert into " + GetTableForAttributeType(vAttr) + " values (" + vSQLValue + ", '" + vAttr.name + "', '" + aObject.ObjectGUID + "')"; } } new SqlCommand(vSQL, fDBConnection).ExecuteNonQuery(); } #region Commit transaction new SqlCommand("Commit transaction", fDBConnection).ExecuteNonQuery(); #endregion } catch (Exception Exc) { new SqlCommand("Rollback transaction", fDBConnection).ExecuteNonQuery(); throw (Exc); } finally { fDBConnection.Close(); } }
string GetTableForAttributeType(FMObject.FMAbstractAttribute aAttribute) { if (aAttribute is FMObject.FMAttribute_derived) return "FMDerived"; else { return "FM" + aAttribute.Type; } }
void LoadObjectByObjectDetails(ObjectDetails vObjectDetails) { FMObject vLoadedObject = new FMObject(objectSpace, vObjectDetails.ObjectGUID); vLoadedObject.FMClass = vObjectDetails.ClassName; foreach (AttributeDetails AD in vObjectDetails.Attributes) vLoadedObject.CreateAttribute(AD.Type, AD.Attribute, AD.Value); foreach (DerivedAttributeDetails DAD in vObjectDetails.DerivedAttributes) vLoadedObject.CreateDerivedAttribute(DAD.Type, DAD.Attribute, DAD.Query); }
bool AttributeExistsInPS(FMObject.FMAbstractAttribute aAttribute) { return EvaluateSQL("select ObjectGUID from " + GetTableForAttributeType(aAttribute) + " where ObjectGUID = '" + aAttribute.thisObject.ObjectGUID + "' and Attribute = '" + aAttribute.name + "'").Rows.Count > 0; }
void PersistObject(FMObject aObject) { try { fDBConnection.Open(); #region Begin transaction SqlCommand vSQLCMD = new SqlCommand("Begin transaction", fDBConnection); vSQLCMD.ExecuteNonQuery(); #endregion string vSQL = ""; bool vOjectInDB = EvaluateSQL("select ObjectGUID from FMObject where ObjectGUID = '" + aObject.ObjectGUID + "'").Rows.Count > 0; if (vOjectInDB) { vSQL = "update FMObject set classname = '" + aObject.FMClass + "' where ObjectGUID = '" + aObject.ObjectGUID + "'"; } else { vSQL = "insert into FMObject values ('" + aObject.ObjectGUID + "', '" + aObject.FMClass + "')"; } new SqlCommand(vSQL, fDBConnection).ExecuteNonQuery(); foreach (KeyValuePair<String, FMObject.FMAbstractAttribute> KVP in aObject.attributes) { vSQL = ""; if (KVP.Value is FMObject.FMAttribute_derived) { FMObject.FMAttribute_derived vDerAttr = KVP.Value as FMObject.FMAttribute_derived; if (AttributeExistsInPS(vDerAttr)) vSQL = "update " + GetTableForAttributeType(vDerAttr) + " set query = '" + vDerAttr.Expression + "' where attribute = '" + vDerAttr.name + "' and objectguid = '" + aObject.ObjectGUID + "' and Type = '" + vDerAttr.Type + "'"; else vSQL = "insert into " + GetTableForAttributeType(vDerAttr) + " values ('" + vDerAttr.Expression + "', '" + vDerAttr.name + "', '" + aObject.ObjectGUID + "', '" + vDerAttr.Type + "')"; } else { FMObject.FMAttribute vAttr = KVP.Value as FMObject.FMAttribute; string vSQLValue = ""; switch (KVP.Value.Type) { case "Int32": case "Decimal": vSQLValue = vAttr.FMValue.ToString(); break; case "String": vSQLValue = "'" + vAttr.FMValue.ToString() + "'"; break; case "DateTime": vSQLValue = ((DateTime)vAttr.FMValue).ToString("yyyy-MM-dd HH:mm:ss"); break; case "Boolean": vSQLValue = (Boolean)vAttr.FMValue? "1" : "0"; break; } if (AttributeExistsInPS(vAttr)) vSQL = "update " + GetTableForAttributeType(vAttr) + " set value = " + vSQLValue+ " where attribute = '" + vAttr.name + "' and objectguid = '" + aObject.ObjectGUID + "'"; else vSQL = "insert into " + GetTableForAttributeType(vAttr) + " values (" + vSQLValue + ", '" + vAttr.name + "', '" + aObject.ObjectGUID + "')"; } new SqlCommand(vSQL, fDBConnection).ExecuteNonQuery(); } #region Commit transaction new SqlCommand("Commit transaction", fDBConnection).ExecuteNonQuery(); #endregion } catch (Exception Exc) { new SqlCommand("Rollback transaction", fDBConnection).ExecuteNonQuery(); throw (Exc); } finally { fDBConnection.Close(); } }