예제 #1
0
            public static DictionaryItem Import(XmlNode xmlData, DictionaryItem parent)
            {
                string key = xmlData.Attributes["Key"].Value;

                XmlNodeList    values     = xmlData.SelectNodes("./Value");
                XmlNodeList    childItems = xmlData.SelectNodes("./DictionaryItem");
                DictionaryItem newItem;
                bool           retVal = false;

                if (!hasKey(key))
                {
                    if (parent != null)
                    {
                        addKey(key, " ", parent.key);
                    }
                    else
                    {
                        addKey(key, " ");
                    }

                    if (values.Count > 0)
                    {
                        //Set language values on the dictionary item
                        newItem = new DictionaryItem(key);
                        foreach (XmlNode xn in values)
                        {
                            string cA       = xn.Attributes["LanguageCultureAlias"].Value;
                            string keyValue = xmlHelper.GetNodeValue(xn);

                            Language valueLang = Language.GetByCultureCode(cA);

                            if (valueLang != null)
                            {
                                newItem.setValue(valueLang.id, keyValue);
                            }
                        }
                    }

                    if (parent == null)
                    {
                        retVal = true;
                    }
                }

                newItem = new DictionaryItem(key);

                foreach (XmlNode childItem in childItems)
                {
                    Import(childItem, newItem);
                }

                if (retVal)
                {
                    return(newItem);
                }
                else
                {
                    return(null);
                }
            }
예제 #2
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!");
                }
            }
예제 #3
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"));
                            
                            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!");
                }
            }
예제 #4
0
            public static DictionaryItem Import(XmlNode xmlData, DictionaryItem parent)
            {
                string key = xmlData.Attributes["Key"].Value;

                XmlNodeList values = xmlData.SelectNodes("./Value");
                XmlNodeList childItems = xmlData.SelectNodes("./DictionaryItem");
                DictionaryItem newItem;
                bool retVal = false;

                if (!hasKey(key))
                {
                    if (parent != null)
                        addKey(key, " ", parent.key);
                    else
                        addKey(key, " ");

                    if (values.Count > 0)
                    {
                        //Set language values on the dictionary item
                        newItem = new DictionaryItem(key);
                        foreach (XmlNode xn in values)
                        {
                            string cA = xn.Attributes["LanguageCultureAlias"].Value;
                            string keyValue = xmlHelper.GetNodeValue(xn);

                            Language valueLang = Language.GetByCultureCode(cA);

                            if (valueLang != null)
                            {
                                newItem.setValue(valueLang.id, keyValue);
                            }
                        }
                    }

                    if (parent == null)
                        retVal = true;
                }

                newItem = new DictionaryItem(key);

                foreach (XmlNode childItem in childItems)
                {
                    Import(childItem, newItem);
                }

                if (retVal)
                    return newItem;
                else
                    return null;
            }