Example #1
0
        public async Task cannot_delete_existing_activity_profile_with_invalid_etag()
        {
            // Arrange
            var state = new ActivityProfileDocument <string>()
            {
                Content = "foo",
                ETag    = ETAG
            };
            var request = DeleteActivityProfileRequest.Create(state);

            request.ActivityId = new Uri(ACTIVITY_ID);
            request.ProfileId  = PROFILE_ID;
            this._mockHttp
            .When(HttpMethod.Delete, this.GetApiUrl("activities/profile"))
            .WithQueryString("activityId", ACTIVITY_ID)
            .WithQueryString("profileId", PROFILE_ID)
            .WithHeaders("If-Match", ETAG)
            .Respond(HttpStatusCode.PreconditionFailed);

            // Act
            bool result = await this._client.ActivityProfiles.Delete(request);

            // Assert
            result.Should().BeFalse();
        }
Example #2
0
        public async Task can_get_activity_profile_with_dynamic_document()
        {
            // Arrange
            var request = new GetActivityProfileRequest()
            {
                ActivityId = new Uri(ACTIVITY_ID),
                ProfileId  = PROFILE_ID
            };

            this._mockHttp
            .When(HttpMethod.Get, this.GetApiUrl("activities/profile"))
            .WithQueryString("activityId", ACTIVITY_ID)
            .WithQueryString("profileId", PROFILE_ID)
            .Respond(this.GetActivityProfileResponseMessage());

            // Act
            ActivityProfileDocument activityProfile = await this._client.ActivityProfiles.Get(request);

            // Assert
            activityProfile.Should().NotBeNull();
            activityProfile.ETag.Should().Be(ETAG);
            activityProfile.LastModified.Should().Be(LAST_MODIFIED);
            string content = activityProfile.Content.ToObject <string>();

            content.Should().NotBeNullOrEmpty();
        }
Example #3
0
        public async Task <ActivityProfileLrsResponse> RetrieveActivityProfileAsync(string id, Activity activity)
        {
            var r = new ActivityProfileLrsResponse();

            var queryParams = new Dictionary <string, string>
            {
                { "profileId", id },
                { "activityId", activity.Id }
            };

            var profile = new ActivityProfileDocument
            {
                Id       = id,
                Activity = activity
            };

            var resp = await GetDocument("activities/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 = profile;

            return(r);
        }
Example #4
0
        public async Task <ActivityProfileLRSResponse> RetrieveActivityProfile(string id, Activity activity)
        {
            var r = new ActivityProfileLRSResponse();

            var queryParams = new Dictionary <string, string>();

            queryParams.Add("profileId", id);
            queryParams.Add("activityId", activity.id);

            var profile = new ActivityProfileDocument();

            profile.id       = id;
            profile.activity = activity;

            var resp = await GetDocument("activities/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 = profile;

            return(r);
        }
        public IHttpActionResult GetProfiles(
            Iri activityId       = null,
            string profileId     = null,
            DateTimeOffset?since = null)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (activityId == null)
            {
                return(BadRequest("ActivityId parameter needs to be provided."));
            }

            if (profileId != null)
            {
                ActivityProfileDocument profile = activityProfileRepository.GetProfile(activityId, profileId);
                if (profile == null)
                {
                    return(NotFound());
                }
                return(new DocumentResult(profile));
            }

            // otherwise we return the array of profileId's associated with that activity
            Object[] profiles = activityProfileRepository.GetProfiles(activityId, since);
            if (profiles == null)
            {
                return(Ok(new string[0]));
            }

            return(new DocumentsResult(profiles));
        }
        public IHttpActionResult DeleteProfile(
            Iri activityId   = null,
            string profileId = null)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (activityId == null)
            {
                return(BadRequest("ActivityId parameter needs to be provided."));
            }
            if (profileId == null)
            {
                return(BadRequest("ProfileId parameter needs to be provided."));
            }
            ActivityProfileDocument profile = activityProfileRepository.GetProfile(activityId, profileId);

            if (profile == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                if (this.ActionContext.TryConcurrencyCheck(profile.Checksum, profile.LastModified, out var statusCode))
                {
                    return(StatusCode(statusCode));
                }
            }
            activityProfileRepository.DeleteProfile(profile);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #7
0
        public ActivityProfileDocument GetActivityProfileDocument(int activityId, string profileId)
        {
            ActivityProfileDocument profileDoc = null;

            using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString()))
            {
                SqlDataReader reader = null;
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(GetProfileIdQuery, connection);
                    command.Parameters.AddWithValue("@profileId", profileId);
                    command.Parameters.AddWithValue("@id", activityId);
                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        profileDoc = new ActivityProfileDocument();

                        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);
        }
Example #8
0
 public void CreateProfile(int activityId, ActivityProfileDocument doc)
 {
     using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString()))
     {
         // get activity
         SqlCommand command = new SqlCommand(CreateActivityProfileQuery, connection);
         command.Parameters.AddRange(new[]
         {
             new SqlParameter("@v1", doc.ProfileId),
             new SqlParameter("@v2", activityId),
             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 <IActionResult> DeleteProfileAsync(string profileId, Iri activityId, Guid?registration = null)
        {
            try
            {
                ActivityProfileDocument profile = await _mediator.Send(new GetActivityProfileQuery()
                {
                    ProfileId    = profileId,
                    ActivityId   = activityId,
                    Registration = registration
                });

                if (profile == null)
                {
                    return(NotFound());
                }

                await _mediator.Send(new DeleteActivityProfileCommand()
                {
                    ProfileId    = profileId,
                    ActivityId   = activityId,
                    Registration = registration
                });

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Example #10
0
        public async Task can_post_existing_activity_profile()
        {
            // Arrange
            var state = new ActivityProfileDocument <string>()
            {
                Content = "foo",
                ETag    = ETAG
            };
            var request = PostActivityProfileRequest.Create(state);

            request.ActivityId = new Uri(ACTIVITY_ID);
            request.ProfileId  = PROFILE_ID;
            this._mockHttp
            .When(HttpMethod.Post, this.GetApiUrl("activities/profile"))
            .WithQueryString("activityId", ACTIVITY_ID)
            .WithQueryString("profileId", PROFILE_ID)
            .WithHeaders("If-Match", ETAG)
            .Respond(HttpStatusCode.NoContent);

            // Act
            bool result = await this._client.ActivityProfiles.Post(request);

            // Assert
            result.Should().BeTrue();
        }
        public async Task <IActionResult> GetProfile([BindRequired] string profileId, [BindRequired] Iri activityId, Guid?registration = null)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ActivityProfileDocument profile = await _mediator.Send(new GetActivityProfileQuery()
            {
                ProfileId    = profileId,
                ActivityId   = activityId,
                Registration = registration
            });

            if (profile == null)
            {
                return(NotFound());
            }

            var result = new FileContentResult(profile.Content, profile.ContentType)
            {
                EntityTag    = new Microsoft.Net.Http.Headers.EntityTagHeaderValue(profile.Tag),
                LastModified = profile.LastModified
            };

            return(Ok(result));
        }
Example #12
0
        public async Task <LRSResponse> DeleteActivityProfile(ActivityProfileDocument profile)
        {
            var queryParams = new Dictionary <string, string>();

            queryParams.Add("profileId", profile.id);
            queryParams.Add("activityId", profile.activity.id);

            return(await DeleteDocument("activities/profile", queryParams));
        }
Example #13
0
        public LRSResponse SaveActivityProfile(ActivityProfileDocument profile)
        {
            var queryParams = new Dictionary <String, String>();

            queryParams.Add("profileId", profile.id);
            queryParams.Add("activityId", profile.activity.id.ToString());

            return(SaveDocument("activities/profile", queryParams, profile));
        }
Example #14
0
        public async Task <LrsResponse> SaveActivityProfileAsync(ActivityProfileDocument profile)
        {
            var queryParams = new Dictionary <string, string>
            {
                { "profileId", profile.Id },
                { "activityId", profile.Activity.Id }
            };

            return(await SaveDocument("activities/profile", queryParams, profile));
        }
Example #15
0
        public LRSResponse DeleteActivityProfile(ActivityProfileDocument profile)
        {
            var queryParams = new Dictionary <String, String>();

            queryParams.Add("profileId", profile.id);
            queryParams.Add("activityId", profile.activity.id.ToString());
            // TODO: need to pass Etag?

            return(DeleteDocument("activities/profile", queryParams));
        }
Example #16
0
        public ActivityProfileDocument GetProfile(Iri activityId, string profileId)
        {
            ActivityProfileDocument document = null;
            int index = this.GetActivityId(activityId)[0];

            if (index != -1)
            {
                document = GetActivityProfileDocument(index, profileId);
            }
            return(document);
        }
Example #17
0
        public void TestDeleteActivityProfile()
        {
            var doc = new ActivityProfileDocument();

            doc.activity = Support.activity;
            doc.id       = "test";

            LRSResponse lrsRes = lrs.DeleteActivityProfile(doc);

            Assert.IsTrue(lrsRes.success);
        }
        public async Task TestDeleteActivityProfile()
        {
            var doc = new ActivityProfileDocument();

            doc.activity = Support.activity;
            doc.id       = "test";

            LRSResponse lrsRes = await lrs.DeleteActivityProfile(doc);

            Assert.True(lrsRes.success);
        }
Example #19
0
        public void SaveProfile(ActivityProfileDocument document)
        {
            int index = GetActivityId(document.ActivityId)[0];

            //If activity doesn't exist we have to create it
            if (index == -1)
            {
                index = CreateActivity(document.ActivityId);
            }
            CreateProfile(index, document);
        }
Example #20
0
        public async Task <LrsResponse> DeleteActivityProfileAsync(ActivityProfileDocument profile)
        {
            var queryParams = new Dictionary <string, string>
            {
                { "profileId", profile.Id },
                { "activityId", profile.Activity.Id }
            };

            // TODO: need to pass Etag?

            return(await DeleteDocument("activities/profile", queryParams));
        }
        public async Task TestSaveActivityProfile()
        {
            var doc = new ActivityProfileDocument();

            doc.activity = Support.activity;
            doc.id       = "test";
            doc.content  = System.Text.Encoding.UTF8.GetBytes("Test value");

            LRSResponse lrsRes = await lrs.SaveActivityProfile(doc);

            Assert.True(lrsRes.success);
        }
Example #22
0
        public async Task TestDeleteActivityProfileAsync()
        {
            var doc = new ActivityProfileDocument
            {
                Activity = Support.Activity,
                Id       = "test"
            };

            var lrsRes = await _lrs.DeleteActivityProfileAsync(doc);

            Assert.IsTrue(lrsRes.Success);
        }
Example #23
0
        public void TestDeleteActivityProfile()
        {
            var doc = new ActivityProfileDocument
            {
                Activity = Support.Activity,
                ID       = "test"
            };

            var lrsRes = _lrs.DeleteActivityProfile(doc);

            Assert.IsTrue(lrsRes.Success);
        }
Example #24
0
        public void TestSaveActivityProfile()
        {
            var doc = new ActivityProfileDocument
            {
                Activity = Support.Activity,
                ID       = "test",
                Content  = Encoding.UTF8.GetBytes("Test value")
            };

            var lrsRes = _lrs.SaveActivityProfile(doc);

            Assert.IsTrue(lrsRes.Success);
        }
Example #25
0
        public async Task TestSaveActivityProfileAsync()
        {
            var doc = new ActivityProfileDocument
            {
                Activity = Support.Activity,
                Id       = "test",
                Content  = System.Text.Encoding.UTF8.GetBytes("Test value")
            };

            var lrsRes = await _lrs.SaveActivityProfileAsync(doc);

            Assert.IsTrue(lrsRes.Success);
        }
Example #26
0
        /// <summary>
        /// Deletes the activity profile.
        /// </summary>
        /// <param name="activityId">The activity identifier.</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&lt;LRSResponse&gt;.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task <LRSResponse> DeleteActivityProfile(string activityId, string profileId, string matchHash, string noneMatchHash)
        {
            var activity = new Activity {
                ID = activityId
            };

            var doc = new ActivityProfileDocument
            {
                Activity = activity,
                ID       = profileId,
            };

            return(await _lrs.DeleteActivityProfileAsync(doc));
        }
Example #27
0
        /// <summary>
        /// Sends the activity profile.
        /// </summary>
        /// <param name="activityId">The activity identifier.</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&lt;LRSResponse&gt;.</returns>
        public async Task <LRSResponse> SendActivityProfile(string activityId, string profileId, string profilEval, string matchHash, string noneMatchHash)
        {
            var activity = new Activity {
                ID = activityId
            };

            var doc = new ActivityProfileDocument
            {
                Activity = activity,
                ID       = profileId,
                Content  = Encoding.UTF8.GetBytes(profilEval)
            };

            return(await _lrs.SaveActivityProfileAsync(doc));
        }
Example #28
0
 public void DeleteProfile(ActivityProfileDocument profile)
 {
     if (profile == null)
     {
         return;
     }
     using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString()))
     {
         SqlCommand command = null;
         command = new SqlCommand(DeleteSingleActivityProfileQuery, connection);
         command.Parameters.AddWithValue("@id", profile.Id);
         try
         {
             connection.Open();
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
         }
     }
 }
        public async Task <IActionResult> SaveProfile([FromQuery] string profileId, [FromQuery] Iri activityId, [FromBody] byte[] document, [FromQuery] Guid?registration = null)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string contentType = Request.ContentType;

            ActivityProfileDocument profile = await _mediator.Send(new CreateActivityProfileCommand()
            {
                ProfileId    = profileId,
                ActivityId   = activityId,
                Content      = document,
                ContentType  = contentType,
                Registration = registration
            });

            Response.Headers["ETag"] = profile.Tag;

            return(NoContent());
        }
Example #30
0
 public void OverwriteProfile(ActivityProfileDocument document)
 {
     using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString()))
     {
         try
         {
             connection.Open();
             // Create the activity
             SqlCommand command = new SqlCommand(UpdateActivityProfileQuery, connection);
             command.Parameters.AddWithValue("@ctt", document.ContentType);
             command.Parameters.AddWithValue("@ct", document.Content);
             command.Parameters.AddWithValue("@cks", document.Checksum);
             command.Parameters.AddWithValue("@lm", document.LastModified);
             command.Parameters.AddWithValue("@id", document.Id);
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
         }
         finally
         {
         }
     }
 }