/// <summary> /// Adds a ASP.NET cookie with encrypted forms auth ticket along with user data. /// </summary> public static void New(string name, WebValueCollection values) { // create encrypted cookie string userData = (values == null) ? string.Empty : values.ToString(false); HttpCookie authCookie = CreateCookie(name, userData); // Manually add the authCookie to the Cookies collection HttpContext.Current.Response.Cookies.Add(authCookie); }
protected virtual string GetContextToken(ReponseRepoMonitor repoMon, ScorableResponse scorableResponse) { WebValueCollection tokenData = new WebValueCollection(); tokenData.Set("oppKey", scorableResponse.OppKey); tokenData.Set("itemKey", scorableResponse.ItemKey); tokenData.Set("position", scorableResponse.Position); tokenData.Set("sequence", scorableResponse.ResponseSequence); tokenData.Set("scoremark", scorableResponse.ScoreMark); tokenData.Set("hubDBIP", repoMon.DBIP); tokenData.Set("hubDBName", repoMon.DBName); tokenData.Set("clientName", repoMon.ClientName); tokenData.Set("environment", repoMon.Environment); return(EncryptionHelper.EncryptToBase64(tokenData.ToString(false))); // encrypt token (do not url encode) }
private void ProcessScore(HttpContext context) { Interlocked.Increment(ref RequestCount); // GET RESPONSE ItemScoreResponse itemScoreResponse; // Get XML using (XmlReader reader = XmlReader.Create(context.Request.InputStream)) { itemScoreResponse = HttpWebHelper.DeserializeXml <ItemScoreResponse>(reader); reader.Close(); } // decrypt token string decryptedToken = EncryptionHelper.DecryptFromBase64(itemScoreResponse.Score.ContextToken); // get test data WebValueCollection tokenData = new WebValueCollection(); tokenData.FillFromString(decryptedToken); // parse test data and collect up the information needed to persist this score ScoredResponse scoredResponse = new ScoredResponse { OppKey = tokenData.Get <Guid>("oppKey"), ItemKey = tokenData.Get("itemKey"), Position = tokenData.Get <int>("position"), Sequence = tokenData.Get <int>("sequence"), ScoreMark = tokenData.Get <Guid>("scoremark"), Score = itemScoreResponse.Score.ScoreInfo.Points, ScoreStatus = itemScoreResponse.Score.ScoreInfo.Status.ToString(), ScoreRationale = HttpWebHelper.SerializeXml(itemScoreResponse.Score.ScoreInfo), ScoreDimensions = GetDimensionsXmlForSP(itemScoreResponse.Score.ScoreInfo) }; string hubDBIP = tokenData.Get <String>("hubDBIP"); string hubDBName = tokenData.Get <String>("hubDBName"); string clientName = tokenData.Get <String>("clientName"); string environment = tokenData.Get <String>("environment"); // create function for submitting scores Action submitScore = delegate { Interlocked.Increment(ref ProgressCount); try { // Save score to DB IResponseRepository responseRepo = ServiceLocator.Resolve <IResponseRespositoryFactory>() .Create(ScoringDaemonSettings.HubConnectionString(hubDBIP, hubDBName), clientName, environment); if (responseRepo != null) { responseRepo.UpdateItemScore(scoredResponse); } else { // this is really unusual. We got a item score response for an unknown hub. string errorMessage = String.Format( "Got a score response for a hub that we dont monitor. oppKey:{0}, itemKey: {1}, position: {2}, sequence:{3}, scoreMark: {4}, clientName: {5}, environment: {6}", scoredResponse.OppKey, scoredResponse.ItemKey, scoredResponse.Position, scoredResponse.Sequence, scoredResponse.ScoreMark, clientName, environment); throw new InvalidDataException(errorMessage); } } catch (Exception ex) { Interlocked.Decrement(ref ProgressCount); Interlocked.Increment(ref ErrorCount); LastError = String.Format("{0} ({1})", ex.Message, DateTime.Now); TDSLogger.Application.Error(new TraceLog("Item Scoring: Error submitting callback score.", ex)); return; } Interlocked.Decrement(ref ProgressCount); Interlocked.Increment(ref SuccessCount); }; // check if thread pooling is enabled for callbacks if (WorkerPool != null) { // async if (!WorkerPool.Enqueue(submitScore)) { Interlocked.Increment(ref RejectCount); } } else { // sync submitScore(); } }