chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1083276 - in /chemistry/site/trunk/content/dotnet: dotcmis.mdtext powershell-example.mdtext
Date Sat, 19 Mar 2011 20:19:13 GMT
Author: fmui
Date: Sat Mar 19 20:19:12 2011
New Revision: 1083276

URL: http://svn.apache.org/viewvc?rev=1083276&view=rev
Log:
added PowerShell page

Added:
    chemistry/site/trunk/content/dotnet/powershell-example.mdtext   (with props)
Modified:
    chemistry/site/trunk/content/dotnet/dotcmis.mdtext

Modified: chemistry/site/trunk/content/dotnet/dotcmis.mdtext
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/dotnet/dotcmis.mdtext?rev=1083276&r1=1083275&r2=1083276&view=diff
==============================================================================
--- chemistry/site/trunk/content/dotnet/dotcmis.mdtext (original)
+++ chemistry/site/trunk/content/dotnet/dotcmis.mdtext Sat Mar 19 20:19:12 2011
@@ -22,8 +22,8 @@ DotCMIS client|[Download](http://www.apa
 <a name="DotCMIS-Documentation"></a>
 ## Documentation
 
-There are starter code snippets on the [Getting started with DotCMIS](getting-started-with-dotcmis.html)
page
-and the API documentation is available as a [CHM Help file](https://builds.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/doc/DotCMISDoc.chm).
+There are starter code snippets on the [Getting started with DotCMIS](getting-started-with-dotcmis.html)
page and the [PowerShell Example](powershell-example.html) page.
+The API documentation is available as a [CHM Help file](https://builds.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/doc/DotCMISDoc.chm).
 
 The interfaces are very similar to the [OpenCMIS](/java/opencmis.html) client API. Please
see the
 OpenCMIS documentation for more insights.
@@ -38,5 +38,5 @@ DotCMIS requires the .NET Framework vers
 
 The DotCMIS unit tests require NUnit 2.5.
 
-Nighty builds can be obtained from here: [Debug DLL](https://hudson.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/bin/Debug/)
- and [Release DLL](https://hudson.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/bin/Release/).
+Nighty builds can be obtained from here: [Debug DLL](https://builds.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/bin/Debug/)
+ and [Release DLL](https://builds.apache.org/hudson/job/Chemistry%20-%20DotCMIS/ws/bin/Release/).

Added: chemistry/site/trunk/content/dotnet/powershell-example.mdtext
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/dotnet/powershell-example.mdtext?rev=1083276&view=auto
==============================================================================
--- chemistry/site/trunk/content/dotnet/powershell-example.mdtext (added)
+++ chemistry/site/trunk/content/dotnet/powershell-example.mdtext Sat Mar 19 20:19:12 2011
@@ -0,0 +1,117 @@
+Title: PowerShell Examples
+# PowerShell Examples
+
+The DotCMIS DLL can be used in PowerShell scripts. Here is a simple example.
+
+
+    # load DotCMIS DLL
+    [Reflection.Assembly]::LoadFile("X:\path\to\DotCMIS.dll")
+    
+    
+    # -----------------------------------------------------------------
+    
+    # helper functions
+    function New-GenericDictionary([type] $keyType, [type]$valueType) {  
+       $base = [System.Collections.Generic.Dictionary``2]  
+       $ct = $base.MakeGenericType(($keyType, $valueType))  
+       New-Object $ct
+    }
+    
+    function New-ContentStream([string] $file, [string] $mimetype) {
+       $fileinfo = ([System.IO.FileInfo]$file)
+       
+       $contentStream = New-Object "DotCMIS.Data.Impl.ContentStream"
+       $contentStream.Filename = $fileinfo.Name
+       $contentStream.Length = $fileinfo.Length
+       $contentStream.MimeType = $mimetype
+       $contentStream.Stream = $fileinfo.OpenRead()
+       
+       $contentStream
+    }
+    
+    function Download-ContentStream([DotCMIS.Client.IDocument] $document, [string] $file)
{
+       $contentStream = $document.GetContentStream()   
+       $fileStream = [System.IO.File]::OpenWrite($file)
+    
+       $buffer = New-Object byte[] 4096  
+       do {  
+          $b = $contentStream.Stream.Read($buffer, 0, 4096)  
+          $fileStream.Write($buffer, 0, $b)  
+       }  
+       while ($b -ne 0)
+       
+       $fileStream.Close()
+       $contentStream.Stream.Close()
+    }
+    
+    
+    # -----------------------------------------------------------------
+    
+    # create session
+    $sp = New-GenericDictionary string string
+    $sp["org.apache.chemistry.dotcmis.binding.spi.type"] = "atompub";
+    $sp["org.apache.chemistry.dotcmis.binding.atompub.url"] = "http://localhost:8080/alfresco/service/cmis"
+    $sp["org.apache.chemistry.dotcmis.user"] = "admin";
+    $sp["org.apache.chemistry.dotcmis.password"] = "admin";
+    
+    $factory = [DotCMIS.Client.Impl.SessionFactory]::NewInstance()
+    $session = $factory.GetRepositories($sp)[0].CreateSession()
+    
+    
+    # print the repository infos
+    $session.Repositoryinfo.Id
+    $session.Repositoryinfo.Name
+    $session.Repositoryinfo.Vendor
+    $session.Repositoryinfo.ProductName
+    $session.Repositoryinfo.ProductVersion
+    
+    
+    # get root folder
+    $root = $session.GetRootFolder()
+    
+    
+    # print root folder children
+    $children = $root.GetChildren()
+    foreach ($object in $children) {
+       $object.Name + "     (" + $object.ObjectType.Id + ")" 
+    }
+    
+    
+    # run a quick query
+    $queryresult = $session.Query("SELECT * FROM cmis:document", $false)
+    foreach ($object in $queryresult) {
+       foreach ($item in $object.Properties) {
+          $item.QueryName + ": " + $item.FirstValue
+       }
+       "----------------------------------"
+    }
+    
+    
+    # create a folder
+    $folderProperties = New-GenericDictionary string object
+    $folderProperties["cmis:name"] = "myNewFolder"
+    $folderProperties["cmis:objectTypeId"] = "cmis:folder"
+    
+    $folder = $root.CreateFolder($folderProperties)
+    
+    
+    # create a document 
+    $documentProperties = New-GenericDictionary string object
+    $documentProperties["cmis:name"] = "myNewDocument"
+    $documentProperties["cmis:objectTypeId"] = "cmis:document"
+    
+    $source = $home + "\source.txt"
+    $mimetype = "text/plain"
+    $contentStream = New-ContentStream $source $mimetype
+    
+    $doc = $folder.CreateDocument($documentProperties, $contentStream, $null)
+    
+    
+    # download a document
+    $target = $home + "\target.txt"
+    Download-ContentStream $doc $target
+    
+    
+    # clean up
+    $doc.Delete($true)
+    $folder.Delete($true)

Propchange: chemistry/site/trunk/content/dotnet/powershell-example.mdtext
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message