Beispiel #1
0
        private void CalcPackage(FilePackageContent filePackage)
        {
            // The package must ALWAYS exist at this point!
            EM_TemplateCalculator calculator     = calculators[filePackage.Key];
            ResultsPackage        resultsPackage = resultsPackages.Find(x => x.packageKey == filePackage.Key);

            try
            {
                bool success = calculator.CalculateStatistics(resultsPackage.microData);
                lock (resultsPackages)
                {
                    resultsPackage.displayResults = calculator.GetDisplayResults();
                    resultsPackage.error          = calculator.GetErrorMessage(); // this may also just be warnings
                    if (!success)
                    {
                        resultsPackage.displayResults.calculated = true;            // if did not succeed, declare this done
                    }
                    // cleanup
                    calculators.Remove(filePackage.Key);
                    resultsPackage.microData = null;
                    filePackage = null;
                }
            }
            catch (Exception exception)
            {
                lock (resultsPackages)
                {
                    resultsPackage.error = exception.Message;
                }
            }
        }
Beispiel #2
0
        private void PrepareAndStartCalculatingResults()
        {
            foreach (FilePackageContent filePackage in filePackages)    // tested multi-threading this, but there was no noticeable gain!
            {
                List <string> filenames = new List <string>();
                // Prepare the filenames and microdata
                List <StringBuilder> microData = new List <StringBuilder>();

                if (template.info.templateType != HardDefinitions.TemplateType.Multi)
                {
                    if (filePackage.MicroDataBase != null)
                    {
                        filenames.Add(string.Empty); microData.Add(filePackage.MicroDataBase);
                    }
                    else
                    {
                        filenames.Add(filePackage.PathBase); microData.Add(null);
                    }
                }
                for (int f = 0; f < Math.Max(filePackage.PathsAlt.Count, filePackage.MicroDataAlt.Count); ++f)
                {
                    filenames.Add(f < filePackage.PathsAlt.Count ? filePackage.PathsAlt[f] : string.Empty);
                    microData.Add(f < filePackage.MicroDataAlt.Count ? filePackage.MicroDataAlt[f] : null);
                }
                if (filePackage.MicroDataBase == null && filePackage.MicroDataAlt.Count == 0)
                {
                    microData = null;
                }

                // Prepare the resultsPackage
                ResultsPackage        resultsPackage = new ResultsPackage();
                EM_TemplateCalculator calculator     = new EM_TemplateCalculator(template, filePackage.Key);
                bool prepared = calculator.Prepare(filenames, out ErrorCollector errorCollector);
                calculators.Add(filePackage.Key, calculator);
                resultsPackage.displayResults = calculator.GetDisplayResults();
                if (!prepared)
                {
                    resultsPackage.displayResults.calculated = true;            // if preperation went wrong, there will not be any results comming later!
                }
                resultsPackage.packageKey = filePackage.Key;
                resultsPackage.error      = errorCollector.GetErrorMessage();
                resultsPackage.microData  = microData;
                resultsPackages.Add(resultsPackage);
            }

            new System.Threading.Thread(() =>
            {
                Parallel.ForEach <FilePackageContent>(filePackages, filePackage =>
                {
                    CalcPackage(filePackage);
                });
            }).Start();
        }