/// <summary> /// Обновить и отправить количество случайных сущностей сервису /// </summary> /// <param name="messageCount">Количество сущностей</param> private static void UpdateAndSendRandomEntity(int messageCount) { if (DbEntities.Count < messageCount) { InitParams(); } List <int> updatedId = new List <int>(); for (int i = 0; i < messageCount; i++) { int randomElemPos; bool isInList; do { randomElemPos = EntityService.RandomGenerator.Next(DbEntities.Count); isInList = updatedId.IndexOf(randomElemPos) != -1; }while (isInList); long oldId = DbEntities[randomElemPos].Id; DbEntities[randomElemPos] = EntityService.GetNewRandomEntity(); DbEntities[randomElemPos].Id = oldId; updatedId.Add(randomElemPos); UpdateRandomEntity(DbEntities[randomElemPos], false); } }
/// <summary> /// Инициализация объектов БД в сервисе /// </summary> private static void InitParams() { DbEntities = WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(SettingsApp.Default.DefaultServiceHost, "api/ParamsEntities", WebApiHelper.HttpMethod.GET)?.Result; int missedEntitiesCount; if (DbEntities == null) { missedEntitiesCount = SettingsApp.Default.MaxEntities; } else { missedEntitiesCount = SettingsApp.Default.MaxEntities - DbEntities.Count; } if (missedEntitiesCount > 0) { for (int i = 0; i < missedEntitiesCount; i++) { UpdateRandomEntity(EntityService.GetNewRandomEntity(), true); } DbEntities = WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(SettingsApp.Default.DefaultServiceHost, "api/ParamsEntities", WebApiHelper.HttpMethod.GET)?.Result; } }