Exemplo n.º 1
0
        public virtual void Patch(PropertyEntity target)
        {
            target.PropertyValueType = PropertyValueType;
            target.IsEnum            = IsEnum;
            target.IsMultiValue      = IsMultiValue;
            target.IsLocaleDependant = IsLocaleDependant;
            target.IsRequired        = IsRequired;
            target.TargetType        = TargetType;
            target.Name = Name;

            target.CatalogId  = CatalogId;
            target.CategoryId = CategoryId;

            if (!PropertyAttributes.IsNullCollection())
            {
                var attributeComparer = AnonymousComparer.Create((PropertyAttributeEntity x) => x.IsTransient() ? x.PropertyAttributeName : x.Id);
                PropertyAttributes.Patch(target.PropertyAttributes, attributeComparer, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
            }
            if (!DictionaryItems.IsNullCollection())
            {
                var dictItemComparer = AnonymousComparer.Create((PropertyDictionaryItemEntity x) => $"{x.Alias}-${x.PropertyId}");
                DictionaryItems.Patch(target.DictionaryItems, dictItemComparer, (sourceDictItem, targetDictItem) => sourceDictItem.Patch(targetDictItem));
            }
            if (!DisplayNames.IsNullCollection())
            {
                var displayNamesComparer = AnonymousComparer.Create((PropertyDisplayNameEntity x) => $"{x.Name}-{x.Locale}");
                DisplayNames.Patch(target.DisplayNames, displayNamesComparer, (sourceDisplayName, targetDisplayName) => sourceDisplayName.Patch(targetDisplayName));
            }

            if (!ValidationRules.IsNullCollection())
            {
                ValidationRules.Patch(target.ValidationRules, (sourceRule, targetRule) => sourceRule.Patch(targetRule));
            }
        }
Exemplo n.º 2
0
 public void Clear( )
 {
     if (UniqueKeys)
     {
         DictionaryItems.Clear( );
     }
     else
     {
         ListItems.Clear( );
     }
 }
Exemplo n.º 3
0
 public Boolean Contains(TKey key)
 {
     if (UniqueKeys)
     {
         return(DictionaryItems.ContainsKey(key));
     }
     else
     {
         return(ListItems.Count(i => i.Key.Equals(key)) > 0);
     }
 }
Exemplo n.º 4
0
 private static void createKey(string key, Guid parentId, string defaultValue)
 {
     if (!hasKey(key))
     {
         Guid newId = Guid.NewGuid();
         Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(_ConnString, CommandType.Text,
                                                                    "Insert into cmsDictionary (id,parent,[key]) values ('" + newId.ToString() +
                                                                    "','" + parentId.ToString() + "','" + key + "')");
         DictionaryItems.Add(key, newId);
         new DictionaryItem(key).setValue(defaultValue);
     }
     else
     {
         throw new ArgumentException("Key being added already exist!");
     }
 }
Exemplo n.º 5
0
    public static void buyItemLevelUp(Items _item, float _moneyItem)
    {
        if (_moneyItem <= WalletController.getValue(ItemsType.coin))
        {
            WalletController.removeItems(ItemsType.coin, _moneyItem);

            DictionaryItems.LevelUp(_item);

            DictionaryItems.playInitItems();

            StoreInterface.updateCoin();
        }
        else
        {
            WarningManager.noMoney();
        }
    }
Exemplo n.º 6
0
            public void delete()
            {
                // delete recursive
                foreach (DictionaryItem dd in Children)
                {
                    dd.delete();
                }

                // remove all language values from key
                Item.removeText(_uniqueId);

                // Remove key from cache
                DictionaryItems.Remove(key);

                // remove key from database
                Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(_ConnString, CommandType.Text,
                                                                           "delete from cmsDictionary where [key] ='" + key + "'");
            }
Exemplo n.º 7
0
        public virtual void Remove(TKey key)
        {
            var exists = Contains(key);

            if (!exists)
            {
                return;
            }

            if (UniqueKeys)
            {
                DictionaryItems.Remove(key);
            }
            else
            {
                ListItems.RemoveAll(i => i.Key.Equals(key));
            }
        }
Exemplo n.º 8
0
        public virtual void Add(TKey key, TItem item)
        {
            var exists = Contains(key);

            if (exists)
            {
                return;
            }

            if (UniqueKeys)
            {
                DictionaryItems.Add(key, item);
            }
            else
            {
                ListItems.Add(new KeyValuePair <TKey, TItem>(key, item));
            }
        }
Exemplo n.º 9
0
            public void delete()
            {
                OnDeleting(EventArgs.Empty);

                // delete recursive
                foreach (DictionaryItem dd in Children)
                {
                    dd.delete();
                }

                // remove all language values from key
                Item.removeText(UniqueId);

                // remove key from database
                SqlHelper.ExecuteNonQuery("delete from cmsDictionary where [key] ='" + key + "'");

                // Remove key from cache
                DictionaryItems.Remove(key);
            }
Exemplo n.º 10
0
            private static int createKey(string key, Guid parentId, string defaultValue)
            {
                if (!hasKey(key))
                {
                    Guid newId = Guid.NewGuid();
                    SqlHelper.ExecuteNonQuery("Insert into cmsDictionary (id,parent,[key]) values (@id, @parentId, @dictionaryKey)",
                                              SqlHelper.CreateParameter("@id", newId),
                                              SqlHelper.CreateParameter("@parentId", parentId),
                                              SqlHelper.CreateParameter("@dictionaryKey", key));

                    using (IRecordsReader dr =
                               SqlHelper.ExecuteReader("Select pk, id, [key], parent from cmsDictionary where id=@id",
                                                       SqlHelper.CreateParameter("@id", newId)))
                    {
                        if (dr.Read())
                        {
                            //create new dictionaryitem object and put in cache
                            var item = new DictionaryItem(dr.GetInt("pk"),
                                                          dr.GetString("key"),
                                                          dr.GetGuid("id"),
                                                          dr.GetGuid("parent"));

                            DictionaryItems.Add(item.key, item);

                            item.setValue(defaultValue);

                            item.OnNew(EventArgs.Empty);

                            return(item.id);
                        }
                        else
                        {
                            throw new DataException("Could not load newly created dictionary item with id " + newId.ToString());
                        }
                    }
                }
                else
                {
                    throw new ArgumentException("Key being added already exists!");
                }
            }
Exemplo n.º 11
0
        /// <summary>
        /// Cvar_WriteVariables
        /// Writes lines containing "set variable value" for all variables
        /// with the archive flag set to true.
        /// </summary>
        public void WriteVariables(Stream stream)
        {
            var sb = new StringBuilder(4096);

            var list = UniqueKeys ? DictionaryItems.Select(i => i.Value) : ListItems.Select(i => i.Value);

            foreach (var cvar in list)
            {
                if (cvar.IsArchive)
                {
                    sb.Append(cvar.Name);
                    sb.Append(" \"");
                    sb.Append(cvar.ValueType == typeof(Boolean) ? cvar.Get <Boolean>() ? "1" : "0" : cvar.Get().ToString());
                    sb.AppendLine("\"");
                }
            }

            var buf = Encoding.ASCII.GetBytes(sb.ToString( ));

            stream.Write(buf, 0, buf.Length);
        }
Exemplo n.º 12
0
        public String[] CompleteName(String partial)
        {
            if (String.IsNullOrEmpty(partial))
            {
                return(null);
            }

            var results = new List <String>( );

            var keysList = UniqueKeys ? DictionaryItems.Select(i => i.Key) : ListItems.Select(i => i.Key);

            foreach (var key in keysList)
            {
                if (key.StartsWith(partial))
                {
                    results.Add(key);
                }
            }

            return(results.Count > 0 ? results.ToArray( ) : null);
        }
Exemplo n.º 13
0
 public static bool hasKey(string key)
 {
     EnsureCache();
     return(DictionaryItems.ContainsKey(key));
 }
        public virtual void RemoveValue(TValue value)
        {
            var i = DictionaryItems.First(kvp => EqualityComparer <TValue> .Default.Equals(kvp.Value, value));

            Remove(i.Key);
        }
Exemplo n.º 15
0
        public object GetInstance(DefContext defContext)
        {
            if (defContext == null) return null;

            var type = defContext.GetTypeOfObj();
            if (type.IsTypeOf<SimpleDefContext>())
                return defContext.CastObj<SimpleDefContext>()
                    .SimpleTypeDef.Value;

            if (type.IsTypeOf<ComplexDefContext>())
            {
                var context = defContext.CastObj<ComplexDefContext>();
                var complexTypeDefs = context.ComplexTypeDefs;
                var typeInfos = context.TypeInfos;

                var typeInfosWithId = new Dictionary<int, TypeInfo>();
                foreach (var typeInfo in typeInfos)
                    typeInfosWithId.Add(typeInfo.Id, typeInfo);

                var instances = new Dictionary<int, object>();
                short indexesAsIds = 0;

                #region Get Instances

                foreach (var complexTypeDef in complexTypeDefs)
                {
                    var typeInfo = typeInfosWithId[complexTypeDef.TypeInfoId];
                    var currentType = Type.GetType(typeInfo.TypeName);
                    if (currentType == null)
                        throw new Exception(string.Format("Unknown type : {0}", typeInfo.TypeName));

                    if (currentType.IsImplOf<Array>())
                    {
                        var arrayDef = complexTypeDef.CastObj<ArrayDef>();
                        instances.Add(indexesAsIds, _complexTypeHelper.CreateInstance(currentType, arrayDef.Indicies));
                    }
                    else
                        instances.Add(indexesAsIds, _complexTypeHelper.CreateInstance(currentType));
                    indexesAsIds++;
                }

                #endregion

                #region Relate Instances

                foreach (var complexTypeDef in complexTypeDefs)
                {
                    var instance = instances[complexTypeDef.Id];
                    var instanceType = instance.GetTypeOfObj();

                    if (instanceType.IsImplOf<Array>())
                    {
                        #region Array

                        var arrayDef = complexTypeDef.CastObj<ArrayDef>();
                        var items = new SimpleList<object>();
                        foreach (var defValue in arrayDef.Items)
                            items.Add(CheckInstance(defValue, instances));
                        var arrayItems = new ArrayItems { Items = items };
                        _complexTypeHelper.SetItems(instance, arrayItems);

                        #endregion
                    }
                    else if (instanceType.IsImplOf<IList>())
                    {
                        #region List

                        var listDef = complexTypeDef.CastObj<ListDef>();
                        var items = new SimpleList<object>();
                        foreach (var defValue in listDef.Items)
                            items.Add(CheckInstance(defValue, instances));
                        var listItems = new ListItems { Items = items };
                        _complexTypeHelper.SetItems(instance, listItems);

                        #endregion
                    }
                    else if (instanceType.IsImplOf<IDictionary>())
                    {
                        #region Dictionary

                        var dictionaryDef = complexTypeDef.CastObj<DictionaryDef>();
                        var keys = new SimpleList<object>();
                        foreach (var defValue in dictionaryDef.Keys)
                            keys.Add(CheckInstance(defValue, instances));

                        var values = new SimpleList<object>();
                        foreach (var defValue in dictionaryDef.Values)
                            values.Add(CheckInstance(defValue, instances));

                        var dictionaryItems = new DictionaryItems { Keys = keys, Values = values };
                        _complexTypeHelper.SetItems(instance, dictionaryItems);

                        #endregion
                    }
                    else // user defined tpye at last
                    {
                        #region UserDefined

                        var userDefinedDef = complexTypeDef.CastObj<UserDefinedDef>();
                        var typeInfo = typeInfosWithId[userDefinedDef.TypeInfoId];
                        var names = new SimpleList<string>();
                        foreach (var index in userDefinedDef.Names)
                            names.Add(typeInfo.PropertyIndexName[index]);

                        var values = new SimpleList<object>();
                        foreach (var defValue in userDefinedDef.Values)
                            values.Add(CheckInstance(defValue, instances));

                        var userDefinedItems = new UserDefinedItems { Names = names, Values = values };
                        _complexTypeHelper.SetItems(instance, userDefinedItems);

                        #endregion
                    }
                }

                #endregion

                return instances[complexTypeDefs.SelectFirst().Id];
            }
            throw new UnknownImplementationException(typeof(DefContext), type);
        }
Exemplo n.º 16
0
        // Mod_Print
        public void Print(CommandMessage msg)
        {
            var names = String.Join("\n", DictionaryItems.Select(m => m.Key));

            ConsoleWrapper.Print($"Cached models:\n{names}\n");
        }