Exemplo n.º 1
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <GroupIterableDataSettings>();

            if (settings == null)
            {
                logger.Error("Cannot access ClearFacetCollectionSettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            IterableDataSettings iterableDataSettings = pipelineContext.GetIterableDataSettings();

            if (iterableDataSettings == null || iterableDataSettings.Data == null)
            {
                return;
            }

            var groupedData = new GroupedDataSettings();

            foreach (object element in iterableDataSettings.Data)
            {
                var record = element as Dictionary <string, string>;
                if (record != null)
                {
                    if (record.ContainsKey(settings.GroupFieldKey))
                    {
                        var key = record[settings.GroupFieldKey];
                        if (!groupedData.Data.ContainsKey(key))
                        {
                            groupedData.Data.Add(key, new List <Dictionary <string, string> >());
                        }
                        groupedData.Data[key].Add(record);
                    }
                }
            }

            pipelineContext.Plugins.Add(groupedData);

            if (settings.RemoveIterableSettingsPlugin)
            {
                // This should be checked if another pipeline step is going to add settings.
                pipelineContext.Plugins.Remove(iterableDataSettings);
            }
        }
Exemplo n.º 2
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            ILogger logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
            }
            else
            {
                PipelinesSettings pipelinesSettings = pipelineStep.GetPipelinesSettings();
                if (pipelinesSettings == null || !pipelinesSettings.Pipelines.Any <Pipeline>())
                {
                    logger.Error("Pipeline step processing will abort because the pipeline step has no sub-pipelines assigned. (pipeline step: {0})", (object)pipelineStep.Name);
                }
                else
                {
                    var iterateGroupedDataSettings = pipelineStep.GetPlugin <IterateThroughGroupedDataSettings>();
                    if (iterateGroupedDataSettings == null || string.IsNullOrEmpty(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Error("No Iterated Group Settings was found with configured group field key");
                        return;
                    }

                    GroupedDataSettings groupedDataSettings = pipelineContext.GetPlugin <GroupedDataSettings>();
                    if (groupedDataSettings == null || groupedDataSettings.Data == null)
                    {
                        //let's try the parent context
                        var parentSettings = pipelineContext.GetPlugin <ParentPipelineContextSettings>();
                        if (parentSettings != null)
                        {
                            groupedDataSettings = parentSettings.ParentPipelineContext.GetPlugin <GroupedDataSettings>();
                        }

                        if (groupedDataSettings == null || groupedDataSettings.Data == null)
                        {
                            logger.Error("No Grouped Data Settings was found in the pipelineContext or parent Pipeline Context ");
                        }

                        return;
                    }

                    if (!groupedDataSettings.Data.ContainsKey(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Warn("No Records Exists for Configured Key: {0}", iterateGroupedDataSettings.GroupFieldKey);
                        return;
                    }

                    int num = 0;

                    try
                    {
                        foreach (object element in groupedDataSettings.Data[iterateGroupedDataSettings.GroupFieldKey])
                        {
                            if (!pipelineContext.PipelineBatchContext.Stopped)
                            {
                                PipelineContext         pipelineContext1        = new PipelineContext(pipelineContext.PipelineBatchContext);
                                SynchronizationSettings synchronizationSettings = this.ResolveSynchronizationSettingsAndSetElement(pipelineStep, pipelineContext, element);
                                pipelineContext1.Plugins.Add((IPlugin)synchronizationSettings);
                                ParentPipelineContextSettings pipelineContextSettings = new ParentPipelineContextSettings()
                                {
                                    ParentPipelineContext = pipelineContext
                                };
                                pipelineContext1.Plugins.Add((IPlugin)pipelineContextSettings);
                                this.ProcessPipelines(pipelineStep, pipelinesSettings.Pipelines, pipelineContext1);
                            }

                            num++;
                        }


                        logger.Info("{0} elements were iterated. (pipeline: {1}, pipeline step: {2})", (object)num, (object)pipelineContext.CurrentPipeline.Name, (object)pipelineContext.CurrentPipelineStep.Name, (object)pipelineContext);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        pipelineContext.CriticalError = true;
                    }
                }
            }
        }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            ILogger logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
            }
            else
            {
                PipelinesSettings pipelinesSettings = pipelineStep.GetPipelinesSettings();
                if (pipelinesSettings == null || !pipelinesSettings.Pipelines.Any <Pipeline>())
                {
                    logger.Error("Pipeline step processing will abort because the pipeline step has no sub-pipelines assigned. (pipeline step: {0})", (object)pipelineStep.Name);
                }
                else
                {
                    var iterateGroupedDataSettings = pipelineStep.GetPlugin <IterateThroughGroupedDataSettings>();
                    if (iterateGroupedDataSettings == null || string.IsNullOrEmpty(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Error("No Iterated Group Settings was found with configured group field key");
                        return;
                    }

                    GroupedDataSettings groupedDataSettings = pipelineContext.GetPlugin <GroupedDataSettings>();
                    if (groupedDataSettings == null || groupedDataSettings.Data == null)
                    {
                        //let's try the parent context
                        var parentSettings = pipelineContext.GetPlugin <ParentPipelineContextSettings>();
                        if (parentSettings != null)
                        {
                            groupedDataSettings = parentSettings.ParentPipelineContext.GetPlugin <GroupedDataSettings>();
                        }

                        if (groupedDataSettings == null || groupedDataSettings.Data == null)
                        {
                            logger.Error("No Grouped Data Settings was found in the pipelineContext or parent Pipeline Context ");
                            return;
                        }
                    }

                    var parentSyncSettings = pipelineContext.GetPlugin <SynchronizationSettings>();
                    var source             = parentSyncSettings.Source as Dictionary <string, string>;
                    if (source == null || !source.ContainsKey(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Warn("Group Field Key {0} doesn;t exist in source.", iterateGroupedDataSettings.GroupFieldKey);
                        return;
                    }

                    var groupValue = source[iterateGroupedDataSettings.GroupFieldKey];

                    int num = 0;

                    try
                    {
                        var childRecordSettings = new ChildRecordSettings();

                        foreach (object element in groupedDataSettings.Data[groupValue])
                        {
                            if (!pipelineContext.PipelineBatchContext.Stopped)
                            {
                                PipelineContext         pipelineContext1        = new PipelineContext(pipelineContext.PipelineBatchContext);
                                SynchronizationSettings synchronizationSettings = this.ResolveSynchronizationSettingsAndSetElement(pipelineStep, pipelineContext, element);

                                //instatiate Target for filling.
                                synchronizationSettings.Target = new Dictionary <string, string>();

                                pipelineContext1.Plugins.Add((IPlugin)synchronizationSettings);
                                ParentPipelineContextSettings pipelineContextSettings = new ParentPipelineContextSettings()
                                {
                                    ParentPipelineContext = pipelineContext
                                };
                                pipelineContext1.Plugins.Add((IPlugin)pipelineContextSettings);
                                this.ProcessPipelines(pipelineStep, pipelinesSettings.Pipelines, pipelineContext1);

                                var record = pipelineContext1.GetPlugin <SynchronizationSettings>().Target as Dictionary <string, string>;
                                if (record != null)
                                {
                                    childRecordSettings.Records.Add(record);
                                }
                            }

                            num++;
                        }

                        pipelineContext.Plugins.Add(childRecordSettings);

                        logger.Info("{0} elements were iterated. (pipeline: {1}, pipeline step: {2})", (object)num, (object)pipelineContext.CurrentPipeline.Name, (object)pipelineContext.CurrentPipelineStep.Name, (object)pipelineContext);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        pipelineContext.CriticalError = true;
                    }
                }
            }
        }