Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            _log.Info("Service start.");

            _cancelToken = new CancellationTokenSource();


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL).
            WithMNOServiceURL(Config.Connection.MNOUrl)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password);

            var restCtx = builder.build();


            _serviceTask = Task.Run(async() =>
            {
                do
                {
                    DateTime start = DateTime.Now;
                    _log.Info("Starting data transformation.");



                    try
                    {
                        Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                                Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                                restCtx, _outFactory, new RecordNames()
                        {
                            SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                            SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                            SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                            SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                            ProjectInfo      = Config.Service.ProjectInfoRecordName,
                            PolicyViolations = Config.Service.PolicyViolationsRecordName
                        },
                                                _cancelToken.Token);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Data transformation finished in {0:0.00} minutes.", DateTime.Now.Subtract(start).TotalMinutes);
                    await Task.Delay(Config.Service.ProcessPeriodMinutes * 60 * 1000, _cancelToken.Token);
                } while (!_cancelToken.Token.IsCancellationRequested);

                _cancelToken.Token.ThrowIfCancellationRequested();
            }, _cancelToken.Token);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            appLog.Info("Start");

            appLog.InfoFormat("CWD: {0}", Directory.GetCurrentDirectory());


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password).
            WithMNOServiceURL(Config.Connection.MNOUrl);

            using (CancellationTokenSource t = new CancellationTokenSource())
            {
                CxRestContext ctx = builder.build();
                Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                        Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                        ctx,
                                        MakeFactory(),
                                        new RecordNames()
                {
                    SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                    SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                    SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                    SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                    ProjectInfo      = Config.Service.ProjectInfoRecordName,
                    PolicyViolations = Config.Service.PolicyViolationsRecordName
                },
                                        t.Token);
            }


            appLog.Info("End");
        }