public static async Task CreateTableAsync(this ITableContext tableContext, Authentication authentication) { var category = await tableContext.GetRandomTableItemAsync(item => item is ITableCategory) as ITableCategory; var template = await category.AddNewTableAsync(authentication); await GenerateColumnsAsync(template, authentication, RandomUtility.Next(3, 10)); if (RandomUtility.Within(25) == true) { await template.SetCommentAsync(authentication, RandomUtility.NextString()); } await template.EndEditAsync(authentication); var tables = template.Target as ITable[]; var table = tables.First(); while (RandomUtility.Within(10)) { var childTemplate = await table.NewTableAsync(authentication); await GenerateColumnsAsync(childTemplate, authentication, RandomUtility.Next(3, 10)); await childTemplate.EndEditAsync(authentication); } var content = table.Content; await content.EnterEditAsync(authentication); await GenerateRowsAsync(content, authentication, RandomUtility.Next(10, 100)); foreach (var item in table.Childs) { await GenerateRowsAsync(item.Content, authentication, RandomUtility.Next(10, 100)); } await content.LeaveEditAsync(authentication); }
public void AddAccessMember(ITypeCategory category, TaskContext context) { category.Dispatcher.Invoke(() => { if (category.Parent == null) { return; } var userContext = category.GetService(typeof(IUserContext)) as IUserContext; var memberID = userContext.Dispatcher.Invoke(() => userContext.Select(item => item.Path).Random()); var accessType = RandomUtility.NextEnum <AccessType>(); if (Verify() == false) { return; } if (NameValidator.VerifyItemPath(memberID) == true) { category.AddAccessMember(context.Authentication, new ItemName(memberID).Name, accessType); } else { category.AddAccessMember(context.Authentication, memberID, accessType); } }); bool Verify() { if (context.AllowException == true) { return(true); } if (category.IsPrivate == false) { return(false); } return(true); } }
public static string ShowDataGrid(Hashtable ht) { string json = string.Empty; if (!htSession.Contains("demoDataGrid")) { htSession.Add("demoDataGrid", RandomUtility.RandomDataTable()); } DataTable funcDs = (DataTable)htSession["demoDataGrid"]; List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); int page = int.Parse(ht["page"].ToString()); int rows = int.Parse(ht["rows"].ToString()); //int start = rows * (page - 1); int end = rows * page < funcDs.Rows.Count ? rows * page : funcDs.Rows.Count; try { for (int start = rows * (page - 1); start < end; start++) { Dictionary <string, object> json1 = new Dictionary <string, object>(); foreach (DataColumn dc in funcDs.Columns) { json1.Add(dc.ColumnName, funcDs.Rows[start][dc.ColumnName].ToString()); } list.Add(json1); } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("total", funcDs.Rows.Count); result.Add("rows", list); json = JsonUtility.GetSuccessJson(result); } catch (Exception ex) { json = JsonUtility.GetErrorJson("Error Message Is " + ex.Message); } return(json); }
public static void UserCreateTest(this ICremaHost cremaHost, Authentication authentication, Authority authority) { cremaHost.Dispatcher.Invoke(() => { var userContext = cremaHost.GetService(typeof(IUserContext)) as IUserContext; if (userContext.Users[authentication.ID].Authority != Authority.Admin) { return; } var category = userContext.Categories.Random(); var identifier = RandomUtility.NextIdentifier(); if (authority == Authority.Admin) { var newID = string.Format("Admin_{0}", identifier); var newName = string.Format("관리자_{0}", identifier); category.AddNewUser(authentication, newID, null, newName, Authority.Admin); } else if (authority == Authority.Member) { var newID = string.Format("Member_{0}", identifier); var newName = string.Format("구성원_{0}", identifier); category.AddNewUser(authentication, newID, null, newName, Authority.Member); } else { var newID = string.Format("Guest_{0}", identifier); var newName = string.Format("손님_{0}", identifier); category.AddNewUser(authentication, newID, null, newName, Authority.Guest); } }); }
public static CremaDataTypeMember CreateMember(this CremaDataType dataType) { var memberName = RandomUtility.NextIdentifier(); if (dataType.Members.Contains(memberName) == true) { return(null); } var member = dataType.NewMember(); member.Name = memberName; if (dataType.IsFlag == true) { member.Value = RandomUtility.NextBit(); } else { member.Value = RandomUtility.Next(dataType.Members.Count); } if (RandomUtility.Within(10) == true) { member.Comment = RandomUtility.NextString(); } try { dataType.Members.Add(member); return(member); } catch { return(null); } }
public static bool GenerateCategory(this ITableContext context, Authentication authentication) { var categoryName = RandomUtility.NextIdentifier(); var category = RandomUtility.Within(50) == true ? context.Root : context.Categories.Random(); if (category.VerifyAccessType(authentication, AccessType.Master) == false) { return(false); } if (GetLevel(category, (i) => i.Parent) > 4) { return(false); } if (category.Categories.ContainsKey(categoryName) == true) { return(false); } category.AddNewCategory(authentication, categoryName); return(true); }
private async Task ImportAsync_Private_TestAsync(Authority authority, AccessType accessType) { var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Private | DataBaseFlags.NotLocked) { Settings = DataBaseSettings.Default }; var dataBase = await dataBaseFilter.GetDataBaseAsync(app); var accessInfo = dataBase.AccessInfo; var query = from item in accessInfo.Members where item.AccessType == accessType select item.ID; var authentication = await this.TestContext.LoginRandomAsync(authority, item => query.Contains(item.ID)); var filter = new CremaDataSetFilter() { OmitContent = true }; var dataSet = await dataBase.GetDataSetAsync(authentication, filter, string.Empty); var comment = RandomUtility.NextString(); await Base_TestAsync(dataBase, authentication, dataSet, comment); }
public static async Task <ITable> GenerateTableAsync(this ITableCategory tableCategory, Authentication authentication, params string[] typeNames) { var tableCollection = tableCategory.GetService(typeof(ITableCollection)) as ITableCollection; var newName = await tableCollection.GenerateNewTableNameAsync("table"); var template = await tableCategory.AddNewTableAsync(authentication); await template.SetTableNameAsync(authentication, newName); foreach (var item in typeNames) { var columnName = await template.GenerateNewColumnNameAsync(); var comment = RandomUtility.NextString(); await template.AddColumnAsync(authentication, columnName, item, comment); } await template.AddRandomColumnsAsync(authentication); await template.EndEditAsync(authentication); return(template.Target as ITable); throw new NotImplementedException(); }
public static async Task <ITable> AddRandomTableAsync(this ITableCategory category, Authentication authentication, DataBaseSettings settings) { var template = await category.AddNewTableAsync(authentication); await template.InitializeRandomAsync(authentication); await template.EndEditAsync(authentication); if (template.Target is ITable[] tables) { foreach (var item in tables) { var minCount = settings.TableContext.MinRowCount; var maxCount = settings.TableContext.MaxRowCount; var count = RandomUtility.Next(minCount, maxCount); await item.AddRandomRowsAsync(authentication, count); } return(tables.First()); } else { throw new NotImplementedException(); } }
private static void GenerateStandardContent(this ITable table, Authentication authentication) { var content = table.Content; content.BeginEdit(authentication); content.EnterEdit(authentication); content.GenerateRows(authentication, RandomUtility.Next(10, 1000)); foreach (var item in content.Childs) { item.GenerateRows(authentication, RandomUtility.Next(10, 100)); } try { content.LeaveEdit(authentication); content.EndEdit(authentication); } catch { content.CancelEdit(authentication); } }
public override void Initialize() { AbstractContinousOptimizationEvaluator evaluator = this._problem.SolutionQualityEvaluator as AbstractContinousOptimizationEvaluator; double mean = (evaluator.MaximumVariableValue + evaluator.MinimumVariableValue) / 2; double initialStdv = (evaluator.MaximumVariableValue - mean) / 3; for (int vectorIndex = 0; vectorIndex < this._colonySize; vectorIndex++) { this._pheromone[vectorIndex] = new double[this._problemSize]; this._inverse[vectorIndex] = new double[this._problemSize]; for (int variableIndex = 0; variableIndex < this._problemSize; variableIndex++) { this._pheromone[vectorIndex][variableIndex] = RandomUtility.Random(evaluator.MinimumVariableValue, evaluator.MaximumVariableValue); this._inverse[vectorIndex][variableIndex] = -this._pheromone[vectorIndex][variableIndex]; this._stdv[variableIndex] = initialStdv; } Solution <double> solution = Solution <double> .FromList(this._pheromone[vectorIndex].ToList()); this.EvaluateSolutionQuality(solution); this._qualityArray[vectorIndex] = solution.Quality; } }
public async Task InvokeAsync(TaskContext context) { var authentication = context.Authentication; var dataBase = context.Target as IDataBase; if (context.IsCompleted(dataBase) == true) { context.Pop(dataBase); } else { if (await dataBase.ContainsAsync(authentication) == false) { return; } if (RandomUtility.Within(35) == true) { var typeItem = await dataBase.GetRandomTypeItemAsync(); await typeItem.Dispatcher.InvokeAsync(() => { if (typeItem.VerifyAccessType(authentication, AccessType.Guest) == true) { context.Push(typeItem); } }); } else { var tableItem = await dataBase.GetRandomTableItemAsync(); context.Push(tableItem); } } }
public async Task TaskCompleted_TestAsync() { var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin); var userCollection = userContext.GetService(typeof(IUserCollection)) as IUserCollection; var user = await userCollection.GetUserAsync(authentication.ID); var password = user.GetPassword(); var actualTaskID = Guid.Empty; await userContext.AddTaskCompletedEventHandlerAsync(UserContext_TaskCompleted); var expectedTaskID = await(user.SetUserNameAsync(authentication, password, RandomUtility.NextName()) as Task <Guid>); Assert.AreEqual(expectedTaskID, actualTaskID); await userContext.RemoveTaskCompletedEventHandlerAsync(UserContext_TaskCompleted); expectedTaskID = await(user.SetUserNameAsync(authentication, password, RandomUtility.NextName()) as Task <Guid>); Assert.AreNotEqual(expectedTaskID, actualTaskID); void UserContext_TaskCompleted(object sender, TaskCompletedEventArgs e) { actualTaskID = e.TaskIDs.Single(); } }
public void CopyChildTable() { var dataSet = new CremaDataSet(); var dataTable = dataSet.Tables.Add(); var childTable1 = dataTable.Childs.Add(); var derivedTable = dataTable.Inherit(); derivedTable.CategoryPath = RandomUtility.NextCategoryPath(); var childTable2 = childTable1.Copy(); var derivedChild1 = derivedTable.Childs[childTable1.TableName]; var derivedChild2 = derivedTable.Childs[childTable2.TableName]; Assert.AreEqual(derivedTable.CategoryPath, derivedChild1.CategoryPath); Assert.AreEqual(derivedTable.CategoryPath, derivedChild2.CategoryPath); Assert.AreEqual(dataTable.Childs.Count, derivedTable.Childs.Count); Assert.AreEqual(childTable1.TableName, derivedChild1.TableName); Assert.AreEqual(childTable2.TableName, derivedChild2.TableName); Assert.AreEqual(childTable1.Name, derivedChild1.TemplatedParentName); Assert.AreEqual(childTable2.Name, derivedChild2.TemplatedParentName); }
public void SetupTraitEndTime() { if (this.HasSpecialCase(PersonalityTrait.SpecialCaseType.CarPartPromise) && !this.mDriver.IsFreeAgent()) { this.mTraitEndTime = this.mDriver.Contract.GetTeam().championship.GetCurrentEventDetails().raceSessions[0].sessionDateTime; } else if (this.HasSpecialCase(PersonalityTrait.SpecialCaseType.ChampionshipPositionPromise) && !this.mDriver.IsFreeAgent()) { this.mTraitEndTime = this.mDriver.Contract.GetTeam().championship.currentSeasonEndDate.AddDays(-1.0); } else if (this.data.possibleLength.Length == 1) { this.mTraitEndTime = Game.instance.time.now.AddDays((double)(7 * this.data.possibleLength[0])); } else if (this.data.possibleLength.Length > 1) { int randomInc = RandomUtility.GetRandomInc(this.data.possibleLength[0], this.data.possibleLength[1]); this.mTraitEndTime = Game.instance.time.now.AddDays((double)(7 * randomInc)); } else { this.mTraitEndTime = Game.instance.time.now.AddDays(1.0); } }
public LinScoredFloat r; //SecondsBetweenShots public PGFBurstData() { this.n = new LinScoredFloat((int)RandomUtility.RandFloat(MIN_BURST_SIZE, MAX_BURST_SIZE), MIN_BURST_SIZE, MAX_BURST_SIZE, MAX_BURST_SIZE); this.r = new LinScoredFloat(RandomUtility.RandFloat(MIN_SECONDS_BETWEEN_SHOTS, MAX_SECONDS_BETWEEN_SHOTS), MIN_SECONDS_BETWEEN_SHOTS, MAX_SECONDS_BETWEEN_SHOTS, MIN_SECONDS_BETWEEN_SHOTS); }
public async Task NotifyMessageAsync_Expired_FailTestAsync() { var userIDs = new string[] { }; var message = RandomUtility.NextString(); await userContext.NotifyMessageAsync(expiredAuthentication, userIDs, message); }
public async Task NotifyMessageAsync_Arg0_Null_FailTestAsync() { var userIDs = new string[] { }; var message = RandomUtility.NextString(); await userContext.NotifyMessageAsync(null, userIDs, message); }
public void Rename() { userItem.Rename(authentication, RandomUtility.NextIdentifier()); }
/// <summary> /// 获取表面上随机的位置 /// </summary> public Vector3 GetRandomPositionInSurface() { Vector3 actualSize = ActualSize; Vector3 pos = Vector3.zero; switch (RandomUtility.Index(actualSize.y * actualSize.z, actualSize.x * actualSize.z, actualSize.x * actualSize.y)) { case 0: pos = new Vector3(RandomUtility.sign * Extents.x, RandomUtility.Extents(Extents.y), RandomUtility.Extents(Extents.z)); break; case 1: pos = new Vector3(RandomUtility.Extents(Extents.x), RandomUtility.sign * Extents.y, RandomUtility.Extents(Extents.z)); break; case 2: pos = new Vector3(RandomUtility.Extents(Extents.x), RandomUtility.Extents(Extents.z), RandomUtility.sign * Extents.z); break; } return(GetWorldSpacePosition(pos)); }
public void SetInvalidName_Fail() { var newName = RandomUtility.NextInvalidIdentifier(); this.attribute.AttributeName = newName; }
public void SetNullDefaultValue() { this.attribute.DefaultValue = RandomUtility.NextString(); this.attribute.DefaultValue = null; Assert.AreEqual(DBNull.Value, this.attribute.DefaultValue); }
public void NewWithName_Fail() { var attributeName = RandomUtility.NextInvalidIdentifier(); new CremaAttribute(attributeName); }
public void SetNullComment() { this.attribute.Comment = RandomUtility.NextString(); this.attribute.Comment = null; Assert.AreEqual(string.Empty, this.attribute.Comment); }
public override Vector3 GetRandomPositionInArea() { return(GetWorldSpacePosition(new Vector3(RandomUtility.Extents(Extents.x), RandomUtility.Extents(Extents.y), RandomUtility.Extents(Extents.z)))); }
public void SetNullName() { this.attribute.AttributeName = RandomUtility.NextIdentifier(); this.attribute.AttributeName = null; Assert.AreEqual(string.Empty, this.attribute.AttributeName); }
public override Vector3 GetRandomPositionInEdge() { Vector3 pos = Vector3.zero; switch (RandomUtility.Index(ActualSize.x, ActualSize.y, ActualSize.z)) { case 0: pos = new Vector3(RandomUtility.Extents(Extents.x), RandomUtility.sign * Extents.y, RandomUtility.sign * Extents.z); break; case 1: pos = new Vector3(RandomUtility.sign * Extents.x, RandomUtility.Extents(Extents.y), RandomUtility.sign * Extents.z); break; case 2: pos = new Vector3(RandomUtility.sign * Extents.x, RandomUtility.sign * Extents.y, RandomUtility.Extents(Extents.z)); break; } return(GetWorldSpacePosition(pos)); }
public static async Task <IUserCategory> GenerateCategoryAsync(this IUserCategoryCollection userCategoryCollection, Authentication authentication) { var category = RandomUtility.Within(50) == true ? userCategoryCollection.Root : await userCategoryCollection.GetRandomUserCategoryAsync(); return(await category.AddNewCategoryAsync(authentication, RandomUtility.NextIdentifier())); }
//Methods void Start() { if (Room.roomTypes.Count == 0) { Room.roomTypes.Add("undefined", 0); Room.roomTypes.Add("public", 1); Room.roomTypes.Add("private", 2); Room.roomTypes.Add("entrance", 3); } randomUtility = gameObject.AddComponent<RandomUtility>(); textObject = GameObject.Find("LoadingText"); loadingText = textObject.GetComponent<Text>(); loadingText.text = "..."; StartCoroutine(Generate()); //StartCoroutine(CreateRooms(amountOfRooms)); //StartCoroutine(TestNTimes(10)); }
private static void DoBoss(BotMain bot, TerritoryStanding terr, SpecialUnit su) { AILog.Log("SpecialUnits", "Considering boss " + su.ID + " on " + bot.TerrString(terr.ID)); var routes = bot.Directives.Where(o => o.StartsWith("BossRoute ")).Select(o => new BossRoute(o, bot)).ToList(); var routeNexts = routes.Select(o => new { Route = o, Terr = o.NextTerr(terr.ID) }).Where(o => o.Terr.HasValue).ToList(); if (routeNexts.Count > 0) { var routeNext = routeNexts.WeightedRandom(o => o.Route.Weight); AILog.Log("SpecialUnits", routeNexts.Count + " matching routes: " + routeNexts.Select(o => o.Route.Name).JoinStrings(", ") + ", selected " + routeNext.Route); if (RandomUtility.RandomPercentage() > routeNext.Route.Chance) { AILog.Log("SpecialUnits", "Skipping boss route to " + routeNext.Terr.Value + " due to failed random chance. "); } else { AILog.Log("SpecialUnits", "Moving boss along route to " + bot.TerrString(routeNext.Terr.Value) + ". "); bot.Orders.AddAttack(terr.ID, routeNext.Terr.Value, AttackTransferEnum.AttackTransfer, 0, true, bosses: true); bot.AvoidTerritories.Add(routeNext.Terr.Value); return; } } else if (routes.Count > 0) { //Move towards the nearest route territory. If there's a tie, take the one that's furthest along in that route var terrRoutes = routes.SelectMany(r => r.Route.Select((t, i) => new { Route = r, Terr = t, Index = i })) .GroupBy(o => o.Terr) .Select(o => o.MaxSelectorOrDefault(r => r.Index)) .ToDictionary(o => o.Terr, o => o); var visited = new HashSet <TerritoryIDType>(); visited.Add(terr.ID); while (true) { var visit = visited.SelectMany(o => bot.Map.Territories[o].ConnectedTo.Keys).ToHashSet(false); if (visit.Count == 0) { throw new Exception("Never found route territory"); } var visitOnRoute = visit.Where(o => terrRoutes.ContainsKey(o)).ToList(); if (visitOnRoute.Count > 0) { var final = visitOnRoute.Select(o => terrRoutes[o]).MaxSelectorOrDefault(o => o.Index); if (RandomUtility.RandomPercentage() > final.Route.Chance) { AILog.Log("SpecialUnits", "Skipping moving boss to route due to failed random check: " + final.Route); break; } else { var move = FindPath.TryFindShortestPath(bot, terr.ID, t => t == final.Terr); AILog.Log("SpecialUnits", "Moving boss to get back to route. Moving to " + bot.TerrString(move[0]) + " to get to " + bot.TerrString(final.Terr) + " index=" + final.Index + " " + final.Route); bot.Orders.AddAttack(terr.ID, move[0], AttackTransferEnum.AttackTransfer, 0, true, bosses: true); bot.AvoidTerritories.Add(final.Terr); return; } } visited.AddRange(visit); } } var attackCandidates = bot.Map.Territories[terr.ID].ConnectedTo.Keys.Select(o => bot.Standing.Territories[o]) .Where(o => !bot.IsTeammateOrUs(o.OwnerPlayerID) && o.NumArmies.DefensePower < 300 && !bot.AvoidTerritories.Contains(o.ID)) .ToList(); if (attackCandidates.Count > 0) { var ranks = attackCandidates.ToDictionary(o => o.ID, ts => { if (bot.IsOpponent(ts.OwnerPlayerID)) { return(bot.Players[ts.OwnerPlayerID].IsAI ? 3 : 2); //prefer human player } else if (ts.OwnerPlayerID == TerritoryStanding.NeutralPlayerID) { return(1); } else { throw new Exception("Unexpected owner " + ts.OwnerPlayerID); } }); var max = ranks.Values.Max(); var to = ranks.Where(o => o.Value == max).Random().Key; AILog.Log("SpecialUnits", "Normal boss move to " + bot.TerrString(to)); bot.Orders.AddAttack(terr.ID, to, AttackTransferEnum.AttackTransfer, 0, false, bosses: true); bot.AvoidTerritories.Add(to); } else { //Surrounded by ourself or teammates. Move towards enemy var move = bot.MoveTowardsNearestBorderNonNeutralThenNeutral(terr.ID); if (move.HasValue) { AILog.Log("SpecialUnits", "Landlocked boss move to " + bot.TerrString(move.Value)); bot.Orders.AddAttack(terr.ID, move.Value, AttackTransferEnum.AttackTransfer, 0, false, bosses: true); } } }
public void SetValue() { member.SetValue(authentication, RandomUtility.NextLong(long.MaxValue)); }