public void RunWithArguments(Document doc, NameValueMap map)
        {
            // write diagnostics data
            LogInputData(doc, map);

            var pathName = doc.FullFileName;

            LogTrace("Processing " + pathName);

            string[] outputFileName = { "", "ResultSmall", "ResultLarge" };

            try
            {
                var documentType = doc.DocumentType;
                var iRuns        = 1;
                if (documentType == DocumentTypeEnum.kPartDocumentObject)
                {
                    iRuns = 2;
                }
                for (int iRun = 1; iRun <= iRuns; iRun++)
                {
                    // load processing parameters
                    string paramsJson = GetParametersToChange(map, iRun);

                    // update parameters in the doc
                    // start HeartBeat around ChangeParameters, it could be a long operation
                    using (new HeartBeat())
                    {
                        ChangeParameters(doc, paramsJson);
                    }

                    var docDir = Path.GetDirectoryName(doc.FullFileName);

                    if (documentType == DocumentTypeEnum.kPartDocumentObject)
                    {
                        PartDocument part           = (PartDocument)doc;
                        double       mass           = part.ComponentDefinition.MassProperties.Mass;
                        string       imageParamName = "ImageLight";

                        // check the mass of the document and download proper image
                        if (mass > 300.0)
                        {
                            imageParamName = "ImageHeavy";
                        }

                        // get Image from the OnDemand parameter
                        OnDemand.HttpOperation(imageParamName, "", null, "", $"file://{outputFileName[iRun]}.png");
                    }

                    // generate outputs
                    if (documentType == DocumentTypeEnum.kPartDocumentObject)
                    {
                        var fileName = Path.Combine(docDir, $"{outputFileName[iRun]}.ipt"); // the name must be in sync with OutputIpt localName in Activity
                        LogTrace("Saving " + fileName);
                        // start HeartBeat around Save, it could be a long operation
                        using (new HeartBeat())
                        {
                            doc.SaveAs(fileName, false);
                        }
                        LogTrace("Saved as " + fileName);

                        // save an image
                        SaveImageFromPart(Path.Combine(docDir, $"{outputFileName[iRun]}.bmp"), doc as PartDocument);
                    }
                    else // Assembly. That's already validated in ChangeParameters
                    {
                        //Generate drawing document with assembly
                        var idwPath = Path.ChangeExtension(Path.Combine(docDir, doc.DisplayName), "idw");
                        LogTrace($"Generate drawing document");
                        SaveAsIDW(idwPath, doc);

                        // cannot ZIP opened assembly, so close it
                        // start HeartBeat around Save, it could be a long operation
                        using (new HeartBeat())
                        {
                            doc.Save2(true);
                        }
                        doc.Close(true);

                        LogTrace("Zipping up updated Assembly.");

                        // assembly lives in own folder under WorkingDir. Get the WorkingDir
                        var workingDir = Path.GetDirectoryName(docDir);
                        var fileName   = Path.Combine(workingDir, "Result.zip"); // the name must be in sync with OutputIam localName in Activity

                        if (File.Exists(fileName))
                        {
                            File.Delete(fileName);
                        }

                        // start HeartBeat around ZipFile, it could be a long operation
                        using (new HeartBeat())
                        {
                            ZipFile.CreateFromDirectory(Path.GetDirectoryName(pathName), fileName, CompressionLevel.Fastest, false);
                        }

                        LogTrace($"Saved as {fileName}");
                    }
                }
            }
            catch (Exception e)
            {
                LogError("Processing failed. " + e.ToString());
            }
        }