Ejemplo n.º 1
0
 /// <summary>
 /// AUTHOR: Ashok Kolwal
 /// COMPANY: VITRANA
 /// Version: 1.0
 /// Description: The execute method of an IDfMoveOperation object moves the current versions of documents or folders from one
 /// repository location to an other by unlinking them from the source location and linking them to the destination.
 /// Versions other than the current version remain linked to the original location.
 /// Last Modified date: 11 Jul,2017
 /// </summary>
 /// <param name="mySession"></param>
 /// <param name="docId"></param>
 /// <param name="destination"></param>
 /// <returns></returns>
 public String MoveObject(IDfSession mySession, String docId, String destination)
 {
     try
     {
         IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + docId + "'");
         // Create a new client instance.
         IDfClientX clientx = new DfClientX();
         // Use the factory method to create an IDfCopyOperation instance.
         IDfMoveOperation mo = clientx.getMoveOperation();
         // Create an instance for the destination directory.
         IDfFolder destinationDirectory = mySession.getFolderByPath(destination);
         // Set the destination directory by ID.
         mo.setDestinationFolderId(destinationDirectory.getObjectId());
         // Create a document object that represents the document being copied.
         IDfDocument doc = (IDfDocument)mySession.getObject(idObj);
         // Create a move node, adding the document to the move operation object.
         IDfMoveNode node = (IDfMoveNode)mo.add(doc);
         // Execute and return results
         if (mo.execute())
         {
             return("Move operation successful.");
         }
         else
         {
             return("Move operation failed.");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error while moving object : " + ex.Message + "\n StackTrace: " + ex.StackTrace);
         return(null);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// AUTHOR: Ashok Kolwal
        /// COMPANY: VITRANA
        /// Version: 1.0
        /// Description: The execute method of an IDfCopyOperation object copies the current versions of documents
        /// or folders from one repository location to another.
        /// Last Modified date: 11 Jul,2017
        /// </summary>
        /// <param name="sessionManager"></param>
        /// <param name="repositoryName"></param>
        /// <param name="docId"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public String CopyDocument(IDfSessionManager sessionManager, String repositoryName, String docId, String destination)
        {
            IDfSession    mySession = null;
            StringBuilder sb        = new StringBuilder("");

            try
            {
                mySession = sessionManager.getSession(repositoryName);
                // Get the object ID based on the object ID string.
                IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + docId + "'");
                // Instantiate an object from the ID.
                IDfSysObject sysObj = (IDfSysObject)mySession.getObject(idObj);
                // Create a new client instance.
                IDfClientX clientx = new DfClientX();
                // Use the factory method to create an IDfCopyOperation instance.
                IDfCopyOperation co = clientx.getCopyOperation();
                // Remove the path separator if it exists.
                if (destination.LastIndexOf("/") == destination.Length - 1 || destination.LastIndexOf("\\") == destination.Length - 1)
                {
                    destination = destination.Substring(0, destination.Length - 1);
                }
                // Create an instance for the destination directory.
                IDfFolder destinationDirectory = mySession.getFolderByPath(destination);
                // Set the destination directory by ID.
                co.setDestinationFolderId(destinationDirectory.getObjectId());
                // Create a document object that represents the document being copied.
                //IDfDocument doc = (IDfDocument)mySession.getObject(new DfId(docId));
                IDfDocument doc = (IDfDocument)mySession.getObject(idObj);
                // Create a copy node, adding the document to the copy operation object.
                IDfCopyNode node = (IDfCopyNode)co.add(doc);
                // Execute and return results
                if (co.execute())
                {
                    return("Copy operation successful.");
                }
                else
                {
                    return("Copy operation failed.");
                }
            }
            // Handle any exceptions.
            catch (Exception ex)
            {
                Console.WriteLine("Error while copying object : " + ex.Message + "\n StackTrace: " + ex.StackTrace);
                return("Exception has been thrown: " + ex);
            }
            // Always, always, release the session in the "finally" clause.
            finally
            {
                sessionManager.release(mySession);
            }
        }