This repository was archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
207 lines (178 loc) · 7.1 KB
/
Program.cs
File metadata and controls
207 lines (178 loc) · 7.1 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
// Namespace reference to unmanaged COM library
using Com.Interwoven.WorkSite.iManage;
namespace Multi_Threaded_Search
{
[GuidAttribute("8EF40B19-7E64-4703-A2AE-809F7AF67924"), ComVisible(true)]
class SortWorkspaceClass : IManObjectSort
{
public bool Less(IManObject obj1, IManObject obj2)
{
IManWorkspace work1 = (IManWorkspace)obj1, work2 = (IManWorkspace)obj2;
if (String.Compare(work1.Name.ToString(), work2.Name.ToString(), true) < 0) // int Compare(string strA, string strB, bool ignoreCase)
return true;
else
return false;
}
}
class Program
{
const string strServer = "win2012svr",
strUsername = "wsadmin",
strPassword = "mhdocs_",
strDatabase = "Cheapside";
private IManDMS _objDMS;
private IManSession _objSession;
private IManDatabase _objDatabase;
public Program()
{
_objDMS = new ManDMS();
_objSession = _objDMS.Sessions.Add(strServer);
_objSession.Login(strUsername, strPassword);
_objSession.MaxRowsForSearch = 1000;
_objSession.MaxRowsNonSearch = 500;
_objDatabase = _objSession.PreferredDatabase;
}
public IManDMS getDMS
{
get
{
return _objDMS;
}
set
{
}
}
public IManSession getSession
{
get
{
return _objSession;
}
set
{
}
}
public IManDatabase getDatabase
{
get
{
return _objDatabase;
}
set
{
}
}
public string do_get_folders()
{
IManProfileSearchParameters srch_params = _objDMS.CreateProfileSearchParameters();
IManWorkspaceSearchParameters wkspc_srch_params = _objDMS.CreateWorkspaceSearchParameters();
IManFolders wkspc_res;
string folder_IDs = "";
List <IManFolder> obj_folders = new List<IManFolder>();
srch_params.Add(imProfileAttributeID.imProfileAuthor, "WSADMIN");
srch_params.Add(imProfileAttributeID.imProfileCustom1, "1002279"); // BearingPoint, Inc.
wkspc_res = _objDatabase.SearchWorkspaces(srch_params, wkspc_srch_params);
Console.WriteLine("\nFound {0} workspaces.\n", wkspc_res.Count);
SortWorkspaceClass objIManSortWorkspace = new SortWorkspaceClass();
wkspc_res.Sort(objIManSortWorkspace);
foreach (IManWorkspace work1 in wkspc_res)
if (work1.SubType.Equals("work"))
{
folder_IDs += work1.FolderID.ToString() + ",";
//Console.WriteLine(work1.Name);
foreach (IManFolder fldr1 in work1.SubFolders)
if (fldr1.ObjectType.ObjectType.Equals(imObjectType.imTypeDocumentFolder))
obj_folders.Add(fldr1);
}
Console.WriteLine("\nobj_folders[] contains: {0} folder_IDs\n", obj_folders.Count);
//char[] trim_chars = { ',', ' ', '\n' };
folder_IDs = folder_IDs.TrimEnd(',');
return folder_IDs;
}
private void thread_worker(ManualResetEvent _reset_event, Mutex _mutex, string folders)
{
int tid = Thread.CurrentThread.ManagedThreadId;
Thread.Sleep(200);
// Perform 10 runs through the folder list
for (int j = 0; j < 10; j++)
foreach (string ID in folders.Split(','))
{
IManFolder imF = _objDatabase.GetFolder(Int16.Parse(ID));
imF.Refresh();
_mutex.WaitOne();
Console.SetCursorPosition(1, tid + 22);
Console.Write("Loop({0}) : GetFolder({1})\t\t", tid, ID);
_mutex.ReleaseMutex();
}
_mutex.WaitOne();
Console.WriteLine("Thread {0} exited.", tid);
_mutex.ReleaseMutex();
_reset_event.Set();
}
public void do_threads(string folder_ids)
{
ManualResetEvent[] _manualResetEvents = new ManualResetEvent[10];
Mutex mutex1 = new Mutex(false);
Stopwatch sw1 = new Stopwatch();
sw1.Start();
// create 10 threads
for (int n = 0; n < 10; n++)
{
ManualResetEvent _mres = new ManualResetEvent(false);
_manualResetEvents[n] = _mres;
Thread t = new Thread(() => thread_worker(_mres, mutex1, folder_ids));
t.Start();
Console.WriteLine("Thread {0,2} started with ({1}, {2}, folder_ids)", t.ManagedThreadId, mutex1.ToString(), _mres.ToString());
}
Console.WriteLine();
WaitHandle.WaitAll(_manualResetEvents);
sw1.Stop();
Console.WriteLine("\n\n\n\n--------------------------------------------------");
Console.WriteLine("\ndo_threads: {0} ms", sw1.ElapsedMilliseconds);
}
static void display_exception_details(Exception e)
{
Console.WriteLine("Message:\n{0{\n\nSource:\n{1}\n\nStack Trace:\n{2}\n\n",
e.Message, e.Source, e.StackTrace);
Console.Write("Press Enter: ");
Console.ReadLine();
System.Environment.Exit(-1);
}
static void Main(string[] args)
{
Stopwatch sw1 = new Stopwatch();
sw1.Start();
Program prog = new Program();
sw1.Stop();
Console.WriteLine("\nprog.Program: {0} ms\n", sw1.ElapsedMilliseconds);
Console.WriteLine("_objDMS.ComputerName\t\t= {0}", prog.getDMS.ComputerName);
Console.WriteLine("_objSession.Timeout\t\t= {0}", prog.getSession.Timeout);
Console.WriteLine("_objSession.AllVersions\t\t= {0}", prog.getSession.AllVersions);
Console.WriteLine("_objSession.MaxRowsForSearch\t= {0}", prog.getSession.MaxRowsForSearch);
string str1 = prog.do_get_folders();
prog.do_threads(str1);
if (prog._objSession.Connected)
try
{
sw1.Restart();
prog._objSession.Logout();
sw1.Stop();
Console.WriteLine("\n_objSession.Logout: {0} ms", sw1.ElapsedMilliseconds);
}
catch (COMException e)
{
display_exception_details(e);
}
Console.Write("\nPress Enter: ");
Console.Beep();
Console.ReadLine();
}
}
}