예제 #1
0
        public void InitializeValues(string filePath)
        {
            Serializer ser = new Serializer();

            filePath = Directory.GetCurrentDirectory() + $@"\{filePath}";
            var xmlInputData = File.ReadAllText(filePath);

            string path = string.Empty;

            //Deserialize XMLInput into xml object

            puzzle = ser.Deserialize <PuzzleXml>(xmlInputData);

            //convert to Hashset

            ConvertPuzzleXmlToHashSet();
        }
예제 #2
0
        public string GenerateFinalXml()
        {
            Serializer ser = new Serializer();

            var puzzleGrid    = GetPuzzleGrid();
            var puzzleXml     = new PuzzleXml();
            var initialValues = new Initialvalues();
            var cells         = new List <Cell>();

            //Loop through hashset to build xmlobject data.

            for (int row = 0; row < OverallDimension.RowSize; row++)
            {
                for (int col = 0; col < OverallDimension.ColSize; col++)
                {
                    var cellValues = puzzleGrid.Where(x => x.X == row && x.Y == col).Select(x => x.Items).ToArray();
                    foreach (var cellValue in cellValues)
                    {
                        foreach (var value in cellValue)
                        {
                            string rowNumber = Convert.ToString(row);
                            string colNumber = Convert.ToString(col);
                            string cellvalue = Convert.ToString(value);
                            cells.Add(new Cell {
                                Row = rowNumber, Col = colNumber, Value = cellvalue
                            });
                        }
                    }
                }
            }

            initialValues.Cell      = cells;
            puzzleXml.Initialvalues = initialValues;

            var xmlOutputData = ser.Serialize(puzzleXml);

            return(xmlOutputData);
        }