-
Notifications
You must be signed in to change notification settings - Fork 0
/
SYS - 274 with Unity only.cs
125 lines (108 loc) · 5.86 KB
/
SYS - 274 with Unity only.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Skeleton generated by Hyland Unity Editor on 6/9/2014 11:36:29 AM
namespace ConvertEformChecksheetToImage
{
using System;
using System.Collections.Generic;
using Hyland.Unity;
using System.IO;
/// <summary>
/// Convert Eform Checksheet to Image
/// </summary>
public class ConvertEformChecksheetToImage : IWorkflowScript
{
private const string CRD_DOCUMENT_TYPE = "CIU - CR - Checksheet";
private const long EFORM_FILE_TYPE = 24;
private const long VFORM_FILE_TYPE = 27;
private const long IMAGE_FILE_TYPE = 2;
private string strFilePath = "";
#region IWorkflowScript
/// <summary>
/// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
/// <seealso cref="IWorkflowScript" />
/// </summary>
/// <param name="app"></param>
/// <param name="args"></param>
public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
{
app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;
try
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Begin Script - 274 - Convert Supporting Document to TIFF");
// Get the active document
Document objCurrentDocument = args.Document;
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Processing document: {0}", objCurrentDocument.ID.ToString()));
// Get the default rendition and verify it is an e-form
Rendition objFormRendition = objCurrentDocument.DefaultRenditionOfLatestRevision;
if (objFormRendition.FileType.ID != EFORM_FILE_TYPE && objFormRendition.FileType.ID != VFORM_FILE_TYPE)
{
throw new InvalidProgramException(string.Format("File format ({0}) is invalid!", objFormRendition.FileType.Name));
}
// Obtain the Image page data
ImageDataProvider objImageProvider = app.Core.Retrieval.Image;
PageData objImageData = objImageProvider.GetDocument(objFormRendition);
string fullPath = String.Format("{0}.{1}", @"c:\Temp", objImageData.Extension);
Stream stream = objImageData.Stream;
Utility.WriteStreamToFile(stream, fullPath);
DocumentType objNewDocType = app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE);
// Prepare to import the new document
StoreNewDocumentProperties objDocProps = app.Core.Storage.CreateStoreNewDocumentProperties(objNewDocType, app.Core.FileTypes.Find(IMAGE_FILE_TYPE));
//Add all keywords
foreach (KeywordRecord objKeyRecord in objCurrentDocument.KeywordRecords)
{
if (objKeyRecord.KeywordRecordType.RecordType == RecordType.StandAlone || objKeyRecord.KeywordRecordType.RecordType == RecordType.SingleInstance)
{
foreach (Keyword objKeyword in objKeyRecord.Keywords)
{
if (objNewDocType.KeywordRecordTypes.FindKeywordType(objKeyword.KeywordType.ID) != null)
{
objDocProps.AddKeyword(objKeyword);
}
}
}
else
{
EditableKeywordRecord objEditRecord = objKeyRecord.CreateEditableKeywordRecord();
objDocProps.AddKeywordRecord(objEditRecord);
}
}
List<string> lstImportFiles = new List<string>();
lstImportFiles.Add(fullPath);
// Store the new document
Document objNewDoc = null;
objNewDoc = app.Core.Storage.StoreNewDocument(lstImportFiles, objDocProps);
if (objNewDoc == null)
{
throw new InvalidProgramException("Failed to store new document");
}
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Stored new document: {0}", objNewDoc.ID.ToString()));
// Clean up
objImageData.Dispose();
// If we got here, the script was successful
args.ScriptResult = true;
}
catch (InvalidProgramException ex)
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Invalid Program Exception: {0}", ex.Message));
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
args.ScriptResult = false;
}
catch (UnityAPIException ex)
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Unity API Exception: {0}", ex.Message));
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
args.ScriptResult = false;
}
catch (Exception ex)
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("General Exception: {0}", ex.Message));
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
args.ScriptResult = false;
}
finally
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "End Script - 274 - Convert HTML to TIFF");
}
}
#endregion
}
}