public void ReadSdssDR7SpectrumTest() { var f = OpenFits("sdssdr7_spSpec.fit"); var cmd = new FileCommand(f); using (var dr = cmd.ExecuteReader()) { Assert.AreEqual(0, dr.FieldCount); dr.NextResult(); Assert.AreEqual(23, dr.FieldCount); var values = new object[dr.FieldCount]; int q = 0; while (dr.Read()) { dr.GetValues(values); q++; } Assert.AreEqual(4, q); } f.Close(); }
protected void ReadTable(DataFileBase source, DestinationTable destination) { // Import the file by wrapping it into a dummy command using (var cmd = new FileCommand(source)) { ImportTable(cmd, destination); } }
public void DoesntExistTest() { var target = new FileCommand(null) { Operation = FileCommand.FileOperation.Exists, SourcePath = @"C:\FileThatDoesntExist.tst" }; object actual = target.Execute(); Assert.AreEqual(false, actual); }
public void CreateTest() { string path = GetTempPath("FileCopy", true); string sourceFile = CreateTempFile(path, "SourceFile.tst"); string targetFile = CreateTempFile(path, "TargetFile.tst"); var target = new FileCommand(new SsisTestSuite(), "Copy", sourceFile, targetFile); object actual = target.Execute(); Assert.AreEqual(0, (int)actual); }
public void FileCommandObjectCreatedIsSameAsAConstructedObject(CommandType commandType) { ISearchQuery searchQuery = new SearchQuery(""); IFileCommand commandFromFactory = (FileCommand)commandFactory.NewFileCommand(commandType, searchQuery); IFileCommand commandConstructedDirectly = new FileCommand(commandType, searchQuery); Assert.IsNotNull(commandFromFactory); Assert.AreEqual(typeof(FileCommand), commandFromFactory.GetType()); Assert.AreEqual(commandConstructedDirectly.CommandType, commandFromFactory.CommandType); Assert.AreEqual(commandConstructedDirectly.Search, commandFromFactory.Search); }
public void ExistsTest() { string path = GetTempPath("FileCopy", true); string sourceFile = CreateTempFile(path, "SourceFile.tst"); var target = new FileCommand(null) { Operation = FileCommand.FileOperation.Exists, SourcePath = sourceFile }; object actual = target.Execute(); Assert.AreEqual(true, actual); }
private bool Receive(FileCommand command) { try { this._socket.Receive(this._buffer); this._socket.ReceiveTimeout = 30000; return (FileCommand)this._buffer[0] == command; } catch { return false; } }
public void MoveTest() { string path = GetTempPath("FileCopy", true); string sourceFile = CreateTempFile(path, "SourceFile.tst"); string targetFile = System.IO.Path.Combine(path, "TargetFile.tst"); var target = new FileCommand(null) { Operation = FileCommand.FileOperation.Move, SourcePath = sourceFile, TargetPath = targetFile }; object actual = target.Execute(); Assert.AreEqual(0, actual); }
public static void RunUnzip(string location, string intermediatePath, string targetDirectory) { var zipFileName = GetZipTool(); FileCommand.Cleanup(intermediatePath); var args = string.Format(UnZipCommandFormat, intermediatePath, location); var result = ProcessRunner.RunProcess(targetDirectory, zipFileName, args); if (result.Failure) { throw new Exception(result.ToString()); } }
public void CopyTest() { string path = GetTempPath("FileCopy", true); string sourceFile = CreateTempFile(path, "SourceFile.tst"); string targetFile = CreateTempFile(path, "TargetFile.tst"); var target = new FileCommand(new SsisTestSuite()) { Operation = FileCommand.FileOperation.Copy, SourcePath = sourceFile, TargetPath = targetFile }; object actual = target.Execute(); Assert.AreEqual(0, actual); }
public string UploadFile([FromForm] FileCommand addFile) { try { // && addFile.files.ContentType == ContentType. var fileExtention = Path.GetExtension(addFile.Files.FileName); ///FileStream fileStream111 = new FileStream(addFile.files.FileName, FileMode.Open); // FileInfo info = new FileInfo(addFile.Files.FileName); // using var fs = new FileStream(addFile.Files.FileName, FileMode.Open, FileAccess.Read); // using var sr = new StreamReader(fs, Encoding.UTF8); // string content = sr.ReadLine(); if (addFile.Files.Length > 0 && fileExtention == ".txt") { // string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", addFile.Files.FileName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (FileStream fileStream = System.IO.File.Create(path + addFile.Files.FileName)) { addFile.Files.CopyTo(fileStream); fileStream.Flush(); var b = addFile.Files.OpenReadStream(); // var c = b.Read.rea; // to impliment saving the file info in database return("uploaded" + addFile.Files.Length); } } else { return("Not Uploaded"); } } catch (Exception ex) { return(ex.Message); } }
public void LineCountTest() { var sb = new StringBuilder(); sb.AppendLine("Test Line Count 1"); sb.AppendLine("Test Line Count 2"); sb.AppendLine("Test Line Count 3"); string path = GetTempPath("FileTest", true); string sourceFile = CreateTempFile(path, "SourceFile.tst", sb.ToString()); var target = new FileCommand(null) { Operation = FileCommand.FileOperation.LineCount, SourcePath = sourceFile }; object actual = target.Execute(); Assert.AreEqual(3, actual); }
public override void run() { if(false){//InitGameData.UseServerConfig FileCommand cmd = new FileCommand("CONF_LuaFormulas.txt", delegate(Hashtable data){ process(data["text"] as string); this.complete(); }, delegate(string err_code,string err_msg,Hashtable data){ Debug.Log("error"); this.error(); } ); cmd.excute(); }else{ TextAsset ta = Resources.Load("configData/CONF_LuaFormulas") as TextAsset; process(ta.text); this.complete(); } }
public void CopyWithoutTargetTest() { string path = GetTempPath("FileCopy", true); string sourceFile = CreateTempFile(path, "SourceFile.tst"); var target = new FileCommand(new SsisTestSuite()) { Operation = FileCommand.FileOperation.Copy, SourcePath = sourceFile }; try { target.Execute(); Assert.Fail("Method did not throw the expected ArgumentException."); } catch (ArgumentException) { Assert.IsTrue(true); } }
protected override void OnExecute() { // Make sure stream is open if (BaseStream == null) { throw new InvalidOperationException(); } // Make sure it's an archive stream if (!(BaseStream is IArchiveInputStream)) { throw new InvalidOperationException(); } // Create the file format factory var ff = GetFileFormatFactory(); // Read the archive file by file and import tables var ais = (IArchiveInputStream)BaseStream; IArchiveEntry entry; while ((entry = ais.ReadNextFileEntry()) != null) { if (!entry.IsDirectory) { // Create source file using (var format = ff.CreateFile(entry.Filename)) { format.Open(BaseStream, DataFileMode.Read); using (var cmd = new FileCommand(format)) { // TODO: Pass table name here ImportTable(cmd, destination); } } } } }
static void Main(string[] args) { var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var neoveroCLIConfigurationFolder = Path.Combine(localAppData, "DevMaid"); Directory.CreateDirectory(neoveroCLIConfigurationFolder); var builder = new ConfigurationBuilder() .SetBasePath(neoveroCLIConfigurationFolder) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) //.AddUserSecrets<Program>() // Habilitar caso queira usar o user secrets .AddEnvironmentVariables(); AppSettings = builder.Build(); Parser.Default.ParseArguments <TableParserOptions, FileCommandOptions>(args) .WithParsed <TableParserOptions>(opts => { TableParserCommand.Parser(opts); }) .WithParsed <FileCommandOptions>(opts => { FileCommand.Combine(opts); }); }
public static void CleanUpDebugFiles(string location) { var files = Directory.GetFiles(location, AllFiles, SearchOption.AllDirectories); foreach (var file in files) { if (removedFiles.Any(x => file.EndsWith(x))) { FileCommand.Cleanup(file); continue; } if (!file.EndsWith(DebugSymbolsExtension)) { continue; } var fileSo = string.Format(DebugSymbolFileTemplate, file.Substring(0, file.Length - DebugSymbolsExtension.Length)); Debug.Log($"Rename {file} --> {fileSo}"); File.Move(file, fileSo); } }
public MenuStripView(FileCommand fileCommand, EditCommand editCommand, FunctionsCommand functionsCommand, ConstantsCommand constantsCommand, ChartCommand chartCommand, TransformCommand transformCommand, ToolsCommand toolsCommand, HelpCommand helpCommand) : this() { SetCommands(fileCommand, editCommand, functionsCommand, constantsCommand, chartCommand, transformCommand, toolsCommand, helpCommand); }
/// <summary> /// 发送响应的指令 /// </summary> /// <param name="length"></param> private void SendData(FileCommand command) { this._socket.Send(new byte[] { (byte)command }, 1, SocketFlags.None); }
public async Task SendTheEntireFile(FileCommand command, bool lastInSeries, CancellationToken cancellationToken) { _packetCrc32 = 0; _lastProgress = 0; Logger.LogDebug("Sending {filename} to device", command.DestinationFileName); try { var response = await SendCommandAsync(command, cancellationToken) .ConfigureAwait(false); if (response.MessageType == MeadowMessageType.DownloadStartFail) { throw new MeadowCommandException(command, "Meadow rejected download request with ", response); } switch (command.RequestType) { // if it's an ESP start file transfer and the download started ok. case HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_ESP_FILE_TRANSFER when response.MessageType == MeadowMessageType.DownloadStartOkay: Logger.LogDebug("ESP32 download request accepted"); break; // if it's an ESP file transfer start and it failed to start case HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_ESP_FILE_TRANSFER when response.MessageType == MeadowMessageType.DownloadStartFail: Logger.LogDebug("ESP32 download request rejected"); throw new MeadowCommandException(command, "Halting download due to an error while preparing Meadow for download", response); case HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_ESP_FILE_TRANSFER when response.MessageType != MeadowMessageType.DownloadStartOkay: throw response.MessageType switch { MeadowMessageType.DownloadStartFail => new MeadowCommandException(command, "Halting download due to an error while preparing Meadow for download", response), MeadowMessageType.Concluded => new MeadowCommandException(command, "Halting download due to an unexpectedly Meadow 'Concluded' received prematurely", response), _ => new MeadowCommandException(command, $"Halting download due to an unexpected Meadow message type {response.MessageType} received", response) }; } var fileBufOffset = 0; ushort sequenceNumber = 1; Logger.LogInformation("Starting File Transfer..."); while (fileBufOffset <= command.FileSize - 1) // equal would mean past the end { int numBytesToSend; if (fileBufOffset + MeadowDeviceManager.MaxAllowableMsgPacketLength > command.FileSize - 1) { numBytesToSend = command.FileSize - fileBufOffset; // almost done, last packet } else { numBytesToSend = MeadowDeviceManager.MaxAllowableMsgPacketLength; } if (command.FileBytes == null) { throw new MeadowCommandException(command, "File bytes are missing for file command"); } await BuildAndSendDataPacketRequest( command.FileBytes, fileBufOffset, numBytesToSend, sequenceNumber, cancellationToken) .ConfigureAwait(false); var progress = (decimal)fileBufOffset / command.FileSize; WriteProgress(progress); fileBufOffset += numBytesToSend; sequenceNumber++; } // echo the device responses //await Task.Delay(250, cancellationToken); // if we're too fast, we'll finish and the device will still echo a little //-------------------------------------------------------------- // Build and send the correct trailer // TODO: Move this into the Command object var trailerCommand = command.RequestType switch { HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_FILE_TRANSFER => new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_END_FILE_TRANSFER) .WithUserData(lastInSeries ? 1U : 0U) .Build(), HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_UPDATE_RUNTIME => new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_UPDATE_FILE_END) .WithUserData(lastInSeries ? 1U : 0U) .WithTimeout(TimeSpan.FromSeconds(60)) .Build(), HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_ESP_FILE_TRANSFER => new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_END_ESP_FILE_TRANSFER) .WithUserData(lastInSeries ? 1U : 0U) .Build(), _ => throw new ArgumentOutOfRangeException( nameof(command.RequestType), "Cannot build trailer for unknown command") }; await SendCommandAsync(trailerCommand, cancellationToken) .ConfigureAwait(false); // bufferOffset should point to the byte after the last byte Debug.Assert(fileBufOffset == command.FileSize); Logger.LogTrace( "Total bytes sent {count} in {packetCount} packets. PacketCRC:{_crc}", fileBufOffset, sequenceNumber, $"{_packetCrc32:x08}"); Logger.LogInformation( "Transfer Complete, wrote {count} bytes to Meadow", fileBufOffset); } catch (Exception except) { Logger.LogError(except, "Exception sending command to Meadow"); throw; } }