Пример #1
0
        public FileSourceCSV(
            FileSourceFactory factory,
            DataFlowOpInitializeContext context,
            AdapterInputSource adapterInputSource,
            bool hasHeaderLine,
            bool hasTitleLine,
            int?numLoops,
            string[] propertyNames,
            string dateFormat)
        {
            _factory            = factory;
            _adapterInputSource = adapterInputSource;
            _hasHeaderLine      = hasHeaderLine;
            _hasTitleLine       = hasTitleLine;
            _numLoops           = numLoops;
            _dateFormat         = dateFormat;

            _statementContext = context.AgentInstanceContext.StatementContext;

            // use event type's full list of properties
            if (!hasTitleLine)
            {
                if (propertyNames != null)
                {
                    _parseMake = SetupProperties(false, propertyNames, factory.OutputEventType, _statementContext, dateFormat);
                }
                else
                {
                    _parseMake = SetupProperties(false, factory.OutputEventType.PropertyNames, factory.OutputEventType, _statementContext, dateFormat);
                }
            }
        }
Пример #2
0
        public FileSourceLineUnformatted(
            FileSourceFactory factory,
            DataFlowOpInitializeContext context,
            AdapterInputSource inputSource,
            string filenameOrUri,
            string propertyNameLine,
            string propertyNameFile)
        {
            _factory          = factory;
            _inputSource      = inputSource;
            _filenameOrUri    = filenameOrUri;
            _propertyNameLine = propertyNameLine;
            _propertyNameFile = propertyNameFile;

            var outputEventType  = factory.OutputEventType;
            var statementContext = context.AgentInstanceContext.StatementContext;

            if ((outputEventType.PropertyNames.Length != 1 || outputEventType.PropertyDescriptors[0].PropertyType != typeof(string)) &&
                propertyNameLine == null)
            {
                throw new ArgumentException(
                          "Expecting an output event type that has a single property that is of type string, or alternatively specify the 'propertyNameLine' parameter");
            }

            if (outputEventType is ObjectArrayEventType && outputEventType.PropertyDescriptors.Count == 1)
            {
                _lineProcessor = new LineProcessorObjectArray();
            }
            else
            {
                var propertyNameLineToUse = propertyNameLine;
                if (propertyNameLineToUse == null)
                {
                    propertyNameLineToUse = outputEventType.PropertyDescriptors[0].PropertyName;
                }

                if (!outputEventType.IsProperty(propertyNameLineToUse))
                {
                    throw new EPException("Failed to find property name '" + propertyNameLineToUse + "' in type '" + outputEventType.Name + "'");
                }

                Type propertyType;
                try {
                    propertyType = outputEventType.GetPropertyType(propertyNameLineToUse);
                }
                catch (PropertyAccessException ex) {
                    throw new EPException("Invalid property name '" + propertyNameLineToUse + "': " + ex.Message, ex);
                }

                if (propertyType != typeof(string))
                {
                    throw new EPException("Invalid property type for property '" + propertyNameLineToUse + "', expected a property of type String");
                }

                var writeables = EventTypeUtility.GetWriteableProperties(outputEventType, false);
                IList <WriteablePropertyDescriptor> writeableList = new List <WriteablePropertyDescriptor>();

                var writeableLine = EventTypeUtility.FindWritable(propertyNameLineToUse, writeables);
                if (writeableLine == null)
                {
                    throw new EPException("Failed to find writable property property '" + propertyNameLineToUse + "', is the property read-only?");
                }

                writeableList.Add(writeableLine);

                if (propertyNameFile != null)
                {
                    var writeableFile = EventTypeUtility.FindWritable(propertyNameFile, writeables);
                    if (writeableFile == null || writeableFile.PropertyType != typeof(string))
                    {
                        throw new EPException("Failed to find writable String-type property '" + propertyNameFile + "', is the property read-only?");
                    }

                    writeableList.Add(writeableFile);
                }

                EventBeanManufacturer manufacturer;
                try {
                    var writables = writeableList.ToArray();
                    manufacturer = EventTypeUtility
                                   .GetManufacturer(outputEventType, writables, statementContext.ImportServiceRuntime, false, statementContext.EventTypeAvroHandler)
                                   .GetManufacturer(statementContext.EventBeanTypedEventFactory);
                }
                catch (EventBeanManufactureException e) {
                    throw new EPException("Event type '" + outputEventType.Name + "' cannot be written to: " + e.Message, e);
                }

                _lineProcessor = new LineProcessorGeneralPurpose(manufacturer);
            }

            if (factory.OutputPortTypes.Length == 2)
            {
                _eofProcessor = GetBeginEndProcessor(context, 1);
            }
            else if (factory.OutputPortTypes.Length == 3)
            {
                _bofProcessor = GetBeginEndProcessor(context, 1);
                _eofProcessor = GetBeginEndProcessor(context, 2);
            }
            else if (factory.OutputPortTypes.Length > 3)
            {
                throw new EPException("Operator only allows up to 3 output ports");
            }
        }