コード例 #1
0
        public void GridList_remove()
        {
            var list = new GridList <int>();

            list.Add(1);
            list.Add(5);
            list.Add(10);
            list.Add(12);
            list.Add(15);
            list.Add(19);
            list.Add(20);

            Assert.Equal(7, list.Count);
            Assert.True(list.TryErase(12, out var previous));
            Assert.NotNull(previous);
            Assert.Equal(10, previous.Value);

            Assert.False(list.TrySearch(12, out previous));
            Assert.Equal(10, previous.Value);

            list.TrySearch(5, out var node5);
            //deleting 12 again should return false
            Assert.False(list.TryErase(12, out previous, node5));
            Assert.NotNull(previous);
            Assert.Equal(10, previous.Value);

            list.Add(7, node5);
            Assert.True(list.TrySearch(7, out previous));
            //deleting 12 again should return false
            Assert.False(list.TryErase(12, out previous, node5));
            Assert.NotNull(previous);
            Assert.Equal(10, previous.Value);

            //remove head
            Assert.True(list.TryErase(1, out previous));
            Assert.Null(previous);
            Assert.False(list.TrySearch(1, out previous));
            Assert.Null(previous);//previous is null for first node
            Assert.True(list.TrySearch(5, out previous));

            Assert.False(list.TrySearch(3, out previous));
            Assert.Null(previous);// previous is null if query is before first node

            //remove tail
            Assert.True(list.TryErase(20, out previous));
            Assert.NotNull(previous);
            Assert.Equal(19, previous.Value);
            Assert.False(list.TrySearch(20, out previous));
            Assert.True(list.TrySearch(19, out previous));

            Assert.Equal(5, list.Count);
            //perform some add after deletion
            list.Add(3);
            Assert.True(list.TrySearch(3, out previous));
            list.Add(21);
            Assert.True(list.TrySearch(21, out previous));
            Assert.Equal(7, list.Count);
        }
コード例 #2
0
 //未インポートのシナリオデータを追加
 public void AddSrourceBook(StringGridDictionary book)
 {
     foreach (var sheet in book.List)
     {
         GridList.Add(sheet.Grid);
     }
 }
コード例 #3
0
        /// <summary>
        /// Add user function.
        /// </summary>
        /// <param name="newUser">User to be added.</param>
        async Task AddUser(User newUser)
        {
            // Show loading panal.
            LoadingPanal.Show();

            // Send the request and wait for result.
            string result = await Controller.AddUser(newUser);

            // Hide loading panal.
            LoadingPanal.Hide();

            if (!string.IsNullOrEmpty(result))
            {
                // If the result is not empty the somthing went wrong in the request, So display the error.
                NotificationPanal.Show(NotificationType.Error, result, true, $"Can't add '{newUser.Username}'!");
            }
            else
            {
                // If everything goes right, Add the user to list.
                UsersList.Add(newUser);

                // Increase total users count.
                UsersList.TotalCount++;

                // Force layout to refreshing component again.
                StateHasChanged();
            }
        }
コード例 #4
0
        private void Parse_MigrationCSVFile()
        {
            bool  needIndexes    = true;
            sbyte nameIndex      = -1;
            sbyte computeIndex   = -1;
            sbyte datastoreIndex = -1;

            MigrationGridList.Clear();

            if (!File.Exists(_MigrationCSVFile))
            {
                MigrationLogger.Error("{0}: File not found.", _MigrationCSVFile);
                return;
            }

            var lines = File.ReadLines(_MigrationCSVFile, Encoding.UTF8);

            foreach (var line in lines)
            {
                var columns = line.Split(',');
                if (needIndexes)
                {
                    foreach (var col in columns)
                    {
                        if (col.TrimStart('"').TrimEnd('"').ToUpper() == "NAME")
                        {
                            nameIndex = (sbyte)Array.IndexOf(columns, col);
                        }
                        if (col.TrimStart('"').TrimEnd('"').ToUpper() == "DESTINATIONSTORAGE")
                        {
                            datastoreIndex = (sbyte)Array.IndexOf(columns, col);
                        }
                        if (col.TrimStart('"').TrimEnd('"').ToUpper() == "DESTINATIONCOMPUTE")
                        {
                            computeIndex = (sbyte)Array.IndexOf(columns, col);
                        }
                    }
                    if (nameIndex != -1 && computeIndex != -1 && datastoreIndex != -1)
                    {
                        needIndexes = false;
                    }
                    MigrationLogger.Trace("Reading CSV File: Name index = {0}; DestinationCompute index = {1}; DestinationStorage index = {2}", nameIndex, computeIndex, datastoreIndex);
                }
                else
                {
                    GridRow vm = new GridRow();
                    vm.Name = columns[nameIndex].TrimStart('"').TrimEnd('"');
                    vm.DestinationStorage = columns[datastoreIndex].TrimStart('"').TrimEnd('"');
                    vm.DestinationCompute = columns[computeIndex].TrimStart('"').TrimEnd('"');
                    vm.State    = "waiting";
                    vm.Progress = 0;
                    MigrationGridList.Add(vm);
                    MigrationLogger.Trace("{0}: items in migrationList", MigrationGridList.Count);
                }
            }
            txtMigrationStatus.Text     = "Ready to migrate " + MigrationGridList.Count().ToString() + " VMs";
            btnStartMigration.IsEnabled = true;
        }
コード例 #5
0
    private static bool RemoveObjectAndUpdateGrid(int objectID)
    {
        int[,] ObjectIDTranslation = new int[LevelManager.currentLevel.grid.levelObjects.Count, 2];
        int[,] translatedGridMap   = new int[Constants.GRID_WIDTH, Constants.GRID_HEIGHT];
        GridList translatedDictionary = new GridList();

        //Remove objectID
        for (int i = 1; i <= LevelManager.currentLevel.grid.levelObjects.Count; i++)
        {
            if (i == objectID)
            {
                ObjectIDTranslation[i - 1, 0] = i;
                ObjectIDTranslation[i - 1, 1] = 0;
            }
            else if (i > objectID)
            {
                ObjectIDTranslation[i - 1, 0] = i;
                ObjectIDTranslation[i - 1, 1] = i - 1;
            }
            else
            {
                ObjectIDTranslation[i - 1, 0] = i;
                ObjectIDTranslation[i - 1, 1] = i;
            }
        }
        //Create a new Dictionary
        for (int i = 0; i < ObjectIDTranslation.GetLength(0); i++)
        {
            if (ObjectIDTranslation[i, 1] == 0)
            {
                continue;
            }
            translatedDictionary.Add(ObjectIDTranslation[i, 1], LevelManager.currentLevel.grid.getLevelObject(ObjectIDTranslation[i, 0]));
        }

        //Create a new Map
        for (int x = 0; x < Constants.GRID_WIDTH; x++)
        {
            for (int y = 0; y < Constants.GRID_HEIGHT; y++)
            {
                for (int i = 0; i < ObjectIDTranslation.GetLength(0); i++)
                {
                    if (ObjectIDTranslation[i, 0] == LevelManager.currentLevel.grid.IDAtPosition(x, y))
                    {
                        translatedGridMap[x, y] = ObjectIDTranslation[i, 1];
                    }
                    else if (LevelManager.currentLevel.grid.IDAtPosition(x, y) == 0)
                    {
                        translatedGridMap[x, y] = 0;
                    }
                }
            }
        }

        LevelManager.currentLevel.grid = new Grid(translatedGridMap, translatedDictionary);
        return(true);
    }
コード例 #6
0
        public void GridList_add()
        {
            var list = new GridList <int>();

            list.Add(1);
            list.Add(5);
            list.Add(10);

            Assert.Equal(3, list.Count);
            GridNode <int> node;

            Assert.True(list.TrySearch(1, out node));
            Assert.Equal(1, node.Value);

            Assert.False(list.TrySearch(0, out node));
            Assert.Null(node);

            Assert.True(list.TrySearch(5, out node));
            Assert.Equal(5, node.Value);

            Assert.False(list.TrySearch(3, out node));
            Assert.Equal(1, node.Value);

            Assert.False(list.TrySearch(12, out node));
            Assert.Equal(10, node.Value);

            //testing add from a given node
            list.TrySearch(5, out var node5);
            list.Add(7, node5);
            Assert.True(list.TrySearch(7, out node));
            Assert.Equal(7, node.Value);

            //testing find from a given node
            Assert.True(list.TrySearch(7, out node, node5));
            Assert.Equal(7, node.Value);
        }
コード例 #7
0
    public Level readLevel()
    {
        Level loadedLevel = null;

        try
        {
            if (File.Exists(filePath))
            {
                reader = new BinaryReader(File.Open(filePath, FileMode.Open));
                string name   = reader.ReadString();
                int    width  = reader.ReadInt16();
                int    height = reader.ReadInt16();

                int[,] map = new int[Constants.GRID_WIDTH, Constants.GRID_HEIGHT];
                for (int x = 0; x < Constants.GRID_WIDTH; x++)
                {
                    for (int y = 0; y < Constants.GRID_HEIGHT; y++)
                    {
                        if (x * height + y >= width * height)
                        {
                            break;
                        }
                        map[x, y] = reader.ReadInt16();
                    }
                }
                int      key = 1;
                string   blockID;
                GridList levelObjects = new GridList();

                while (!endOfFile())
                {
                    blockID = reader.ReadString();
                    levelObjects.Add(key, blockID);
                    key++;
                }

                loadedLevel = new Level(name, new Grid(map, levelObjects));
                reader.Close();
            }
        } catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
        }

        return(loadedLevel);
    }
コード例 #8
0
        public void Get_test()
        {
            var list = new GridList <int>();

            list.Add(1);
            list.Add(5);
            list.Add(10);
            list.Add(12);
            list.Add(15);
            list.Add(19);
            list.Add(20);

            Assert.NotNull(list.Get(0));
            Assert.Equal(5, list.Get(1).Value);
            Assert.Equal(20, list.Get(6).Value);
            Assert.Null(list.Get(7));
        }
コード例 #9
0
        // Fonction qui récupère les données du fichier sélectionné et affiche chaque grille dans la liste.
        public void getGridFile(String path)
        {
            _path = path;
            if (readFile())
            {
                Grille g;
                Case   c;
                string line;
                int    tailleGrille;
                //Lire ligne par ligne
                while ((line = file.ReadLine()) != null)
                {
                    gridCount++;
                    g            = new Grille();
                    g.Nom        = file.ReadLine();
                    g.Date       = file.ReadLine();
                    g.Symbole    = file.ReadLine();
                    tailleGrille = g.Symbole.Length;
                    g.initializeTab(tailleGrille);
                    for (int i = 0; i < tailleGrille; i++)
                    {
                        string values = file.ReadLine();
                        for (int j = 0; j < values.Length; j++)
                        {
                            c = new Case(values[j], i, j, g.numSquare(i, j));
                            g.setTable(i, j, c);
                        }
                    }

                    //ajouter la grille créée à partir du fichier
                    GridList.Add(g);
                }
                //fermer le fichier
                file.Close();
            }
        }