Sample - Relationship Service

Version 2

    Versions: 2.1.2 - current

    Product Availability: ArcFM for Silverlight SDK

    Customization Type: Client-Side

     

    Custom relationships allow you to retrieve external data associated with features or rows in the geodatabase and display this data as relationships. For example, customer data is often stored in a separate database. Those customer records do not participate in geodatabase relationships, but they still need to be associated with features. The IRelationshipService interface allows you to define these custom relationships. The source of the relationship can be anything (e.g., web service, RDBMS, XML).

     

    This developer sample illustrates how to implement the IRelationshipService interface to bring in custom data and display it as a relationship for a particular feature class. It uses three sources for the custom relationship: Customer.xml, Service.xml, and Relationships.xml. In the GetRelationshipsAsync method, this implementation pulls the relationship ID and related table ID from Relationships.xml, Customer Name and Account ID from Customer.xml, and the Service Address from Service.xml. Then it concatenates the data and displays it.

         

    Note: The Attribute Viewer always instantiates a new instance of the custom relationship service. This is so that it can handle multiple, asynchronous requests, but it means that the developer cannot store state in the implementation. The correct pattern here is to inherit the relationship information class to include whatever data the relationship service requires (e.g., database connection info). This relationship information will be passed in on each call to GetRelationshipsAsync, along with an array of the ObjectIDs and a spatial reference.

    How to Implement:

    1. Open the ArcFMSilverlight solution and connect any broken references.
    2. In MainPage.xaml.cs, locate the following:

    // * CUSTOM RELATIONSHIP CODE to add custom relationships to Service points *//
    int layerForCustomRelationships = 13;

    IRelationshipService service = new CustomRelationshipService();

    IEnumerable<IResultSet> rsEnumerable = e.Results.Where(result => result.ID == layerForCustomRelationships);

    if (rsEnumerable.Count() > 0) rsEnumerable.First().RelationshipService = service;

    // * * //

    1. Change the layerForCustomRelationships to equal your REST Service Point layer ID.
          LayerID_RelationshipService.png
    2. Under ArcFMSilverlight.Web, open Page.config and locate the following:

    <Layer MapServiceName="Electric" Url="http://ServerName/arcgis/rest/services/Electric/MapServer"
      Visible
    ="True" Type="ArcGISDynamicMapServiceLayer"/>

       </Layers>

      <!--configuration section that handles related data-->

      <RelatedData>

       <Path LayerId="13" Url="http://ServerName/arcgis/rest/services/Electric/MapServer" RelationshipIds="34" />

      </RelatedData>

    1. Change the Urls to point to your REST service.
    2. Change the LayerId to match the layerForCustomRelationships Service Point layer ID from step 3.
    3. Change the RelationshipIds to any whole number (999, 1234, 2012, etc.).
    4. Open Relationships.xml and locate the following:

    <Relationship>

       <Name>

      CustomerInfo

       </Name>

       <LayerId>

      16

       </LayerId>

       <RelationshipId>

      48

       </RelationshipId>

       <RelatedTableId>

      50

       </RelatedTableId>

      </Relationship>

    1. Change the LayerID to match the layerForCustomRelationships Service Point layer ID (from steps 3 and 6).
    2. Change the RelationshipId to match the RelationshipsIds number created in step 7.
    3. Change the RelatedTableId to any whole number that is not used for the other ID values (777, 411, 1776, etc.).
    4. Open CustomRelationshipService.cs and locate the following:

    public CustomRelationshipService()

      {

       // Two related tables as embedded resources
      _tableNames.Add(0,"Relationships.xml");

      _tableNames.Add(13, "Service.xml");

      _tableNames.Add(34, "Customer.xml");

       foreach (var xml in _tableNames.Values)

      {

       string name = Assembly.GetExecutingAssembly().FullName;

    1. Change the _tableNames.Add(13, "Service.xml") to match the layerForCustomRelationships Service Point layer ID (from steps 3 and 6). For example, _tableNames.Add(16, "Service.xml").
    2. Change the _tableNames.Add(34, "Customer.xml") to match the RelationshipsIds number created in step 11. For example, _tableNames.Add(1776, "Customer.xml").
    3. Build the solution.
    4. Right-click ArcFMSilverlight.Web and select Set as StartUp Project.
    5. Right-click ArcFMSilverlightTestPage.aspx and select Set as Start Page.
    6. Run the solution to view results.

                 

    To view results outside of Visual Studio:

    1. Right-click ArcFMSilverlight.Web and select Publish.
    2. Select a Publish method of File System
    3. Set a target location (such as C:\inetpub\wwwroot\CustomRelationships) to store the .aspx file.
    4. Click Publish.
    5. Open a browser and enter the .aspx address (such as http://localhost/CustomRelationships/ArcFMSilverlightTestPage.aspx) to view the results.

     

    CustomerInformation.png  

     

     

    Requires:

    All of the files shown below are required for the project to compile successfully.

     

    FileDescription
    Customer.xmlXML that represents a table named Customer.
    CustomRelationshipService.csThe class module that implements IRelationshipService.
    MainPage.xaml and MainPage.xaml.csThe XAML and C# code for the control.
    Relationships.xmlXML that represents the relationship between LayerID and RelationshipID.
    Service.xmlXML that represents a table named Service.
    App.xaml and App.xaml.csContains resources
    AssemblyInfo.csAssembly metadata
    ConfigUtility.csCode that loads from Page.config
    DelegateCommand.csContains button information
    Extents.csControls previous and next extents