-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGraphHost.cs
153 lines (121 loc) · 5.46 KB
/
GraphHost.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using NFX;
using NFX.ApplicationModel;
using NFX.Environment;
using NFX.DataAccess.CRUD;
using Agni.Social.Graph.Server.Data;
namespace Agni.Social.Graph.Server
{
/// <summary>
/// Provides hosting API for the graph system in the particular business system scope
/// </summary>
public abstract class GraphHost : ApplicationComponent, IConfigurable
{
protected GraphHost(GraphOperationContext director, IConfigSectionNode config) : base(director)
{
ConfigAttribute.Apply(this, config);
}
/// <summary>
/// Limits the number of responses to comments
/// </summary>
public abstract int MaxResponseForComment { get; }
/// <summary>
/// Perform actual work of event delivery.
/// Returns true if event was (scheduled-to be) delivered
/// </summary>
public bool DeliverEvent(GraphNode nodeRecipient, GraphNode nodeSender, Event evt, string subscriptionParameters)
{
return DoDeliverEvent(nodeRecipient, nodeSender, evt, subscriptionParameters);
}
//filter event batch start
//filter event recipient
//filter event batch end
public void Configure(IConfigSectionNode node)
{
DoConfigure(node);
}
/// <summary>
/// Convert binary data to Row Node
/// </summary>
public abstract TypedRow NodeBinaryDataToObject(string nodeType, byte[] data);
/// <summary>
/// Convert Row Node to binary data
/// </summary>
public abstract byte[] ObjectToNodeBinaryData(string nodeType, TypedRow data);
/// <summary>
/// Filter by query
/// </summary>
public abstract IEnumerable<GraphNode> FilterByOriginQuery(IEnumerable<GraphNode> data, string orgQry);
/// <summary>
///
/// </summary>
public abstract IEnumerable<SubscriberRow> FilterEventsChunk(IEnumerable<SubscriberRow> subscribersChunk, Event evt, IConfigSectionNode cfg);
/// <summary>
/// This function must not leak exceptions
/// Returns the subscriptions that could not be delivered now - the system will try to redeliver them later asynchronously
/// </summary>
public abstract IEnumerable<SubscriberRow> DeliverEventsChunk(IEnumerable<SubscriberRow> filtered, Event evt, IConfigSectionNode cfg);
/// <summary>
/// Returns true if specified node types can be friends in the specified direction.
/// Keep in mind that friendship is bidirectional so this method only checks the initiating party
/// </summary>
public abstract bool CanBeFriends(string fromNodeType, string toNodeType);
/// <summary>
/// Returns true if specified node types can be subscribed
/// </summary>
public abstract bool CanBeSubscribed(string subscriberNodeType, string emitterNodeType);
#region Graph comment
/// <summary>
/// Returns true if specified node type can rate other nodes
/// </summary>
public abstract bool CanBeRatingActor(string ratingNodeType, string dimension);
/// <summary>
/// Returns true if the specified node type requires rating for the specified dimension
/// </summary>
public abstract bool CommentRatingRequired(string ratedNodeType, string dimension);
/// <summary>
/// Returns a span of time within which a comment can be edited
/// </summary>
public abstract TimeSpan EditCommentSpan(GraphNode targetNode, string dimension);
/// <summary>
/// Returns true if authorNode can create new comment of specified targetNode as of commentDate and
/// if rating value can be applied
/// </summary>
public virtual bool CanCreateComment(GraphNode authorNode,
GraphNode targetNode,
string dimension,
DateTime commentDate,
RatingValue rating)
{
var ratingRequired = CommentRatingRequired(targetNode.NodeType, dimension);
if (ratingRequired && rating == RatingValue.Undefined)
return false;
if (ratingRequired && !CanBeRatingActor(authorNode.NodeType, dimension))
return false;
return DoCanCreateComment(authorNode, targetNode, dimension, commentDate, rating);
}
/// <summary>
/// Returns true if authorNode can create a response to the specified comment as of commentDate and
/// if rating value can be applied
/// </summary>
public virtual bool CanCreateCommentResponse(Comment parent, GraphNode authorNode, DateTime responseDate)
{
if (parent.ResponseCount > MaxResponseForComment) return false;
return DoCanCreateCommentResponse(parent, authorNode, responseDate);
}
/// <summary>
/// A hook invoked upon physical deletion of comment
/// </summary>
public abstract void DeleteComment(GraphNode authorNode, CommentID comment);
#endregion
protected abstract void DoConfigure(IConfigSectionNode node);
protected abstract bool DoDeliverEvent(GraphNode nodeRecipient, GraphNode nodeSender, Event evt, string subscriptionParameters);
protected abstract bool DoCanCreateComment(GraphNode authorNode,
GraphNode targetNode,
string dimension,
DateTime commentDate,
RatingValue rating);
protected abstract bool DoCanCreateCommentResponse(Comment parent, GraphNode authorNode, DateTime responseDate);
}
}