예제 #1
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
 public FMAbstractAttribute(FMObject aThisObject, string aType, string aName)
 {
     Subscribers = new Dictionary <FMAttribute_derived, int>();
     thisObject  = aThisObject;
     type        = aType;
     name        = aName;
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
 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;
 }
예제 #4
0
 public static ObjectForm OpenObject(FMObject aRootObject)
 {
     ObjectForm vFrm = new ObjectForm();
     vFrm.rootObject = aRootObject;
     vFrm.rootObject_PropertyChanged(null, null);
     vFrm.Show();
     return vFrm;
 }
예제 #5
0
 public void Subscribe(FMObject.FMAttribute_derived aSubscriber)
 {
     if (!InstanceSubscribers.ContainsKey(aSubscriber))
     {
         InstanceSubscribers.Add(aSubscriber, 0);
         this.AllObjectsCollectionChanged += aSubscriber.ObservedItemChanged;
         aSubscriber.ObjectSpaceSubscriptions.Add(this);
     }
 }
예제 #6
0
 public void UnSubscribe(FMObject.FMAttribute_derived aSubscriber)
 {
     if (InstanceSubscribers.ContainsKey(aSubscriber))
     {
         InstanceSubscribers.Remove(aSubscriber);
         this.AllObjectsCollectionChanged -= aSubscriber.ObservedItemChanged;
         aSubscriber.ObjectSpaceSubscriptions.Remove(this);
     }
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
 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);
 }
예제 #9
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
            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;
            }
예제 #10
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
 public FMAttribute(FMObject aThisObject, string aType, string aName, Object aValue)
     : base(aThisObject, aType, aName)
 {
     this.fMValue = aValue;
 }
예제 #11
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
 public FMAbstractAttribute(FMObject aThisObject, string aType, string aName)
 {
     Subscribers = new Dictionary<FMAttribute_derived, int>();
     thisObject = aThisObject;
     type = aType;
     name = aName;
 }
예제 #12
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();
            }
        }
예제 #13
0
 string GetTableForAttributeType(FMObject.FMAbstractAttribute aAttribute)
 {
     if (aAttribute is FMObject.FMAttribute_derived)
         return "FMDerived";
     else
     {
         return "FM" + aAttribute.Type;
     }
 }
예제 #14
0
 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);
 }
예제 #15
0
파일: FMObject.cs 프로젝트: knowthat/FMSim
 public FMAttribute(FMObject aThisObject, string aType, string aName, Object aValue)
     : base(aThisObject, aType, aName)
 {
     this.fMValue = aValue;
 }
예제 #16
0
 bool AttributeExistsInPS(FMObject.FMAbstractAttribute aAttribute)
 {
     return EvaluateSQL("select ObjectGUID from " + GetTableForAttributeType(aAttribute) + " where ObjectGUID = '" + aAttribute.thisObject.ObjectGUID + "' and Attribute = '" + aAttribute.name + "'").Rows.Count > 0;
 }
예제 #17
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();
            }
        }