/// <summary> /// Thread safe agreegate function, should be called from Pre/Post validate only. The result will be stored in container data /// </summary> /// <param name="columnName">Name of the column which is to be agreegated</param> /// <param name="isSytemColumn">True if the system columns to be searched</param> /// <param name="operationType">Aggregate operation type; default is 'Sum'</param> /// <param name="containerDataKeyName">Name of the container data key where the result will be added or updated</param> /// <returns>calculated value as double</returns> public double Aggregate(string columnName, bool isSytemColumn = false, AggregateOperationTypes operationType = AggregateOperationTypes.Sum, string containerDataKeyName = null) { double calculatedValue = 0; lock (_lock) { List <double> values = new List <double>(); if (isSytemColumn) { values = (from r in Rows select r.ColumnsSystem[columnName].ValueDouble).ToList(); } else { values = (from r in Rows select r.Columns[columnName].ValueDouble).ToList(); } switch (operationType) { case AggregateOperationTypes.Sum: calculatedValue = values.Sum(); break; case AggregateOperationTypes.Average: calculatedValue = values.Average(); break; case AggregateOperationTypes.Min: calculatedValue = values.Min(); break; case AggregateOperationTypes.Max: calculatedValue = values.Max(); break; } calculatedValue = Math.Round(calculatedValue, 2); if (containerDataKeyName != null) { ProcessVariables.AddOrUpdate(containerDataKeyName, calculatedValue, (keyx, oldValue) => calculatedValue); ExtensionMethods.TraceInformation("Aggregate method '{0}' has been called on '{1}' and calculated value '{2}' has been assigned to ContainerData with key as '{3}'" , operationType.ToString(), calculatedValue, containerDataKeyName, containerDataKeyName); } else { ExtensionMethods.TraceInformation("Aggregate method '{0}' has been called on '{1}' and calculated value '{2}' was returned." , operationType.ToString(), calculatedValue, containerDataKeyName); } return(calculatedValue); } }
private void ExtractHeaderFooter() { IdpeKey headerAttribute = DataSource.Key(IdpeKeyTypes.HeaderLine1Attribute); IdpeKey footerAttribute = DataSource.Key(IdpeKeyTypes.FooterLine1Attribute); if ((headerAttribute == null) && (footerAttribute == null)) { return; } headerAttribute = null; footerAttribute = null; try { string[] allLines = FileContent.ToString().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string line = string.Empty; int howManyFound = 0; for (int i = 1; i <= 6; i++) { IdpeKeyTypes keyType = (IdpeKeyTypes)Enum.Parse(typeof(IdpeKeyTypes), "HeaderLine" + i + "Attribute"); headerAttribute = DataSource.Key(keyType); if (headerAttribute != null) { line = allLines[i - 1]; ProcessVariables.AddOrUpdate(headerAttribute.Value, line, (key, oldValue) => line); } else { break; } howManyFound++; } allLines = allLines.SubArray(howManyFound, allLines.Length - howManyFound); howManyFound = 0; for (int i = 6; i >= 1; i--) { IdpeKeyTypes keyType = (IdpeKeyTypes)Enum.Parse(typeof(IdpeKeyTypes), "FooterLine" + i + "Attribute"); footerAttribute = DataSource.Key(keyType); if (footerAttribute == null) { continue; } else { line = allLines[allLines.Length - (howManyFound + 1)]; ProcessVariables.AddOrUpdate(footerAttribute.Value, line, (key, oldValue) => line); } howManyFound++; } allLines = allLines.SubArray(0, allLines.Length - howManyFound); FileNameWithoutHeaderAndOrFooter = FileName + ShortGuid.NewGuid().ToString(); using (StreamWriter sw = new StreamWriter(FileNameWithoutHeaderAndOrFooter)) { for (int i = 0; i < allLines.Length; i++) { sw.WriteLine(allLines[i]); } } return; } catch (Exception ex) { ExtensionMethods.TraceInformation(ex.ToString()); this.Errors.Add("File content is invalid! Please check that file has required header(s) and footer(s) and at least 1 valid record!"); } }