示例#1
0
 public static IConsumer CreateConsumer(DataFlowContext context, DataFlowType flowType)
 {
     if (flowType == DataFlowType.Decompress)
     {
         return(new DecompressConsumer(context));
     }
     return(new CompressConsumer(context));
 }
示例#2
0
        private static void Run(string entityType, DataFlowType dataFlowType)
        {
            try
            {
                // Mapping generated db by bcp
                IEnumerable<XElement> dataFromDB = Utility.GenerateMappedDataFile(entityType);

                // Get necessary type of Assemble for invoke specific method
                string targetClass = string.Format("{0}.{1}{2}", Utility.FactoryName, entityType, "Factory");
                var assembly = Assembly.GetAssembly(typeof(IBuilder));
                var type = assembly.GetType(targetClass);
                if (type == null)
                {
                    throw new ArgumentNullException("Cannot find type: " + targetClass);
                }

                object[] argsGenerator = new object[1] { dataFromDB };
                object entitiesObject = Activator.CreateInstance(type, argsGenerator);

                // Invoke Constructor
                ConstructorInfo ctor = type.GetConstructor(new[] { typeof(IEnumerable<XElement>) });
                object instance = ctor.Invoke(argsGenerator);

                switch (dataFlowType)
                {
                    case DataFlowType.Out:
                        // Invoke Method
                        type.InvokeMember(Utility.FactoryCreateEntityFileToDestination, BindingFlags.InvokeMethod, null, entitiesObject, null);
                        break;

                    case DataFlowType.In:
                        type.InvokeMember(Utility.FactoryReadEntityFileToDB, BindingFlags.InvokeMethod, null, entitiesObject, null);
                        break;

                    default:
                        break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }