Пример #1
0
 public void UnSubscribe(FMObject.FMAttribute_derived aSubscriber)
 {
     if (InstanceSubscribers.ContainsKey(aSubscriber))
     {
         InstanceSubscribers.Remove(aSubscriber);
         this.AllObjectsCollectionChanged -= aSubscriber.ObservedItemChanged;
         aSubscriber.ObjectSpaceSubscriptions.Remove(this);
     }
 }
Пример #2
0
 public void Subscribe(FMObject.FMAttribute_derived aSubscriber)
 {
     if (!InstanceSubscribers.ContainsKey(aSubscriber))
     {
         InstanceSubscribers.Add(aSubscriber, 0);
         this.AllObjectsCollectionChanged += aSubscriber.ObservedItemChanged;
         aSubscriber.ObjectSpaceSubscriptions.Add(this);
     }
 }
Пример #3
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();
            }
        }