Exemplo n.º 1
0
        bool Process(ProcessItem processItem)
        {
            const String fcn = "Process";

            if (this.unProcessed.TryRemove(processItem.Resource.GetUrl(), out var value) == false)
            {
                throw new Exception($"Error removing item from unprocessed list");
            }
            ;

            //Trace.WriteLine($"++++++++ Starting {processItem.Title}");
            this.ConversionInfo(this.GetType().Name,
                                fcn,
                                $"Processing {processItem.Resource.GetName()}");
            bool mergedFlag = false;

            foreach (String fragmentUrl in processItem.Resource.ReferencedFragments())
            {
                if (this.processed.TryGetValue(fragmentUrl, out ProcessItem fragment) == false)
                {
                    throw new Exception("Processed fragment {fragmentUrl} not found in processed dictionary");
                }

                if (processItem.AddIncludedFragment(fragment) == true)
                {
                    this.ConversionWarn(this.GetType().Name,
                                        fcn,
                                        $"Fragment {fragment.Resource.GetName()} has already been included");
                }
                else
                {
                    this.ConversionInfo(this.GetType().Name,
                                        fcn,
                                        $"Merging fragment {fragment.Resource.GetName()} into {processItem.Resource.GetName()}");

                    Merger m = new Merger(this, processItem, fragment);
                    if (
                        (this.BreakOnTitle == null) ||
                        (processItem.Title == this.BreakOnTitle)
                        )
                    {
                        m.BreakOnElementId = this.BreakOnElementId;
                    }

                    if (m.Merge(out bool mergedElements) == false)
                    {
                        this.ConversionError(this.GetType().Name, fcn, $"Merge of fragment {fragment.Resource.GetName()} into {processItem.Resource.GetName()} failed ");
                        return(false);
                    }
                    if (mergedElements == true)
                    {
                        mergedFlag = true;
                    }
                }
            }
            if (mergedFlag == true)
            {
                this.FixDifferential(processItem);
            }

            // save intermediate merged file?
            if (String.IsNullOrEmpty(this.MergedDir) == false)
            {
                SaveResource(MergedDir, processItem, false);
            }

            if (this.processed.TryAdd(processItem.Resource.GetUrl(), processItem) == false)
            {
                throw new Exception($"Error adding item to Processed list");
            }
            ;

            //Trace.WriteLine($"-------- Completed{processItem.Title}");
            return(true);
        }