public AgentProfileDocument GetAgentProfileDocument(int agentId, string profileId) { AgentProfileDocument profileDoc = null; using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString())) { SqlDataReader reader = null; try { connection.Open(); SqlCommand command = new SqlCommand(GetAgentProfileIdQuery, connection); command.Parameters.AddWithValue("@profileId", profileId); command.Parameters.AddWithValue("@id", agentId); reader = command.ExecuteReader(); if (reader.Read()) { profileDoc = new AgentProfileDocument(); if (!reader.IsDBNull(0)) { profileDoc.Id = (int)reader[0]; } if (!reader.IsDBNull(1)) { profileDoc.ProfileId = (string)reader[1]; } /* if (!reader.IsDBNull(2)) * { * profileDoc.ActivityId = (int)reader[2]; * }*/ if (!reader.IsDBNull(3)) { profileDoc.ContentType = (string)reader[3]; } profileDoc.Content = DbUtils.GetBytes(reader, 4); if (!reader.IsDBNull(5)) { profileDoc.Checksum = reader.GetString(5); } if (!reader.IsDBNull(6)) { profileDoc.LastModified = (DateTimeOffset)reader[6]; } return(profileDoc); } } catch (Exception ex) { } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } } return(profileDoc); }
public IHttpActionResult DeleteProfile( [FromUri] Agent agent = null, string profileId = null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (agent == null) { return(BadRequest("Agent parameter needs to be provided.")); } if (profileId == null) { return(BadRequest("ProfileId parameter needs to be provided.")); } AgentProfileDocument profile = agentProfileRepository.GetProfile(agent, profileId); if (profile == null) { return(StatusCode(HttpStatusCode.NoContent)); } else { if (this.ActionContext.TryConcurrencyCheck(profile.Checksum, profile.LastModified, out var statusCode)) { return(StatusCode(statusCode)); } } agentProfileRepository.DeleteProfile(profile); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetProfiles( [FromUri] Agent agent = null, string profileId = null, DateTimeOffset?since = null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (agent == null) { return(BadRequest("Agent object needs to be provided.")); } if (profileId != null) { AgentProfileDocument profile = agentProfileRepository.GetProfile(agent, profileId); if (profile == null) { return(NotFound()); } return(new DocumentResult(profile)); } // otherwise we return the array of profileId's associated with that agent Object[] profiles = agentProfileRepository.GetProfiles(agent, since); if (profiles == null) { return(Ok(new string[0])); } return(new DocumentsResult(profiles)); }
public async Task cannot_delete_existing_agent_profile_with_invalid_etag() { // Arrange var state = new AgentProfileDocument <string>() { Content = "foo", ETag = ETAG }; var request = DeleteAgentProfileRequest.Create(state); request.Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }; request.ProfileId = PROFILE_ID; this._mockHttp .When(HttpMethod.Delete, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .WithHeaders("If-Match", ETAG) .Respond(HttpStatusCode.PreconditionFailed); // Act bool result = await this._client.AgentProfiles.Delete(request); // Assert result.Should().BeFalse(); }
public async Task can_get_agent_profile_with_string_document() { // Arrange var request = new GetAgentProfileRequest() { Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }, ProfileId = PROFILE_ID }; this._mockHttp .When(HttpMethod.Get, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .Respond(this.GetAgentProfileResponseMessage()); // Act AgentProfileDocument <string> agentProfile = await this._client.AgentProfiles.Get <string>(request); // Assert agentProfile.Should().NotBeNull(); agentProfile.ETag.Should().Be(ETAG); agentProfile.LastModified.Should().Be(LAST_MODIFIED); agentProfile.Content.Should().NotBeNullOrEmpty(); }
public async Task can_delete_existing_agent_profile() { // Arrange var state = new AgentProfileDocument <string>() { Content = "foo" }; var request = DeleteAgentProfileRequest.Create(state); request.Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }; request.ProfileId = PROFILE_ID; this._mockHttp .When(HttpMethod.Delete, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .With(x => x.Headers.IfNoneMatch.Count == 0 && x.Headers.IfMatch.Count == 0) .Respond(HttpStatusCode.NoContent); // Act bool result = await this._client.AgentProfiles.Delete(request); // Assert result.Should().BeTrue(); }
public async Task can_post_existing_agent_profile() { // Arrange var state = new AgentProfileDocument <string>() { Content = "foo", ETag = ETAG }; var request = PostAgentProfileRequest.Create(state); request.Agent = new Agent() { Name = AGENT_NAME, MBox = new Uri(AGENT_MBOX) }; request.ProfileId = PROFILE_ID; this._mockHttp .When(HttpMethod.Post, this.GetApiUrl("agents/profile")) .WithQueryString("agent", AGENT_QS) .WithQueryString("profileId", PROFILE_ID) .WithHeaders("If-Match", ETAG) .Respond(HttpStatusCode.NoContent); // Act bool result = await this._client.AgentProfiles.Post(request); // Assert result.Should().BeTrue(); }
public void CreateProfile(int agentId, AgentProfileDocument doc) { using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString())) { // get activity SqlCommand command = new SqlCommand(CreateAgentProfileQuery, connection); command.Parameters.AddRange(new[] { new SqlParameter("@v1", doc.ProfileId), new SqlParameter("@v2", agentId), new SqlParameter("@v3", doc.ContentType), new SqlParameter("@v4", doc.Content), new SqlParameter("@v5", doc.Checksum), new SqlParameter("@v6", doc.LastModified), new SqlParameter("@v7", doc.CreateDate), }); try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { } } }
public async Task <AgentProfileLRSResponse> RetrieveAgentProfile(string id, Agent agent) { var r = new AgentProfileLRSResponse(); var queryParams = new Dictionary <string, string>(); queryParams.Add("profileId", id); queryParams.Add("agent", agent.ToJSON(version)); var profile = new AgentProfileDocument(); profile.id = id; profile.agent = agent; var resp = await GetDocument("agents/profile", queryParams, profile); if (resp.status != HttpStatusCode.OK && resp.status != HttpStatusCode.NotFound) { r.success = false; r.httpException = resp.ex; r.SetErrMsgFromBytes(resp.content); return(r); } r.success = true; r.content = new AgentProfileDocument(); r.content.content = resp?.content; r.content.contentType = resp?.contentType; r.content.etag = resp?.etag; return(r); }
async Task <LRSResponse> SaveAgentProfile(AgentProfileDocument profile, RequestType requestType) { var queryParams = new Dictionary <string, string>(); queryParams.Add("profileId", profile.id); queryParams.Add("agent", profile.agent.ToJSON(version)); return(await SaveDocument("agents/profile", queryParams, profile, requestType)); }
public async Task <LRSResponse> DeleteAgentProfile(AgentProfileDocument profile) { var queryParams = new Dictionary <string, string>(); queryParams.Add("profileId", profile.id); queryParams.Add("agent", profile.agent.ToJSON(version)); return(await DeleteDocument("agents/profile", queryParams)); }
public LRSResponse SaveAgentProfile(AgentProfileDocument profile) { var queryParams = new Dictionary <String, String>(); queryParams.Add("profileId", profile.id); queryParams.Add("agent", profile.agent.ToJSON(version)); return(SaveDocument("agents/profile", queryParams, profile)); }
public LRSResponse DeleteAgentProfile(AgentProfileDocument profile) { var queryParams = new Dictionary <String, String>(); queryParams.Add("profileId", profile.id); queryParams.Add("agent", profile.agent.ToJSON(version)); // TODO: need to pass Etag? return(DeleteDocument("agents/profile", queryParams)); }
public async Task <LrsResponse> SaveAgentProfileAsync(AgentProfileDocument profile) { var queryParams = new Dictionary <string, string> { { "profileId", profile.Id }, { "agent", profile.Agent.ToJson(Version) } }; return(await SaveDocument("agents/profile", queryParams, profile)); }
/// <summary> /// Deletes the agent profile. /// </summary> /// <param name="agent">The agent.</param> /// <param name="profileId">The profile identifier.</param> /// <param name="matchHash">The match hash.</param> /// <param name="noneMatchHash">The none match hash.</param> /// <returns>Task<LRSResponse>.</returns> /// <exception cref="System.NotImplementedException"></exception> public async Task <LRSResponse> DeleteAgentProfile(Agent agent, string profileId, string matchHash, string noneMatchHash) { var doc = new AgentProfileDocument { Agent = agent, ID = profileId, }; return(await _lrs.DeleteAgentProfileAsync(doc)); }
public void SaveProfile(AgentProfileDocument document) { int index = GetAgentId(document.Agent); //If agent doesn't exist we have to create it if (index == -1) { index = CreateAgent(document.Agent); } CreateProfile(index, document); }
public async Task TestDeleteAgentProfile() { var doc = new AgentProfileDocument(); doc.agent = Support.agent; doc.id = "test"; LRSResponse lrsRes = await lrs.DeleteAgentProfile(doc); Assert.True(lrsRes.success); }
public AgentProfileDocument GetProfile(Agent agent, string profileId) { AgentProfileDocument document = null; int index = this.GetAgentId(agent); if (index != -1) { document = GetAgentProfileDocument(index, profileId); } return(document); }
public void TestDeleteAgentProfile() { var doc = new AgentProfileDocument(); doc.agent = Support.agent; doc.id = "test"; LRSResponse lrsRes = lrs.DeleteAgentProfile(doc); Assert.IsTrue(lrsRes.success); }
/// <summary> /// Sends the agent profile. /// </summary> /// <param name="agent">The agent.</param> /// <param name="profileId">The profile identifier.</param> /// <param name="profilEval">The profil eval.</param> /// <param name="matchHash">The match hash.</param> /// <param name="noneMatchHash">The none match hash.</param> /// <returns>Task<LRSResponse>.</returns> /// <exception cref="System.NotImplementedException"></exception> public async Task <LRSResponse> SendAgentProfile(Agent agent, string profileId, string profilEval, string matchHash, string noneMatchHash) { var doc = new AgentProfileDocument { Agent = agent, ID = profileId, Content = Encoding.UTF8.GetBytes(profilEval) }; return(await _lrs.SaveAgentProfileAsync(doc)); }
public async Task TestSaveAgentProfile() { var doc = new AgentProfileDocument(); doc.agent = Support.agent; doc.id = "test"; doc.content = System.Text.Encoding.UTF8.GetBytes("Test value"); LRSResponse lrsRes = await lrs.SaveAgentProfile(doc); Assert.True(lrsRes.success); }
public void TestDeleteAgentProfile() { var doc = new AgentProfileDocument { Agent = Support.Agent, ID = "test" }; var lrsRes = _lrs.DeleteAgentProfile(doc); Assert.IsTrue(lrsRes.Success); }
public async Task TestDeleteAgentProfileAsync() { var doc = new AgentProfileDocument { Agent = Support.Agent, Id = "test" }; var lrsRes = await _lrs.DeleteAgentProfileAsync(doc); Assert.IsTrue(lrsRes.Success); }
public async Task <LrsResponse> DeleteAgentProfileAsync(AgentProfileDocument profile) { var queryParams = new Dictionary <string, string> { { "profileId", profile.Id }, { "agent", profile.Agent.ToJson(Version) } }; // TODO: need to pass Etag? return(await DeleteDocument("agents/profile", queryParams)); }
public void TestSaveAgentProfile() { var doc = new AgentProfileDocument { Agent = Support.Agent, ID = "test", Content = Encoding.UTF8.GetBytes("Test value") }; var lrsRes = _lrs.SaveAgentProfile(doc); Assert.IsTrue(lrsRes.Success); }
public async Task TestSaveAgentProfileAsync() { var doc = new AgentProfileDocument { Agent = Support.Agent, Id = "test", Content = System.Text.Encoding.UTF8.GetBytes("Test value") }; var lrsRes = await _lrs.SaveAgentProfileAsync(doc); Assert.IsTrue(lrsRes.Success); }
async Task <AgentProfileDocument> IAgentProfilesApi.Get(GetAgentProfileRequest request) { var options = new RequestOptions(ENDPOINT); this.CompleteOptions(options, request); HttpResponseMessage response = await this._client.GetJson(options); JToken content = await response.Content.ReadAsAsync <JToken>(new[] { new StrictJsonMediaTypeFormatter() }); var document = new AgentProfileDocument(); document.ETag = response.Headers.ETag?.Tag; document.LastModified = response.Content.Headers.LastModified; document.Content = content; return(document); }
public void DeleteProfile(AgentProfileDocument profile) { if (profile == null) { return; } using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString())) { SqlCommand command = null; command = new SqlCommand(DeleteSingleAgentProfileQuery, connection); command.Parameters.AddWithValue("@id", profile.Id); try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { } } }
public async Task <ActionResult> SaveAgentProfileAsync(string profileId, [FromQuery(Name = "agent")] string strAgent, [FromBody] byte[] content) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string contentType = Request.ContentType; Agent agent = new Agent(strAgent); AgentProfileDocument profile = await _mediator.Send(new MergeAgentProfileCommand() { Agent = agent, ProfileId = profileId, Content = content, ContentType = contentType }); Response.Headers.Add("ETag", $"\"{profile.Tag}\""); Response.Headers.Add("LastModified", profile.LastModified?.ToString("o")); return(NoContent()); }
public async Task <AgentProfileLrsResponse> RetrieveAgentProfileAsync(string id, Agent agent) { var r = new AgentProfileLrsResponse(); var queryParams = new Dictionary <string, string> { { "profileId", id }, { "agent", agent.ToJson(Version) } }; var profile = new AgentProfileDocument { Id = id, Agent = agent }; var resp = await GetDocument("agents/profile", queryParams, profile); if (resp.Status != HttpStatusCode.OK && resp.Status != HttpStatusCode.NotFound) { r.Success = false; r.HttpException = resp.Ex; r.SetErrMsgFromBytes(resp.Content); return(r); } profile.Content = resp.Content; profile.ContentType = resp.ContentType; profile.Etag = resp.Etag; r.Success = true; r.Content = profile; return(r); }