Пример #1
0
        /// <summary>
        /// Creates a new transformed record. By default the Kinesis Firehose Base64 data is decoded into UTF8 before being passed to the tranform function.
        /// </summary>
        /// <param name="record">The Kinesis Firehose record</param>
        /// <param name="transform">The function that will transform the data from the Kinesis Firehose record</param>
        /// <param name="useDefaultEncoding">Specifies if the data in the Kinesis Firehose record should be decoded using
        /// the default text encoding, UTF8. If this is false, the data will be passed to the transform function as a Base64 encoded string</param>
        /// <returns>The transformed record</returns>
        public static async Task <KinesisFirehoseTransformedRecord> BuildAsync(KinesisFirehoseRecord record, Func <string, Task <TransformationResult> > transform, bool useDefaultEncoding = true)
        {
            ParameterTests.NonNull(record, "record");
            ParameterTests.NonNull(transform, "transform");

            try
            {
                string Data = record.Data;

                if (useDefaultEncoding)
                {
                    Data = record.DecodeData();
                }

                TransformationResult Result = await transform.Invoke(Data);

                return(new KinesisFirehoseTransformedRecord(record.RecordId, Result.Data, Result.Result));
            }
            catch (AggregateException e)
            {
                return(new KinesisFirehoseTransformedRecord(record.RecordId, Convert.ToBase64String(Encoding.UTF8.GetBytes($"{e.InnerException.GetType().FullName} : {e.InnerException.Message}")), TransformationResultStatus.PROCESSING_FAILED));
            }
            catch (Exception e)
            {
                return(new KinesisFirehoseTransformedRecord(record.RecordId, Convert.ToBase64String(Encoding.UTF8.GetBytes($"{e.GetType().FullName} : {e.Message}")), TransformationResultStatus.PROCESSING_FAILED));
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a new transformed record. The Kinesis Firehose Base64 data is decided using the provided encoding parameter before being passed to the
        /// transform function.
        /// </summary>
        /// <param name="record">The Kinesis Firehose record</param>
        /// <param name="transform">The function that will transform the data from the Kinesis Firehose record</param>
        /// <param name="encoding">The encoding used to convert the bytes from the Base64 string into a readable string</param>
        /// <returns>The transformed record</returns>
        public static KinesisFirehoseTransformedRecord Build(KinesisFirehoseRecord record, Func <string, TransformationResult> transform, Encoding encoding)
        {
            ParameterTests.NonNull(record, "record");
            ParameterTests.NonNull(transform, "transform");
            ParameterTests.NonNull(encoding, "encoding");

            try
            {
                TransformationResult Result = transform.Invoke(record.DecodeData(encoding));
                return(new KinesisFirehoseTransformedRecord(record.RecordId, Result.Data, Result.Result));
            }
            catch (Exception e)
            {
                return(new KinesisFirehoseTransformedRecord(record.RecordId, Convert.ToBase64String(Encoding.UTF8.GetBytes($"{e.GetType().FullName} : {e.Message}")), TransformationResultStatus.PROCESSING_FAILED));
            }
        }