-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartDispatcherExtension.cs
More file actions
254 lines (231 loc) · 11.1 KB
/
Copy pathSmartDispatcherExtension.cs
File metadata and controls
254 lines (231 loc) · 11.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*--------------------------------------------------------------------------------------+
//----------------------------------------------------------------------------
// DOCUMENT ID:
// LIBRARY:
// CREATOR: Mark Anderson
// DATE: 02-15-2017
//
// NAME: SmartDispatcherExtension.cs
//
// DESCRIPTION: Utility.
//
// REFERENCES: ProjectWise.
//
// ---------------------------------------------------------------------------
// NOTICE
// NOTICE TO ALL PERSONS HAVING ACCESS HERETO: This document or
// recording contains computer software or related information
// constituting proprietary trade secrets of Black & Veatch, which
// have been maintained in "unpublished" status under the copyright
// laws, and which are to be treated by all persons having acdcess
// thereto in manner to preserve the status thereof as legally
// protectable trade secrets by neither using nor disclosing the
// same to others except as may be expressly authorized in advance
// by Black & Veatch. However, it is intended that all prospective
// rights under the copyrigtht laws in the event of future
// "publication" of this work shall also be reserved; for which
// purpose only, the following is included in this notice, to wit,
// "(C) COPYRIGHT 1997 BY BLACK & VEATCH, ALL RIGHTS RESERVED"
// ---------------------------------------------------------------------------
/*
/* CHANGE LOG
* $Archive: /ProjectWise/ASFramework/HPEDocumentProcessor/SmartDispatcherExtension.cs $
* $Revision: 1 $
* $Modtime: 2/15/17 7:18a $
* $History: SmartDispatcherExtension.cs $
*
* ***************** Version 1 *****************
* User: Mark.anderson Date: 2/15/17 Time: 7:45a
* Created in $/ProjectWise/ASFramework/HPEDocumentProcessor
* A General purpose document processor. This will use an application
* name and command line to load in to the msprocessor
*
*/
using System;
using System.Xml;
using Bentley.Automation;
using Bentley.Automation.Extensions;
using Bentley.Automation.Messaging;
using Bentley.Orchestration.MSProcessor;
using Bentley.Orchestration.Extensibility;
using PwApiWrapper;
namespace HPE.Automation.Extensions.HPEGeneralProcessor
{
/// <summary>
/// Summary description for SmartDispatcherExtension. This is called to
/// interact with the ms processor. it will process the job definition.
/// For this application it set the command to load the application then
/// queue the command to process the file.
/// </summary>
public class SmartDispatcherExtension : ASSmartDispatcherExtension
{
public SmartDispatcherExtension()
: base(Constants.DocumentProcessorName,
new Guid(Constants.DocumentProcessorGuid),
Constants.DocumentProcessorDescription)
{
// The smart dispatcher extension is only used by pasSmartDispatcher.exe, so only pasSmartDispatcher should load it.
System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
if (0 == String.Compare(currentProcess.ProcessName, "pasSmartDispatcher", true))
{
LogServer.Log(LogServer.LogASConstants.AutomationServicesLoggerNamespace,
LogServer.LogASConstants.LAYER_JobBuilder,
LogServer.LEVEL_Info,
"***** HPE.Automation.Extensions.HPEGeneralProcessor.SmartDispatcherExtension loaded *********");
}
else
{
}
}
/// <summary>
/// this is only for processing design files.
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private bool isCADFile(string filePath)
{
if (filePath.ToLower().EndsWith("dgn") || filePath.ToLower().EndsWith("dwg"))
return true;
return false;
}
private ProcessingInstruction GenerateFirstCADIndexInstruction(ASContext asContext)
{
MSProcessorInstruction pi = new MSProcessorInstruction();
pi.DocumentProcessorName = DocumentProcessorName;
pi.DocumentProcessorGuid = DocumentProcessorGuid.ToString();
pi.Step = Constants.Steps.KeyInStep;
pi.MicroStationMessage = GenerateMicroStationInstructions(asContext);
return pi;
}
private void ParseKeyinString(string sKeyin, MicroStationMessage msm)
{
string[] split = sKeyin.Split(new Char[] { ';' });
foreach (string s in split)
{
if (s.Trim() != "")
msm.AddKeyin(s);
}
}
/// <summary>
/// this will load the mdl application and login to PW (Optional)
/// then queue the command to execute on the "current" file.
/// </summary>
/// <param name="asContext"></param>
/// <returns></returns>
private MicroStationMessage GenerateMicroStationInstructions(ASContext asContext)
{
MicroStationMessage msm = new MicroStationMessage();
msm.AddKeyin("rd=" + asContext.WorkingDocumentInfo.FilePath);
// Retrieving custom data on a job definition as an XmlElement.
XmlNode xmlNode = (XmlNode)asContext.JobDefinition.GetCustomData(DocumentProcessorGuid);
if (xmlNode != null)
{
ConfigData myDocProcConfigData = new ConfigData((XmlElement)xmlNode);
// by convention use this as then name of your mdl application
if (0 < myDocProcConfigData.MDLAppName.Length)
{
string sMDLPath;/* = PwApiWrapper.Util.GetProjectWisePath();
sMDLPath += @"bin\";*/
sMDLPath = myDocProcConfigData.MDLAppName;
string loadKeyin = "mdl silentload \"" + sMDLPath + "\"";
msm.AddKeyin(loadKeyin);
}
// by convention use this to log in to PW from MS
if (0 < myDocProcConfigData.PWLoginCMD.Length)
{
if (null != myDocProcConfigData.PWUser &&
null != myDocProcConfigData.PWPassword)
{
string sLoginCmd = myDocProcConfigData.PWLoginCMD + " " +
asContext.JobDefinition.ProjectWiseDataSource + " " +
myDocProcConfigData.PWUser + " " +
myDocProcConfigData.PWPassword + " " +
asContext.WorkingDocumentInfo.VaultID.ToString() + " " +
asContext.WorkingDocumentInfo.DocumentID.ToString();
msm.AddKeyin(sLoginCmd);
}
else
{
if (0 < myDocProcConfigData.MSKeyin4.Length)
ParseKeyinString(myDocProcConfigData.MSKeyin4+" " +
asContext.WorkingDocumentInfo.VaultID.ToString() + " " +
asContext.WorkingDocumentInfo.DocumentID.ToString()
, msm);
}
}
if (0 < myDocProcConfigData.AppKeyin.Length)
ParseKeyinString(myDocProcConfigData.AppKeyin + " " +
asContext.WorkingDocumentInfo.VaultID.ToString() + " " +
asContext.WorkingDocumentInfo.DocumentID.ToString(), msm);
if (0 < myDocProcConfigData.MSKeyin5.Length)
ParseKeyinString(myDocProcConfigData.MSKeyin5, msm);
//turn off the save design feature
//msm.AddKeyin("SAVE DESIGN");
}
return msm;
}
private ProcessingInstruction GenerateFileReplaceInstruction(ProcessingInstruction previousPi)
{
DelegateInstruction di = new DelegateInstruction();
LogServer.Log(LogServer.LogASConstants.AutomationServicesLoggerNamespace,
LogServer.LogASConstants.LAYER_SmartDispatcher, LogServer.LEVEL_Info, "Creating Replace Instruction");
di.DocumentProcessorName = DocumentProcessorName;
di.DocumentProcessorGuid = DocumentProcessorGuid.ToString();
di.Step = Constants.Steps.ReplaceFileStep;
return di;
}
private ProcessingInstruction GenerateExitInstruction(ProcessingInstruction previousPi)
{
ExitInstruction ei = new ExitInstruction(true, "complete");
LogServer.Log(LogServer.LogASConstants.AutomationServicesLoggerNamespace,
LogServer.LogASConstants.LAYER_SmartDispatcher, LogServer.LEVEL_Info, "Creating Exit Instruction");
ei.DocumentProcessorName = DocumentProcessorName;
ei.DocumentProcessorGuid = DocumentProcessorGuid.ToString();
return ei;
}
private ProcessingInstruction GenerateCADProcessingInstructions(ASContext asContext, ProcessingInstruction previousPi, bool isFirstRequestForProcessingInstructions)
{
ProcessingInstruction nextPi = null;
if (isFirstRequestForProcessingInstructions)
{
// Step 1 - attribute data in xml file to delegate processor for indexing
nextPi = GenerateFirstCADIndexInstruction(asContext);
// nextPi = GenerateFileReplaceInstruction(previousPi);
}
else if (Constants.Steps.KeyInStep == previousPi.Step)
{
// Step 2 - replace the file
nextPi = GenerateFileReplaceInstruction(previousPi);
}
else if (Constants.Steps.ReplaceFileStep == previousPi.Step)
{
// Step 3 - to exit for reporting and cleanup
nextPi = GenerateExitInstruction(previousPi);
}
else
{
// Don't understand the previous step, do nothing.
nextPi = null;
}
return nextPi;
}
/// <summary>
/// Gives the smart dispatcher the sequence of steps needed to index widgets.
/// </summary>
/// <param name="asContext">Automation Services context object</param>
/// <param name="previousPi">The previous step</param>
/// <param name="isFirstRequestForProcessingInstructions">First step?</param>
/// <returns>The next processing instruction to execute</returns>
public override ProcessingInstruction GenerateProcessingInstructions
(
ASContext asContext,
ProcessingInstruction previousPi,
bool isFirstRequestForProcessingInstructions
)
{
ProcessingInstruction nextPi = GenerateCADProcessingInstructions(asContext, previousPi,
isFirstRequestForProcessingInstructions);
return nextPi;
}
}
}