using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.opentext.api;
namespace StressTest
{
class CreateDocument
{
//class member functions
[STAThread]
static void Main(string[] args)
{
try
{
//
if (args.Length == 0 )
{
Console.WriteLine("Expecting unique argument such as 'One','two','three'");
Console.ReadLine();
return;
}
//Create a new Livelink Session
//PUT YOUR LLSERVER DETAILS HERE
LLSession session = null;
session = new LLSession("servername", 2099, "", "Admin", "adminpassword", null);
//Initialize any LAPI Objects
LAPI_DOCUMENTS doc = new LAPI_DOCUMENTS(session);
//////////////////////////////////////////////////////////////////////
//Code to Create a Document
//////////////////////////////////////////////////////////////////////
//Define the parent object's dataID and volumeID (also called ownerID)
LLValue entInfo = (new LLValue()).setAssocNotSet();
if (doc.AccessEnterpriseWS(entInfo) != 0)
{
GetErrors(session);
return;
}
//create the output variable objectInfo, which will contain the object's information
LLValue objectInfo = (new LLValue()).setAssocNotSet();
//Setup any information for creation
LLValue createInfo = (new LLValue()).setAssocNotSet();
LLValue request = (new LLValue()).setAssocNotSet();
request.add("Comment", "These are the document's comments.");
createInfo.add("request", request);
//Create the document object in Livelink
if (doc.CreateObjectEx(0, entInfo.toInteger("ID"), LAPI_DOCUMENTS.OBJECTTYPE, LAPI_DOCUMENTS.FOLDERSUBTYPE, "Stress Test Folder-"+args[0], createInfo, objectInfo) != 0)
{
GetErrors(session);
return;
}
else
Console.WriteLine("Folder Created.");
//rteain folderid for subsequent operation
int folderid = objectInfo.toInteger("ID");
for (int i = 0; i < 100; i++)
{
//Create the document object in Livelink
if (doc.CreateObjectEx(0, folderid, LAPI_DOCUMENTS.OBJECTTYPE, LAPI_DOCUMENTS.DOCUMENTSUBTYPE, "SAMPLE PDF_" + i.ToString(), createInfo, objectInfo) != 0)
{
GetErrors(session);
return;
}
else
Console.WriteLine("Document Object Created.");
//create the output variable versionInfo, which will contain the version's information
LLValue versionInfo = (new LLValue()).setAssocNotSet();
//Add a version to the document object
if (doc.CreateVersion(0, objectInfo.toInteger("ID"), "c:\\temp\\sample.pdf", versionInfo) != 0)
{
GetErrors(session);
return;
}
else
Console.WriteLine("Version Created.");
//////////////////////////////////////////////////////////////////////
}
}
catch (Exception e)
{
Console.WriteLine("Application encountered an exception:");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.ReadLine();
}
}
//This function outputs any errors from the session
static void GetErrors(LLSession session)
{
// Get the error information
int stat = session.getStatus();
string message = session.getStatusMessage();
string errMsg = session.getErrMsg();
string apiError = session.getApiError();
Console.WriteLine("Session failure status is " + stat +
" (0x" + Convert.ToString(stat) + ")");
if (message != "" || errMsg != "" || apiError != "")
{
Console.WriteLine("Message=" + message);
Console.WriteLine("errMsg=" + errMsg);
Console.WriteLine("apiError=" + apiError);
}
Console.ReadLine();
}
}
}