예제 #1
0
 public override ITargetResult Send(TestResults.TestResult testResult, Action <object> outputProcessor, params object[] inputArgs)
 {
     return(new TargetResult()
     {
         Sent = true, Message = "pretend"
     });
 }
        internal static int UpdateItemsToScore(TestResults.TestResult testResult, List <TestResults.ItemResponse> responses, bool scoreInvalidations, bool batchScoring, bool updateSameReportingVersion, bool handscored)
        {
            int responsesUpdated = 0;

            if (responses.Count == 0)
            {
                return(responsesUpdated);
            }

            using (SqlConnection conn = new SqlConnection(TDSQCConnectionString))
            {
                conn.Open();

                //actually, I don't think we need the transaction.  If it updates a subset of the items, the test will have to be
                //  resubmitted anyway at which point it'll get the rest.
                //using (SqlTransaction tran = conn.BeginTransaction())
                //{
                foreach (TestResults.ItemResponse r in responses)
                {
                    using (SqlCommand cmd = new SqlCommand("TIS_UpdateItemToScore", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@OppID", testResult.Opportunity.OpportunityID);
                        cmd.Parameters.AddWithValue("@status", testResult.Opportunity.Status);
                        cmd.Parameters.AddWithValue("@_efk_Item", r.ItemKey);
                        cmd.Parameters.AddWithValue("@_efk_ItemBank", r.BankKey);
                        cmd.Parameters.AddWithValue("@reportingversion", testResult.Opportunity.ReportingVersion);
                        cmd.Parameters.AddWithValue("@OppKey", testResult.Opportunity.Key);
                        cmd.Parameters.AddWithValue("@_efk_ClientName", testResult.Opportunity.ClientName);
                        cmd.Parameters.AddWithValue("@testID", testResult.TestID);
                        cmd.Parameters.AddWithValue("@ItemType", r.Format);
                        cmd.Parameters.AddWithValue("@position", r.Position);
                        cmd.Parameters.AddWithValue("@response", r.Response);
                        cmd.Parameters.AddWithValue("@scoreInvalidations", scoreInvalidations);
                        cmd.Parameters.AddWithValue("@batchScoring", batchScoring);
                        cmd.Parameters.AddWithValue("@updateSameReportingVersion", updateSameReportingVersion);
                        cmd.Parameters.AddWithValue("@handscored", handscored);

                        responsesUpdated += Convert.ToInt32(cmd.ExecuteScalar());
                    }
                }
                //    tran.Commit();
                //}
            }

            return(responsesUpdated);
        }
        public override ITargetResult Send(TestResults.TestResult testResult, Action <object> outputProcessor, params object[] inputArgs)
        {
            // first save items to the database using the item scoring daemon target
            ItemScoringDaemonTarget isd    = new ItemScoringDaemonTarget(this.Name);
            ITargetResult           result = isd.Send(testResult, null);

            // if there were no items to send, and it's not a reset or invalidation, then return the !sent result.
            //  If it was a reset or invalidation, we want to send this to TSS even if all items have already been scored.
            //  Resets in particular should cause the opp to be reset in TSS.  TSS can ignore invalidations if they want
            //  or apply special handling for those too.
            if (!result.Sent &&
                !testResult.Opportunity.Status.Equals("reset", StringComparison.InvariantCultureIgnoreCase) &&
                !testResult.Opportunity.Status.Equals("invalidated", StringComparison.InvariantCultureIgnoreCase))
            {
                return(result);
            }

            // check "pretend" setting now that we've written the items to the item scoring table
            if (ItemScoringManager.Instance.Pretend)
            {
                return new TargetResult()
                       {
                           Sent = true
                       }
            }
            ;

            // now send to TSS using the multipart REST target
            RESTMultipartTarget rmt = new RESTMultipartTarget(base.Name, base.Class, base.Type, base.XmlVersion, base.TransformSpec, base.TransformArgs);

            return(rmt.Send(testResult, delegate(object o)
            {
                TSSResponse response = Serialization.DeserializeJson <TSSResponse>((String)o);
                if (response.Files.Count == 0)
                {
                    throw new ApplicationException(String.Format("Error sending oppID: {0} to Target: {1}. Response contains no Files!", testResult.Opportunity.OpportunityID, base.Name));
                }
                if (!response.Files[0].Success)
                {
                    if (!(QASystemConfigSettings.Instance.IgnoreHandscoringDuplicates && (response.Files[0].ErrorMessage ?? "").Contains("duplicate opportunity")))
                    {
                        throw new ApplicationException(String.Format("Error sending oppId: {0} to Target: {1}.  Error message: {2}", testResult.Opportunity.OpportunityID, base.Name, response.Files[0].ErrorMessage));
                    }
                }
            }));
        }
    }