public async Task <IActionResult> Edit(int id, [Bind("CsFiles,TsFile,Id")] CreatedFiles CreatedFiles) { if (id != CreatedFiles.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(CreatedFiles); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CreatedFilesExists(CreatedFiles.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(CreatedFiles)); }
public void UpdateOnlyChapterNumberOfListingUsingChapterNumberFromFolder_UnitTestsAlsoUpdated_ListingsAndTestsUpdated() { ICollection <string> filesToMake = new List <string> { "Chapter42/Listing01.01.cs", "Chapter42/Listing01.01A.Some.cs", "Chapter42/Listing01.01B.cs", "Chapter42/Listing01.01C.cs", "Chapter42/Listing01.05.cs", "Chapter42.Tests/Listing01.01.cs", "Chapter42.Tests/Listing01.01A.Some.cs", "Chapter42.Tests/Listing01.01B.cs", "Chapter42.Tests/Listing01.01C.cs", "Chapter42.Tests/Listing01.05.cs" }; ICollection <string> expectedFiles = new List <string> { @"Chapter42\Listing42.01.cs", @"Chapter42\Listing42.01A.Some.cs", @"Chapter42\Listing42.01B.cs", @"Chapter42\Listing42.01C.cs", @"Chapter42\Listing42.05.cs", @"Chapter42.Tests\Listing42.01.cs", @"Chapter42.Tests\Listing42.01A.Some.cs", @"Chapter42.Tests\Listing42.01B.cs", @"Chapter42.Tests\Listing42.01C.cs", @"Chapter42.Tests\Listing42.05.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); CreatedDirectories.Add("Chapter42"); CreatedDirectories.Add("Chapter42.Tests"); ListingManager.UpdateChapterListingNumbers(Path.Combine(Environment.CurrentDirectory, "Chapter42"), byFolder: true, chapterOnly: true); var files = FileManager.GetAllFilesAtPath(Environment.CurrentDirectory, true) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); //Assert CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
private void WriteFile(string fileName, IEnumerable <string> toWrite = null) { FileInfo file = new FileInfo(fileName); file.Directory?.Create(); File.WriteAllLines(fileName, toWrite ?? new List <string>()); CreatedFiles.Add(fileName); }
public async Task <IActionResult> Create([Bind("CsFiles,TsFile,Id")] CreatedFiles CreatedFiles) { if (ModelState.IsValid) { _context.Add(CreatedFiles); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(CreatedFiles)); }
public void Add([NotNull] FtpSummary other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Deleted.AddRange(other.Deleted); DeletedDirectories.AddRange(other.DeletedDirectories); CreatedDirectories.AddRange(other.CreatedDirectories); UpdatedFiles.AddRange(other.UpdatedFiles); CreatedFiles.AddRange(other.CreatedFiles); CreatedFiles = CreatedFiles.Except(UpdatedFiles).ToList(); IgnoredFiles.AddRange(other.IgnoredFiles); IgnoredDirectories.AddRange(other.IgnoredDirectories); }
public void UpdateChapterListingNumbers_AdditionalListings_ListingsRenumbered() { ICollection <string> filesToMake = new List <string> { "Listing01.01.cs", "Listing01.01A.Some.cs", "Listing01.01B.cs", "Listing01.01C.cs", "Listing01.02.cs", "Listing01.02A.Test.cs" }; ICollection <string> expectedFiles = new List <string> { "Listing01.01.cs", "Listing01.02.Some.cs", "Listing01.03.cs", "Listing01.04.cs", "Listing01.05.cs", "Listing01.06.Test.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); ListingManager.UpdateChapterListingNumbers(Environment.CurrentDirectory); var files = Directory.EnumerateFiles(Environment.CurrentDirectory) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
/// <summary> /// creates a new instance of the MATLAB connector. /// </summary> /// <param name="Flav"> /// octave or MATLAB /// </param> /// <param name="ExecutablePath"> /// Where to find the executable on the current system. /// If NULL, the standard installation path is assumed. /// In the case of Cygwin/octave, the path to the Cygwin bash.exe; /// </param> /// <param name="WorkingPath"> /// working directory of the MATLAB instance; /// if NULL, a temporary directory is created. /// </param> public BatchmodeConnector(string WorkingPath = null) { ilPSP.MPICollectiveWatchDog.Watch(csMPI.Raw._COMM.WORLD); csMPI.Raw.Comm_Rank(csMPI.Raw._COMM.WORLD, out Rank); this.m_Flav = Flav; // create/check working path // ========================= if (Rank == 0) { if (WorkingPath == null) { var rnd = new Random(); bool Exists = false; do { var tempPath = Path.GetTempPath(); var tempDir = rnd.Next().ToString(); WorkingDirectory = new DirectoryInfo(Path.Combine(tempPath, tempDir)); Exists = WorkingDirectory.Exists; if (!Exists) { WorkingDirectory.Create(); DelWorkingDir = true; } } while (Exists == true); } else { WorkingDirectory = new DirectoryInfo(WorkingPath); if (!WorkingDirectory.Exists) { throw new ArgumentException("Given working directory is inexistent."); } } } MPIEnviroment.Broadcast(this.WorkingDirectory, 0, csMPI.Raw._COMM.WORLD); // more checks // =========== if (MatlabExecuteable != null) { if (!File.Exists(MatlabExecuteable)) { throw new ArgumentException("Unable to find file '" + MatlabExecuteable + "' on this system."); } } // setup MATLAB process // ==================== if (Rank == 0) { psi = new ProcessStartInfo(); psi.WorkingDirectory = WorkingDirectory.FullName; psi.UseShellExecute = false; //psi.RedirectStandardOutput = true; //psi.RedirectStandardError = true; //psi.RedirectStandardInput = true; PlatformID CurrentSys = System.Environment.OSVersion.Platform; switch (CurrentSys) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: { if (m_Flav == Flavor.Matlab) { if (MatlabExecuteable == null) { MatlabExecuteable = get_program_path("matlab.exe"); if (MatlabExecuteable == null) { throw new ApplicationException("Unable to find 'matlab.exe' in your PATH environment; please provide path to 'matlab.exe'."); } } psi.FileName = MatlabExecuteable; psi.Arguments = "-nosplash -nodesktop -minimize -wait -r " + CMDFILE + " -logfile " + LOGFILE; } else if (m_Flav == Flavor.Octave) { this.Cygwin = true; // octave and windows must be cygwin! if (MatlabExecuteable == null) { if (File.Exists("c:\\cygwin64\\bin\\octave")) { psi.FileName = "c:\\cygwin64\\bin\\bash.exe"; } else if (File.Exists("c:\\cygwin\\bin\\octave")) { psi.FileName = "c:\\cygwin\\bin\\bash.exe"; } else { throw new NotSupportedException("Cygwin/Octave are expected to be in the default path: C:\\cygwin or c:\\cygwin64"); } } else { //throw new NotSupportedException("Cygwin/Octave are expected to be in the default path: C:\\cygwin or c:\\cygwin64"); if (!MatlabExecuteable.EndsWith("bash.exe")) { throw new NotSupportedException("For Cygwin/Octave, the 'MatlabExecuteable' is expected to point to 'bash.exe'."); } psi.FileName = MatlabExecuteable; } psi.Arguments = "--login -c \"cd " + TranslatePath(WorkingDirectory.FullName) + " " + "&& octave --no-gui " + CMDFILE + ".m" + " > " + LOGFILE + " \""; //+ "pwd && ls - l && pwd"; } else { throw new NotImplementedException(); } break; } case PlatformID.Unix: case PlatformID.MacOSX: { throw new NotImplementedException("will implement on request"); } default: throw new NotSupportedException("unable to use MATLAB on " + CurrentSys.ToString()); } CreatedFiles.Add(Path.Combine(WorkingDirectory.FullName, LOGFILE)); var ScriptsToWrite = new List <Tuple <string, string> >(); ScriptsToWrite.Add(new Tuple <string, string>("ReadMsr.m", Resource1.ReadMsr)); ScriptsToWrite.Add(new Tuple <string, string>("SaveVoronoi.m", Resource1.SaveVoronoi)); foreach (var t in ScriptsToWrite) { string name = t.Item1; string script = t.Item2; var rmPath = Path.Combine(WorkingDirectory.FullName, name); CreatedFiles.Add(rmPath); File.WriteAllText(rmPath, script); } } // create command file // =================== if (Rank == 0) { var p = Path.Combine(WorkingDirectory.FullName, CMDFILE + ".m"); CommandFile = new StreamWriter(p, false); CreatedFiles.Add(p); } }
public override async Task Split() { var fileInfo = new FileInfo(FileSplittingInfo.FilePath); long originalSize = fileInfo.Length; long chunkSize = (long)Math.Ceiling((double)fileInfo.Length / FileSplittingInfo.NumberOfChunks); long totalChunksSize = 0; using (var readStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize, FileOptions.Asynchronous)) { for (int i = 0; i < FileSplittingInfo.NumberOfChunks; i++) { string chunkFileName = ProcessUtils.GetChunkFileName(fileInfo.Name, FileSplittingInfo.DestinationPath, i + 1); using (var writeStream = new FileStream(chunkFileName, FileMode.Create, FileAccess.Write, FileShare.Read, BufferSize, FileOptions.Asynchronous)) { if (!readStream.CanRead) { throw new FileSplitterMergerException($"Can't read file: '{FileSplittingInfo.FilePath}'"); } if (!writeStream.CanWrite) { throw new FileSplitterMergerException($"Can't write to path: '{chunkFileName}'"); } if (totalChunksSize == originalSize) { // create empty file when all the bytes of the original file have been written (should just be one in edge cases) await writeStream.WriteAsync(new ReadOnlyMemory <byte>()); continue; } long currentChunkSize = 0; while (currentChunkSize < chunkSize) { int currentBufferSize = ProcessUtils.GetCurrentBufferSize(currentChunkSize, chunkSize, BufferSize); byte[] currentBuffer = new byte[currentBufferSize]; await readStream.ReadAsync(currentBuffer, 0, currentBufferSize); await writeStream.WriteAsync(currentBuffer, 0, currentBufferSize); currentChunkSize += currentBufferSize; if (currentChunkSize == chunkSize) { await writeStream.FlushAsync(); await writeStream.DisposeAsync(); totalChunksSize += chunkSize; CreatedFiles.Add(chunkFileName); } } } if (originalSize - totalChunksSize > 0 && originalSize - totalChunksSize < chunkSize) { chunkSize = originalSize - totalChunksSize; } } } if (originalSize - totalChunksSize != 0) { throw new FileSplitterMergerException($"File not split correctly! Difference in bytes: { originalSize - totalChunksSize }"); } }
public void UpdateChapterListingNumbers_MultipleListingsMissing_ListingsRenumbered() { ICollection <string> filesToMake = new List <string> { "Listing09.01.DeclaringAStruct.cs", "Listing09.02.ErroneousInitialization.cs", "Listing09.03.AccessError.cs", "Listing09.05.SubtleBoxAndUnboxInstructions.cs", "Listing09.06.UnboxMustBeSameType.cs", "Listing09.07.SubtleBoxingIdiosyncrasies.cs", "Listing09.08.AvoidingUnboxingAndCopying.cs", "Listing09.09.ComparingAnIntegerSwitchToAnEnumSwitch.cs", "Listing09.10.DefiningAnEnum.cs", "Listing09.11.DefiningAnEnumType.cs", "Listing09.12.CastingBetweenArraysOfEnums.cs", "Listing09.13.ConvertingAStringToAnEnumUsingEnum.Parse.cs", "Listing09.14.ConvertingAStringToAnEnumUsingEnum.TryParse.cs", "Listing09.15.UsingEnumsAsFlags.cs", "Listing09.16.UsingBitwiseORandANDWithFlagEnums.cs", "Listing09.17.DefiningEnumValuesforFrequentCombinations.cs", "Listing09.18.UsingFlagsAttribute.cs" }; ICollection <string> expectedFiles = new List <string> { "Listing09.01.DeclaringAStruct.cs", "Listing09.02.ErroneousInitialization.cs", "Listing09.03.AccessError.cs", "Listing09.04.SubtleBoxAndUnboxInstructions.cs", "Listing09.05.UnboxMustBeSameType.cs", "Listing09.06.SubtleBoxingIdiosyncrasies.cs", "Listing09.07.AvoidingUnboxingAndCopying.cs", "Listing09.08.ComparingAnIntegerSwitchToAnEnumSwitch.cs", "Listing09.09.DefiningAnEnum.cs", "Listing09.10.DefiningAnEnumType.cs", "Listing09.11.CastingBetweenArraysOfEnums.cs", "Listing09.12.ConvertingAStringToAnEnumUsingEnum.Parse.cs", "Listing09.13.ConvertingAStringToAnEnumUsingEnum.TryParse.cs", "Listing09.14.UsingEnumsAsFlags.cs", "Listing09.15.UsingBitwiseORandANDWithFlagEnums.cs", "Listing09.16.DefiningEnumValuesforFrequentCombinations.cs", "Listing09.17.UsingFlagsAttribute.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); ListingManager.UpdateChapterListingNumbers(Environment.CurrentDirectory); var files = Directory.EnumerateFiles(Environment.CurrentDirectory) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
public override async Task Split() { var fileInfo = new FileInfo(FileSplittingInfo.FilePath); long originalSize = fileInfo.Length; if (FileSplittingInfo.ChunkSize > originalSize) { throw new FileSplitterMergerException($"The file size is smaller than the requested chunk size: {originalSize}B"); } if (FileSplittingInfo.ChunkSize == originalSize) { return; } int numberOfChunks = (int)Math.Ceiling((double)fileInfo.Length / FileSplittingInfo.ChunkSize); long totalChunksSize = 0; long currentChunkFinalSize = FileSplittingInfo.ChunkSize; using (var readStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize, FileOptions.Asynchronous)) { for (int i = 0; i < numberOfChunks; i++) { string chunkFileName = ProcessUtils.GetChunkFileName(fileInfo.Name, FileSplittingInfo.DestinationPath, i + 1); using (var writeStream = new FileStream(chunkFileName, FileMode.Create, FileAccess.Write, FileShare.Read, BufferSize, FileOptions.Asynchronous)) { if (!readStream.CanRead) { throw new FileSplitterMergerException($"Can't read file: '{FileSplittingInfo.FilePath}'"); } if (!writeStream.CanWrite) { throw new FileSplitterMergerException($"Can't write to path: '{chunkFileName}'"); } long currentChunkSize = 0; while (currentChunkSize < currentChunkFinalSize) { int currentBufferSize = ProcessUtils.GetCurrentBufferSize(currentChunkSize, currentChunkFinalSize, BufferSize); byte[] currentBuffer = new byte[currentBufferSize]; await readStream.ReadAsync(currentBuffer, 0, currentBufferSize); await writeStream.WriteAsync(currentBuffer, 0, currentBufferSize); currentChunkSize += currentBufferSize; if (currentChunkSize == currentChunkFinalSize) { await writeStream.FlushAsync(); await writeStream.DisposeAsync(); totalChunksSize += currentChunkFinalSize; CreatedFiles.Add(chunkFileName); } } } if (originalSize - totalChunksSize > 0 && originalSize - totalChunksSize < currentChunkFinalSize) { currentChunkFinalSize = originalSize - totalChunksSize; } } } if (originalSize - totalChunksSize != 0) { throw new FileSplitterMergerException($"File not split correctly! Difference in bytes: { originalSize - totalChunksSize }"); } }