31.10.2014 Views

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

50 | Developer’s <strong>Guide</strong> <strong>EPiServer</strong> Community 3.1<br />

2.13 ConnectionLink<br />

ConnectionLink uses data from StarCommunity.Modules.Contact and performs Breadth First Search (BFS) algorithms to<br />

decide the shortest path between 2 users.<br />

2.13.1 Getting the Shortest Path<br />

Use the ConnectionLinkHandler to get aUserCollection containing userA and the users representing the shortest path<br />

to userB based on contact relations.<br />

Import Necessary Namespaces<br />

First import the necessary namespaces that will be used to manage the connection link and users. The namespace<br />

StarCommunity.Modules.ConnectionLink, StarCommunity.Core and StarCommunity.Core.Modules.Security is described<br />

by clicking on their names. Make sure you add the assemblies as a reference, mentioned in Setting up Visual Studio.<br />

using StarCommunity.Core;<br />

using StarCommunity.Core.Modules.Security;<br />

using StarCommunity.Modules.ConnectionLink;<br />

Get the two users, userA and userB, to compare.<br />

//Get the userA and userB by id<br />

IUser userA =<br />

(IUser)StarCommunitySystem.CurrentContext.DefaultSecurity.GetUser(1234);<br />

IUser userB =<br />

(IUser)StarCommunitySystem.CurrentContext.DefaultSecurity.GetUser(1235);<br />

Get the UserCollection with the users representing the shortest path from userA to userB<br />

UserCollection connections =<br />

ConnectionLinklHandler.GetShortestPath( userA, userB );<br />

2.14 Contact<br />

Management of contacts is done through the ContactHandler class in the StarCommunity.Contact namespace. The<br />

connection between the user and its contact relations is done via the ContactContainer class. However, a<br />

ContactContainer is created automatically for a user upon user creation, for each site in the system, and it is normally<br />

not done by the developer.<br />

2.14.1 Adding a Contact Relation<br />

To add a ContactRelation, first create an instance of the ContactRelation class (there are several constructors available).<br />

The ContactRelation constructor needs the ContactContainer for the user that is adding the contact relation (userA),<br />

the user to be added to the contact list (userB) and a ContactType. The contact type can be either<br />

ContactType.Request or ContactType.Contact.ContactType.Request is used when the contact relation must be<br />

approved by userB and ContactType.Contact is used when the contact relation should come into effect immediately.<br />

© <strong>EPiServer</strong> AB

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!