protected override ISyncChannel ProduceInternal(ISyncContext context, RecordConfiguration configuration)
        {
            ISyncChannel channel;
            ISchema      schema;

            IEnumerable <IPayload>    payloads;
            IEnumerable <ISyncRecord> records;

            if ((object)context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if ((object)configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            this.AssertValidConfiguration();

            TTextualConnectorSpecificConfiguration fsConfig = this.Configuration.StageSpecificConfiguration;

            if (!context.LocalState.TryGetValue(this, out IDictionary <string, object> localState))
            {
                localState = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                context.LocalState.Add(this, localState);
            }

            schema = localState[Constants.ContextComponentScopedSchema] as ISchema;

            if ((object)schema == null)
            {
                throw new SyncPremException(nameof(schema));
            }

            schema = localState[Constants.ContextComponentScopedSchema] as ISchema;

            if ((object)schema == null)
            {
                throw new SyncPremException(nameof(schema));
            }

            payloads = this.TextualReader.ReadRecords();

            if ((object)payloads == null)
            {
                throw new SyncPremException(nameof(payloads));
            }

            records = payloads.Select(rec => new DefaultSyncRecord(schema, rec, string.Empty, Partition.None, Offset.None));

            if ((object)records == null)
            {
                throw new SyncPremException(nameof(records));
            }

            channel = context.CreateChannel(records);

            return(channel);
        }
Example #2
0
        protected override ISyncChannel ProduceInternal(ISyncContext context, RecordConfiguration configuration)
        {
            ISyncChannel channel = null;
            ISchema      schema;

            IEnumerable <IPayload> payloads;
            IEnumerable <IAdoNetStreamingResult> results;
            IEnumerable <DbParameter>            dbParameters;

            if ((object)context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if ((object)configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            this.AssertValidConfiguration();

            AdoNetConnectorSpecificConfiguration fsConfig = this.Configuration.StageSpecificConfiguration;

            if ((object)fsConfig.ExecuteCommand == null)
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", nameof(fsConfig.ExecuteCommand)));
            }

            if (SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(fsConfig.ExecuteCommand.CommandText))
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}.{1}'.", nameof(fsConfig.ExecuteCommand), nameof(fsConfig.ExecuteCommand.CommandText)));
            }

            dbParameters = fsConfig.ExecuteCommand.GetDbDataParameters(this.SourceUnitOfWork);

            results = this.SourceUnitOfWork.ExecuteResults(fsConfig.ExecuteCommand.CommandType ?? CommandType.Text, fsConfig.ExecuteCommand.CommandText, dbParameters);

            if ((object)results == null)
            {
                throw new SyncPremException(nameof(results));
            }

            var channels = this.GetMultiplexedChannels(context, results);
            var records  = channels.SelectMany(x => x.Records);

            channel = context.CreateChannel(records);

            return(channel);
        }
Example #3
0
        private IEnumerable <ISyncChannel> GetMultiplexedChannels(ISyncContext context, IEnumerable <IAdoNetStreamingResult> results)
        {
            ISyncChannel channel;

            IEnumerable <IPayload> payloads;

            if ((object)context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if ((object)results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            foreach (IAdoNetStreamingResult result in results)
            {
                ISchema schema;                 // prevent closure bug

                if (!context.LocalState.TryGetValue(this, out IDictionary <string, object> localState))
                {
                    localState = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                    context.LocalState.Add(this, localState);
                }

                schema = localState[Constants.ContextComponentScopedSchema] as ISchema;

                if ((object)schema == null)
                {
                    throw new SyncPremException(nameof(schema));
                }

                payloads = result.Records;

                if ((object)payloads == null)
                {
                    throw new SyncPremException(nameof(payloads));
                }

                var records = payloads.Select(rec => new DefaultSyncRecord(schema, rec, string.Empty, Partition.None, Offset.None));

                channel = context.CreateChannel(records);

                yield return(channel);
            }
        }