Example #1
0
        /// <summary>
        /// The one method to put different types of estate objects into caches. <br/>
        /// Key is chosen automatically. <br/>
        /// Method checks referential integrity on: <br/>
        /// EstateObject.SellerID - Person.key. <br/>
        /// EstateObject.LocationID - Location.key.
        /// </summary>
        /// <param name="value">Estate object to put into cache.</param>
        public static void PutEstateObject (EstateObject value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.SellerID is not found.
                if (!(PersonCache.ContainsKey(value.SellerID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into EstateObject cache.")
                    {
                        Operation = "put",
                        TableName = "EstateObject",
                        FieldName = "SellerID",
                        ReadableMessage = $"Can not put new entry into EstateObject cache because Person with key {value.SellerID} does not exist."
                    };
                }

                // Error if Location not found.
                if (!(LocationCache.ContainsKey(value.LocationID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into EstateObject cache.")
                    {
                        Operation = "put",
                        TableName = "EstateObject",
                        FieldName = "LocationID",
                        ReadableMessage = $"Can not put new entry into EstateObject cache because Location with key {value.LocationID} does not exist."
                    };
                }

                // Normal operation.
                int key = LastUsedKeys.Get("estateobject");
                switch ((char)value.Variant)
                {
                    case 'o':
                    ObjectCache.Put (key, value);
                    break;

                    case 'h':
                    HouseCache.Put (key, (House)value);
                    break;
                    
                    case 'f':
                    FlatCache.Put (key, (Flat)value);
                    break;

                    case 'l':
                    LandplotCache.Put (key, (Landplot)value);
                    break;

                    default: 
                    break;
                }
                LastUsedKeys.Put("estateobject", key+1);
                tx.Commit();
            }
        }
Example #2
0
 /// <summary>
 /// Put location entity into Location cache.
 /// </summary>
 /// <param name="value">Location entity to put into cache.</param>
 public static void PutLocation (Location value)
 {
     using (var tx = Client.GetTransactions().TxStart())
     {
         int key = LastUsedKeys.Get("location");
         LocationCache.Put(key, value);
         key++;
         LastUsedKeys.Put("location", key);
         tx.Commit();
     }
 }
Example #3
0
        /// <summary>
        /// Create new account, using Person entity, password, and optionally privilegies level.
        /// </summary>
        /// <param name="person"></param>
        /// <param name="password"></param>
        /// <param name="privilegies"></param>
        public static void CreateAccount(Person person, string password, char privilegies = 'c')
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Referential integrity check
                if (CredentialCache.ContainsKey(person.Phone))
                {
                    tx.Commit();
                    throw new ReferentialException("Can not create new account.")
                          {
                              ReadableMessage = $"Can not create account because account with phone {person.Phone} already exists."
                          };
                }
                if (!LocationCache.ContainsKey(person.LocationID))
                {
                    tx.Commit();
                    throw new ReferentialException("Can not create new account.")
                          {
                              ReadableMessage = $"Can not create account because location with key {person.LocationID} does not exist."
                          };
                }

                // Normal operation
                int key = LastUsedKeys.Get("person");
                PersonCache.Put(key, person);
                LastUsedKeys.Put("person", key + 1);

                Credential c = new Credential
                {
                    Password    = password,
                    Privilegies = (byte)privilegies,
                    Status      = (byte)'n',
                    PersonID    = key
                };

                CredentialCache.Put(person.Phone, c);
                tx.Commit();
            }
        }
Example #4
0
        /// <summary>
        /// Put a person into the cache.<br/>
        /// This method checks referential integrity on field Person.LocationID: <br/>
        /// Location with _key = Person.LocationID has to exist. <br/>
        /// Otherwise, method throws ReferentialException. <br/>
        /// This and other put methods DO NOT validate the entity.
        /// </summary>
        /// <param name="p">Person to put into the cache.</param>
        public static void PutPerson (Person p)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Check if Location cache contains Location with key p.LocationID, throw error if not.
                if (!(LocationCache.ContainsKey(p.LocationID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Person cache.")
                    {
                        Operation = "put",
                        TableName = "Person",
                        FieldName = "LocationID",
                        ReadableMessage = $"Can not put new entry into Person cache because Location with key {p.LocationID} does not exist."
                    };
                }

                // Check if Credential cache contains Credential with key p.Phone, throw error if yes.
                if (CredentialCache.ContainsKey(p.Phone))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Person cache.")
                    {
                        Operation = "put",
                        TableName = "Person",
                        FieldName = "Phone",
                        ReadableMessage = $"Can not put new entry into Person cache because Person with Phone '{p.Phone}' and Credential with the same key already exist."
                    };
                }

                // Normal operation.
                int key = LastUsedKeys.Get("person");
                PersonCache.Put(key, p);
                key++;
                LastUsedKeys.Put ("person", key);
                tx.Commit();
            }
        }
Example #5
0
        /// <summary>
        /// Put ClientWish entity into the cache. <br/>
        /// Referential integrity check is done on: <br/>
        /// ClientWish.ClientID - Person.key <br/>
        /// ClientWish.LocationID - Location.key 
        /// </summary>
        /// <param name="value">ClientWish to put into the cache.</param>
        public static void PutClientWish (ClientWish value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.ClientID is not found.
                if (!(PersonCache.ContainsKey(value.ClientID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into ClientWish cache.")
                    {
                        Operation = "put",
                        TableName = "ClientWish",
                        FieldName = "ClientID",
                        ReadableMessage = $"Can not put new entry into ClientWish cache because Person with key {value.ClientID} does not exist."
                    };
                }

                // Error if Location not found.
                if (!(LocationCache.ContainsKey(value.LocationID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into ClientWish cache.")
                    {
                        Operation = "put",
                        TableName = "ClientWish",
                        FieldName = "LocationID",
                        ReadableMessage = $"Can not put new entry into ClientWish cache because Location with key {value.LocationID} does not exist."
                    };
                }

                // Normal operation.
                int key = LastUsedKeys.Get ("clientwish");
                ClientWishCache.Put (key, value);
                LastUsedKeys.Put ("clientwish", key+1);
                tx.Commit();
            }
        }