The following C# code example creates a relationship between
two resources in the LiveCycle repository. (See Creating Resource Relationships.)
/*
* Ensure that you create a .NET client assembly that uses
* base64 encoding. This is required to populate a BLOB
* object with data or retrieve data from a BLOB object.
*
* For information, see "Invoking LiveCycle using Base64 Encoding"
* in Programming with LiveCycle
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
namespace RepositoryWebService
{
class CreateRelationship
{
[STAThread]
static void Main(string[] args)
{
try
{
//Create a RepositoryServiceService object
RepositoryServiceService repositoryClient = new RepositoryServiceService();
repositoryClient.Credentials = new System.Net.NetworkCredential("administrator", "password");
// Specify the URI of the target folder for writing the resource
String testFolderUri = "/Applications/FormsApplication/1.0/FormsFolder";
// Create the 2 resources to be written to the folder
Resource testResource1 = new Resource();
testResource1.id = new Id();
testResource1.lid = new Lid();
testResource1.name = "FormFolderC";
testResource1.description = "test resource1";
Resource testResource2 = new Resource();
testResource2.id = new Id();
testResource2.lid = new Lid();
testResource2.name = "FormFolderD";
testResource1.description = "test resource2";
// Write the resources to the folder
repositoryClient.writeResource(testFolderUri, testResource1, null, null);
repositoryClient.writeResource(testFolderUri, testResource2, null, null);
// Retrieve the resources' URIs
String resourceUri1 = testFolderUri + "/" + testResource1.name;
String resourceUri2 = testFolderUri + "/" + testResource2.name;
// Retrieve the resources to verify that they were successfully written
Resource r1 = repositoryClient.readResource(resourceUri1, null, null);
Resource r2 = repositoryClient.readResource(resourceUri2, null, null);
// Create a relationship between the two resources
repositoryClient.createRelationship(
resourceUri1,
resourceUri2,
3,
true,
null
);
// Verify the relationship
int[] relationshipTypes = new int[1];
relationshipTypes[0] = 3;
object[] relations = repositoryClient.getRelated(
resourceUri1,
true,
relationshipTypes,
false,
false,
false,
true,
null,
null);
// Print the relationship
for (int i = 0; i < relations.Length; i++)
{
Resource r = (Resource)(relations[i]);
Console.WriteLine("Related resource: " + r.name);
}
}
catch (Exception e)
{
Console.WriteLine(
"Exception thrown while trying to create the relationship" +
e.Message
);
}
}
}
}
|
|
|