Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var logger = new CmdletLoggerPS(this, false);

            try
            {
                var generatedFiles = new List <string>();

                var solutionRepository  = new SolutionRepository(new CrmServiceClient(ConnectionString), logger);
                var solutionAuditor     = new CrmAuditor(solutionRepository, logger);
                var publishersToInclude = RequiredPublishers.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();


                var crmInstance = solutionAuditor.AuditCrmInstance(InstanceName, publishersToInclude);

                logger.Verbose("About to generate HTML report");
                var htmlWriter = new HtmlReport(OutputDir);
                var htmlFiles  = htmlWriter.SaveSolutionAudit(crmInstance);
                generatedFiles.Add(htmlFiles.First(x => x.Contains("Home_")));
                logger.Verbose("HTML report completed");

                if (GenerateExcelReport)
                {
                    logger.Verbose("About to generate Excel report");
                    var excelWriter = new ExcelReport(OutputDir);
                    generatedFiles.AddRange(excelWriter.SaveSolutionAudit(crmInstance));
                    logger.Verbose("Excel report completed");
                }

                if (GenerateJsonReport)
                {
                    logger.Verbose("About to generate JSON report");
                    var jsonWriter = new JsonReport(OutputDir);
                    generatedFiles.AddRange(jsonWriter.SaveSolutionAudit(crmInstance));
                    logger.Verbose("JSON report completed");
                }

                if (GenerateXmlReport)
                {
                    logger.Verbose("About to generate XML report");
                    var xmlWriter = new XmlReport(OutputDir);
                    generatedFiles.AddRange(xmlWriter.SaveSolutionAudit(crmInstance));
                    logger.Verbose("XML report completed");
                }

                if (!string.IsNullOrWhiteSpace(SendGridKey) && !string.IsNullOrWhiteSpace(ReportsToRecipients))
                {
                    SendReportsToRecipients(SendGridKey, ReportsToRecipients, crmInstance.Name.Replace(".dynamics.com", ""), generatedFiles, ReportName);
                }
            }
            catch (Exception exception)
            {
                var errorMessage = $"Dynamics365 solution audit failed: {exception.Message}";
                logger.Verbose(errorMessage);
                logger.Error(errorMessage);
                throw;
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var logger = new CmdletLoggerPS(this, TreatWarningsAsErrors);

            try
            {
                logger.Info("About to start exporting data from Dynamics365");
                var manager = new Dynamics365DataManager();

                var cancellationTokenSource = new CancellationTokenSource();

                var exportConfig = new CrmExporterConfig();
                if (!string.IsNullOrWhiteSpace(ConfigFilePath))
                {
                    if (!File.Exists(ConfigFilePath))
                    {
                        WriteWarning($"Export config file path does not exist, will be ignored {ConfigFilePath}");
                    }
                    else
                    {
                        exportConfig = CrmExporterConfig.GetConfiguration(ConfigFilePath);
                    }
                }

                PopulateConfiguration(exportConfig);

                if (!Directory.Exists(JsonFolderPath))
                {
                    WriteWarning($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                    throw new DirectoryNotFoundException($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                }
                else
                {
                    foreach (var file in Directory.GetFiles(JsonFolderPath, $"{exportConfig.FilePrefix}_*.csv"))
                    {
                        WriteVerbose($"Delete Csv file {file}");
                        File.Delete(file);
                    }

                    foreach (var file in Directory.GetFiles(JsonFolderPath, $"{exportConfig.FilePrefix}_*.json"))
                    {
                        WriteVerbose($"Delete Json file {file}");
                        File.Delete(file);
                    }
                }

                manager.StartSingleThreadedExport(exportConfig, logger, cancellationTokenSource, ConnectionString);
                logger.Info("Export has finished");
            }
            catch (Exception exception)
            {
                var errorMessage = $"Dynamics365 data export failed: {exception.Message}";
                logger.Verbose(errorMessage);
                logger.Error(errorMessage);
                throw;
            }
        }