예제 #1
0
        public long get_ID_Node(string authTocken, long parent_id, string nom_dossier)
        {
            DocumentManagementClient docManClient = new DocumentManagementClient();

            CWS.DocumentManagement.OTAuthentication otAuthDocManger = new CWS.DocumentManagement.OTAuthentication();
            otAuthDocManger.AuthenticationToken = authTocken;
            Node folder = null;

            try
            {
                folder = docManClient.GetNodeByName(ref otAuthDocManger, parent_id, nom_dossier);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                // Always close the client
                docManClient.Close();
            }
            if (folder != null)
            {
                return(folder.ID);
            }
            else
            {
                return(0);
            }
        }
 private long UploadFile(long parentId, string path,DoWorkEventArgs e)
 {
     if (_worker.CancellationPending){ e.Cancel = true;
         return -1;
     }
     ContentServiceClient contentService=new ContentServiceClient();
     DocumentManagementClient docMan = new DocumentManagementClient();
     FileInfo info = new FileInfo(path);
     _worker.ReportProgress(_counter, new {CurrentFile=info.Name});
     FileAtts fileAtts = new FileAtts
     {
         CreatedDate = info.CreationTime,
         FileName = info.Name,
         FileSize = info.Length,
         ModifiedDate = info.LastWriteTime
     };
     var stream = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read);
     ProgressStream pStream = new ProgressStream(stream);
     pStream.ProgressChanged += pStream_ProgressChanged;
     try
     {
         bool isVersionAdded = false;
         var res =
             docMan.GetNodeByName(ref _otAuthentication, parentId,
                 info.Name);
         string contextId;
         if (res == null)
         {
             contextId=docMan.CreateDocumentContext(ref _otAuthentication, parentId, info.Name, null,
                 false, null);
         }
         else
         {
             contextId = docMan.AddVersionContext(ref _otAuthentication, res.ID, null);
             isVersionAdded = true;
         }
         var id = contentService.UploadContent(ref _otAuthentication, contextId, fileAtts, pStream);
         ++_counter;
         _worker.ReportProgress(_counter,new {Message=isVersionAdded
                 ? string.Format("{{{0}}} - Version {1} added.", id, info.Name)
                 : string.Format("{{{0}}} - Document {1} added.", id, info.Name)});
     }
     catch (Exception ex)
     {
         _worker.ReportProgress(_counter, new {Message=ex.ToString()});
     }
     finally
     {
         contentService.Close();
         docMan.Close();
         stream.Close();
     }
     return -1;
 }
 private long CreateFolder(long parentId, string path)
 {
     DirectoryInfo info = new DirectoryInfo(path);
     _worker.ReportProgress(_counter, new {CurrentFile=info.Name});
     DocumentManagementClient documentManagementClient = new DocumentManagementClient();
     var node = documentManagementClient.GetNodeByName(ref _otAuthentication, parentId,
         info.Name);
     if (node == null)
     {
         var createFolderRes = documentManagementClient.CreateFolder(ref _otAuthentication,
             parentId,
             info.Name, null, null);
         documentManagementClient.Close();
         node = createFolderRes;
         ++_counter;
         _worker.ReportProgress(_counter, new{Message=string.Format("{{{0}}} - Folder {1} added.", node.ID, info.Name)});
     }
     else
     {
         ++_counter;
         _worker.ReportProgress(_counter, new{Message=string.Format("{{{0}}} - Folder {1} already exits.",node.ID,info.Name)});
     }
     return node.ID;
 }