-
Notifications
You must be signed in to change notification settings - Fork 0
/
CEUtil.cs
108 lines (94 loc) · 3.41 KB
/
CEUtil.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
// #define P8_451 // Define this in Project, Build, Conditional Compilation Settings
using System;
using System.Collections;
#if P8_451
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
#elif P8_511
using FileNet.Api.Authentication;
#else
#error Must define one of P8_451 or P8_511
#endif
using FileNet.Api.Action;
using FileNet.Api.Admin;
using FileNet.Api.Meta;
using FileNet.Api.Collection;
using FileNet.Api.Constants;
using FileNet.Api.Core;
using FileNet.Api.Property;
using FileNet.Api.Query;
using FileNet.Api.Util;
namespace WindowsFormsApplication1
{
class CEUtil
{
private static CEUtil gCEUtil;
private static IConnection conn;
private static IDomain domain;
private static IObjectStore objStore;
private static bool isCredentialsEstablished;
private const int MAX_RESULTS = 20;
public delegate void LogMsg(string msg);
private LogMsg logMsg;
private CEUtil(string ceUri, string osName, string ceUser, string password, LogMsg logMsg)
{
#if (P8_451)
// P8 4.5 authentication
UsernameToken token = new UsernameToken(ceUser, password, PasswordOption.SendPlainText);
UserContext.SetProcessSecurityToken(token);
#else
// P8 5.0 authentication
UsernameCredentials cred = new UsernameCredentials(ceUser, password);
ClientContext.SetProcessCredentials(cred);
#endif
conn = Factory.Connection.GetConnection(ceUri);
isCredentialsEstablished = true;
// Get domain name
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(0, null, null, "Name", null);
pf.AddIncludeProperty(0, null, null, "Id", null);
domain = Factory.Domain.FetchInstance(conn, null, null);
objStore = Factory.ObjectStore.FetchInstance(domain, osName, null);
// Successfully initialized CEUtil object: save singleton instance
this.logMsg = logMsg;
gCEUtil = this;
}
public void Close()
{
gCEUtil = null;
}
public IDomain Domain
{
get { return domain; }
}
public string DomainName
{
get { return domain.Name; }
}
public static CEUtil GetInstance (string ceUri, string osName, string ceUser, string password, LogMsg logMsg)
{
// Singleton
if (gCEUtil == null)
gCEUtil = new CEUtil (ceUri, osName, ceUser, password, logMsg);
return gCEUtil;
}
public bool IsCredentialsEstablished
{
get { return isCredentialsEstablished; }
}
public IDocumentSet queryDocs(string sSql, int maxRecords, int pageSize)
{
logMsg("mkQuery(" + sSql + "), maxRecords=" + maxRecords + ", batchSize=" + pageSize + "...");
SearchScope search = new SearchScope(objStore);
SearchSQL searchSql = new SearchSQL();
if (maxRecords > 0)
searchSql.SetMaxRecords(maxRecords);
// This must be done separately in order to call SetMaxRecords() etc
searchSql.SetQueryString(sSql);
IDocumentSet documents =
(IDocumentSet)search.FetchObjects(searchSql, pageSize, null, true);
return documents;
}
}
}