/// <summary> /// On start create all the instances if the referenced object is a prefab /// </summary> protected void Start() { for (int i = 0; i < ButtonStates.Length; i++) { if (ButtonStates[i].Prefab != null) { if (StaticExtensions.IsPrefab(ButtonStates[i].Prefab)) { ButtonStates[i].Instance = Instantiate(ButtonStates[i].Prefab, this.transform.position, this.transform.rotation) as GameObject; ButtonStates[i].Instance.transform.parent = this.transform; // Remove Clone Name ButtonStates[i].Instance.name = ButtonStates[i].Instance.name.Substring(0, ButtonStates[i].Instance.name.Length - 7); } else { ButtonStates[i].Instance = ButtonStates[i].Prefab; } ButtonStates[i].Instance.transform.localScale = Vector3.Scale(ButtonStates[i].Instance.transform.localScale, ButtonStates[i].Scale); ButtonStates[i].Instance.transform.localPosition = ButtonStates[i].Instance.transform.localPosition + ButtonStates[i].Offset; // Now set inactive till state change ButtonStates[i].Instance.SetActive(false); } OnStateChange(ButtonStateEnum.Observation); } }
public async Task TestConvertFileSystemToGraphAsyncTaskWithoutHashWithoutPersistence() { var asyncFileReadBlockSize = 4096; var enableHash = false; //var partitionInfoEx = new PartitionInfoEx(Hardware.Enumerations.PartitionFileSystem.NTFS, new UnitsNet.Information(1.2m, UnitsNet.Units.InformationUnit.Terabyte), new List<char>() { 'E' }, new Philote.Philote<IPartitionInfoEx>().Now()); //var root = partitionInfoEx.DriveLetters.First(); var root = 'E'; // In Windows, root is a single letter, but in *nix, root is a string. Convert the single char to a string // ToDo: replace with ATAP.Utilities RunTimeKind, and make it *nix friendly var rootstring = root.ToString() + ":/"; // Create storage for the results and progress var convertFileSystemToGraphProgress = new ConvertFileSystemToGraphProgress(); // Cancellation token for the task var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSourceId = new IdAsStruct <CancellationTokenSource>(Guid.NewGuid()); var cancellationToken = cancellationTokenSource.Token; ConvertFileSystemToGraphResult convertFileSystemToGraphResult; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { Func <Task <ConvertFileSystemToGraphResult> > run = () => StaticExtensions.ConvertFileSystemToGraphAsyncTask(rootstring, asyncFileReadBlockSize, enableHash, convertFileSystemToGraphProgress, null, null, cancellationToken); convertFileSystemToGraphResult = await run.Invoke().ConfigureAwait(false); } catch (Exception) { throw; } finally { cancellationTokenSource.Dispose(); } stopWatch.Stop(); convertFileSystemToGraphResult.FSEntityAdjacencyGraph.VertexCount.Should().Be(15); convertFileSystemToGraphResult.FSEntityAdjacencyGraph.EdgeCount.Should().Be(16); }
public SaveWorldForm(SaveManager manager, Form PrevForm, IMouse mouse, Engine.IDrawer drawer, IGameScene scene) : base(new Color(200, 100, 0), 300, PrevForm, mouse, drawer) { controls.Add(new Label(new Vector2(0, 40), "Enter path to file", 50, drawer, mouse)); txtFile = new Button(new Vector2(0, 0), " ", 50, StaticExtensions.configureAsTextBox(false, scene), drawer, mouse); controls.Add(new Button(new Vector2(0, -50), "Save world", 50, SaveSave, drawer, mouse)); controls.Add(txtFile); this.manager = manager; }
public LoadWorldForm(Form previousForm, Integration.IMouse mouse, Engine.IDrawer drawer, IGameScene scene, StartUp init) : base(new Color(100, 200, 255), 300, previousForm, mouse, drawer) { controls.Add(new Label(new Vector2(0, 40), "Enter path to file", 50, drawer, mouse)); txtFile = new Button(new Vector2(0, 0), " ", 50, StaticExtensions.configureAsTextBox(false, scene), drawer, mouse); controls.Add(new Button(new Vector2(0, -50), "Load Save", 50, LoadSave, drawer, mouse)); controls.Add(txtFile); this.init = init; }
public async Task TestConvertFileSystemToGraphAsyncTaskWithoutHashWithoutPersistenceToDigraph() { var asyncFileReadBlockSize = 4096; var enableHash = false; //var partitionInfoEx = new PartitionInfoEx(Hardware.Enumerations.PartitionFileSystem.NTFS, new UnitsNet.Information(1.2m, UnitsNet.Units.InformationUnit.Terabyte), new List<char>() { 'E' }, new Philote.Philote<IPartitionInfoEx>().Now()); //var root = partitionInfoEx.DriveLetters.First(); var root = 'E'; // In Windows, root is a single letter, but in *nix, root is a string. Convert the single char to a string // ToDo: replace with ATAP.Utilities RunTimeKind, and make it *nix friendly var rootstring = root.ToString() + ":/"; // Create storage for the results and progress var convertFileSystemToGraphProgress = new ConvertFileSystemToGraphProgress(); // Cancellation token for the task var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSourceId = new IdAsStruct <CancellationTokenSource>(Guid.NewGuid()); var cancellationToken = cancellationTokenSource.Token; ConvertFileSystemToGraphResult convertFileSystemToGraphResult; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { Func <Task <ConvertFileSystemToGraphResult> > run = () => StaticExtensions.ConvertFileSystemToGraphAsyncTask(rootstring, asyncFileReadBlockSize, enableHash, convertFileSystemToGraphProgress, null, null, cancellationToken); convertFileSystemToGraphResult = await run.Invoke().ConfigureAwait(false); } catch (Exception) { throw; } finally { cancellationTokenSource.Dispose(); } stopWatch.Stop(); var digraph = new StringBuilder(); digraph.Append("digraph G {"); digraph.Append(Environment.NewLine); foreach (var e in (convertFileSystemToGraphResult.FSEntityAdjacencyGraph.Edges .Select(edge => { string fs = edge.Source.GetFullName(); string ts = edge.Target.GetFullName(); var tu = (fs, ts); return(tu); })).ToList <(string, string)>()) { digraph.Append($"\"{e.Item1.Replace("\\", "\\\\")}\" -> \"{e.Item2.Replace("\\", "\\\\")}\""); digraph.Append(Environment.NewLine); } digraph.Append("}"); #if DEBUG TestOutput.WriteLine($"{digraph}"); #endif convertFileSystemToGraphResult.FSEntityAdjacencyGraph.VertexCount.Should().Be(15); }
public NewWorldForm(Form previousForm, StartUp init, IMouse mouse, IDrawer drawer, IGameScene scene) : base(new Color(200, 100, 0), 300, previousForm, mouse, drawer) { IList <Box> PreBoxs = new Box[] { new Box("0", StaticExtensions.configureAsTextBox(true, scene)), new Box("0", StaticExtensions.configureAsTextBox(true, scene)), new Box("Generate", GenerateWorld) }; controls.Add(new Label(new Vector2(-30, 20), "size", 20, drawer, mouse)); controls.Add(new Label(new Vector2(-30, -10), "seed", 20, drawer, mouse)); parameters = new SelectBox(new Vector2(0, 20), PreBoxs, drawer, mouse); controls.Add(parameters); this.init = init; }
/// <summary> /// Init widgets goes through and validates if a widget /// needs to be spawned or already exists. /// </summary> public void InitWidgets() { foreach (CursorWidgetData data in CursorWidgets) { // Only instantiate widgets that don't exist yet, in case more have been added if (data.CursorWidgetPrefab != null && data.CursorWidgetObject == null) { if (StaticExtensions.IsPrefab(data.CursorWidgetPrefab.gameObject)) { data.CursorWidgetObject = Instantiate(data.CursorWidgetPrefab); } else { data.CursorWidgetObject = data.CursorWidgetPrefab; } data.CursorWidgetObject.CursorObj = this.gameObject; data.CursorWidgetObject.SwitchAnchorType(data.CursorWidgetObject.AnchorType); data.CursorWidgetObject.gameObject.SetActive(false); } } }
public static Employee fromUser(User user) { Employee newEmployee = new Employee() { FirstName = user.FirstName, LastName = user.LastName, BirthDate = StaticExtensions.RandomDate(), Address = user.Address, Email = user.Email, Phone = user.Phone, Sex = user.Sex, Photo = user.Photo, PhotoData = user.Photo.toByteArray(), ImageURL = user.PhotoURL, Punctuality = StaticExtensions.rand.Next(0, 100), TeamWorkEfficiency = StaticExtensions.rand.Next(0, 100), WorkQuality = StaticExtensions.rand.Next(0, 100), SomeAnotherQuality = StaticExtensions.rand.Next(0, 100), }; List <Task> taskList = new List <Task>(); for (int i = StaticExtensions.rand.Next(3, 10); i > 0; i--) { taskList.Add(new Task() { Name = StaticExtensions.RandomString(), PercentDone = StaticExtensions.rand.Next(0, 100), Performer = newEmployee }); } newEmployee.Tasks = taskList; return(newEmployee); }
public async Task TestConvertFileSystemToGraphAsyncTaskFileWithoutHashWithPersistence() { // Arrange var asyncFileReadBlockSize = 4096; var enableHash = false; //var partitionInfoEx = new PartitionInfoEx(Hardware.Enumerations.PartitionFileSystem.NTFS, new UnitsNet.Information(1.2m, UnitsNet.Units.InformationUnit.Terabyte), new List<char>() { 'E' }, new Philote.Philote<IPartitionInfoEx>().Now()); //var root = partitionInfoEx.DriveLetters.First(); var root = 'E'; // In Windows, root is a single letter, but in *nix, root is a string. Convert the single char to a string // ToDo: replace with ATAP.Utilities RunTimeKind, and make it *nix friendly var rootstring = root.ToString() + ":/"; // Create storage for the results and progress var convertFileSystemToGraphProgress = new ConvertFileSystemToGraphProgress(); // Cancellation token for the task var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSourceId = new IdAsStruct <CancellationTokenSource>(Guid.NewGuid()); var cancellationToken = cancellationTokenSource.Token; // PersistenceViaFiles // Create temporary files to hold the persistence data var numfiles = 2; var temporaryFiles = new TemporaryFile[numfiles]; var filePaths = new string[2]; for (int i = 0; i < 2; i++) { temporaryFiles[i] = new TemporaryFile().CreateTemporaryFileEmpty(); filePaths[i] = temporaryFiles[i].FileInfo.FullName; #if DEBUG TestOutput.WriteLine($"File {i} is named {temporaryFiles[i].FileInfo.FullName}"); #endif } // Call the SetupViaFileFuncBuilder here, execute the Func that comes back, with filePaths as the argument var setupResults = ATAP.Utilities.Persistence.Extensions.SetupViaFileFuncBuilder()(new SetupViaFileData(filePaths)); //var insertFunc = InsertViaFileFuncBuilder(setupResults); // Create an insertFunc that references the local variable setupResults, closing over it var insertFunc = new Func <IEnumerable <IEnumerable <object> >, IInsertViaFileResults>((insertData) => { int numberOfFiles = insertData.ToArray().Length; #if DEBUG TestOutput.WriteLine($"Got {numberOfFiles} arrays of data to write"); #endif int numberOfStreamWriters = setupResults.StreamWriters.Length; #if DEBUG TestOutput.WriteLine($"Got {numberOfStreamWriters} streamwriters to write to"); #endif for (var i = 0; i < numberOfFiles; i++) { foreach (string str in insertData.ToArray()[i]) { //ToDo: add async versions await setupResults.StreamWriters[i].WriteLineAsync(str); //ToDo: exception handling setupResults.StreamWriters[i].WriteLine(str); #if DEBUG TestOutput.WriteLine($"writing {str} to file {i}"); #endif } } return(new InsertViaFileResults(true)); }); Persistence <IInsertResultsAbstract> persistence = new Persistence <IInsertResultsAbstract>(insertFunc); ConvertFileSystemToGraphResult convertFileSystemToGraphResult; // Act try { Func <Task <ConvertFileSystemToGraphResult> > run = () => StaticExtensions.ConvertFileSystemToGraphAsyncTask(rootstring, asyncFileReadBlockSize, enableHash, convertFileSystemToGraphProgress, persistence, null, cancellationToken); convertFileSystemToGraphResult = await run.Invoke().ConfigureAwait(false); } catch (Exception) { throw; } finally { setupResults.Dispose(); cancellationTokenSource.Dispose(); } //Assert convertFileSystemToGraphResult.FSEntityAdjacencyGraph.VertexCount.Should().Be(15); convertFileSystemToGraphResult.FSEntityAdjacencyGraph.EdgeCount.Should().Be(14); // Convert the IList objects to List objects List <FSEntityAbstract> verticesAsAbstract = convertFileSystemToGraphResult.FSEntityAdjacencyGraph.Vertices.ToList(); List <FSEEdge <FSEntityAbstract> > edgesAsAbstract = convertFileSystemToGraphResult.FSEntityAdjacencyGraph.Edges.ToList(); verticesAsAbstract.Count.Should().Be(15); edgesAsAbstract.Count.Should().Be(14); List <string> verticesAsString = verticesAsAbstract.Select(x => x.GetFullName()).ToList(); List <string> edgesAsString = edgesAsAbstract.Select((x) => x.Source.GetFullName() + " -> " + x.Target.GetFullName()).ToList();; List <string> verticesfromFile = File.ReadLines(temporaryFiles[0].FileInfo.FullName).ToList(); List <string> edgesfromFile = File.ReadLines(temporaryFiles[1].FileInfo.FullName).ToList(); #if DEBUG TestOutput.WriteLine($"File 0 (vertices) contains {verticesfromFile.Count} vertices"); foreach (var str in verticesfromFile) { TestOutput.WriteLine(str); } TestOutput.WriteLine($"File 1 (edges) contains {edgesfromFile.Count} edges"); foreach (var str in edgesfromFile) { TestOutput.WriteLine(str); } #endif verticesAsString.Should().BeEquivalentTo(verticesfromFile); edgesAsString.Should().BeEquivalentTo(edgesfromFile); }