public static WriteToFile ( string files, string text ) : void | ||
files | string | Comma or semi-colon delimitted list of file names to which the |
text | string | Text to be written to the |
Результат | void |
/// <summary> /// Processes the <paramref name="export"/> using the current <see cref="DataListener.Data"/>. /// </summary> /// <param name="export"><see cref="Export"/> to be processed.</param> /// <exception cref="ArgumentException"><b>OutputFile</b> setting is missing from the <see cref="Export.Settings"/> of the <paramref name="export"/>.</exception> protected override void ProcessExport(Export export) { // Ensure that required settings are present. ExportSetting outputFileSetting = export.FindSetting("OutputFile"); if (outputFileSetting == null) { throw new ArgumentException("OutputFile setting is missing"); } // Write the current data for the export to the specified files in CSV format. FileHelper.WriteToFile(outputFileSetting.Value, "CSV", GetExportDataAsDataset(export, null)); }
/// <summary> /// Processes the <paramref name="export"/> using the current <see cref="DataListener.Data"/>. /// </summary> /// <param name="export"><see cref="Export"/> to be processed.</param> /// <exception cref="ArgumentException"><b>OutputFile</b> or <b>OutputFormat</b> setting is missing from the <see cref="Export.Settings"/> of the <paramref name="export"/>.</exception> protected override void ProcessExport(Export export) { DataSet rawData = GetBufferedData(export.Name); try { // Ensure that required settings are present. ExportSetting outputFileSetting = export.FindSetting("OutputFile"); if (outputFileSetting == null) { throw new ArgumentException("OutputFile setting is missing"); } ExportSetting outputFormatSetting = export.FindSetting("OutputFormat"); if (outputFormatSetting == null) { throw new ArgumentException("OutputFormat setting is missing"); } if (rawData != null) { // Buffered data exists for exporting. lock (rawData) { // Update the export timestamp, row count and interval. rawData.Tables[1].Rows.Add(DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt"), rawData.Tables[0].Rows.Count, string.Format("{0} seconds", export.Interval)); // Write the buffered raw data for the export to the specified files in specified format. FileHelper.WriteToFile(outputFileSetting.Value, outputFormatSetting.Value, rawData); } } } catch { throw; } finally { if (rawData != null) { lock (rawData) { // Clear the buffered data to make space for new data that is to be buffered. rawData.Tables[0].Clear(); rawData.Tables[1].Clear(); } } } }
/// <summary> /// Processes the <paramref name="export"/> using the current <see cref="DataListener.Data"/>. /// </summary> /// <param name="export"><see cref="Export"/> to be processed.</param> /// <exception cref="ArgumentException"><b>OutputFile</b> or <b>OutputFormat</b> setting is missing from the <see cref="Export.Settings"/> of the <paramref name="export"/>.</exception> protected override void ProcessExport(Export export) { // Ensure that required settings are present. ExportSetting outputFileSetting = export.FindSetting("OutputFile"); if (outputFileSetting == null) { throw new ArgumentException("OutputFile setting is missing"); } ExportSetting outputFormatSetting = export.FindSetting("OutputFormat"); if (outputFormatSetting == null) { throw new ArgumentException("OutputFormat setting is missing"); } // Get the calculated statistics. Statistics stats = GetStatistics(export); // Get the dataset template we'll be outputting. DataSet output = DatasetTemplate("Statistics"); // Modify the dataset template for statistical values. DataTable data = output.Tables[0]; data.PrimaryKey = null; data.Columns.Clear(); data.Columns.Add("MinimumValue", typeof(double)); data.Columns.Add("MaximumValue", typeof(double)); data.Columns.Add("AverageValue", typeof(double)); foreach (DataColumn column in data.Columns) { column.ColumnMapping = MappingType.Attribute; } // Add the calculated statistical value. data.Rows.Add(stats.MinimumValue, stats.MaximumValue, stats.AverageValue); // Update the export timestamp, row count and interval. output.Tables[1].Rows.Add(DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt"), output.Tables[0].Rows.Count, string.Format("{0} seconds", export.Interval)); // Write the statistical data for the export to the specified files in specified format. FileHelper.WriteToFile(outputFileSetting.Value, outputFormatSetting.Value, output); }
/// <summary> /// Processes the <paramref name="export"/> using the current <see cref="DataListener.Data"/>. /// </summary> /// <param name="export"><see cref="Export"/> to be processed.</param> /// <exception cref="ArgumentException"><b>OutputFile</b>, <b>OutputFormat</b> or <b>OutputTimespan</b> setting is missing from the <see cref="Export.Settings"/> of the <paramref name="export"/>.</exception> protected override void ProcessExport(Export export) { // Ensure that required settings are present. ExportSetting outputFileSetting = export.FindSetting("OutputFile"); if (outputFileSetting == null) { throw new ArgumentException("OutputFile setting is missing"); } ExportSetting outputFormatSetting = export.FindSetting("OutputFormat"); if (outputFormatSetting == null) { throw new ArgumentException("OutputFormat setting is missing"); } ExportSetting outputTimespanSetting = export.FindSetting("OutputTimespan"); if (outputTimespanSetting == null) { throw new ArgumentException("OutputTimespan setting is missing"); } // Initialize local variables. DataSet output = null; string[] outputFiles = outputFileSetting.Value.Split(';', ','); DataSet current = GetExportDataAsDataset(export, null); DateTime dataStartDate = DateTime.UtcNow.AddMinutes(-Convert.ToInt32(outputTimespanSetting.Value)); // Make the output filenames absolute. for (int i = 0; i < outputFiles.Length; i++) { outputFiles[i] = FilePath.GetAbsolutePath(outputFiles[i].Trim()); } // Try to read-in data that might have been exported previously. foreach (string outputFile in outputFiles) { if (File.Exists(outputFile)) { // Wait for a lock on the file before reading. FilePath.WaitForReadLock(outputFile, FileLockWaitTime); // Read the file data and keep it in memory to be merged later. output = current.Clone(); switch (outputFormatSetting.Value.ToLower()) { case "xml": output.ReadXml(outputFile); break; case "csv": MergeTables(output.Tables[0], File.ReadAllText(outputFile).ToDataTable(",", true), dataStartDate); break; default: break; } break; // Don't look any further. } } if (output == null) { // Output will be just current data since there is no previously exported data. output = current; } else { // Merge previously exported data loaded from file with the current data for the export. MergeTables(output.Tables[0], current.Tables[0], dataStartDate); } // Delete any old data from the output that don't fall in the export's rolling window. string filterCondition = string.Format("Convert(Time, System.DateTime) < #{0}#", dataStartDate); foreach (DataRow row in output.Tables[0].Select(filterCondition)) { row.Delete(); } // Update the export timestamp, row count and interval. DataRowCollection info = output.Tables[1].Rows; info.Clear(); info.Add(DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt"), output.Tables[0].Rows.Count, string.Format("{0} seconds", export.Interval)); // Write the data for the export to the specified files in specified format. FileHelper.WriteToFile(outputFileSetting.Value, outputFormatSetting.Value, output); }