Exemple #1
0
 /// <summary>
 /// The constructor to specify the base unit
 /// </summary>
 /// <param name="operation">Must always be <c>ConversionOperation.Base</c> or <c>ConversionOperation.Negate</c></param>
 public ConversionAttribute(ConversionOperation operation) : this(operation, 0, ConversionOperation.None, 0)
 {
     if (operation != ConversionOperation.Base && operation != ConversionOperation.Negate)
     {
         throw new ArgumentException("Operation must be either Base or Negate", nameof(operation));
     }
 }
Exemple #2
0
 /// <summary>
 /// The constructor to specify two-operation conversion
 /// </summary>
 /// <param name="operation">The first operation to convert the unit into base unit</param>
 /// <param name="factor">The numeric factor for the first operation</param>
 /// <param name="secondOperation">The second operation to convert the unit into base unit</param>
 /// <param name="secondFactor">The numeric factor for the second operation</param>
 public ConversionAttribute(ConversionOperation operation, double factor, ConversionOperation secondOperation, double secondFactor)
 {
     Operation       = operation;
     Factor          = factor;
     SecondOperation = secondOperation;
     SecondFactor    = secondFactor;
 }
Exemple #3
0
        public void Full()
        {
            var stopwatch          = new Stopwatch();
            var connectionString   = "Server=.;Database=ETLTest;Integrated Security=SSPI;";
            var connectionProvider = new Func <SqlConnection>(() => new SqlConnection(connectionString));
            var read     = new DatabaseSource <Record>(connectionProvider, "SELECT * FROM TestTableSize");
            var convert  = new ConversionOperation <Record, ResultingRecord>(input => input);
            var write    = new SqlBulkCopyOperation <ResultingRecord>(connectionProvider, "ResultingRecord");
            var pipeline = CreateNewPipeline();

            pipeline.AddOperation(read);
            pipeline.AddOperation(convert);
            pipeline.AddOperation(write);
            stopwatch.Start();
            pipeline.Execute();
            stopwatch.Stop();
            Debug.WriteLine(string.Format("Processed in {0}", stopwatch.Elapsed));
        }
Exemple #4
0
        /// <summary>
        /// The constructor to specify a custom conversion
        /// </summary>
        /// <param name="operation">Must always be `ConversionOperation.Base`</param>
        /// <param name="name">The full name (namespace + name) of the type that implements <see cref="ICustomConversionOperation">ICustomConversionOperation</see> interface</param>
        public ConversionAttribute(ConversionOperation operation, string name) : this(operation, 0, ConversionOperation.None, 0)
        {
            if (operation != ConversionOperation.Custom)
            {
                throw new ArgumentException("Operation must be Custom", nameof(operation));
            }

            if (!gTypes.TryGetValue(name, out Type type))
            {
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                type = null;
                foreach (var assembly in assemblies)
                {
                    foreach (var type1 in assembly.GetTypes())
                    {
                        if (type1.FullName == name)
                        {
                            type = type1;
                            break;
                        }
                    }
                    if (type != null)
                    {
                        break;
                    }
                }
                if (type == null)
                {
                    throw new ArgumentException($"Type {name} is not found", nameof(name));
                }
                gTypes.TryAdd(name, type);
            }
            ConversionInterface = Activator.CreateInstance(type) as ICustomConversionOperation;
            if (ConversionInterface == null)
            {
                throw new ArgumentException($"Type {name} does not supprt {nameof(ICustomConversionOperation)}", nameof(name));
            }
        }
        private static Expression OperationToReverseExpression(Expression value, ConversionOperation operation, double factor, ICustomConversionOperation op = null)
        {
            switch (operation)
            {
            case ConversionOperation.Base:
                return(value);

            case ConversionOperation.Add:
                return(Expression.Subtract(value, Expression.Constant(factor)));

            case ConversionOperation.Subtract:
                return(Expression.Add(value, Expression.Constant(factor)));

            case ConversionOperation.SubtractFromFactor:
                return(Expression.Negate(Expression.Subtract(value, Expression.Constant(factor))));

            case ConversionOperation.Multiply:
                return(Expression.Divide(value, Expression.Constant(factor)));

            case ConversionOperation.Divide:
                return(Expression.Multiply(value, Expression.Constant(factor)));

            case ConversionOperation.DivideFactor:
                return(Expression.Divide(Expression.Constant(factor), value));

            case ConversionOperation.Negate:
                return(Expression.Negate(value));

            case ConversionOperation.Atan:
                return(Expression.Call(null, gTan, new Expression[] { value }));

            case ConversionOperation.Custom:
                return(Expression.Call(Expression.Constant(op), op.GetType().GetMethod(nameof(ICustomConversionOperation.FromBase)), new Expression[] { value }));
            }
            return(Expression.Constant(0.0));
        }
Exemple #6
0
 /// <summary>
 /// The constructor to specify one operation conversion
 /// </summary>
 /// <param name="operation">The operation to convert the unit into base unit</param>
 /// <param name="factor">The numeric factor for the operation</param>
 public ConversionAttribute(ConversionOperation operation, double factor) : this(operation, factor, ConversionOperation.None, 0)
 {
 }