public void WeenieSearch_ByContent_DoesntExplode() { SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.ContentGuid = Guid.NewGuid(); var results = worldDb.SearchWeenies(criteria); Assert.IsNotNull(results); }
public void WeenieSearch_ByItemType_DoesntExplode() { SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.ItemType = Entity.Enum.ItemType.LifeStone; var results = worldDb.SearchWeenies(criteria); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0, "no lifestones (itemtype) in the database is bad."); }
public void WeenieSearch_ByWeenieClassId_DoesntExplode() { SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.WeenieClassId = 6353; // Pyreal Mote var results = worldDb.SearchWeenies(criteria); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); }
public void WeenieSearch_ByName_ReturnsKnownWeenies() { SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.PartialName = "Pyreal Mote"; var results = worldDb.SearchWeenies(criteria); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); }
public bool UserModifiedFlagPresent() { // seach weenies or look for a single user mod flag ? SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.UserModified = true; var result = SearchWeenies(criteria); if (result.Count > 0) { return(true); } return(false); }
public List <WeenieSearchResult> WeenieSearch(string token, SearchWeeniesCriteria criteria) { RestRequest request = BuildRequest("/Weenie/Search", Method.POST, token); request.AddJsonBody(criteria); IRestResponse response = _client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { return(JsonConvert.DeserializeObject <List <WeenieSearchResult> >(response.Content)); } throw new ApplicationException("Unable to search for weenies from server: " + response.Content, response.ErrorException); }
public void WeenieSearch_ByFloatProperty_ReturnsObject() { SearchWeeniesCriteria criteria = new SearchWeeniesCriteria(); criteria.PartialName = "Peerless Healing Kit"; criteria.PropertyCriteria.Add(new SearchWeenieProperty() { PropertyType = AceObjectPropertyType.PropertyDouble, PropertyId = (uint)PropertyDouble.HealkitMod, PropertyValue = "1.75" }); var results = worldDb.SearchWeenies(criteria); Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0, "no Peerless Healing Kit in the database is bad."); }
public List <WeenieSearchResult> SearchWeenies(SearchWeeniesCriteria criteria) { List <WeenieSearchResult> results = new List <WeenieSearchResult>(); List <MySqlParameter> mysqlParams = new List <MySqlParameter>(); var properties = GetPropertyCache(typeof(WeenieSearchResult)); var dbTable = GetDbTableAttribute(typeof(WeenieSearchResult)); string sql = "SELECT " + string.Join(", ", properties.Select(p => "`v`." + p.Item2.DbFieldName)) + " FROM " + dbTable.DbTableName + " `v` "; string where = null; if (criteria?.ContentGuid != null) { where = where != null ? where + " AND " : ""; where += "`v`.aceObjectId IN (SELECT weenieId FROM ace_content_weenie WHERE contentGuid = ?)"; var p = new MySqlParameter("", MySqlDbType.Binary); p.Value = criteria.ContentGuid.Value.ToByteArray(); mysqlParams.Add(p); } if (criteria?.ItemType != null) { where = where != null ? where + " AND " : ""; where += "`itemType` = ?"; var p = new MySqlParameter("", MySqlDbType.Int32); p.Value = (int)criteria.ItemType.Value; mysqlParams.Add(p); } if (criteria?.WeenieType != null) { where = where != null ? where + " AND " : ""; where += "`weenieType` = ?"; var p = new MySqlParameter("", MySqlDbType.Int32); p.Value = (int)criteria.WeenieType.Value; mysqlParams.Add(p); } if (criteria?.WeenieClassId != null) { where = where != null ? where + " AND " : ""; where += "`v`.aceObjectId = ?"; var p = new MySqlParameter("", MySqlDbType.UInt32); p.Value = (uint)criteria.WeenieClassId.Value; mysqlParams.Add(p); } if (criteria?.UserModified != null) { where = where != null ? where + " AND " : ""; where += "`v`.userModified = ?"; var p = new MySqlParameter("", MySqlDbType.Bit); p.Value = criteria.UserModified.Value; mysqlParams.Add(p); } if (!string.IsNullOrWhiteSpace(criteria?.PartialName)) { where = where != null ? where + " AND " : ""; where += "`v`.`name` LIKE '%" + EscapeStringLiteral(criteria.PartialName) + "%'"; } int index = 0; if (criteria?.PropertyCriteria != null) { foreach (var prop in criteria.PropertyCriteria) { // this should be the 99% use case switch (prop.PropertyType) { case AceObjectPropertyType.PropertyBool: sql += $" INNER JOIN ace_object_properties_bool `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.boolPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {bool.Parse(prop.PropertyValue)}"; break; case AceObjectPropertyType.PropertyString: sql += $" INNER JOIN ace_object_properties_string `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.strPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue like '%{EscapeStringLiteral(prop.PropertyValue)}%'"; break; case AceObjectPropertyType.PropertyDouble: float fnum = float.Parse(prop.PropertyValue); sql += $" INNER JOIN ace_object_properties_double `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.dblPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {fnum}"; break; case AceObjectPropertyType.PropertyDataId: uint did = uint.Parse(prop.PropertyValue); sql += $" INNER JOIN ace_object_properties_did `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.didPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {did}"; break; case AceObjectPropertyType.PropertyInstanceId: uint iid = uint.Parse(prop.PropertyValue); sql += $" INNER JOIN ace_object_properties_iid `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.iidPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {iid}"; break; case AceObjectPropertyType.PropertyInt: uint id = uint.Parse(prop.PropertyValue); sql += $" INNER JOIN ace_object_properties_int `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.intPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {id}"; break; case AceObjectPropertyType.PropertyInt64: ulong id64 = ulong.Parse(prop.PropertyValue); sql += $" INNER JOIN ace_object_properties_int `prop{index}` ON `v`.`aceObjectId` = `prop{index}`.aceObjectId " + $"AND `prop{index}`.intPropertyId = {prop.PropertyId} " + $"AND `prop{index}`.propertyValue = {id64}"; break; case AceObjectPropertyType.PropertyBook: // TODO: implement break; case AceObjectPropertyType.PropertyPosition: // TODO: implement. this will look up the static weenie mappings of where things are supposed to be spawned break; default: break; } index++; } } // note, "sql" may have had additional joins done on it with criteria if (where != null) { sql += " WHERE " + where; } sql += " ORDER BY aceObjectId"; using (var connection = new MySqlConnection(connectionString)) { using (var command = new MySqlCommand(sql, connection)) { mysqlParams.ForEach(p => command.Parameters.Add(p)); connection.Open(); using (var commandReader = command.ExecuteReader(CommandBehavior.Default)) { while (commandReader.Read()) { results.Add(ReadObject <WeenieSearchResult>(commandReader)); } } } } return(results); }
public List <WeenieSearchResult> SearchWeenies(SearchWeeniesCriteria criteria) { return(_wrappedDatabase.SearchWeenies(criteria)); }
public List <WeenieSearchResult> WeenieSearch(string token, SearchWeeniesCriteria criteria) { var copy = Weenies.Values.Select(w => w); if (criteria != null) { if (criteria.WeenieClassId.HasValue) { copy = copy.Where(w => w.WeenieId == criteria.WeenieClassId); } if (criteria.ItemType.HasValue) { copy = copy.Where(w => w.ItemType == (int)criteria.ItemType); } if (criteria.WeenieType.HasValue) { copy = copy.Where(w => w.WeenieTypeId == (int)criteria.WeenieType); } if (!string.IsNullOrWhiteSpace(criteria.PartialName)) { copy = copy.Where(w => w.Name.ToLower().Contains(criteria.PartialName.ToLower())); } if (criteria.PropertyCriteria?.Count > 0) { criteria.PropertyCriteria.ForEach(pc => { try { if (string.IsNullOrEmpty(pc.PropertyValue)) { return; } switch (pc.PropertyType) { case PropertyType.PropertyBool: copy = copy.Where(w => w.BoolStats.Any(p => p.Key == pc.PropertyId && p.BoolValue == bool.Parse(pc.PropertyValue))); break; case PropertyType.PropertyDataId: copy = copy.Where(w => w.DidStats.Any(p => p.Key == pc.PropertyId && p.Value == uint.Parse(pc.PropertyValue))); break; case PropertyType.PropertyDouble: copy = copy.Where(w => w.FloatStats.Any(p => p.Key == pc.PropertyId && p.Value == double.Parse(pc.PropertyValue))); break; case PropertyType.PropertyInt: copy = copy.Where(w => w.IntStats.Any(p => p.Key == pc.PropertyId && p.Value == int.Parse(pc.PropertyValue))); break; case PropertyType.PropertyInt64: copy = copy.Where(w => w.Int64Stats.Any(p => p.Key == pc.PropertyId && p.Value == long.Parse(pc.PropertyValue))); break; case PropertyType.PropertyString: copy = copy.Where(w => w.StringStats.Any(p => p.Key == pc.PropertyId && p.Value.Contains(pc.PropertyValue))); break; default: log.Warn($"Weenie search for unsupported property type {pc.PropertyType}"); break; } } catch (Exception ex) { log.Error($"Weenie Search {ex.ToString()}"); } }); } } return(copy.Select(w => new WeenieSearchResult() { Description = w.StringStats.Find(p => p.Key == (int)StringPropertyId.ShortDesc)?.Value, LastModified = w.LastModified, ModifiedBy = w.ModifiedBy, Name = w.Name, ItemType = (ItemType?)w.ItemType, WeenieClassId = w.WeenieId, WeenieType = (WeenieType?)w.WeenieTypeId, IsDone = w.IsDone, HasSandboxChange = !w.IsDone && w.LastModified != null }).ToList()); }
public HttpResponseMessage Search([FromBody] SearchWeeniesCriteria request) { return(Request.CreateResponse(HttpStatusCode.OK, WorldDb.SearchWeenies(request))); }
public List <WeenieSearchResult> WeenieSearch(string token, SearchWeeniesCriteria criteria) { return(_backingProvider.WeenieSearch(token, criteria)); }
public JsonResult WeenieFinder(SearchWeeniesCriteria model) { List <WeenieSearchResult> results = ContentProviderHost.CurrentProvider.WeenieSearch(GetUserToken(), model); return(Json(results)); }