예제 #1
0
        public bool IsDirty()
        {
            if (isDirtyOverride)
            {
                return(true);
            }

            var schemaFiles = InputFiles
                              .Select(file => detailsStore.FileTree.GetFullPathForRelativeSchema(file))
                              .Select(path => fileSystem.GetFileInfo(path))
                              .ToList();

            var existingFiles = OutputFiles
                                .Select(entry => fileSystem.GetFileInfo(Path.Combine(OutputDirectory, entry)))
                                .ToList();

            if (schemaFiles.Count == 0 || existingFiles.Count == 0)
            {
                return(true);
            }

            //Ensure that all expected output files exist
            foreach (var file in existingFiles)
            {
                if (!file.Exists())
                {
                    return(true);
                }
            }

            var sortedSchemaFileInfo = schemaFiles.OrderByDescending(item => item.LastWriteTime).ToList();
            var sortedExistingFiles  = existingFiles.OrderByDescending(item => item.LastWriteTime).ToList();

            return(sortedSchemaFileInfo.First().LastWriteTime > sortedExistingFiles.First().LastWriteTime);
        }
예제 #2
0
        public ProcessController(AccessManager amgr)
        {
            var vfs = amgr.GetFullAccessFileSystem();

            _pdfHandler  = new PdfHandler(vfs);
            _outputFiles = new OutputFiles(vfs);
        }
예제 #3
0
        private void LoadDefaults()
        {
            Language = Configuration.CodeGeneration.GetLanguage();
            RootPath = Configuration.CodeGeneration.GetOutputPath();
            RootFile = Configuration.CodeGeneration.GetOutputFile();

            RootPath = RootPath.Replace("\\.\\", "\\");

            CodeGenerationFileType[] types =
            {
                CodeGenerationFileType.AttributeConstants,
                CodeGenerationFileType.Entities,
                CodeGenerationFileType.OptionSets,
                CodeGenerationFileType.Requests,
                CodeGenerationFileType.Responses,
                CodeGenerationFileType.ServiceContext
            };

            foreach (var type in types)
            {
                var    options = Configuration.CodeGeneration.GetOutputOptions(type);
                string file    = options.GetComputedFile(RootPath);
                string path    = Path.GetDirectoryName(file);

                OutputFiles.Add(type, file);
                OutputPaths.Add(type, path);
            }
        }
예제 #4
0
 public void AddOutputFile(string path, DateTime timestamp, bool shouldExist)
 {
     OutputFiles.Add(path);
     if (shouldExist)
     {
         myFileSystem.AddFile(path, timestamp);
     }
 }
        public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore) : base(baseOutputDir, fileSystem, detailsStore)
        {
            workerTypesToGenerate = ExtractWorkerTypes(CodeGeneratorOptions.Instance.WorkerJsonDirectory);

            OutputFiles.Add(Path.Combine(relativeEditorPath, workerFileName));
            OutputFiles.Add(Path.Combine(relativeEditorPath, workerListFileName));
            OutputFiles.Add(Path.Combine(relativeOutputPath, buildSystemFileName));
        }
        public DocumentsController(AccessManager amgr, DownloadFolder downloader, IOptions <Config> options, PrettyTextFile prettifier)
        {
            var vfs = amgr.GetReadOnlyFileSystem();

            this._outputFiles = new OutputFiles(vfs);
            this._imageRatio  = options.Value.ImageRatio;
            this._downloader  = downloader;
            this._prettifier  = prettifier;
        }
예제 #7
0
        private void Render(PascalTreeWriter treeWriter, string path)
        {
            var writer = new CsRender();

            treeWriter.InsertUsings();
            treeWriter.Tree.Resolve(writer);
            writer.Write(path);
            OutputFiles.Add(path);
        }
예제 #8
0
        public ArticlesController(AccessManager amgr, PrettyTextFile prettifier, IOptions <Config> options)
        {
            var vfs = amgr.GetReadOnlyFileSystem();

            _outputFiles = new OutputFiles(vfs);

            _imageRatio = options.Value.ImageRatio;

            this._prettifier = prettifier;
        }
예제 #9
0
        public void MoveOutputFiles()
        {
            //Ensure the the first file is the first in TempOutputFiles
            TempOutputFiles = TempOutputFiles.OrderBy(x => x).ToList();

            _outfilebody = DetermineOutfileBody();

            var isFirstFile = true;

            foreach (var tempOutputFile in TempOutputFiles)
            {
                var extension = PathSafe.GetExtension(tempOutputFile);
                var num       = DetermineNumWithDigits(tempOutputFile);

                _currentOutputFile = _outfilebody + num + extension;

                //first file in interactive workflow
                if (isFirstFile && !Profile.AutoSave.Enabled && OnRetypeOutputFilename != null)
                {
                    if (!CopyFileWithInteractiveOutputFilenameTemplateQuery(tempOutputFile, num, extension))
                    {
                        return; //cancelled by user
                    }
                }
                else
                {
                    lock (LockObject)
                    {
                        var uniqueFilename = new UniqueFilename(_currentOutputFile, DirectoryWrap, FileWrap);
                        if (Profile.AutoSave.Enabled && Profile.AutoSave.EnsureUniqueFilenames)
                        {
                            _currentOutputFile = EnsureUniqueFilename(uniqueFilename);
                        }

                        if (!CopyFile(tempOutputFile, _currentOutputFile))
                        {
                            _currentOutputFile = EnsureUniqueFilename(uniqueFilename);

                            if (!CopyFile(tempOutputFile, _currentOutputFile))
                            {
                                //Throw exception after second attempt to copy failes.
                                throw new DeviceException(
                                          "Error while copying to target file in second attempt. Process gets canceled.", 2);
                            }
                        }
                    }
                }

                DeleteFile(tempOutputFile);
                OutputFiles.Add(_currentOutputFile);
                isFirstFile = false;
            }

            OutputFiles = OutputFiles.OrderBy(x => x).ToList();
        }
        public static string GetFileName(OutputFiles value)
        {
            foreach (var item in AllConstants)
            {
                if (value == item.Key)
                {
                    return(item.Value.file);
                }
            }

            return(string.Empty);
        }
예제 #11
0
        private void MoveOutputFile(string file)
        {
            var fileMover = new SingleFileMover();

            if (Profile.AutoSave.Enabled && Profile.AutoSave.EnsureUniqueFilenames)
            {
                fileMover.UniqueFileNameEnabled = true;
            }

            var movedFile = fileMover.MoveSingleOutputFile(file, OutputFilenameTemplate);

            OutputFiles.Add(movedFile);
        }
        private static void loadOutputFiles(BinaryReader reader)
        {
            // Clear current list of output files
            OutputFiles.Clear();

            // Get number of output files
            int count = reader.ReadInt32();

            // For each output file
            for (int i = 0; i < count; i++)
            {
                // Get output file
                string file = reader.ReadString();

                // Add output file to list
                OutputFiles.Add(file);
            }
        }
예제 #13
0
파일: XpsJob.cs 프로젝트: u001tag/clawPDF
#pragma warning restore CS0067

        protected override JobState RunJobWork()
        {
            SetThreadName();

            OutputFiles.Clear();
            SetUpActions();

            var converter = new XpsConverter(JobInfo);
            var path      = Path.Combine(JobTempOutputFolder, JobTempFileName + Path.GetExtension(OutputFilenameTemplate));

            converter.Convert(path);

            //PDFProcessor.process

            MoveOutputFile(path);

            JobState = JobState.Succeeded;
            return(JobState);
        }
예제 #14
0
        public void ProcessCumulativeData(List <Metrics> metrics)
        {
            foreach (Metrics metric in metrics)
            {
                // 1) Create a new List<CalculatedValue>
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
                List <CalculatedValue> allValues = new List <CalculatedValue>();
                string namedMetric = "jh-cumulative-";

                switch (metric)
                {
                case Metrics.Deaths:

                    namedMetric += "deaths";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(sd.Deaths), sd.Date));
                    }
                    break;

                case Metrics.Cases:

                    namedMetric += "positives";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(sd.Positives), sd.Date));
                    }
                    break;

                case Metrics.Tests:
                    namedMetric += "tests";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        double tests = Convert.ToDouble(sd.Tests);
                        allValues.Add(new CalculatedValue(namedMetric, tests, sd.Date));
                    }
                    break;

                case Metrics.PercentPositive:
                    namedMetric += "percentPositive";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        double percentPositive = Convert.ToDouble(sd.Positives) / Convert.ToDouble(sd.Tests);
                        allValues.Add(new CalculatedValue(namedMetric, percentPositive, sd.Date));
                    }
                    break;

                default:
                    break;
                }

                // Add all the cumulative items
                OutputFiles.Add(namedMetric, allValues);

                // 3) do the per capita calculation
                if (metric != Metrics.PercentPositive)
                {
                    foreach (CalculatedValue cv in allValues)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreStateData.State.Population) * 100000), cv.Date));
                    }

                    namedMetric += "-per100K";
                    OutputFiles.Add(namedMetric, processedValues);
                }
            }
        }
예제 #15
0
        public void ProcessCumulativeData(List <Metrics> metrics, bool isPerCapita = true)
        {
            foreach (Metrics metric in metrics)
            {
                // 1) Create a new List<CalculatedValue>
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
                List <CalculatedValue> allValues = new List <CalculatedValue>();
                string namedMetric = "cumulative-";

                switch (metric)
                {
                case Metrics.DosesAdministered:
                    namedMetric += "dosesAdmin";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        if (isPerCapita)
                        {
                            allValues.Add(new CalculatedValue(namedMetric + "-per100K", Convert.ToDouble(vs.AdministeredPer100K), vs.Date));
                        }
                        else
                        {
                            allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.DosesAdministered), vs.Date));
                        }
                    }
                    break;

                case Metrics.DosesDistributed:
                    namedMetric += "dosesDist";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        if (isPerCapita)
                        {
                            allValues.Add(new CalculatedValue(namedMetric + "-per100K", Convert.ToDouble(vs.DistributedPer100K), vs.Date));
                        }
                        else
                        {
                            allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.DosesDistributed), vs.Date));
                        }
                    }
                    break;

                case Metrics.SeriesCompleteAdultPct:
                    namedMetric += "adultPctVaccinated";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, vs.PercentAdultVaccinated, vs.Date));
                    }
                    break;

                case Metrics.SeriesCompleteSeniorPct:
                    namedMetric += "seniorsPctVaccinated";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, vs.PercentSeniorsVaccinated, vs.Date));
                    }
                    break;

                default:
                    break;
                }
                if (isPerCapita)
                {
                    namedMetric += "-per100K";
                }

                OutputFiles.Add(namedMetric, allValues);
            }
        }
예제 #16
0
        public void ProcessDailyData(List <Metrics> metrics, bool isRollingAverage = false, int rollingAverage = 7, bool isPerCapita = true)
        {
            //List<StateDay> sortedDays = CoreStateData.CovidData.OrderByDescending(d => d.DateInt).ToList();

            // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
            foreach (Metrics metric in metrics)
            {
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                List <CalculatedValue> preProcess      = new List <CalculatedValue>();
                string namedMetric = "dailychange-";

                switch (metric)
                {
                case Metrics.DosesAdministered:
                    namedMetric += "dosesAdmin";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        if (isPerCapita)
                        {
                            preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.AdministeredPer100K), vs.Date));
                        }
                        else
                        {
                            preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.DosesAdministered), vs.Date));
                        }
                    }
                    break;

                case Metrics.DosesDistributed:
                    namedMetric += "dosesDist";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        if (isPerCapita)
                        {
                            preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.DistributedPer100K), vs.Date));
                        }
                        else
                        {
                            preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(vs.DosesDistributed), vs.Date));
                        }
                    }
                    break;

                case Metrics.SeriesCompleteAdultPct:
                    namedMetric += "adultPctVaccinated";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, vs.PercentAdultVaccinated, vs.Date));
                    }
                    break;

                case Metrics.SeriesCompleteSeniorPct:
                    namedMetric += "seniorsPctVaccinated";
                    foreach (VaccineDay vs in CoreVaccineStateData.VaccineData)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, vs.PercentSeniorsVaccinated, vs.Date));
                    }
                    break;

                default:
                    break;
                }
                List <CalculatedValue> averageValues = new List <CalculatedValue>();
                foreach (CalculatedValue cv in preProcess)
                {
                    var comparativeDate  = cv.Date - new TimeSpan(rollingAverage, 0, 0, 0);
                    var comparativeValue = preProcess.FirstOrDefault(val => val.Date.Date == comparativeDate);
                    if (comparativeValue == null)
                    {
                        averageValues.Add(new CalculatedValue(cv.MetricName, 0, cv.Date));
                    }
                    else
                    {
                        var avgValue = (cv.Value - comparativeValue.Value) / rollingAverage;
                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", avgValue, cv.Date));
                    }
                }

                if (isRollingAverage)
                {
                    namedMetric += "-" + rollingAverage.ToString() + "dayavg";
                    preProcess   = averageValues;
                }

                if (isPerCapita)
                {
                    foreach (CalculatedValue cv in preProcess)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreVaccineStateData.StateBase.Population) * 100000), cv.Date));
                    }
                    namedMetric += "-per100K";
                }
                else
                {
                    processedValues = preProcess;
                }

                OutputFiles.Add(namedMetric, processedValues);
            }
        }
 public TestCodegenJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore) : base(
         baseOutputDir, fileSystem, detailsStore)
 {
     OutputFiles.Add(relativeOutputPath);
     OutputFiles.Add(relativeTemplateOutputPath);
 }
예제 #18
0
        public void ProcessDailyData(List <Metrics> metrics, bool isRollingAverage = false, int rollingAverage = 7, bool isPerCapita = true)
        {
            //List<StateDay> sortedDays = CoreStateData.CovidData.OrderByDescending(d => d.DateInt).ToList();

            // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
            foreach (Metrics metric in metrics)
            {
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                List <CalculatedValue> preProcess      = new List <CalculatedValue>();
                string namedMetric = "world-dailychange-";

                switch (metric)
                {
                case Metrics.Deaths:
                    namedMetric += "deaths";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(od.TotalDeaths), od.Date));
                    }
                    break;

                case Metrics.Cases:
                    namedMetric += "positives";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, Convert.ToDouble(od.TotalCases), od.Date));
                        if (CoreCountryData.CountryName == "Germany")
                        {
                            Debug.WriteLine("Germany - " + od.DateString + " - positives - " + od.TotalCases + ", " + od.NewCases);
                        }
                    }
                    break;

                case Metrics.Tests:
                    namedMetric += "tests";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        double tests = Convert.ToDouble(od.TotalCases) + Convert.ToDouble(od.TotalTests);
                        preProcess.Add(new CalculatedValue(namedMetric, tests, od.Date));
                    }
                    break;

                case Metrics.PercentPositive:
                    namedMetric += "percentPositive";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        double percentPositive = Convert.ToDouble(od.TotalCases) / Convert.ToDouble(od.TotalTests);
                        preProcess.Add(new CalculatedValue(namedMetric, percentPositive, od.Date));
                    }
                    break;

                case Metrics.CaseJerk:
                    namedMetric += "caseJerk";

                    break;

                default:
                    break;
                }

                // 3) doing a rolling average? roll that average
                List <CalculatedValue> averageValues = new List <CalculatedValue>();
                foreach (CalculatedValue cv in preProcess)
                {
                    var comparativeDate  = cv.Date - new TimeSpan(rollingAverage, 0, 0, 0);
                    var comparativeValue = preProcess.FirstOrDefault(val => val.Date.Date == comparativeDate);
                    if (comparativeValue == null)
                    {
                        averageValues.Add(new CalculatedValue(cv.MetricName, 0, cv.Date));
                    }
                    else if (cv.MetricName.Contains("percentPositive"))
                    {
                        var percentPos = GetPercentPositiveRollingAvg(cv.Date, rollingAverage);
                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", percentPos, cv.Date));
                    }
                    else if (cv.MetricName.Contains("currentHospital"))
                    {
                        var    hospitalVals    = preProcess.FindAll(val => val.Date.Date < cv.Date.Date && val.Date.Date >= comparativeValue.Date.Date);
                        double allHospitalVals = 0;
                        foreach (CalculatedValue otherCv in hospitalVals)
                        {
                            allHospitalVals += otherCv.Value;
                        }

                        allHospitalVals = allHospitalVals / rollingAverage;

                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", allHospitalVals, cv.Date));
                    }
                    else
                    {
                        var avgValue = (cv.Value - comparativeValue.Value) / rollingAverage;
                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", avgValue, cv.Date));
                    }
                }

                if (isRollingAverage)
                {
                    namedMetric += "-" + rollingAverage.ToString() + "dayavg";
                    preProcess   = averageValues;
                }

                // 4) do a perCapita calculation
                if (isPerCapita && metric != Metrics.PercentPositive)
                {
                    foreach (CalculatedValue cv in preProcess)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreCountryData.Population) * 100000), cv.Date));
                    }

                    namedMetric += "-per100K";
                }
                else
                {
                    processedValues = preProcess;
                }

                OutputFiles.Add(namedMetric, processedValues);
            }
        }
예제 #19
0
        public void ProcessCumulativeData(List <Metrics> metrics, bool isPerCapita = true)
        {
            foreach (Metrics metric in metrics)
            {
                // 1) Create a new List<CalculatedValue>
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
                List <CalculatedValue> allValues = new List <CalculatedValue>();
                string namedMetric = "world-cumulative-";

                switch (metric)
                {
                case Metrics.Deaths:

                    namedMetric += "deaths";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(od.TotalDeaths), od.Date));
                    }
                    break;

                case Metrics.Cases:

                    namedMetric += "positives";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(od.TotalCases), od.Date));
                    }
                    break;

                case Metrics.Tests:
                    namedMetric += "tests";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        double tests = Convert.ToDouble(od.TotalTests);
                        allValues.Add(new CalculatedValue(namedMetric, tests, od.Date));
                    }
                    break;

                case Metrics.PercentPositive:
                    namedMetric += "percentPositive";
                    foreach (OwidDay od in CoreCountryData.Data)
                    {
                        double percentPositive = Convert.ToDouble(od.TotalCases) / Convert.ToDouble(od.TotalTests);
                        allValues.Add(new CalculatedValue(namedMetric, percentPositive, od.Date));
                    }
                    break;

                default:
                    break;
                }

                // 3) do the per capita calculation

                if (isPerCapita && metric != Metrics.PercentPositive)
                {
                    foreach (CalculatedValue cv in allValues)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreCountryData.Population) * 100000), cv.Date));
                    }

                    namedMetric += "-per100K";
                }
                else
                {
                    processedValues = allValues;
                }

                OutputFiles.Add(namedMetric, processedValues);
            }
        }
예제 #20
0
        public DocumentsController(AccessManager amgr)
        {
            var vfs = amgr.GetReadOnlyFileSystem();

            _outputFiles = new OutputFiles(vfs);
        }
        public DocumentOutputTreeTagHelper(AccessManager amgr)
        {
            var web = amgr.GetReadOnlyFileSystem();

            _outputFiles = new OutputFiles(web);
        }
예제 #22
0
        /// <summary>
        ///     Run the Job
        /// </summary>
        protected override JobState RunJobWork()
        {
            try
            {
                if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
                {
                    Thread.CurrentThread.Name = "JobWorker";
                }
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                _ghostScript.Output += Ghostscript_Output;
                OnJobCompleted      += (sender, args) => _ghostScript.Output -= Ghostscript_Output;

                OutputFiles.Clear();

                Logger.Trace("Setting up actions");
                SetUpActions();

                Logger.Debug("Starting Ghostscript Job");

                OutputDevice device;
                switch (Profile.OutputFormat)
                {
                case OutputFormat.PdfA1B:
                case OutputFormat.PdfA2B:
                case OutputFormat.PdfX:
                case OutputFormat.Pdf:
                    device = new PdfDevice(this);
                    break;

                case OutputFormat.Png:
                    device = new PngDevice(this);
                    break;

                case OutputFormat.Jpeg:
                    device = new JpegDevice(this);
                    break;

                case OutputFormat.Tif:
                    device = new TiffDevice(this);
                    break;

                case OutputFormat.Txt:
                    device = new TextDevice(this);
                    break;

                default:
                    throw new Exception("Illegal OutputFormat specified");
                }

                Logger.Trace("Output format is: {0}", Profile.OutputFormat.ToString());

                _ghostScript.Output += Ghostscript_Logging;
                var success = _ghostScript.Run(device, JobTempFolder);
                _ghostScript.Output -= Ghostscript_Logging;

                Logger.Trace("Finished Ghostscript execution");

                if (!success)
                {
                    var errorMessage = ExtractGhostscriptErrors(GhostscriptOutput);
                    Logger.Error("Ghostscript execution failed: " + errorMessage);
                    ErrorMessage = errorMessage;

                    JobState = JobState.Failed;
                    return(JobState);
                }

                ProcessOutput();

                Logger.Trace("Moving output files to final location");
                MoveOutputFiles();

                Logger.Trace("Finished Ghostscript Job");
                JobState = JobState.Succeeded;
                return(JobState);
            }
            catch (ProcessingException)
            {
                JobState = JobState.Failed;
                throw;
            }
            catch (DeviceException)
            {
                JobState = JobState.Failed;
                throw;
            }
            catch (Exception ex)
            {
                JobState = JobState.Failed;
                Logger.Error("There was an error while converting the Job {0}: {1}", JobInfo.InfFile, ex);
                throw;
            }
        }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Experiments.BaseExperiment`2"/> class.
 /// </summary>
 /// <param name="outputRoot">Output root.</param>
 /// <param name="plotRoot">Plot root.</param>
 /// <param name="scriptRoot">Script root.</param>
 public BaseAnalysis(string outputRoot, string plotRoot, string scriptRoot)
 {
     this.OutputFiles = new OutputFiles(outputRoot, plotRoot, scriptRoot);
 }
 public OutputFilesEnum(OutputFiles value, string file)
 {
     this.value = value;
     this.file  = file;
 }
예제 #25
0
        private void OnExecute()
        {
            ParametersModel parameters = new ParametersModel();

            // parse and validate arguments
            parameters.Mode            = (ShapeType)Mode;
            parameters.Alpha           = (byte)(Alpha ?? 0x80);
            parameters.Repeat          = Repeat ?? 0;
            parameters.Nprimitives     = Nprimitives ?? 10;
            parameters.NthFrame        = NthFrame ?? 1;
            parameters.CanvasResize    = InputResize ?? 256;
            parameters.RenderSize      = OutputSize ?? 1024;
            parameters.WorkersCount    = Workers ?? 0;
            parameters.ShapeProbeCount = ShapeProbeCount ?? 1000;
            parameters.ShapeAge        = ShapeAge ?? 100;

            // determine worker count
            if (parameters.WorkersCount < 1)
            {
                parameters.WorkersCount = Environment.ProcessorCount;
            }

            // read input image
            Logger.WriteLine(1, "reading {0}", InputFile);
            Image <Rgba32> inputImage = File.LoadImage(InputFile);

            // determine background color
            if (String.IsNullOrEmpty(Background))
            {
                parameters.Background = Core.Core.AverageImageColor(inputImage);
            }
            else
            {
                parameters.Background = Rgba32.FromHex(Background);
            }

            // run algorithm
            RendererModel model = new RendererModel(inputImage, parameters);

            model.RunRenderer();

            // write output image(s)
            foreach (var outFile in OutputFiles.Split(' '))
            {
                var  ext        = System.IO.Path.GetExtension(outFile).ToLower();
                bool percent    = outFile.Contains("{0");
                bool saveFrames = percent && !ext.Equals(".gif");

                Logger.WriteLine(1, "writing {0}", outFile);
                switch (ext)
                {
                case ".png":
                case ".jpg":
                case ".jpeg":
                    File.SaveFrames(outFile, model.GetFrames(saveFrames, parameters.NthFrame));
                    break;

                case ".svg":
                    File.SaveSVG(outFile, model.GetSVG(saveFrames, parameters.NthFrame));
                    break;

                case ".gif":
                    File.SaveGIF(outFile, model.GetFrames(0.001), 0, 0);
                    break;

                default:
                    throw new Exception("unrecognized file extension: " + ext);
                }
            }

            System.Console.WriteLine("End");
        }
예제 #26
0
        public void ProcessDailyData(List <Metrics> metrics, bool isRollingAverage = true, int rollingAverage = 7)
        {
            //List<StateDay> sortedDays = CoreStateData.CovidData.OrderByDescending(d => d.DateInt).ToList();

            // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
            foreach (Metrics metric in metrics)
            {
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                List <CalculatedValue> preProcess      = new List <CalculatedValue>();
                string namedMetric = "jh-daily-";

                switch (metric)
                {
                case Metrics.Deaths:
                    namedMetric += "deaths";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, sd.Deaths, sd.Date));
                    }
                    break;

                case Metrics.Cases:
                    namedMetric += "positives";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        preProcess.Add(new CalculatedValue(namedMetric, sd.Positives, sd.Date));
                    }
                    break;

                case Metrics.Tests:
                    namedMetric += "tests";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        double tests = sd.Tests;
                        preProcess.Add(new CalculatedValue(namedMetric, sd.Tests, sd.Date));
                    }
                    break;

                case Metrics.PercentPositive:
                    namedMetric += "percentPositive";
                    foreach (JhCovidDay sd in CoreStateData.CovidData)
                    {
                        double percentPositive = sd.Positives / sd.Tests;
                        preProcess.Add(new CalculatedValue(namedMetric, percentPositive, sd.Date));
                    }
                    break;

                default:
                    break;
                }

                // 3) doing a rolling average? roll that average
                List <CalculatedValue> averageValues = new List <CalculatedValue>();
                foreach (CalculatedValue cv in preProcess)
                {
                    var comparativeDate  = cv.Date - new TimeSpan(rollingAverage, 0, 0, 0);
                    var comparativeValue = preProcess.FirstOrDefault(val => val.Date.Date == comparativeDate);
                    if (comparativeValue == null)
                    {
                        averageValues.Add(new CalculatedValue(cv.MetricName, 0, cv.Date));
                    }
                    else if (cv.MetricName.Contains("percentPositive"))
                    {
                        var percentPos = GetPercentPositiveRollingAvg(cv.Date, rollingAverage);
                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", percentPos, cv.Date));
                    }
                    else
                    {
                        var avgValue = (cv.Value - comparativeValue.Value) / rollingAverage;
                        averageValues.Add(new CalculatedValue(cv.MetricName + "-" + rollingAverage.ToString() + "dayavg", avgValue, cv.Date));
                    }
                }

                if (isRollingAverage)
                {
                    namedMetric += "-" + rollingAverage.ToString() + "dayavg";
                    preProcess   = averageValues;
                }

                OutputFiles.Add(namedMetric, preProcess);

                // 4) do a perCapita calculation
                if (metric != Metrics.PercentPositive)
                {
                    foreach (CalculatedValue cv in preProcess)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreStateData.State.Population) * 100000), cv.Date));
                    }

                    namedMetric += "-per100K";

                    OutputFiles.Add(namedMetric, processedValues);
                }
            }
        }
예제 #27
0
 public override string ToString()
 {
     return($"Config@{GetHashCode()} [First data file : {DataFiles.FirstOrDefault()} ; First output file : {OutputFiles.FirstOrDefault()} ; First content file : {ContentFiles.FirstOrDefault()}]");
 }
예제 #28
0
        public void ProcessCumulativeData(List <Metrics> metrics, bool isPerCapita = true)
        {
            foreach (Metrics metric in metrics)
            {
                // 1) Create a new List<CalculatedValue>
                List <CalculatedValue> processedValues = new List <CalculatedValue>();
                // 2) Look at the metric, pick out the appropriate data for that metric (and give it a name)
                List <CalculatedValue> allValues = new List <CalculatedValue>();
                string namedMetric = "cumulative-";

                switch (metric)
                {
                case Metrics.Deaths:

                    namedMetric += "deaths";
                    foreach (StateDay sd in CoreStateData.CovidData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(sd.Death), sd.Date));
                    }
                    break;

                case Metrics.Cases:

                    namedMetric += "positives";
                    foreach (StateDay sd in CoreStateData.CovidData)
                    {
                        allValues.Add(new CalculatedValue(namedMetric, Convert.ToDouble(sd.Positive), sd.Date));
                    }
                    break;

                case Metrics.Tests:
                    namedMetric += "tests";
                    foreach (StateDay sd in CoreStateData.CovidData)
                    {
                        double tests = Convert.ToDouble(sd.Positive) + Convert.ToDouble(sd.Negative);
                        allValues.Add(new CalculatedValue(namedMetric, tests, sd.Date));
                    }
                    break;

                case Metrics.PercentPositive:
                    namedMetric += "percentPositive";
                    foreach (StateDay sd in CoreStateData.CovidData)
                    {
                        double percentPositive = Convert.ToDouble(sd.Positive) / Convert.ToDouble(sd.Negative + sd.Positive);
                        allValues.Add(new CalculatedValue(namedMetric, percentPositive, sd.Date));
                    }
                    break;

                case Metrics.HospitalCurrent:
                    namedMetric += "currentHosp";
                    foreach (StateDay sd in CoreStateData.CovidData)
                    {
                        double currentHosp = sd.HospitalizedCurrently != null?Convert.ToDouble(sd.HospitalizedCurrently) : 0;

                        allValues.Add(new CalculatedValue(namedMetric, currentHosp, sd.Date));
                    }
                    break;

                case Metrics.CaseJerk:
                    namedMetric += "caseJerk";

                    break;

                default:
                    break;
                }

                // 3) do the per capita calculation

                if (isPerCapita && metric != Metrics.PercentPositive)
                {
                    foreach (CalculatedValue cv in allValues)
                    {
                        processedValues.Add(new CalculatedValue(namedMetric, ((cv.Value / CoreStateData.StateBase.Population) * 100000), cv.Date));
                    }

                    namedMetric += "-per100K";
                }
                else
                {
                    processedValues = allValues;
                }

                OutputFiles.Add(namedMetric, processedValues);
            }
        }
예제 #29
0
 /// <summary>
 ///     Add a MetalsharpFile to the input files
 /// </summary>
 ///
 /// <example>
 ///     ```c#
 ///         new MetalsharpProject()
 ///         .AddInput(new MetalsharpFile("# File Text", "path\\to\\file.md");
 ///     ```
 /// </example>
 ///
 /// <param name="file">
 ///     The file to add.
 /// </param>
 ///
 /// <returns>
 ///     The current `MetalsharpProject`, allowing it to be fluent.
 /// </returns>
 public MetalsharpProject AddOutput(MetalsharpFile file)
 {
     OutputFiles.Add(file);
     return(this);
 }
예제 #30
0
        public void ModifyProjectFile(string path)
        {
            if (!File.Exists(path))
            {
                Errors.Warn("Project file " + path + " not found!");
                return;
            }

            XmlDocument proj = new XmlDocument();

            proj.Load(path);
            var  projectDir = Path.GetDirectoryName(path);
            bool modified   = false;

            var csns = "http://schemas.microsoft.com/developer/msbuild/2003";
            XmlNamespaceManager nsm = new XmlNamespaceManager(proj.NameTable);

            nsm.AddNamespace("x", csns);

            var projectRoot    = proj.SelectSingleNode("x:Project", nsm);
            var generatedGroup = proj.SelectSingleNode("x:Project/x:ItemGroup[@Label='Gluon Generated']", nsm) as XmlElement;

            if (generatedGroup == null)
            {
                generatedGroup = (XmlElement)projectRoot.AppendChild(proj.CreateElement("ItemGroup", csns));
                generatedGroup.SetAttribute("Label", "Gluon Generated");
                modified = true;
            }

            Action <string> ensureSource = source =>
            {
                var relsource = U.GetRelativePath(source, projectDir);
                var el        = (XmlElement)proj.SelectSingleNode("x:Project/x:ItemGroup/x:Compile[translate(@Include, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + relsource.ToLower() + "']", nsm);

                if (el == null)
                {
                    el = proj.CreateElement("Compile", csns);
                    el.SetAttribute("Include", relsource);
                    generatedGroup.AppendChild(el);

                    if (relsource.StartsWith(".."))
                    {
                        var linkel = proj.CreateElement("Link", csns);

                        var linkPath = U.GetRelativePath(source, Settings.OutputFolder);
                        linkel.InnerText = linkPath;
                        el.AppendChild(linkel);
                    }
                    modified = true;
                }
            };

            foreach (var file in OutputFiles)
            {
                if (file.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase))
                {
                    ensureSource(file);
                }
            }

            OutputFiles.Add(path);
            if (modified)
            {
                proj.Save(path);
            }
        }