Example #1
0
        // long running method called by seperate thread
        public void Execute()
        {
            var gateHelper = new GateHelper(
                this.TaskInstanceId,
                this.HubName,
                this.JobId,
                this.PlanId,
                this.TimelineId,
                this.ProjectId,
                this.VstsUrl,
                this.AuthToken);


            // query dynatrace with monspec. this is a long running command
            // sending live log message
            gateHelper.SendLiveLogMessage("querying Dynatrace with monspec...");
            var response = this.MonspecPullRequestReturnString();
            var pullCompareResponseObj = JsonConvert.DeserializeObject <PullCompareResponse>(response);

            gateHelper.SendLiveLogMessage("finished querying Dynatrace");

            // finished with long running work, will now send offline logs and then send task complete event back to vsts
            gateHelper.SendOfflineLog(response);

            // check response and either pass or fail gate
            if (pullCompareResponseObj.totalViolations == 0)
            {
                this.Log.Info("There are zero violations, sending succeeded to gate");
                gateHelper.FinishGate(GateHelper.Result.Succeeded, response);
            }
            else
            {
                this.Log.Error("There is a violation (" + pullCompareResponseObj.totalViolations + "), sending fail to gate: " + response);
                //gateHelper.FinishGate(GateHelper.Result.Succeeded, response);
                gateHelper.FinishGate(GateHelper.Result.Failed, response);
            }
        }
Example #2
0
        // TODO - remove if not going to use this approach
        // This method is used for ASyncronous processing
        public void Execute()
        {
            Boolean success    = false;
            var     logMessage = "ExecuteObject.Execute(): Start";

            this.Log.Info(logMessage);

            String response;
            var    gateHelper = new GateHelper(
                this.TaskInstanceId,
                this.HubName,
                this.JobId,
                this.PlanId,
                this.TimelineId,
                this.ProjectId,
                this.VstsUrl,
                this.AuthToken,
                this.Log);

            this.Log.Info("ExecuteObject.Execute(): finished creating new GateHelper");

            try
            {
                // Setup connections and obtain DevOps details
                gateHelper.GetVstsConnection();
                gateHelper.GetTaskClient();
                gateHelper.GetTaskClientPlan();
                gateHelper.GetTaskTimelineRecord();
                logMessage = "ExecuteObject.Execute(): finished getting connections and obtain DevOps task details";
                gateHelper.SendLiveLogMessage(logMessage);
                this.Log.Info(logMessage);

                // query dynatrace with monspec. this is a long running command
                logMessage = "ExecuteObject.Execute(): querying Dynatrace with monspec";
                gateHelper.SendLiveLogMessage(logMessage);
                this.Log.Info(logMessage);
                response   = this.MonspecPullRequestReturnString();
                logMessage = "ExecuteObject.Execute(): finished Dynatrace monspec query";
                gateHelper.SendLiveLogMessage(logMessage);
                this.Log.Info(logMessage);

                var pullCompareResponseObj = JsonConvert.DeserializeObject <PullCompareResponse>(response);
                logMessage = "ExecuteObject.Execute(): finished deserializing monspec response";
                gateHelper.SendLiveLogMessage(logMessage);
                this.Log.Info(logMessage);

                // finished with long running work, will now send offline logs and then send task complete event back to vsts
                gateHelper.SendOfflineLog(response);
                this.Log.Info(response);

                // check response and either pass or fail gate
                if (pullCompareResponseObj.totalViolations == 0)
                {
                    this.Log.Info("ExecuteObject.Execute(): There are zero violations, sending succeeded to gate");
                    gateHelper.FinishGate(GateHelper.Result.Succeeded, response);
                    success = true;
                }
                else
                {
                    this.Log.Error("ExecuteObject.Execute(): There is a violation (" + pullCompareResponseObj.totalViolations + "), sending fail to gate: " + response);
                    gateHelper.FinishGate(GateHelper.Result.Failed, response);
                    return;
                }
            }
            catch (Exception e)
            {
                logMessage = "ExecuteObject.Execute() exception: " + e.Message;
                this.Log.Error(logMessage);
                throw;
            }

            if (!success)
            {
                try
                {
                    this.Log.Error("ExecuteObject.Execute(): calling FinishGate for processing exception FAILURE");
                    gateHelper.FinishGate(GateHelper.Result.Failed, logMessage);
                }
                catch (Exception e2)
                {
                    logMessage = "ExecuteObject.Execute(): There was an exception calling gateHelper.FinishGate" + e2.Message + ": " + e2.StackTrace;
                    this.Log.Error(logMessage);
                    throw;
                }
            }
        }