Skip to content

Commit

Permalink
Add ./src/Agni/Social
Browse files Browse the repository at this point in the history
  • Loading branch information
itadapter committed Jun 3, 2018
1 parent e3d4546 commit a9d8680
Show file tree
Hide file tree
Showing 115 changed files with 9,189 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Agni.Social/Agni.Social.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Agni OS Social Network Assembly</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\out\Debug\</OutputPath>
<DocumentationFile>..\..\out\Debug\Agni.Social.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\out\Release\</OutputPath>
<DocumentationFile>..\..\out\Release\Agni.Social.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="$(ProjectDir)pre-build $(SolutionDir) $(ConfigurationName)" />
</Target>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="$(ProjectDir)post-build $(SolutionDir) $(ConfigurationName)" />
</Target>

<ItemGroup>
<ProjectReference Include="..\Agni\Agni.csproj" />
</ItemGroup>


<ItemGroup>
<Reference Include="NFX">
<HintPath>..\lib\nfx\NFX.dll</HintPath>
</Reference>
<Reference Include="NFX.Wave">
<HintPath>..\lib\nfx\NFX.Wave.dll</HintPath>
</Reference>
<Reference Include="NFX.Web">
<HintPath>..\lib\nfx\NFX.Web.dll</HintPath>
</Reference>
</ItemGroup>


<ItemGroup>
<EmbeddedResource Include="BUILD_INFO.txt" />
<EmbeddedResource Include="Graph\Server\Data\Scripts\**" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions src/Agni.Social/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

using NFX;

namespace Agni.Social
{
/// <summary>
/// Base exception thrown by the social framework
/// </summary>
[Serializable]
public class SocialException : AgniException
{
public SocialException() : base() { }
public SocialException(int code) : base(code) { }
public SocialException(int code, string message) : base(code, message) { }
public SocialException(string message) : base(message) { }
public SocialException(string message, Exception inner) : base(message, inner) { }
public SocialException(string message, Exception inner, int code, string sender, string topic) : base(message, inner, code, sender, topic) { }
protected SocialException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}
221 changes: 221 additions & 0 deletions src/Agni.Social/Graph/Client/GraphCommentManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Agni.Coordination;
using NFX.DataAccess.Distributed;

namespace Agni.Social.Graph
{
public sealed class GraphCommentManager : GraphCommentManagerBase
{
public GraphCommentManager(HostSet hostSet) : base(hostSet)
{
}

public override Comment Create(GDID gAuthorNode, GDID gTargetNode, string dimension, string content, byte[] data,
PublicationState publicationState, RatingValue rating = RatingValue.Undefined, DateTime? epoch = null)
{
var pair = HostSet.AssignHost(gTargetNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, Comment>(
commentSystem => commentSystem.Create(gAuthorNode, gTargetNode, dimension, content, data, publicationState, rating, epoch),
pair.Select(host => host.RegionPath)
);
}

public override Comment Respond(GDID gAuthorNode, CommentID parent, string content, byte[] data)
{
var pair = HostSet.AssignHost(parent.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, Comment>(
commentSystem => commentSystem.Respond(gAuthorNode, parent, content, data),
pair.Select(host => host.RegionPath)
);
}

public override GraphChangeStatus Update(CommentID ratingId, RatingValue value, string content, byte[] data)
{
var pair = HostSet.AssignHost(ratingId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, GraphChangeStatus>(
commentSystem => commentSystem.Update(ratingId, value, content, data),
pair.Select(host => host.RegionPath)
);
}

public override GraphChangeStatus DeleteComment(CommentID commentId)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, GraphChangeStatus>(
commentSystem => commentSystem.DeleteComment(commentId),
pair.Select(host => host.RegionPath)
);
}

public override GraphChangeStatus Like(CommentID commentId, int deltaLike, int deltaDislike)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, GraphChangeStatus>(
commentSystem => commentSystem.Like(commentId, deltaLike, deltaDislike),
pair.Select(host => host.RegionPath)
);
}

public override bool IsCommentedByAuthor(GDID gNode, GDID gAuthor, string dimension)
{
var pair = HostSet.AssignHost(gNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, bool>(
commentSystem => commentSystem.IsCommentedByAuthor(gNode, gAuthor, dimension),
pair.Select(host => host.RegionPath)
);
}

public override IEnumerable<SummaryRating> GetNodeSummaries(GDID gNode)
{
var pair = HostSet.AssignHost(gNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, IEnumerable<SummaryRating>>(
commentSystem => commentSystem.GetNodeSummaries(gNode),
pair.Select(host => host.RegionPath)
);
}

public override IEnumerable<Comment> Fetch(CommentQuery query)
{
var pair = HostSet.AssignHost(query.G_TargetNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, IEnumerable<Comment>>(
commentSystem => commentSystem.Fetch(query),
pair.Select(host => host.RegionPath)
);
}

public override IEnumerable<Comment> FetchResponses(CommentID commentId)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, IEnumerable<Comment>>(
commentSystem => commentSystem.FetchResponses(commentId),
pair.Select(host => host.RegionPath)
);
}

public override IEnumerable<Complaint> FetchComplaints(CommentID commentId)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, IEnumerable<Complaint>>(
commentSystem => commentSystem.FetchComplaints(commentId),
pair.Select(host => host.RegionPath)
);
}

public override Comment GetComment(CommentID commentId)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, Comment>(
commentSystem => commentSystem.GetComment(commentId),
pair.Select(host => host.RegionPath)
);
}

public override GraphChangeStatus Complain(CommentID commentId, GDID gAuthorNode, string kind, string message)
{
var pair = HostSet.AssignHost(commentId.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, GraphChangeStatus>(
commentSystem => commentSystem.Complain(commentId, gAuthorNode, kind, message),
pair.Select(host => host.RegionPath)
);
}

public override GraphChangeStatus Justify(CommentID commentID)
{
var pair = HostSet.AssignHost(commentID.G_Volume);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphCommentSystemClient, GraphChangeStatus>(
commentSystem => commentSystem.Justify(commentID),
pair.Select(host => host.RegionPath)
);
}
}
/// <summary>
/// Заглушка для интерфейса IGraphCommentSystem на клиенте
/// </summary>
public sealed class NOPGraphCommentManager : GraphCommentManagerBase
{
public NOPGraphCommentManager(HostSet hostSet) : base(hostSet)
{
}

public override Comment Create(GDID gAuthorNode, GDID gTargetNode, string dimension, string content, byte[] data,
PublicationState publicationState, RatingValue rating = RatingValue.Undefined, DateTime? epoch = null)
{
return default(Comment);
}

public override Comment Respond(GDID gAuthorNode, CommentID parent, string content, byte[] data)
{
return default(Comment);
}

public override GraphChangeStatus Update(CommentID ratingId, RatingValue value, string content, byte[] data)
{
return GraphChangeStatus.NotFound;
}

public override GraphChangeStatus DeleteComment(CommentID commentId)
{
return GraphChangeStatus.NotFound;
}

public override GraphChangeStatus Like(CommentID commentId, int deltaLike, int deltaDislike)
{
return GraphChangeStatus.NotFound;
}

public override bool IsCommentedByAuthor(GDID gNode, GDID gAuthor, string dimension)
{
return false;
}

public override IEnumerable<SummaryRating> GetNodeSummaries(GDID gNode)
{
yield break;
}

public override IEnumerable<Comment> Fetch(CommentQuery query)
{
yield break;
}

public override IEnumerable<Comment> FetchResponses(CommentID commentId)
{
yield break;
}

public override IEnumerable<Complaint> FetchComplaints(CommentID commentId)
{
yield break;
}

public override Comment GetComment(CommentID commentId)
{
return default(Comment);
}

public override GraphChangeStatus Complain(CommentID commentId, GDID gAuthorNode, string kind, string message)
{
return GraphChangeStatus.NotFound;
}

public override GraphChangeStatus Justify(CommentID commentID)
{
return GraphChangeStatus.NotFound;
}
}
}
83 changes: 83 additions & 0 deletions src/Agni.Social/Graph/Client/GraphEventManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Agni.Coordination;
using NFX.DataAccess.Distributed;

namespace Agni.Social.Graph
{
public sealed class GraphEventManager : GraphEventManagerBase
{
public GraphEventManager(HostSet hostSet) : base(hostSet)
{
}

public override void EmitEvent(Event evt)
{
var pair = HostSet.AssignHost(evt.G_EmitterNode);
Contracts.ServiceClientHub
.CallWithRetry<IGraphEventSystemClient>(eventSystem => eventSystem.EmitEvent(evt), pair.Select(host => host.RegionPath));
}

public override void Subscribe(GDID gRecipientNode, GDID gEmitterNode, byte[] parameters)
{
var pair = HostSet.AssignHost(gEmitterNode);
Contracts.ServiceClientHub
.CallWithRetry<IGraphEventSystemClient>(eventSystem => eventSystem.Subscribe(gRecipientNode, gEmitterNode, parameters), pair.Select(host => host.RegionPath));
}

public override void Unsubscribe(GDID gRecipientNode, GDID gEmitterNode)
{
var pair = HostSet.AssignHost(gEmitterNode);
Contracts.ServiceClientHub
.CallWithRetry<IGraphEventSystemClient>(eventSystem => eventSystem.Unsubscribe(gRecipientNode, gEmitterNode), pair.Select(host => host.RegionPath));
}

public override long EstimateSubscriberCount(GDID gEmitterNode)
{
var pair = HostSet.AssignHost(gEmitterNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphEventSystemClient, long>(eventSystem => eventSystem.EstimateSubscriberCount(gEmitterNode), pair.Select(host => host.RegionPath));
}

public override IEnumerable<GraphNode> GetSubscribers(GDID gEmitterNode, long start, int count)
{
var pair = HostSet.AssignHost(gEmitterNode);
return Contracts.ServiceClientHub
.CallWithRetry<IGraphEventSystemClient, IEnumerable<GraphNode>>(eventSystem => eventSystem.GetSubscribers(gEmitterNode, start, count), pair.Select(host => host.RegionPath));
}
}

/// <summary>
/// Заглушка для интерфейса IGraphEventSystem на клиенте
/// </summary>

public sealed class NOPGraphEventManager : GraphEventManagerBase
{
public NOPGraphEventManager(HostSet hostSet) : base(hostSet)
{
}

public override void EmitEvent(Event evt)
{
}

public override void Subscribe(GDID gRecipientNode, GDID gEmitterNode, byte[] parameters)
{
}

public override void Unsubscribe(GDID gRecipientNode, GDID gEmitterNode)
{
}

public override long EstimateSubscriberCount(GDID gEmitterNode)
{
return 0;
}

public override IEnumerable<GraphNode> GetSubscribers(GDID gEmitterNode, long start, int count)
{
yield break;
}
}
}
Loading

0 comments on commit a9d8680

Please sign in to comment.