internal static ProbeIdentity ResolveIdentity(string identityParameter, bool isDcOrDedicated) { IEnumerable <ProbeIdentity> enumerable = OutlookConnectivity.AllProbes; ProbeIdentity probeIdentity = null; if ((!MonitoringItemIdentity.MonitorIdentityId.IsValidFormat(identityParameter) || !ExchangeComponent.WellKnownComponents.ContainsKey(MonitoringItemIdentity.MonitorIdentityId.GetHealthSet(identityParameter))) && !MonitoringItemIdentity.MonitorIdentityId.IsValidFormat(identityParameter = "\\" + identityParameter)) { throw new ArgumentException(Strings.InvalidOutlookProbeIdentity(identityParameter)); } string healthSetLookup = MonitoringItemIdentity.MonitorIdentityId.GetHealthSet(identityParameter); if (!string.IsNullOrEmpty(healthSetLookup)) { if (ExchangeComponent.WellKnownComponents.ContainsKey(healthSetLookup)) { enumerable = from probe in enumerable where probe.Component.Name.Equals(healthSetLookup, StringComparison.InvariantCultureIgnoreCase) select probe; } else { identityParameter = "\\" + identityParameter; } } string monitor = MonitoringItemIdentity.MonitorIdentityId.GetMonitor(identityParameter); string targetResource = MonitoringItemIdentity.MonitorIdentityId.GetTargetResource(identityParameter); foreach (ProbeIdentity probeIdentity2 in enumerable) { if (probeIdentity2.Name.IndexOf(monitor, StringComparison.InvariantCultureIgnoreCase) >= 0) { if (probeIdentity != null) { throw new ArgumentException(Strings.AmbiguousOutlookProbeIdentity(identityParameter, probeIdentity.ToString(), probeIdentity2.ForTargetResource(targetResource).ToString())); } probeIdentity = probeIdentity2.ForTargetResource(targetResource); } } if (probeIdentity != null && isDcOrDedicated && probeIdentity.Name.IndexOf("CTP", StringComparison.InvariantCultureIgnoreCase) >= 0) { probeIdentity = null; } if (probeIdentity == null) { throw new ArgumentException(Strings.OutlookProbeIdentityNotFound(identityParameter)); } return(probeIdentity); }
protected override void InternalValidate() { TaskLogger.LogEnter(); try { if (this.RunFromServerId == null) { this.RunFromServerId = new ServerIdParameter(new Fqdn(ComputerInformation.DnsPhysicalFullyQualifiedDomainName)); } this.server = (Server)base.GetDataObject <Server>(this.RunFromServerId, base.DataSession, this.RootId, new LocalizedString?(Strings.ErrorServerNotFound(this.RunFromServerId.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(this.RunFromServerId.ToString()))); this.WriteInfo(Strings.RunFromServer(this.RunFromServerId.ToString())); if (this.MailboxId != null) { this.mailboxAdUser = (ADUser)base.GetDataObject <ADUser>(this.MailboxId, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.MailboxId.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.MailboxId.ToString()))); } this.WriteInfo((this.mailboxAdUser == null) ? Strings.UsingTargetMonitoringMailbox : Strings.UsingTargetMailbox(this.mailboxAdUser.PrimarySmtpAddress.ToString())); if (!TestOutlookConnectivity.IsMailboxCredentialEmpty(this.Credential)) { if (this.MailboxId == null) { base.WriteError(new ArgumentException(Strings.MissingMailboxId(this.Credential.UserName)), (ErrorCategory)1000, null); } this.authenticateAsUser = (ADUser)base.GetDataObject <ADUser>(new RecipientIdParameter(this.Credential.UserName), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.OutlookConnectivityErrorUserNotFound(this.Credential.UserName.ToString())), new LocalizedString?(Strings.OutlookConnectivityErrorUserNotUnique(this.Credential.UserName.ToString()))); } this.WriteInfo((this.Credential != null) ? Strings.UsingAuthenticationCredentials(this.Credential.UserName) : Strings.UsingMonitoringMailboxAuthenticationCredentials); string probeIdentity = this.ProbeIdentity; ProbeIdentity probeIdentity2 = null; try { probeIdentity2 = OutlookConnectivity.ResolveIdentity(probeIdentity, TestOutlookConnectivity.IsDcOrDedicated); } catch (ArgumentException exception) { base.WriteError(exception, (ErrorCategory)1000, null); } this.ProbeIdentity = probeIdentity2.GetIdentity(true); this.WriteInfo(Strings.UsingProbeIdentity(this.ProbeIdentity)); if (!TestOutlookConnectivity.IsMailboxCredentialEmpty(this.Credential) && !this.IsProbePasswordAuthenticated) { this.WriteWarning(Strings.IgnoredAuthenticationWarning); } } finally { TaskLogger.LogExit(); } }
/* * Get all Users */ public JsonResult GetAllUsers() { try { List <Probe.Models.ApplicationUser> userList = new ProbeIdentity().GetAllUsers(); var users = userList.OrderBy(u => u.UserName).Select(u => new { u.Id, u.UserName }); var itemsVar = new SelectList(users, "Id", "UserName"); var items = itemsVar.ToList(); return(Json(items, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.ToDataSourceResult())); } }
public IHttpActionResult PostPlayer([ModelBinder(typeof(PlayerModelBinderProvider))] PlayerDTO playerDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } /* * Let's make sure the gameplayid and gamecode match up correctly. check for malicious activity */ try { ProbeValidate.ValidateGameCodeVersusId(playerDTO.GameId, playerDTO.GameCode); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah return(BadRequest(ModelState)); } int nbrPlayersAnswersCorrect = 0; DateTime dateTimeNow = DateTime.UtcNow; Player player = new Player(); //Create a GameAnswers Collection ICollection <GameAnswer> gameAnswers = new List <GameAnswer>(); foreach (GameAnswerDTO gameAnswerDTO in playerDTO.GameAnswers) { //we need to create a gameAnswer (to record in the database) GameAnswer gameAnswer = new GameAnswer { PlayerId = playerDTO.Id, ChoiceId = gameAnswerDTO.ChoiceId }; gameAnswers.Add(gameAnswer); } //foreach (GameAnswerDTO gameAnswerDTO in playerDTO.GameAnswers) Game g = db.Game.Find(playerDTO.GameId); string userNameOfGameAuthor = new ProbeIdentity().GetUserNameFromUserId(g.AspNetUsersId); ProbeGame probeGame = new ProbeGame(g); /* * If we've gotten this far, then the required fields and game code security * validations have passed */ try { //business validations if (!probeGame.IsActive()) { throw new GameNotActiveException(); } player.Id = playerDTO.Id; if (!probeGame.IsPlayerSubmitted(player)) { //In here, we know this is a new player player = new Player { Id = playerDTO.Id, GameId = playerDTO.GameId, FirstName = playerDTO.FirstName, LastName = playerDTO.LastName, NickName = playerDTO.NickName, EmailAddr = playerDTO.EmailAddr, Sex = playerDTO.Sex, //Active = true, //Do not specify at this point SubmitDate = dateTimeNow.Date, SubmitTime = DateTime.Parse(dateTimeNow.ToShortTimeString()) }; //will throw the following exceptions if there is a problem //GameDuplicatePlayerNameException, GameInvalidFirstNameException, GameInvalidNickNameException //ONLY NEED TO VALIDATE IF THE PLAYER HAS NOT SUBMITTED FOR A GAME YET probeGame.ValidateGamePlayer(player); player.Active = true; //Player is always active to begin with db.Person.Add(player); } else { //we get here only if it's an existing player player = db.Player.Find(playerDTO.Id); if (!probeGame.IsPlayerActive(player)) { throw new GamePlayerInActiveException(); } }//if (!probeGame.IsPlayerSubmitted(player)) //Making this API backward compatible. Will not attempt to record game answers if its //client version v1.0 if (playerDTO.ClientVersion != ProbeConstants.ClientVersionPostPlayerWithoutAnswers) { if (playerDTO.GameAnswers == null) { throw new PlayerDTOMissingAnswersException(); } else if (!probeGame.IsValidGameAnswer(gameAnswers)) { throw new InvalidGameAnswersException(); } //Determine if the GameAnswer submission is not too early. We pass the DTO version because it has the question number //Note: This audit had to come after the player is submitted check and player added to database if (!probeGame.IsPlayerGameAnswerNotTooEarly(dateTimeNow, gameAnswers)) { throw new GameAnswersTooEarlyException(); } //Determine if the GameAnswer submission is ontime. We pass the DTO version because it has the question number //Note: This audit had to come after the player is submitted check and player added to database if (!probeGame.IsPlayerGameAnswerOnTime(dateTimeNow, gameAnswers)) { throw new GameAnswersTooLateException(); } //create GameAnswerDTO's (Id, PlayerId, ChoiceId) foreach (GameAnswer gameAnswer in gameAnswers) { //we need to create a gameAnswer (to record in the database) GameAnswer GameAnswerforDB = new GameAnswer { Player = player, //player could have been created new or an existing ChoiceId = gameAnswer.ChoiceId }; db.GameAnswer.Add(GameAnswerforDB); } //foreach (GameAnswerDTO gameAnswerDTOIn in gameAnswersDTOsIn) db.SaveChanges(Request != null ? Request.Headers.UserAgent.ToString() : null); //record all gameanswers to player //We pass in the playerDO.GameAnswers because it holds the QuestionId of each question. Much //more assurance that we are correcting the appropriate questions and answers nbrPlayersAnswersCorrect = probeGame.NbrPlayerAnswersCorrect(playerDTO.GameAnswers); //if the game is LMS - Determine if any of the answers submitted were wrong. //If so then we are going to make the player inactive if (probeGame.GameType == ProbeConstants.LMSGameType) { if (playerDTO.GameAnswers.Count() > nbrPlayersAnswersCorrect) { //We need to make the player inactive. probeGame.SetPlayerStatus(player, false, Player.PlayerGameReasonType.ANSWER_REASON_INCORRECT); } } //if (probeGame.GameType == ProbeConstants.LMSGameType) } //if (!playerDTO.ClientVersion.Contains("v1.0")) //notify clients of game author of game change NotifyProbe.NotifyGameChanged(userNameOfGameAuthor); playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.NbrPlayers = probeGame.NbrPlayers; playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive; playerDTO.PlayerGameStatus.NbrAnswersCorrect = nbrPlayersAnswersCorrect; playerDTO.PlayerGameStatus.PlayerActive = probeGame.IsPlayerActive(player); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_NoError; playerDTO.Id = player.Id; //if a new player created then we have to set the Id to be passed back to the client return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); //EVERYTHING IS GOOD! } //try catch (GameNotActiveException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_GameNotActive; playerDTO.PlayerGameStatus.Message = "This game is not active at this time."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameDuplicatePlayerNameException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerDupInGame; string playername = new ProbePlayer(player).PlayerGameName; playerDTO.PlayerGameStatus.Message = "The player's name (" + playername + ") has already been used in this game."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameInvalidFirstNameException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerFirstNameInvalid; playerDTO.PlayerGameStatus.Message = "The player's first name is invalid."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameInvalidNickNameException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerNickNameInvalid; playerDTO.PlayerGameStatus.Message = "The player's nick name is invalid."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (PlayerDTOMissingAnswersException) { //cleanup first if (!probeGame.IsPlayerHaveAnswers(player)) { ProbeGame.DeletePlayer(db, player); //notify clients of game author of game change NotifyProbe.NotifyGameChanged(userNameOfGameAuthor); } playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionMissingAnswers; playerDTO.PlayerGameStatus.Message = "The client player answer submission is missing question-answers."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (InvalidGameAnswersException) { //cleanup first if (!probeGame.IsPlayerHaveAnswers(player)) { ProbeGame.DeletePlayer(db, player); //notify clients of game author of game change NotifyProbe.NotifyGameChanged(userNameOfGameAuthor); } playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionInvalidAnswers; playerDTO.PlayerGameStatus.Message = "The client player answer submission possess the incorrect number of question-answers."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameInvalidPlayerNameException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerNameInvalid; playerDTO.PlayerGameStatus.Message = "The player's name is invalid."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameInvalidLastNameException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerLastNameInvalid; playerDTO.PlayerGameStatus.Message = "The player's last name is invalid."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameAnswersTooLateException) { //Everything is not good. The GameAnswer submission did not come in ontime. So the //player will become inactive. However, we will still send player game stats to the client. //We need to make the player inactive. //Note: we want to keep the player in the datbase (as inactive) also. probeGame.SetPlayerStatus(player, false, Player.PlayerGameReasonType.ANSWER_REASON_DEADLINE); playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.NbrPlayers = probeGame.NbrPlayers; playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive; playerDTO.PlayerGameStatus.NbrAnswersCorrect = nbrPlayersAnswersCorrect; playerDTO.PlayerGameStatus.PlayerActive = probeGame.IsPlayerActive(player); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionNotOntime; playerDTO.PlayerGameStatus.Message = "The player submission was beyond the deadline."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GameAnswersTooEarlyException) { //Everything is not good. The GameAnswer submission is too early. //We will still send player game stats to the client. //We will keep the player status active at this point. //probeGame.SetPlayerStatus(player, false); DONT NEED THIS FOR NOW playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.NbrPlayers = probeGame.NbrPlayers; playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive; playerDTO.PlayerGameStatus.NbrAnswersCorrect = nbrPlayersAnswersCorrect; playerDTO.PlayerGameStatus.PlayerActive = probeGame.IsPlayerActive(player); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionTooEarly; playerDTO.PlayerGameStatus.Message = "The player submission was too early."; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (GamePlayerInActiveException) { playerDTO.PlayerGameStatus = new PlayerGameStatus(); playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_GamePlayerInActive; string playername = new ProbePlayer(player).PlayerGameName; playerDTO.PlayerGameStatus.Message = "The player (" + playername + ") is inactive for the game"; return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah //cleanup first - different type of cleanup depends on game type if (probeGame.GameType == ProbeConstants.LMSGameType) { //if LMS - we only delete the player if there are no answers for that player if (!probeGame.IsPlayerHaveAnswers(player)) { ProbeGame.DeletePlayer(db, player); //notify clients of game author of game change NotifyProbe.NotifyGameChanged(userNameOfGameAuthor); } } else { //If Match or Test, then we remove any remants of the player and her answers ProbeGame.DeletePlayer(db, player); } var errorObject = new { errorid = ex.HResult, errormessage = ex.Message, errorinner = ex.InnerException, errortrace = ex.StackTrace }; return(CreatedAtRoute("DefaultApi", new { id = errorObject.errorid }, errorObject)); } }//public IHttpActionResult PostPlayer([...