/// <summary> /// Closes the file stream writer. /// </summary> public static void CloseFileWriter(OutputFileType fileType) { // Make sure the file writer actually exists before attempting to close it if (FileWriters.ContainsKey(fileType) == false) { throw new Exception( string.Format("Cannot close file writer as no file writer of type {0} has been created.", fileType)); } // Close the file writer and dispose of the stream FileWriters[fileType].Close(); FileWriters[fileType].Dispose(); }
public void ExportExtractedWords(OutputFileType outputFileType) { if (!IsProcessCompleted || extractedWords == null) return; switch (outputFileType) { case OutputFileType.Text: break; case OutputFileType.Excel: ExportToExcel(); break; case OutputFileType.PDF: break; default: break; } }
public string ProcessFile(byte[] fileContent, int startingPosition, int numberOfCharacters, OutputFileType outputFileType) { IsProcessCompleted = false; MemoryStream fileInputStream = new MemoryStream(fileContent); extractedWords = new StringBuilder(); using (StreamReader reader = new StreamReader(fileInputStream)) { string currentLine = ""; while ((currentLine = reader.ReadLine()) != null) { extractedWords.Append(currentLine.Substring(startingPosition, numberOfCharacters) + "\r"); } } IsProcessCompleted = true; return extractedWords.ToString(); }
/// <summary> /// Returns a new instance of the appropriate Scan Reader class. /// </summary> /// <param name="file">The target file being written.</param> /// <param name="type">The type of the target file.</param> /// <returns></returns> public static IScanWriter GetWriter(OutputFileType type) { switch (type) { case OutputFileType.csv: return(new CsvWriter()); case OutputFileType.mzxml: return(new MzXmlWriter()); case OutputFileType.exmzxml: return(new ExtendedMzXmlWriter()); case OutputFileType.mzml: return(new MzMlWriter()); default: break; } throw new Exception("Unrecognized file type selected for output"); }
public void SetOutputFileType(OutputFileType fileType) { var newOutputKind = fileType switch { OutputFileType.Console => OutputKind.ConsoleApplication, OutputFileType.Windows => OutputKind.WindowsApplication, OutputFileType.Library => OutputKind.DynamicallyLinkedLibrary, OutputFileType.Module => OutputKind.NetModule, OutputFileType.AppContainer => OutputKind.WindowsRuntimeApplication, OutputFileType.WinMDObj => OutputKind.WindowsRuntimeMetadata, _ => throw new ArgumentException( "fileType was not a valid OutputFileType", nameof(fileType) ), }; if (_outputKind != newOutputKind) { _outputKind = newOutputKind; UpdateProjectForNewHostValues(); } }
public void SetOutputFileType(OutputFileType fileType) { OutputKind newOutputKind; switch (fileType) { case OutputFileType.Console: newOutputKind = OutputKind.ConsoleApplication; break; case OutputFileType.Windows: newOutputKind = OutputKind.WindowsApplication; break; case OutputFileType.Library: newOutputKind = OutputKind.DynamicallyLinkedLibrary; break; case OutputFileType.Module: newOutputKind = OutputKind.NetModule; break; case OutputFileType.AppContainer: newOutputKind = OutputKind.WindowsRuntimeApplication; break; case OutputFileType.WinMDObj: newOutputKind = OutputKind.WindowsRuntimeMetadata; break; default: throw new ArgumentException("fileType was not a valid OutputFileType", "fileType"); } SetOption(ref _outputKind, newOutputKind); }
private string GetRelativePath(OutputFileType fileType) { return _relativePaths[fileType]; }
public void SetOutputFileType(OutputFileType fileType) { VisualStudioProjectOptionsProcessor.SetOutputFileType(fileType); }
TextWriter(string name, bool writeByteOrderMark, OutputFileType outputFileType) { this.name = name; this.writeByteOrderMark = writeByteOrderMark; this.outputFileType = outputFileType; }
public static String GetExtentionByType(OutputFileType type) { return(values[(int)(type)]); }
public void WriteFile(OutputFileType outputFileType) { throw new NotImplementedException(); }
public void WriteUtf8File(OutputFileType fileType, string fileName, string fileContents) { FileHelper.WriteUtf8Text(GetOutputPath(fileType, fileName), fileContents); }
/// <summary> /// Opens the file stream writer. /// </summary> /// <param name="fileName">The name of the flat file to write into.</param> /// <param name="fileType">The type of data being written.</param> public static void OpenFileWriter(string fileName, OutputFileType fileType) { // Make sure a writer of the given type has not already been opened. if (FileWriters.ContainsKey(fileType)) { throw new Exception(string.Format("File writer for type {0} already opened.", fileType)); } // Open the stream writer FileWriters.Add(fileType, new StreamWriter(fileName) {AutoFlush = true}); }
/// <inheritdoc /> public async Task <string> GetStatisticForUsers(ICollection <string> users, DateTime startDate, int identifier) { if (!await IsUserAdmin(identifier)) { return(string.Empty); } var results = new List <UserResult>(); var query = $"SELECT username, result, finishtime FROM {UserResultsTable} WHERE (finishtime > convert(datetime,'{startDate:dd-MM-yy}', 5) AND username IS NOT NULL)"; if (users != null && users.Any()) { query += @" AND (" + string.Join(@" OR ", users.Select(user => $"username = '******'")) + @")"; } query += @";"; try { await _connection.OpenAsync().ConfigureAwait(false); using (var command = new SqlCommand(query, _connection)) { var reader = await command.ExecuteReaderAsync().ConfigureAwait(false); while (await reader.ReadAsync().ConfigureAwait(false)) { var user = reader.GetString(0); var result = (int)reader.GetDouble(1); var date = reader.GetDateTime(2); if (results.Any(item => item.User == user)) { results[results.FindIndex(item => item.User == user)].Result[date] = result; } else { results.Add(new UserResult { User = user, Result = new Dictionary <DateTime, int> { { date, result } } }); } } } } catch (Exception exception) { Console.WriteLine(exception); if (Logger.IsErrorEnabled) { Logger.Error(@"Не удалось получить результаты пользователей!", exception); } return(string.Empty); } finally { _connection.Close(); } foreach (var result in results) { var sortedResult = new SortedDictionary <DateTime, int>(result.Result); var keyValuePairs = sortedResult.OrderBy(item => item.Key); result.Result = keyValuePairs.ToDictionary(item => item.Key, item => item.Value); } if (OutputFileType.Equals(StatisticOutputFileType.Image)) { return(_resultFileGenerator.GenerateAsImage(results)); } if (OutputFileType.Equals(StatisticOutputFileType.Text)) { return(_resultFileGenerator.GenerateAsText(results)); } throw new ArgumentOutOfRangeException("", OutputFileType, @"Неизвестный тип выходного файла!"); }
public string ProcessFile(System.IO.Stream inputStream, int startingPosition, int numberOfCharacters, OutputFileType outputFileType) { throw new NotImplementedException(); }
public string GetRelativePath(OutputFileType fileType, string fileName) { return GetRelativePath(fileType) + "/" + fileName; }
public string GetOutputPath(OutputFileType fileType, string fileName) { return Path.Combine(GetOutputPath(fileType), fileName); }
public string SetOutputFile(string name, OutputFileType type) { string arg = EnumHelper.GetDescription(type); switch(type) { case OutputFileType.Csv: if(Path.HasExtension(name)) { name = Path.ChangeExtension(name, "csv"); } else { name += ".csv"; } break; case OutputFileType.Xml: if(Path.HasExtension(name)) { name = Path.ChangeExtension(name, "xml"); } else { name += ".xml"; } break; case OutputFileType.PepXml: if(Path.HasExtension(name)) { name = Path.ChangeExtension(name, "pepXML"); } else { name += ".pepXML"; } break; } SetArgument(arg, name); return name; }
/// <summary> /// Initialize a new instance of <see cref="OutputFile" /> /// </summary> /// <param name="path">The path of the file</param> /// <param name="outputFileType">The type of the file</param> public OutputFile(string path, OutputFileType outputFileType) { Path = path; OutputFileType = outputFileType; }