public override void ExportDocument(SIEESettings settings, SIEEDocument document, string name, SIEEFieldlist fieldlist) { List <SqlColumn> columns = new List <SqlColumn>(); foreach (ColumnDescription colDes in mySettings.Columns.Where(n => n.SqlTypeName != null)) { SqlColumn col = new SqlColumn() { Name = colDes.Name, SqlType = SqlTypes.GetSqlType(colDes.SqlTypeName), IsDocument = colDes.IsDocument, }; if (colDes.IsDocument) { col.ValueString = document.PDFFileName; } else { SIEEField f = fieldlist.Where(n => n.ExternalId == colDes.Name).FirstOrDefault(); col.ValueString = f == null ? null : f.Value; } columns.Add(col); } try { sqlClient.SetObjectValues(columns); } catch (Exception e) { document.NonRecoverableError = true; throw e; } sqlClient.Insert(columns); }
public string getRelativePath(SIEEDocument doc) { switch (mySettings.FolderHandling) { case SPOSettings.FolderHandlingType.Folder: return(normalizePath(mySettings.FolderName)); case SPOSettings.FolderHandlingType.Field: { SIEEField f = doc.Fieldlist.Where(n => n.Name == mySettings.FieldName).FirstOrDefault(); if (f != null) { return(normalizePath(f.Value)); } f = doc.AuxFields.Where(n => n.Name == mySettings.FieldName).FirstOrDefault(); if (f != null) { return(normalizePath(f.Value)); } throw new Exception($"Could not find field: {mySettings.FieldName}"); } case SPOSettings.FolderHandlingType.Auto: return(normalizePath(getAutoPath())); case SPOSettings.FolderHandlingType.None: default: return(string.Empty); } }
private void t06_testExport (SPOViewModel vm, SPOClientMock spoClient, SPOExport export, string expectedFolder) { SIEEDocument document = new SIEEDocument() { PDFFileName = "file.pdf" }; string documentName = "document"; export.Init(vm.Settings); export.ExportDocument(vm.Settings, document, documentName, vm.Settings.CreateSchema()); Assert.AreEqual( spoClient.LastExportResult.Folder, expectedFolder); }
private SIEEBatch createBatch(string filename, string docName) { SIEEField field = new SIEEField() { Name = "SomeField", ExternalId = "SomeField", Value = "SomeValue" }; SIEEFieldlist fieldlist = new SIEEFieldlist(); fieldlist.Add(field); SIEEDocument document = new SIEEDocument(); document.PDFFileName = filename; document.InputFileName = docName; document.BatchId = "4711"; document.DocumentId = "0"; document.Fieldlist = fieldlist; SIEEBatch batch = new SIEEBatch(); batch.Add(document); return(batch); }
public override void ExportDocument(SIEESettings settings, SIEEDocument document, string targetFileName, SIEEFieldlist fieldlist) { List <SPOField> fields = new List <SPOField>(); foreach (SIEEField f in fieldlist) { SPOField spof = mySettings.Fields.Where(n => n.InternalName == f.ExternalId).FirstOrDefault(); if (spof != null) { spof.Value = f.Value; fields.Add(spof); } } int itemId = spoClient.AddDocument( mySettings.SelectedList, getRelativePath(document) + targetFileName + ".pdf", document.PDFFileName, fields); document.TargetDocumentId = itemId.ToString(); }
public void t04_Export() { SPOViewModel vm = createViewModel(); vm.LT.SelectedList = new SPOList() { Title = "SomeList" }; vm.LoadFieldsButtonHandler(); SIEEFieldlist schema = vm.Settings.CreateSchema(); Assert.AreEqual(2, schema.Count); schema.Where(n => n.ExternalId == "Id1").First().Value = "myTitle"; schema.Where(n => n.ExternalId == "Id3").First().Value = "true"; schema.Add(new SIEEField() { Name = "SomeName", ExternalId = "xx", Value = "SomeValue" }); SPOClientMock spoClient = new SPOClientMock(); SPOExport export = new SPOExport(spoClient); export.Init(vm.Settings); SIEEDocument document = new SIEEDocument() { PDFFileName = "file.pdf" }; export.ExportDocument(vm.Settings, document, "sub/Document", schema); Assert.AreEqual("SomeList", spoClient.LastExportResult.ListTitle); Assert.AreEqual("sub/Document.pdf", spoClient.LastExportResult.DocumentPath); Assert.AreEqual("file.pdf", spoClient.LastExportResult.FilePath); verifyField("Id1", "myTitle", schema, spoClient.LastExportResult.Fields); verifyField("Id3", "true", schema, spoClient.LastExportResult.Fields); }
public override void ExportDocument(SIEESettings settings, SIEEDocument document, string name, SIEEFieldlist fieldlist) { CMISFolder folder = determineFolder(fieldlist); string docName = name; // Collision detection and handling (except for version handling) CMISDocument existingDocument = cmisClient.GetDocument(folder, docName + pdfExtension); if (existingDocument != null) { switch (mySettings.SelectedConflictHandling) { case CMISSettings.ConflictHandling.Replace: { cmisClient.DeleteDocument(existingDocument); break; } case CMISSettings.ConflictHandling.AddBlurb: { docName = getDocumentNameWithBlurb(docName); break; } case CMISSettings.ConflictHandling.AddNumber: { docName = getDocumentNameWithNumber(docName, folder); break; } default: break; } } // Create property list string checkInComment = "OCC created version"; Dictionary <string, object> props = new Dictionary <string, object>(); props["cmis:objectTypeId"] = selectedTypeId; foreach (SIEEField f in fieldlist) { if (f.ExternalId == "cmis:checkinComment") { checkInComment = f.Value; continue; } if (mySettings.UseSubFolderField && mySettings.SubFolderTypeFixed && f.ExternalId == mySettings.SubFolderField) { continue; } if (mySettings.UseSubFolderField && mySettings.SubFolderTypeFromField && f.ExternalId == mySettings.SubFolderTypeField) { continue; } try { props[f.ExternalId] = convert(mySettings, f); } catch (Exception e) { throw new Exception( "Error converting value for field '" + f.ExternalId + "' Value = '" + f.Value + "' \nReason: " + e.Message ); } } try { string dn = docName + pdfExtension; if (cmisClient.GetDocument(folder, docName + pdfExtension) == null || !versionHandling()) { bool?v = null; if (versionHandling()) { v = mySettings.Major; } cmisClient.StoreDocument(folder, document.PDFFileName, dn, props, v); } else { cmisClient.UpdateDocument(folder, document.PDFFileName, dn, props, mySettings.Major, checkInComment); } } catch (Exception e) { trace.WriteError(e.Message); throw; } document.TargetDocumentId = folder + ":" + document.PDFFileName; }
// Simulate some exports and verify the final location public void t05_SubfolderHandling() { SPOViewModel vm = createViewModel(); // Create schema based on mocked SPOList vm.LT.SelectedList = new SPOList() { Title = "SomeList" }; vm.LoadFieldsButtonHandler(); SIEEFieldlist schema = vm.Settings.CreateSchema(); Assert.AreEqual(2, schema.Count); schema.Where(n => n.ExternalId == "Id1").First().Value = "myTitle"; schema.Where(n => n.ExternalId == "Id3").First().Value = "true"; schema.Add(new SIEEField() { Name = "SomeName", ExternalId = "xx", Value = "SomeValue" }); SIEEDocument document = new SIEEDocument() { PDFFileName = "file.pdf" }; SPOClientMock spoClient = vm.SPOClient as SPOClientMock; // was: new SPOClientMock(); SPOExport export = new SPOExport(spoClient); string documentName = "abc/document"; var td = new[] { new { n = 0, folderType = SPOSettings.FolderHandlingType.None, folder = string.Empty, auxField = false, expError = false, fieldContent = string.Empty, result = documentName, }, new { n = 1, folderType = SPOSettings.FolderHandlingType.Folder, folder = "sub/subsub", auxField = false, expError = false, fieldContent = string.Empty, result = "sub/subsub/" + documentName, }, new { n = 2, folderType = SPOSettings.FolderHandlingType.Folder, folder = "/sub/subsub/", auxField = false, expError = false, fieldContent = string.Empty, result = "sub/subsub/" + documentName, }, new { n = 3, folderType = SPOSettings.FolderHandlingType.Folder, folder = "/", auxField = false, expError = false, fieldContent = string.Empty, result = documentName, }, new { n = 4, folderType = SPOSettings.FolderHandlingType.Field, folder = string.Empty, auxField = false, expError = false, fieldContent = "sub/subsub", result = "sub/subsub/" + documentName, }, new { n = 5, folderType = SPOSettings.FolderHandlingType.Field, folder = string.Empty, auxField = false, expError = false, fieldContent = "/sub/subsub/", result = "sub/subsub/" + documentName, }, new { n = 6, folderType = SPOSettings.FolderHandlingType.Field, folder = string.Empty, auxField = false, expError = false, fieldContent = "/", result = documentName, }, new { n = 7, folderType = SPOSettings.FolderHandlingType.Field, folder = string.Empty, auxField = true, expError = false, fieldContent = "/sub/subsub/", result = "sub/subsub/" + documentName, }, new { n = 8, folderType = SPOSettings.FolderHandlingType.Field, folder = string.Empty, auxField = true, expError = true, fieldContent = "/sub/subsub/", result = "sub/subsub/" + documentName, }, }; int doOnly = -1; for (int i = 0; i != td.Length; i++) { if (doOnly > 0 && td[i].n != doOnly) { continue; } vm.FT.FolderHandling = SPOSettings.FolderHandlingType.None; vm.FT.FolderName = td[i].folder; vm.FT.FieldName = string.Empty; document.AuxFields = new SIEEFieldlist(); if (td[i].folderType == SPOSettings.FolderHandlingType.Field) { if (td[i].auxField == false) { vm.FT.FieldName = "SomeName"; schema.Where(n => n.Name == "SomeName").First().Value = td[i].fieldContent; } else { vm.FT.FieldName = "auxField" + (td[i].expError ? "-err" : ""); document.AuxFields.Add(new SIEEField("auxField", "", td[i].fieldContent)); } } vm.FT.FolderHandling = td[i].folderType; document.Fieldlist = schema; export.Init(vm.Settings); bool exception = false; try { export.ExportDocument(vm.Settings, document, documentName, schema); } catch { exception = true; } if (td[i].expError) { Assert.IsTrue(exception); } else { Assert.IsFalse(exception); Assert.AreEqual(td[i].result + ".pdf", spoClient.LastExportResult.DocumentPath); } } Assert.IsTrue(doOnly < 0, "Not all tests executed"); }