Imports
System.Data.Common
Imports System.Data.SqlClient Imports System.Text Imports System Imports System.Collections.Generic Imports System.Data Imports IDataAccess.ContextRegistryServiceReference Imports IDataAccess.ObjectServiceReference Imports IDataAccess.QueryServiceReference Imports IDataAccess.SearchServiceReference Imports System.ServiceModel Imports System.Configuration Imports System.Net Imports System.IO Namespace Documentum Public Class DocumentStorageCustomDAL Implements IDocumentStorageCustomDAL Public Sub DeleteDocByStorageId(ByVal storageId As String) Implements IDataAccess.Documentum.IDocumentStorageCustomDAL.DeleteDocByStorageId Try Dim objectService As New ObjectServicePortClient("ObjectServicePort") ' Find a document to return Dim q As New ObjectServiceReference.Qualification() q.String = "dm_document WHERE r_object_id = '" & storageId & "'" q.qualificationValueType = ObjectServiceReference.QualificationValueType.STRING q.qualificationValueTypeSpecified = True ' Set the identity Dim objectIdentity As New ObjectServiceReference.ObjectIdentity() objectIdentity.valueType = ObjectServiceReference.ObjectIdentityType.QUALIFICATION objectIdentity.valueTypeSpecified = True objectIdentity.Item = q objectIdentity.repositoryName = ConfigurationManager.AppSettings("repositoryName") Dim objectIdentitySet As New IDataAccess.ObjectServiceReference.ObjectIdentitySet() objectIdentitySet.Identities = New ObjectServiceReference.ObjectIdentity(0) {} objectIdentitySet.Identities(0) = objectIdentity ' Specify the format to return (used when multiple renditions exist) ' FormatFilter.ANY should return the default format Dim contentProfile As New IDataAccess.ObjectServiceReference.ContentProfile() contentProfile.formatFilter = ObjectServiceReference.FormatFilter.ANY 'contentProfile.format = "crtext"; 'contentProfile.format = "pdf" 'contentProfile.formatFilterSpecified = True Dim operationOptions As New ObjectServiceReference.OperationOptions() operationOptions.Profiles = New IDataAccess.ObjectServiceReference.Profile(0) {} operationOptions.Profiles(0) = contentProfile Dim dataPackage As ObjectServiceReference.DataPackage = Nothing Using scope As New OperationContextScope(objectService.InnerChannel) ' Add the correct SOAP header ' Use the ServiceContext Dim scx As New ServiceContextHeader() Dim repoId As New RepositoryIdentity() repoId.repositoryName = ConfigurationManager.AppSettings("repositoryName") repoId.userName = ConfigurationManager.AppSettings("username") repoId.password = ConfigurationManager.AppSettings("password") scx.AddRepositoryIdentity(repoId) OperationContext.Current.OutgoingMessageHeaders.Add(scx) ' Make the call objectService.delete(objectIdentitySet, operationOptions) End Using Catch ex As SqlException End Try End Sub Public Sub UpdateDocumentByStorageId(ByVal storageId As String, ByVal document As Byte()) Implements IDataAccess.Documentum.IDocumentStorageCustomDAL.UpdateDocumentByStorageId Try Catch ex As SqlException End Try End Sub Public Sub DeleteDocByStorageId(ByVal storageIds As List(Of System.String)) Implements IDataAccess.Documentum.IDocumentStorageCustomDAL.DeleteDocByStorageIds End Sub Public Function UploadDocument(ByVal pdfDoc As DocumentStorageEntity) As String Implements IDataAccess.Documentum.IDocumentStorageCustomDAL.UploadDocument Dim rObjectID As String = String.Empty Try Dim objectService As ObjectServicePortClient objectService = New ObjectServicePortClient("ObjectServicePort") Dim oi As ObjectServiceReference.ObjectIdentity oi = New ObjectServiceReference.ObjectIdentity() oi.repositoryName = ConfigurationManager.AppSettings("repositoryName").ToString() Dim o As ObjectServiceReference.DataObject o = New ObjectServiceReference.DataObject o.Identity = oi o.type = pdfDoc.ObjectType Dim pp As ObjectServiceReference.PropertyProfile pp = New ObjectServiceReference.PropertyProfile pp.filterMode = ObjectServiceReference.PropertyFilterMode.ALL Dim tp As ObjectServiceReference.ContentTransferProfile tp = New ObjectServiceReference.ContentTransferProfile tp.transferMode = ObjectServiceReference.ContentTransferMode.BASE64 Dim operationOptions As ObjectServiceReference.OperationOptions operationOptions = New ObjectServiceReference.OperationOptions Dim profile(2) As ObjectServiceReference.Profile operationOptions.Profiles = profile operationOptions.Profiles(0) = pp operationOptions.Profiles(1) = tp Dim pset As ObjectServiceReference.PropertySet pset = New ObjectServiceReference.PropertySet Dim doN As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty doN.name = "object_name" doN.Value = pdfDoc.ObjectName Dim dLN As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dLN.name = "locationnum" dLN.Value = pdfDoc.LocationNumber Dim dCN As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dCN.name = "contractnum" dCN.Value = pdfDoc.ContractNumber Dim dPN As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dPN.name = "purchasername" dPN.Value = pdfDoc.PurchaseName Dim dDN As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dDN.name = "deceasedname" dDN.Value = pdfDoc.DeceasedName Dim dDT As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dDT.name = "documenttype" dDT.Value = pdfDoc.DocumentType Dim dCT As ObjectServiceReference.StringProperty = New ObjectServiceReference.StringProperty dCT.name = "contracttype" dCT.Value = pdfDoc.ContractType Dim ps As ObjectServiceReference.Property() = {doN, dLN, dCN, dPN, dDN, dDT, dCT} pset.Properties = ps o.Properties = pset Dim dhc As ObjectServiceReference.DataHandlerContent dhc = New ObjectServiceReference.DataHandlerContent dhc.format = pdfDoc.ContentType dhc.Value = pdfDoc.ReadDocument o.Contents = New ObjectServiceReference.Content(0) {} o.Contents(0) = dhc Dim packageIn As ObjectServiceReference.DataPackage packageIn = New ObjectServiceReference.DataPackage Dim dataObjects() As ObjectServiceReference.DataObject = {o} packageIn.DataObjects = dataObjects Dim packageOut As ObjectServiceReference.DataPackage Using scope As New ServiceModel.OperationContextScope(objectService.InnerChannel) ' Use the ServiceContext Dim scx As New ServiceContextHeader() Dim repoId As New RepositoryIdentity() repoId.repositoryName = ConfigurationManager.AppSettings("repositoryName").ToString() repoId.userName = ConfigurationManager.AppSettings("userName").ToString() repoId.password = ConfigurationManager.AppSettings("password").ToString() scx.AddRepositoryIdentity(repoId) OperationContext.Current.OutgoingMessageHeaders.Add(scx) Try If objectService.State = CommunicationState.Created Then packageOut = objectService.create(packageIn, operationOptions) Dim retObj As ObjectServiceReference.ObjectId = TryCast(packageOut.DataObjects(0).Identity.Item, ObjectServiceReference.ObjectId) rObjectID = retObj.id End If Catch ex As Exception Return ex.Message End Try Return rObjectID End Using Catch ex As Exception End Try Return rObjectID End Function Public Function GetDocByObjectId(ByVal ObjectID As String) As GetFileData Dim response As New GetFileData() Try Dim objectService As New ObjectServicePortClient("ObjectServicePort") ' Find a document to return Dim q As New ObjectServiceReference.Qualification() q.String = "dm_document WHERE r_object_id = '" & ObjectID & "'" q.qualificationValueType = ObjectServiceReference.QualificationValueType.STRING q.qualificationValueTypeSpecified = True ' Set the identity Dim objectIdentity As New ObjectServiceReference.ObjectIdentity() objectIdentity.valueType = ObjectServiceReference.ObjectIdentityType.QUALIFICATION objectIdentity.valueTypeSpecified = True objectIdentity.Item = q objectIdentity.repositoryName = ConfigurationManager.AppSettings("repositoryName") Dim objectIdentitySet As New IDataAccess.ObjectServiceReference.ObjectIdentitySet() objectIdentitySet.Identities = New ObjectServiceReference.ObjectIdentity(0) {} objectIdentitySet.Identities(0) = objectIdentity ' Specify the format to return (used when multiple renditions exist) ' FormatFilter.ANY should return the default format Dim contentProfile As New IDataAccess.ObjectServiceReference.ContentProfile() contentProfile.formatFilter = ObjectServiceReference.FormatFilter.SPECIFIED 'contentProfile.format = "txt" contentProfile.format = "pdf" contentProfile.formatFilterSpecified = True Dim operationOptions As New ObjectServiceReference.OperationOptions() operationOptions.Profiles = New IDataAccess.ObjectServiceReference.Profile(0) {} operationOptions.Profiles(0) = contentProfile Dim dataPackage As ObjectServiceReference.DataPackage = Nothing Using scope As New OperationContextScope(objectService.InnerChannel) ' Add the correct SOAP header ' Use the ServiceContext Dim scx As New ServiceContextHeader() Dim repoId As New RepositoryIdentity() repoId.repositoryName = ConfigurationManager.AppSettings("repositoryName") repoId.userName = ConfigurationManager.AppSettings("username") repoId.password = ConfigurationManager.AppSettings("password") scx.AddRepositoryIdentity(repoId) OperationContext.Current.OutgoingMessageHeaders.Add(scx) ' Make the call dataPackage = objectService.get(objectIdentitySet, operationOptions) End Using ' Dump the content to a file ' If Not dataPackage.DataObjects(0).Contents Is Nothing Then For Each content As ObjectServiceReference.Content In dataPackage.DataObjects(0).Contents Dim p As ObjectServiceReference.Property() = dataPackage.DataObjects(0).Properties.Properties Dim fileName As String = "File" ' Set the filename to the object_name For Each prop As ObjectServiceReference.Property In p If prop.name = "object_name" Then Dim sp As ObjectServiceReference.StringProperty = TryCast(prop, ObjectServiceReference.StringProperty) If sp IsNot Nothing AndAlso String.IsNullOrEmpty(sp.Value) = False Then fileName = sp.Value Exit For End If End If Next ' Check the format here If content.format = "crtext" Then fileName = IO.Path.ChangeExtension(fileName, "txt") End If If content.format = "pdf" Then fileName = IO.Path.ChangeExtension(fileName, "pdf") End If ' Put the file on the desktop ' fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName); ' If ACS is used, the returned content will be UrlContent. If it's not used, the returned ' content will be BinaryContent If TypeOf content Is IDataAccess.ObjectServiceReference.BinaryContent Then 'AddText("The content was returned as BinaryContent"); Dim binContent As IDataAccess.ObjectServiceReference.BinaryContent = DirectCast(content, IDataAccess.ObjectServiceReference.BinaryContent) 'SaveBytesToFile(binContent.Value, fileName); 'AddText("The file has been saved here: " + fileName); Dim s As String = binContent.format() response.ID = ObjectID response.ObjectName = fileName response.FileContents = binContent.Value response.ErrorNo = False 'response.Extn = content.format Return response ElseIf TypeOf content Is IDataAccess.ObjectServiceReference.UrlContent Then Dim urlContent As IDataAccess.ObjectServiceReference.UrlContent = DirectCast(content, IDataAccess.ObjectServiceReference.UrlContent) 'AddText("The content was returned as UrlContent."); ' AddText("The URL is: " + urlContent.url); Dim url As New Uri(urlContent.url) response.ID = ObjectID response.ObjectName = fileName response.FileContents = SaveUrlContentToByte(url) response.ErrorNo = False response.Extn = content.format 'AddText("The file has been saved here: " + fileName); Return response End If Exit For Next response.ErrorNo = True response.ErrorDetails = "All processing finshed but no data was found." Return response 'Else 'response.ErrorDetails = "Document Object Not Found" 'response.ErrorNo = True 'End If Catch ex As Exception response.ErrorNo = True response.ErrorDetails = ex.Message Return response End Try End Function Public Function SaveUrlContentToByte(ByVal url As Uri) As Byte() Try ' Get the content from the ACS server ' Dim stream As IO.Stream = Nothing Dim fstream As FileStream = Nothing Dim response As HttpWebResponse = Nothing Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest) response = DirectCast(request.GetResponse(), HttpWebResponse) Using stream = response.GetResponseStream() Dim buffer As Byte() = New Byte(32767) {} Using ms As New MemoryStream() While True Dim read As Integer = stream.Read(buffer, 0, buffer.Length) If read <= 0 Then Return ms.ToArray() End If ms.Write(buffer, 0, read) End While End Using End Using Catch ex As Exception ' AddText(ex.Message); Return Nothing End Try End Function Public Function GetDocByStorageId(ByVal storageId As String) As DocumentStorageEntity Implements IDataAccess.Documentum.IDocumentStorageCustomDAL.GetDocByStorageId Dim documentStorage As DocumentStorageEntity Try Catch ex As SqlException End Try Return documentStorage End Function Partial Friend Class SQLServerDocumentStorageCustomDALConstants Public Const storageId As String = "StorageId" Public Const ID As String = "ID" Public Const DeleteDocByStorageId As String = "DeleteDocByStorageId" Public Const UploadDoc As String = "UploadDoc" Public Const GetDocByStorageId As String = "GetDocByStorageId" Public Const UserId As String = "UserId" Public Const Document As String = "Document" Public Const ContentType As String = "ContentType" Public Const CreatedDate As String = "CreatedDate" Public Const UpdatedDate As String = "UpdatedDate" Public Const DocumentName As String = "DocumentName" Public Const UpdateDocByStorageId As String = "UpdateDocByStorageId" End Class Public Function GetExtensionofFile(ByVal objectId As String) As String Dim response As New GetFileData() Try Dim objectService As New ObjectServicePortClient("ObjectServicePort") ' Find a document to return Dim q As New ObjectServiceReference.Qualification() 'q.String = "dm_document WHERE r_object_id = '" & objectId & "'" q.String = "dm_format WHERE r_object_id = '" & objectId & "'" q.qualificationValueType = ObjectServiceReference.QualificationValueType.STRING q.qualificationValueTypeSpecified = True ' Set the identity Dim objectIdentity As New ObjectServiceReference.ObjectIdentity() objectIdentity.valueType = ObjectServiceReference.ObjectIdentityType.QUALIFICATION objectIdentity.valueTypeSpecified = True objectIdentity.Item = q objectIdentity.repositoryName = ConfigurationManager.AppSettings("repositoryName") Dim objectIdentitySet As New IDataAccess.ObjectServiceReference.ObjectIdentitySet() objectIdentitySet.Identities = New ObjectServiceReference.ObjectIdentity(0) {} objectIdentitySet.Identities(0) = objectIdentity ' Specify the format to return (used when multiple renditions exist) ' FormatFilter.ANY should return the default format Dim contentProfile As New IDataAccess.ObjectServiceReference.ContentProfile() contentProfile.formatFilter = ObjectServiceReference.FormatFilter.ANY 'contentProfile.format = "txt" 'contentProfile.format = "pdf" contentProfile.formatFilterSpecified = True Dim operationOptions As New ObjectServiceReference.OperationOptions() operationOptions.Profiles = New IDataAccess.ObjectServiceReference.Profile(0) {} operationOptions.Profiles(0) = contentProfile Dim dataPackage As ObjectServiceReference.DataPackage = Nothing Using scope As New OperationContextScope(objectService.InnerChannel) ' Add the correct SOAP header ' Use the ServiceContext Dim scx As New ServiceContextHeader() Dim repoId As New RepositoryIdentity() repoId.repositoryName = ConfigurationManager.AppSettings("repositoryName") repoId.userName = ConfigurationManager.AppSettings("username") repoId.password = ConfigurationManager.AppSettings("password") scx.AddRepositoryIdentity(repoId) OperationContext.Current.OutgoingMessageHeaders.Add(scx) ' Make the call dataPackage = objectService.get(objectIdentitySet, operationOptions) End Using Dim fileName As String = String.Empty ' Dump the content to a file ' If Not dataPackage.DataObjects(0).Contents Is Nothing Then For Each content As ObjectServiceReference.Content In dataPackage.DataObjects(0).Contents Dim p As ObjectServiceReference.Property() = dataPackage.DataObjects(0).Properties.Properties ' Set the filename to the object_name For Each prop As ObjectServiceReference.Property In p If prop.name = "dos_extension" Then Dim sp As ObjectServiceReference.StringProperty = TryCast(prop, ObjectServiceReference.StringProperty) If sp IsNot Nothing AndAlso String.IsNullOrEmpty(sp.Value) = False Then fileName = sp.Value Exit For End If End If Next ' Check the format here If content.format = "crtext" Then fileName = IO.Path.ChangeExtension(fileName, "txt") End If If content.format = "pdf" Then fileName = IO.Path.ChangeExtension(fileName, "pdf") End If Exit For Next Return fileName Catch ex As Exception End Try End Function Public Structure GetFileData Public ErrorNo As Boolean Public ErrorDetails As String Public ID As String Public ObjectName As String Public FileContents As Byte() Public Extn As String End Structure End Class End Namespace --- This is another class with in that business layer ' This sample code has been built using EMC Documentum Foundation Services (DFS) ' version 6.5 SP1, Visual Studio 2008 and .NET 3.5 (Windows Communication Foundation ' "v2" and LINQ to XML--System.Xml.Linq). It is not supported by EMC. ' ' In order to build and run this sample you must have DFS 6.5 SP1 (i.e. its web ' services) properly deployed (e.g. into a JEE application server such as JBoss ' 4.2.2). ' ' The primary intent of this sample code is to demonstrate direct-to-WSDL consumption ' of DFS using standard Microsoft tools (Visual Studio) and frameworks (WCF). ' ' Please visit the EMC Developer Network for more on DFS: ' https://community.emc.com/community/edn/documentum Imports System.Collections.Generic Imports System.Globalization Imports System.ServiceModel.Channels Imports System.Xml Imports System.Xml.Serialization Imports System.IO Imports System.Xml.Linq Imports IDataAccess.ContextRegistryServiceReference Namespace Documentum Friend Class ServiceContextHeader Inherits MessageHeader Private ReadOnly repositoryIdentities As New List(Of RepositoryIdentity)() Private contentTransferProfile As ContentTransferProfile Public Sub AddRepositoryIdentity(ByVal rid As RepositoryIdentity) If rid Is Nothing Then Exit Sub End If repositoryIdentities.Add(rid) End Sub Public Sub AddContentTransferProfile(ByVal ctp As ContentTransferProfile) If ctp Is Nothing Then Exit Sub End If contentTransferProfile = ctp End Sub Protected Overloads Overrides Sub OnWriteHeaderContents(ByVal writer As XmlDictionaryWriter, ByVal messageVersion As MessageVersion) ' If there are no ids, do nothing If repositoryIdentities.Count < 1 Then Exit Sub End If ' Add ids to the ServiceContext Dim serviceContext As New ServiceContext() serviceContext.Identities = New Identity(repositoryIdentities.Count - 1) {} For x As Integer = 0 To repositoryIdentities.Count - 1 serviceContext.Identities(x) = repositoryIdentities(x) Next ' If there is a ContentTransferProfile, add it If contentTransferProfile IsNot Nothing Then serviceContext.Profiles = New ContentTransferProfile(0) {} serviceContext.Profiles(0) = contentTransferProfile End If ' Serialize the objects to XML Dim doc As XDocument = Nothing Using sw As New StringWriter(CultureInfo.CurrentCulture) Dim xs As New XmlSerializer(GetType(ServiceContext)) xs.Serialize(sw, serviceContext) doc = XDocument.Load(New StringReader(sw.ToString())) End Using ' Add Identities to the ServiceContext header For Each el As XElement In doc.Descendants(XName.[Get]("Identities", "http://context.core.datamodel.fs.documentum.emc.com/")) Dim r As XmlReader = XmlReader.Create(New StringReader(el.ToString())) writer.WriteNode(r, True) Next ' Add Profiles to the ServiceContext header If serviceContext.Profiles IsNot Nothing Then For Each el As XElement In doc.Descendants(XName.[Get]("Profiles", "http://context.core.datamodel.fs.documentum.emc.com/")) Dim r As XmlReader = XmlReader.Create(New StringReader(el.ToString())) writer.WriteNode(r, False) Next End If End Sub Public Overloads Overrides ReadOnly Property Name() As String Get Return "ServiceContext" End Get End Property Public Overloads Overrides ReadOnly Property [Namespace]() As String Get Return "http://context.core.datamodel.fs.documentum.emc.com/" End Get End Property End Class End Namespace |
--- create a webpage... and paste this code Imports IDataAccess.Documentum Imports System.IO Imports System.Configuration Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnSendDocument_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendDocument.Click Try Dim objEntity As New DocumentStorageEntity Dim objFile As New FileInfo(fuBrowse.FileName) objEntity.ObjectName = txtLocationNum.Text + "-" + txtContractNum.Text + "-" + txtDocumentType.Text objEntity.ObjectType = "customercontract" If fuBrowse.HasFile Then objEntity.ReadDocument = fuBrowse.FileBytes() Else Return End If objEntity.LocationNumber = txtLocationNum.Text objEntity.ContractNumber = txtContractNum.Text objEntity.PurchaseName = txtPurName.Text objEntity.DeceasedName = txtDeceasedName.Text objEntity.DocumentName = fuBrowse.FileName objEntity.ContentType = "pdf" 'objFile.Extension objEntity.ContractType = "Trust Contract" objEntity.DocumentType = txtDocumentType.Text Dim objDocument As New DocumentStorageCustomDAL lblDocumentId.Text = "Document Id is:- " + objDocument.UploadDocument(objEntity) Catch ex As Exception Response.Write(ex.ToString()) End Try End Sub Protected Sub btnGetDoc_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetDoc.Click Try Dim objDocument As New DocumentStorageCustomDAL Dim objGetFile As DocumentStorageCustomDAL.GetFileData objGetFile = objDocument.GetDocByObjectId(txtGetDoc.Text) If (objGetFile.ErrorNo = False) Then Dim url As String = AppDomain.CurrentDomain.BaseDirectory & "GetFile." & objGetFile.Extn Using binWriter As New BinaryWriter(File.Open(url, FileMode.Create)) binWriter.Write(objGetFile.FileContents) End Using System.Diagnostics.Process.Start(url) End If Catch ex As Exception Response.Write(ex.ToString()) End Try End Sub Protected Sub btnDeleteDoc_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDeleteDoc.Click Try Dim objDocument As New DocumentStorageCustomDAL Dim fileExt As String fileExt = objDocument.GetExtensionofFile(txtGetDoc.Text) lblDocumentId.Text = fileExt 'objDocument.DeleteDocByStorageId(txtGetDoc.Text) 'lblDocumentId.Text = txtGetDoc.Text + " Deleted Successfully" Catch ex As Exception Response.Write(ex.ToString()) End Try End Sub End Class |
No comments:
Post a Comment