Exemple #1
0
        public void WriteFile(string fileroot, int index, XmlTriplet triplet)
        {
            File.Learner = triplet.Learners.ToArray();
            File.LearnerDestinationandProgression = triplet.Progressions.ToArray();
            // ILR-LLLLLLLL-YYYY-yyyymmdd-hhmmss-NN.XML
            string filename = $"{fileroot}ILR-{triplet.UKPRN}-1718-{File.Header.Source.DateTime.ToString("yyyyMMdd-HHmmss")}-0{index}.xml";

            foreach (var frl in triplet.FileRuleLearners)
            {
                frl.Filename = filename;
            }

            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Message));
            using (TextWriter sw = new StreamWriter(filename))
            {
                writer.Serialize(sw, File);
            }
        }
Exemple #2
0
 internal void PopulateHeaders(FilePreparationDateRequired fpdr, XmlTriplet triplet)
 {
     File                  = new Message();
     File.Header           = CreateHeader(fpdr, triplet.UKPRN);
     File.LearningProvider = CreateLearningProvider(triplet.UKPRN);
 }
        internal int GenerateAndMutate(
            string ruleName,
            bool valid,
            int currentLearnerIndex,
            List <XmlTriplet> triplets,
            ref long ULNIndex)
        {
            XmlTriplet       triplet = triplets.First();
            int              result  = 0;
            LearnerGenerator lg      = new LearnerGenerator(_cache);

            foreach (var functor in _ruleFunctors[ruleName])
            {
                foreach (var funcy in functor.LearnerMutators(_cache))
                {
                    GenerationOptions options = lg.CreateGenerationOptions(funcy.LearnerType);
                    funcy.DoMutateOptions(options);
                    if (options.OverrideUKPRN.HasValue)
                    {
                        var ftrip = triplets.Where(s => s.UKPRN == options.OverrideUKPRN.Value);
                        if (ftrip.Count() == 0)
                        {
                            triplet = new XmlTriplet()
                            {
                                UKPRN = options.OverrideUKPRN.Value
                            };
                            triplets.Add(triplet);
                        }
                    }
                    else
                    {
                        triplet = triplets.First();
                    }

                    lg.Options = options;
                    List <MessageLearner> generated = lg.Generate(ruleName, funcy.LearnerType, currentLearnerIndex, ref ULNIndex);
                    generated.ForEach(s =>
                    {
                        triplet.FileRuleLearners.Add(new FileRuleLearner()
                        {
                            ExclusionRecord = funcy.ExclusionRecord,
                            RuleName        = ruleName,
                            LearnRefNumber  = s.LearnRefNumber,
                            ValidLines      = funcy.ValidLines,
                            InvalidLines    = funcy.InvalidLines,
                            Valid           = valid
                        });
                        funcy.DoMutateLearner(s, valid);
                        if (lg.Options.CreateDestinationAndProgression)
                        {
                            MessageLearnerDestinationandProgression prog = lg.GenerateProgression(ruleName, s);
                            funcy.DoMutateProgression?.Invoke(prog, valid);
                            triplet.Progressions.Add(prog);
                        }
                    });
                    triplet.Learners.AddRange(generated);
                    currentLearnerIndex += generated.Count;
                    result += generated.Count;
                }
            }

            return(result);
        }