public async Task <string> React(PublicId userId, PublicId toId, ReactionType type) { var reaction = (ActivityObject)Activator.CreateInstance(CustomJsonSerializer.TypeOf(type.ToString())); reaction.actor = new List <BaseObject> { new Common.Person { PublicId = userId, } }.ToCollection(); var target = await _activityContent.Get(toId, userId); if (target != null) { reaction.target = new List <BaseObject> { target }.ToCollection(); var res = await _activityStream.Post("outbox", reaction); return(reaction.id); } else { return(null); } }
public Teacher(string name, string phone, string email, decimal salary, string subjectTaught) : base(name, phone, email, salary) { SubjectTaught = subjectTaught; Salary = salary; TeacherId = PublicId.ToString() + "T"; }
public static Eu.Xroad.UsFolkV3.Producer.PublicId PublicId(PublicId id) { return(new Eu.Xroad.UsFolkV3.Producer.PublicId() { value = id.Value }); }
public void ConceptChronologyDTOIsEquivalentTest() { { ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO; ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO; Assert.True(a.IsEquivalent(b)); } { ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO; ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO with { PublicId = new PublicId(Misc.other) }; Assert.False(a.IsEquivalent(b)); } { ConceptChronologyDTO a = new ConceptChronologyDTO( Misc.PublicIdG, Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray() ); ConceptChronologyDTO b = new ConceptChronologyDTO( Misc.PublicIdG, new ConceptVersionDTO[] { Misc.cv1(Misc.PublicIdG) }.ToImmutableArray() ); Assert.False(a.IsEquivalent(b)); } }
public void PatternChronologyDTOIsEquivalentTest() { { PatternChronologyDTO a = Misc.CreatePatternChronologyDTO; PatternChronologyDTO b = Misc.CreatePatternChronologyDTO; Assert.True(a.IsEquivalent(b)); } { PatternChronologyDTO a = Misc.CreatePatternChronologyDTO; PatternChronologyDTO b = Misc.CreatePatternChronologyDTO with { PublicId = new PublicId(Misc.other) }; Assert.False(a.IsEquivalent(b)); } { PatternChronologyDTO a = Misc.CreatePatternChronologyDTO; PatternChronologyDTO b = Misc.CreatePatternChronologyDTO with { Versions = new PatternVersionDTO[] { Misc.CreatePatternVersionDTO with { PublicId = new PublicId(Misc.other) } }.ToImmutableArray()
public void ConceptChronologyDTOCompareToTest() { { ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO; ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO; Assert.True(a.CompareTo(b) == 0); } { ConceptChronologyDTO a = Misc.CreateConceptChronologyDTO; ConceptChronologyDTO b = Misc.CreateConceptChronologyDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { ConceptChronologyDTO a = new ConceptChronologyDTO( Misc.PublicIdG, Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray() ); ConceptChronologyDTO b = new ConceptChronologyDTO( Misc.PublicIdG, new ConceptVersionDTO[] { Misc.cv1(Misc.PublicIdG) }.ToImmutableArray() ); Assert.False(a.CompareTo(b) == 0); } }
public async Task <CollectionObject> GetMediaForUser(PublicId userId, int?viewerId, CommonMediaType?type, PaginationModel pagination) { if (userId.PeerId == 0) { var query = _dbContext.ArchivedMedia.Where(p => p.UserId == userId.Id); if (type.HasValue) { query = query.Where(m => m.MediaType == type.Value); } var paginated = await query.ToListAsync(); // .OrderByDescending(p => p.WhenCreated) var keepers = new List <BaseObject>(); foreach (var p in paginated) { keepers.Add(await Transform(p)); } return(new OrderedCollectionPageObject { items = keepers.Skip(pagination.start).Take(pagination.count).ToList(), totalItems = keepers.Count(), startIndex = pagination.start, }); } else { return(new CollectionObject()); } }
public void PatternVersionDTOFieldsTest() { FieldDefinitionDTO fdoa = Misc.CreateFieldDefinition; FieldDefinitionDTO fdob = Misc.CreateFieldDefinition with { DataTypePublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) } ; PatternVersionDTO dtoStart = new PatternVersionDTO( Misc.PublicIdG, Misc.CreateStampDTO, Misc.PublicIdH, Misc.PublicIdI, new FieldDefinitionDTO[] { fdoa, fdob }.ToImmutableArray() ); Misc.Compare(dtoStart.PublicId, Misc.PublicIdG); Assert.True(dtoStart.StampDTO.CompareTo(Misc.CreateStampDTO) == 0); Misc.Compare(dtoStart.FieldDefinitions, new FieldDefinitionDTO[] { Misc.CreateFieldDefinition, Misc.CreateFieldDefinition with { DataTypePublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) } }
public override int GetHashCode() { int hash = 1; if (PublicId.Length != 0) { hash ^= PublicId.GetHashCode(); } if (AccessToken.Length != 0) { hash ^= AccessToken.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } hash ^= items_.GetHashCode(); if (Health != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Health); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task <BaseObject> GetMedia(PublicId id, int?viewerId) { if (id.PeerId == 0) { return(await Transform(await _dbContext.ArchivedMedia.FindAsync(id.Id))); } return(null); }
private async Task <IActionResult> ViewPost(PublicId id) { var user = await GetCurrentUserAsync(); var post = await _activityStreams.Get(new ActivityStreamFilter("outbox") { id = id, viewerId = user?.UserId }); ViewData["PartialName"] = "Activity/_Container"; return(View("_NoLayout", post)); }
private void TestGetPersonMediumByPublicId() { Console.WriteLine("# TestGetPersonMediumByPublicId"); var person = MediumClient().GetPerson( PublicId.Create(1157442) ); PrintPerson(person); }
public async Task <BaseObject> Get(PublicId id, PublicId viewerId) { var target = (BaseObject)Activator.CreateInstance(CustomJsonSerializer.TypeOf(id.Type)); target.PublicId = id; await BindSqlContent(target); return(target); }
public async Task SetLimitForUser(PublicId userId, string property, int?limit) { if (limit.HasValue) { await _redis.FieldSet <ActorRateLimitModel>(userId, property, limit.Value.ToString(), "limit"); } else { await _redis.FieldDelete <ActorRateLimitModel>(property, userId, "limit"); } }
public async Task <CollectionObject> GetFollowers(PublicId id, int?viewerId) { if (id.PeerId == 0) { return((await Task.WhenAll((await _locals.GetFollowers(id.Id.Value, viewerId)).Select(u => Transform(u, id.PeerId.Value, viewerId)))).ToCollection()); } else { return(null); } }
public async Task <CollectionObject> Get(PublicId id, int?viewerId) { // var fromRedis = await _redis.Get<ReactionsSummaryModel>(id); // if (fromRedis == null) // { // f // } //var reactions = GetReactionsList(subject); //return reactions.Where(r => r.ToId == id.Id && r.ToPeerId == id.PeerId && r.UserId == viewerId.Value).ToListAsync(); return(null); }
public string ToUri(PublicId focus) { var str = ToPath(focus); var args = ToUrlFormEncoded(); if (string.IsNullOrWhiteSpace(args)) { return(str); } else { return($"{System.IO.Path.ChangeExtension(str, null)}?{args}.index"); } }
public async Task <BaseObject> GetPostsForUser(PublicId userId, int?viewerId, bool includeReplies, PaginationModel pagination) { if (userId.PeerId == 0) { return(await _activityStreams.Get(new ActivityStreamFilter("outbox") { id = userId, includeReplies = includeReplies, })); } else { return(new CollectionObject()); } }
public void Insert() { TinkarId alpha = new TinkarId(1L, 0L); TinkarId beta = new TinkarId(2L, 0L); TinkarId delta = new TinkarId(3L, 0L); { PublicId pid = new PublicId(alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 1); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, beta.Uuid, delta.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(beta.Uuid, delta.Uuid, alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, delta.Uuid, beta.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, beta.Uuid, alpha.Uuid, delta.Uuid, alpha.Uuid, alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } }
public void SemanticChronologyDTOCompareToTest() { { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO; Assert.True(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { PatternForSemantic = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { ReferencedComponentPublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { SemanticVersions = new SemanticVersionDTO[] { Misc.CreateSemanticVersionDTO, Misc.CreateSemanticVersionDTO }.ToImmutableArray() }; Assert.False(a.CompareTo(b) == 0); } }
public async Task <bool> TryActorAction(PublicId userId, string action) { var rate = await GetRateForUser(userId, action); var limit = await GetLimitForUser(userId, action); if (rate < limit) { await IncrementRateForUser(userId, action); return(true); } else { return(false); } }
private async Task <IActionResult> React(PublicId toId, ReactionType t) { var user = await GetCurrentUserAsync(); var reactionId = await _reactions.React(user.PublicId, toId, t); ViewData["PartialName"] = "Button/ReactButton"; return(View("_NoLayout", new ReactViewModel() { HasReacted = true, Enabled = true, ToId = toId, Type = t, ViewerId = user.UserId, Count = await _reactions.GetCount(toId, t), })); }
private async Task BindSqlExtra(ActivityDeliveryContext ctx, BaseObject bindTo) { if (bindTo.ViewerId.HasValue) { var viewerId = new PublicId(bindTo?.ViewerId.Value, 0); viewerId.Type = "Person"; var reactionsFilter = new ActivityStreamFilter("outbox") { id = viewerId, viewerId = bindTo?.ViewerId.Value, targetId = bindTo.PublicId, includeReplies = false, }.ReactionsOnly(); var reactionsBox = ctx.context.GetBox(reactionsFilter); bindTo.Reactions = await reactionsBox.Get(reactionsFilter); if (bindTo.Reactions.items.Count > 0) { var reactionTypes = bindTo.Reactions.items.Select(r => r.type).ToHashSet(); if (reactionTypes.Count > 0) { bindTo.HasLiked = reactionTypes.Contains(nameof(ReactionType.Like)); bindTo.HasDisliked = reactionTypes.Contains(nameof(ReactionType.Dislike)); bindTo.HasUpvoted = reactionTypes.Contains(nameof(ReactionType.Upvote)); bindTo.HasDownvoted = reactionTypes.Contains(nameof(ReactionType.Downvote)); bindTo.HasFollowed = reactionTypes.Contains(nameof(ReactionType.Follow)); bindTo.HasIgnored = reactionTypes.Contains(nameof(ReactionType.Ignore)); bindTo.HasBlocked = reactionTypes.Contains(nameof(ReactionType.Block)); bindTo.HasReported = reactionTypes.Contains(nameof(ReactionType.Report)); bindTo.HasBeenBlockedOrReportedByViewer = bindTo.HasReported || bindTo.HasBlocked; } } } var reactionsSummary = await _redis.Get <ReactionsSummaryModel>(bindTo.id); if (reactionsSummary != null) { bindTo.LikeCount = reactionsSummary.LikeCount; bindTo.DislikeCount = reactionsSummary.DislikeCount; bindTo.UpvoteCount = reactionsSummary.UpvoteCount; bindTo.DownvoteCount = reactionsSummary.DownvoteCount; bindTo.FollowCount = reactionsSummary.FollowCount; bindTo.IgnoreCount = reactionsSummary.IgnoreCount; bindTo.BlockCount = reactionsSummary.BlockCount; bindTo.ReportCount = reactionsSummary.ReportCount; } }
public async Task <ObjectContentModel> UploadObject(PublicId publisherId, BaseObject obj) { if (obj.from == null || obj.from.items.Count == 0) { throw new ArgumentException("Missing from in obj"); } var newObj = new ObjectContentModel { UserId = publisherId.Id.Value, Published = DateTime.UtcNow, Content = obj.content, Summary = obj.summary, Name = obj.name, MediaType = obj.mediaType, Visibility = Enum.TryParse(typeof(Visibility), (obj.audience ?? obj.to)?.items?.OfType <ActorObject>()?.FirstOrDefault()?.Handle, out var vis) ? (Visibility)vis : Visibility.VISIBLE_TO_WORLD, Deleted = obj.deleted, Updated = obj.updated, IsMature = obj.IsMature ?? false, AttachmentCSV = obj.attachment.ToCsv(), AttributedToCSV = obj.attributedTo.ToCsv(), AudienceCSV = obj.audience.ToCsv(), ContextCSV = obj.context.ToCsv(), IconCSV = obj.icon.ToCsv(), ImageCSV = obj.image.ToCsv(), InReplyToCSV = obj.inReplyTo.ToCsv(), LocationCSV = obj.location.ToCsv(), RepliesCSV = obj.replies.ToCsv(), FromCSV = obj.from.ToCsv(), TagCSV = obj.tag.ToCsv(), ToCSV = obj.to.ToCsv(), BtoCSV = obj.bto.ToCsv(), CcCSV = obj.cc.ToCsv(), BccCSV = obj.bcc.ToCsv(), }; var list = GetHandleList(obj.type) ?? throw new ArgumentOutOfRangeException(nameof(obj.type), obj.type, "Invalid type"); await list.AddAsync(newObj); await _db.SaveChangesAsync(); obj.PeerId = publisherId.PeerId; obj.PublicId.UserId = publisherId.Id; obj.objectId = newObj.Id; obj.published = newObj.Published; return(newObj); }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (ResellerCloudIdentityId.Length != 0) { hash ^= ResellerCloudIdentityId.GetHashCode(); } if (LinkState != global::Google.Cloud.Channel.V1.ChannelPartnerLinkState.Unspecified) { hash ^= LinkState.GetHashCode(); } if (InviteLinkUri.Length != 0) { hash ^= InviteLinkUri.GetHashCode(); } if (createTime_ != null) { hash ^= CreateTime.GetHashCode(); } if (updateTime_ != null) { hash ^= UpdateTime.GetHashCode(); } if (PublicId.Length != 0) { hash ^= PublicId.GetHashCode(); } if (channelPartnerCloudIdentityInfo_ != null) { hash ^= ChannelPartnerCloudIdentityInfo.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public string ToPath(PublicId focus) { var str = string.Empty; if (id != null) { if (!string.IsNullOrWhiteSpace(str)) { str += "/"; } str += id; } if (!string.IsNullOrWhiteSpace(index)) { if (!string.IsNullOrWhiteSpace(str)) { str += "/"; } str += index; } if (focus != null) { if (focus.IsGuid) { return($"{str}/{focus.AsGuid()}.json"); } else if (focus.PeerId.HasValue) { return($"{str}/{focus.PeerId}-{focus.Id}.json"); } else { return($"{str}/{focus.Id}.json"); } } else { return($"{str}.index"); } }
public async Task Save(List <TagModel> tags, int userId, PublicId toId) { //var val = await _redis.GetDatabase().StringGetAsync(new RedisKey[] { "", "" }); //return //val.FirstOrDefault().IsInteger ? int.Parse(val.FirstOrDefault().ToString()) : 0; // DbSet<TaggedModel> src = null; // switch (subject) // { // case ReactionSubject.ArchivedMedia: // src = _dbContext.ArchivedMediaTags; // break; // case ReactionSubject.Post: // src = _dbContext.PostTags; // break; // case ReactionSubject.Profile: // src = _dbContext.ProfileTags; // break; // case ReactionSubject.Shop: // src = _dbContext.ShopTags; // break; // default: // break; // } // var alreadyTaggedIds = await src.Where(t => t.ToId == toId && t.UserId == userId).ToDictionaryAsync(k => k.TagId, v => v); // var taggeds = tags.Where(t => !alreadyTaggedIds.ContainsKey(t.Id)).Select(t => new TaggedModel() { TagId = t.Id, ToId = toId, UserId = userId, WhenCreated = DateTime.UtcNow }).ToList(); // var noLongerTagged = new List<TaggedModel>(); // foreach (var noLongerTaggedId in alreadyTaggedIds.Keys.Except(tags.Select(t => t.Id))) // { // noLongerTagged.Add(alreadyTaggedIds[noLongerTaggedId]); // } // if (taggeds.Count > 0) // { // await src.AddRangeAsync(taggeds); // } // if (noLongerTagged.Count > 0) // { // src.RemoveRange(noLongerTagged); // } }
public void SemanticVersionDTOIsEquivalentTest() { { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO; Assert.True(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { PublicId = new PublicId(Misc.other) }; Assert.False(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { StampDTO = Misc.CreateStampDTO with { StatusPublicId = new PublicId(Misc.g2) } }; Assert.False(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { Fields = new Object[] { 1, "abcdef" }.ToImmutableArray() }; Assert.False(a.IsEquivalent(b)); } }
public void FieldCompareTest() { { Assert.True(FieldCompare.Same("abc", "abc")); Assert.False(FieldCompare.Same("abc", "abcd")); } { Assert.True(FieldCompare.Same(0, 0)); Assert.False(FieldCompare.Same(0, 1)); } { Assert.True(FieldCompare.Same(0.1F, 0.1F)); Assert.False(FieldCompare.Same(0.0F, 1.0F)); } { Assert.True(FieldCompare.Same(true, true)); Assert.False(FieldCompare.Same(true, false)); } { Assert.True(FieldCompare.Same(new DateTime(2020, 1, 1), new DateTime(2020, 1, 1))); Assert.False(FieldCompare.Same(new DateTime(2020, 1, 1), new DateTime(2020, 2, 1))); } { Assert.True(FieldCompare.Same(new byte[] { 1, 2, 3 }, new byte[] { 1, 2, 3 })); Assert.False(FieldCompare.Same(new byte[] { 1, 2, 3 }, new byte[] { 1, 3, 2 })); } { Assert.True(FieldCompare.Same(Misc.CreateConceptChronologyDTO, Misc.CreateConceptChronologyDTO)); Assert.False(FieldCompare.Same( Misc.CreateConceptChronologyDTO, Misc.CreateConceptChronologyDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }));
public void SemanticVersionDTOCompareToTest() { { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO; Assert.True(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { StampDTO = Misc.CreateStampDTO with { StatusPublicId = new PublicId(Misc.g2) } }; Assert.False(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { Fields = new Object[] { 1, "abcdef" }.ToImmutableArray() }; Assert.False(a.CompareTo(b) == 0); } }