示例#1
0
文件: Form1.cs 项目: daxfohl/SudokuCS
        void OpenFile(string name)
        {
            _name = name;
            // Open and read the file
            try {
                TextReader reader = new FileInfo(name).OpenText();
                var text = reader.ReadToEnd();
                reader.Dispose();
                var lines = text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);

                // Create a new model and solver, and add event listeners
                if (_model != null) {
                    _model.ModelChanged -= HandleModelModelChanged;
                    _solver.ScanFinished -= HandleSolverScanFinished;
                    _solver.Finished -= HandleSolverFinished;
                }
                _model = new SudokuModel(lines.Length);
                _solver = new Solver(_model);
                _model.ModelChanged += HandleModelModelChanged;
                _solver.ScanFinished += HandleSolverScanFinished;
                _solver.Finished += HandleSolverFinished;

                // Update the screen
                _grid.Model = _model;
                _txtProgress.Clear();

                // Load data into the model
                for (var row = 0; row < lines.Length; ++row) {
                    var cells = lines[row].Split(',');
                    for (var col = 0; col < lines.Length; ++col) {
                        if (!string.IsNullOrEmpty(cells[col])) {
                            _model.SetValue(col, row, cells[col][0] - 'A');
                        }
                    }
                }
            } catch (FileNotFoundException) {}
        }
        public void Refresh() {
            string fileName = "test1";
            string fullPath = Path.Combine(this.testFolder.FullName, fileName);
            IFileSystemInfo fileInfo = Factory.CreateFileInfo(fullPath);

            // trigger lacy loading
            Assert.That(fileInfo.Exists, Is.EqualTo(false));
            var stream = new FileInfo(fullPath).Create();
            stream.Dispose();
            fileInfo.Refresh();
            Assert.That(fileInfo.Exists, Is.EqualTo(true));
        }
 public void GetFilesFor2() {
     string file1 = "file1";
     string file2 = "file2";
     string fullPath1 = Path.Combine(this.testFolder.FullName, file1);
     string fullPath2 = Path.Combine(this.testFolder.FullName, file2);
     var stream = new FileInfo(fullPath1).Create();
     stream.Dispose();
     var stream2 = new FileInfo(fullPath2).Create();
     stream2.Dispose();
     IDirectoryInfo dirInfo = Factory.CreateDirectoryInfo(this.testFolder.FullName);
     Assert.That(dirInfo.GetFiles().Length, Is.EqualTo(2));
     Assert.That(dirInfo.GetFiles()[0].Name, Is.EqualTo(file1));
     Assert.That(dirInfo.GetFiles()[1].Name, Is.EqualTo(file2));
 }
示例#4
0
        private void AssertFilesBinaryEqual(string expectedFileName, string actualFileName)
        {
            int row = 0;
            FileStream expectedStream = new FileInfo(expectedFileName).Open(FileMode.Open, FileAccess.Read);
            FileStream actualStream = new FileInfo(actualFileName).Open(FileMode.Open, FileAccess.Read);

            string failMessage = string.Empty;

            try
            {
                while (!IsEOF(expectedStream) && !IsEOF(actualStream))
                {
                    byte[] bufferExpected = new byte[16];
                    byte[] bufferActual = new byte[16];

                    expectedStream.Read(bufferExpected, 0, 16);
                    actualStream.Read(bufferActual, 0, 16);

                    int i = 0;
                    for (; i < 16; i++)
                        if (bufferExpected[i] != bufferActual[i]) break;

                    if (i < 16)
                    {
                        int diffPosition = row * 16 + i;
                        failMessage = string.Format("files differ at byte {0}", diffPosition);
                        break;
                    }

                    row++;
                }

                if (failMessage == string.Empty)
                {
                    if (!IsEOF(expectedStream))
                        Assert.Fail("expected is longer");
                    else if (!IsEOF(actualStream))
                        Assert.Fail("actual is longer");
                }
            }
            finally
            {
                expectedStream.Close();
                expectedStream.Dispose();
                actualStream.Close();
                actualStream.Dispose();
            }

            if (failMessage != string.Empty)
            {
                Console.WriteLine("AssertBinaryFilesEqual failed expected file {0} actual file {1}: {2}",
                    expectedFileName, actualFileName, failMessage);
                AssertFailMyXls(failMessage, expectedFileName, actualFileName);
            }
        }