/// <summary> /// Crée un dictionnaire { nom de la propriété => valeur } pour un item à insérer. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Dictionnaire contenant { nom de la propriété => valeur }.</returns> protected abstract Dictionary <string, string> CreatePropertyValueDictionary(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded);
/// <summary> /// Retourne la ligne d'insert. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Requête.</returns> private string GetInsertLine(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded) { Dictionary <string, string> propertyValueDict = CreatePropertyValueDictionary(modelClass, initItem, isPrimaryKeyIncluded); return(GetInsertLine(modelClass.DataContract.Name, propertyValueDict)); }
/// <summary> /// Crée un dictionnaire { nom de la propriété => valeur } pour un item à insérer. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Dictionnaire contenant { nom de la propriété => valeur }.</returns> protected Dictionary <string, string> CreatePropertyValueDictionary(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded) { var nameValueDict = new Dictionary <string, string>(); IDictionary <string, object> definition = initItem.Bean; foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (!property.DataDescription.IsPrimaryKey || isPrimaryKeyIncluded) { object propertyValue = definition[property.Name]; string propertyValueStr = propertyValue == null ? "null" : propertyValue.ToString(); if (propertyValue != null && propertyValue.GetType() == typeof(string)) { nameValueDict[property.DataMember.Name] = "'" + propertyValueStr.Replace("'", "''") + "'"; } else { nameValueDict[property.DataMember.Name] = propertyValueStr; } } } return(nameValueDict); }
/// <summary> /// Retourne la ligne d'insert. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="siPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Requête.</returns> private static string GetInsertLine(ModelClass modelClass, ItemInit initItem, bool siPrimaryKeyIncluded) { // Remplissage d'un dictionnaire nom de colonne => valeur. BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean); Dictionary <string, string> nameValueDict = new Dictionary <string, string>(); foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (!property.DataDescription.IsPrimaryKey || siPrimaryKeyIncluded || property.DataDescription.Domain.Code == "DO_CD") { BeanPropertyDescriptor propertyDescriptor = definition.Properties[property.Name]; object propertyValue = propertyDescriptor.GetValue(initItem.Bean); string propertyValueStr = propertyValue == null ? "NULL" : propertyValue.ToString(); if (property.DataType == "byte[]") { nameValueDict[property.DataMember.Name] = propertyValueStr; } else if (propertyDescriptor.PrimitiveType == typeof(string)) { nameValueDict[property.DataMember.Name] = propertyValue == null ? "NULL" : "N'" + ScriptUtils.PrepareDataToSqlDisplay(propertyValueStr) + "'"; } else { nameValueDict[property.DataMember.Name] = propertyValue == null ? "NULL" : propertyValueStr; } } } // Création de la requête. StringBuilder sb = new StringBuilder(); sb.Append("\tINSERT INTO " + modelClass.DataContract.Name + "("); bool isFirst = true; foreach (string columnName in nameValueDict.Keys) { if (!isFirst) { sb.Append(", "); } isFirst = false; sb.Append(columnName); } sb.Append(") VALUES("); isFirst = true; foreach (string value in nameValueDict.Values) { if (!isFirst) { sb.Append(", "); } isFirst = false; sb.Append(value); } sb.Append(");"); return(sb.ToString()); }
/// <summary> /// Crée un dictionnaire { nom de la propriété => valeur } pour un item à insérer. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Dictionnaire contenant { nom de la propriété => valeur }.</returns> protected override Dictionary <string, string> CreatePropertyValueDictionary(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded) { Dictionary <string, string> nameValueDict = new Dictionary <string, string>(); BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean); foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (!property.DataDescription.IsPrimaryKey || isPrimaryKeyIncluded) { BeanPropertyDescriptor propertyDescriptor = definition.Properties[property.Name]; object propertyValue = propertyDescriptor.GetValue(initItem.Bean); string propertyValueStr = propertyValue == null ? string.Empty : propertyValue.ToString(); if (property.DataType.Equals("bool")) { // gestion d'un booléen sous Oracle: number appartenant à {0,1} nameValueDict[property.DataMember.Name] = propertyValueStr.Equals("true") ? "1" : "0"; } else if (propertyDescriptor.PrimitiveType == typeof(string)) { nameValueDict[property.DataMember.Name] = "'" + propertyValueStr.Replace("'", "''") + "'"; } else if (propertyDescriptor.PrimitiveType == typeof(DateTime)) { nameValueDict[property.DataMember.Name] = "to_date('" + string.Format("{0:MM/dd/yy}", (DateTime)propertyValue) + "', 'DD/MM/YY')"; } else { nameValueDict[property.DataMember.Name] = propertyValueStr; } } else { // cas de la clé primaire non spécifiée sous Oracle: on utilise une séquence pour auto incrémenter la valeur de la clé nameValueDict[property.DataMember.Name] = GetSequenceName(modelClass) + ".nextval"; } } return(nameValueDict); }
private void Application_Startup(object sender, StartupEventArgs e) { ItemInit.Init(); CraftInit.Init(); }
/// <summary> /// Crée un dictionnaire { nom de la propriété => valeur } pour un item à insérer. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Dictionnaire contenant { nom de la propriété => valeur }.</returns> protected override Dictionary <string, string> CreatePropertyValueDictionary(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded) { Dictionary <string, string> nameValueDict = new Dictionary <string, string>(); BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean); foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (!property.DataDescription.IsPrimaryKey || isPrimaryKeyIncluded) { BeanPropertyDescriptor propertyDescriptor = definition.Properties[property.Name]; object propertyValue = propertyDescriptor.GetValue(initItem.Bean); string propertyValueStr = propertyValue == null ? string.Empty : propertyValue.ToString(); if (property.DataType == "byte[]") { nameValueDict[property.DataMember.Name] = GetBulkColumn(propertyValueStr); } else if (propertyDescriptor.PrimitiveType == typeof(string)) { nameValueDict[property.DataMember.Name] = "'" + propertyValueStr.Replace("'", "''") + "'"; } else { nameValueDict[property.DataMember.Name] = propertyValueStr; } } } return(nameValueDict); }
/// <summary> /// Retourne l'instruction d'update de l'item dans la calsse ModelClass. /// </summary> /// <param name="modelClass">Table.</param> /// <param name="initItem">Item.</param> /// <returns>Nombre de lignes mises à jour.</returns> private static string GetUpdateLine(ModelClass modelClass, ItemInit initItem) { StringBuilder sb = new StringBuilder(); sb.Append("UPDATE " + modelClass.DataContract.Name + " SET "); BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean); int persistentPropertyCount = definition.Properties.Count; int idx = 0; BeanPropertyDescriptorCollection propertyList = definition.Properties; ModelProperty key = null; foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (propertyList.Contains(property.Name)) { ++idx; if (property.DataDescription.IsPrimaryKey || (key == null && property.IsUnique)) { key = property; } else { sb.Append(property.DataMember.Name); sb.Append(" = "); object propertyValue = propertyList[property.Name].GetValue(initItem.Bean); string propertyValueStr = propertyValue == null ? string.Empty : propertyValue.ToString(); if (property.DataType == "byte[]") { sb.Append(GetBulkColumn(propertyValueStr)); } else if (propertyList[property.Name].PrimitiveType == typeof(string)) { sb.Append("'" + propertyValueStr.Replace("'", "''") + "'"); } else { sb.Append(propertyValueStr); } if (idx < persistentPropertyCount) { sb.Append(", "); } } } } sb.Append(" WHERE "); sb.Append(key.DataMember.Name); sb.Append(" = "); if (propertyList[key.Name].PrimitiveType == typeof(string)) { sb.Append("'" + propertyList[key.Name].GetValue(initItem.Bean).ToString().Replace("'", "''") + "'"); } else { sb.Append(propertyList[key.Name].GetValue(initItem.Bean).ToString()); } sb.Append(";"); return(sb.ToString()); }
public void OnServerInit() { Logger.log(Logger.LogLevel.INFO, "######################## Initalise ########################"); cursor = Cursor.getCursor(); RandomManager.GetRandom(); Test.Text3DTest.Init(); ItemInit.Init(); DefaultItems.Init(); DayTime.Init(); DayTime.setTime(0, 12, 0); #if SSM_AI AI.AISystem.Init(); #endif DefaultWorld.Init(); DamageScript.Init(); #if SSM_CHAT //chat = new Chat(); //chat.Init(); //important: register notification types for notification areas! NotificationManager.GetNotificationManager().AddNotificationArea(100, 100, 50, 8, new NotificationType[] { NotificationType.ChatMessage, NotificationType.ServerMessage, NotificationType.PlayerStatusMessage, NotificationType.MobsiMessage, NotificationType.Sound }); CommandInterpreter.GetCommandInterpreter(); Chat.GetChat(); EventNotifier.GetEventNotifier(); #endif Modules.Init(); //Modules.addModule(new Test.ListTestModule()); #if SSM_ACCOUNT AccountSystem accSystem = new AccountSystem(); accSystem.Init(); #endif #if SSM_WEB Web.http_server.Init(); #endif Logger.log(Logger.LogLevel.INFO, "###################### End Initalise ######################"); }