/// <summary> /// Try to read a document object. /// </summary> /// <remarks>This function calls internally <see cref="TryGetSord"/>. /// An Exception is thrown, if the returned object is not a document object.</remarks> /// <param name="objId"><see cref="TryGetSord"/></param> /// <param name="accessMode"><see cref="TryGetSord"/></param> /// <param name="docAction">DocAction. If set to <c>DocAction.EditDocument</c> and AccessModes.Lock, the document will copied to the checkout-directory.</param> /// <returns><see cref="TryGetSord"/></returns> /// <exception>IOException: <see cref="TryGetSord"/></exception> /// <exception>InvalidOperationException: object is not a document.</exception> public virtual FWDocument TryGetDocument(string objId, FWAccessModes accessMode, DocAction docAction) { FWSord xsord = TryGetSord(objId, accessMode); if (xsord != null) { if (!(xsord is FWDocument)) { throw new InvalidOperationException("Object " + objId + " is not a document."); } } return((FWDocument)xsord); }
/// <summary> /// Try to read a folder object. /// </summary> /// <remarks>This function calls internally <see cref="TryGetSord"/>. /// An Exception is thrown, if the returned object is not a folder object.</remarks> /// <param name="objId"><see cref="TryGetSord"/></param> /// <param name="accessMode"><see cref="TryGetSord"/></param> /// <returns><see cref="TryGetSord"/></returns> /// <exception>IOException: <see cref="TryGetSord"/></exception> /// <exception>InvalidOperationException: object is not a folder.</exception> public virtual FWFolder TryGetFolder(String objId, FWAccessModes accessMode) { FWSord xsord = TryGetSord(objId, accessMode); if (xsord != null) { if (!(xsord is FWFolder)) { throw new InvalidOperationException("Object " + objId + " is not a folder."); } } return((FWFolder)xsord); }
/// <summary> /// Try to read a document. /// </summary> /// <param name="objId">Object ID</param> /// <param name="accessMode">A combination of the FWAccessMode constants.</param> /// <returns>Null, if throwEx=false and the document does not exist. /// Otherwise a FWDocument object is returned.</returns> public override FWDocument TryGetDocument(String objId, FWAccessModes accessMode) { FWDocument xdoc = null; if (FWLockMode.HasLock(accessMode)) { try { // The document must be checked out via ELOFS. // Thus we have to find out the file system path of the document first. // call checkoutDoc to read the archive path Sord sord = Conn.Ix.checkoutDoc(objId, null, new EditInfoZ(0L, new SordZ(SordC.mbId | SordC.mbType | SordC.mbLockId | SordC.mbRefPaths | SordC.mbDocVersionMembers)), LockC.NO).sord; if (sord.id == 1 || sord.type < SordC.LBT_DOCUMENT) { throw new InvalidOperationException("Object " + objId + " is not a document."); } // checkout: set file attribute archive, reset file attribute read-only String winPath = GetFileSystemPath(sord, sord.docVersion); FileAttributes attrs = File.GetAttributes(winPath); attrs |= FileAttributes.Archive; attrs &= ~FileAttributes.ReadOnly; File.SetAttributes(winPath, attrs); // get all required values xdoc = base.TryGetDocument(objId, FWAccessModes.Nothing); } catch (Exception e) { if ((accessMode & FWAccessModes.MustExist) != 0) { throw e; } if (e.Message.IndexOf("[ELOIX:" + IXExceptionC.NOT_FOUND) < 0) { throw e; } } } else { xdoc = base.TryGetDocument(objId, accessMode); } return(xdoc); }
/// <summary> /// Makes a LockZ object from a FWAccessModes enum. /// </summary> /// <param name="accessMode">Access mode</param> /// <returns>Lock object</returns> public static LockZ MakeLockZ(FWAccessModes accessMode) { LockZ lockZ = LockC.NO; if ((accessMode & FWAccessModes.Lock) == FWAccessModes.Lock) { lockZ = LockC.IF_FREE; } if ((accessMode & FWAccessModes.LockAgain) == FWAccessModes.LockAgain) { lockZ = LockC.YES; } if ((accessMode & FWAccessModes.LockForce) == FWAccessModes.LockForce) { lockZ = LockC.FORCE; } return(lockZ); }
/// <summary> /// Returns true, if the given access mode contains any lock /// </summary> /// <param name="accessMode">Access mode</param> /// <returns>True, if accessMode contains one of the lock constants</returns> public static bool HasLock(FWAccessModes accessMode) { return((accessMode & FWAccessModes.Lock) != 0); }
/// <summary> /// Try to read a document object. /// </summary> /// <remarks>This function calls internally <see cref="TryGetSord"/>. /// An Exception is thrown, if the returned object is not a document object.</remarks> /// <param name="objId"><see cref="TryGetSord"/></param> /// <param name="accessMode"><see cref="TryGetSord"/></param> /// <returns><see cref="TryGetSord"/></returns> /// <exception>IOException: <see cref="TryGetSord"/></exception> /// <exception>InvalidOperationException: object is not a document.</exception> public virtual FWDocument TryGetDocument(String objId, FWAccessModes accessMode) { return(TryGetDocument(objId, accessMode, DocAction.EditOnlyIndexData)); }
/// <summary> /// Try to read a Sord object. /// </summary> /// <param name="objId">Object ID</param> /// <param name="accessMode">A combination of the FWAccessMode constants.</param> /// <param name="docAction">DocAction. /// If the Sord object is a <c>FWDocument</c> and the parameter is set to <c>DocAction.EditDocument</c> and FWAccessMode.Lock is set, the document will copied to the checkout-directory. /// Th eparameter will be ignored, if the Sord object is a <c>FWFolder</c>. /// </param> /// <returns>Sord object or null, if the object does not exist and accessMode does not include MustExist.</returns> /// <exception>IOException: object already locked, access denied, etc.</exception> public virtual FWSord TryGetSord(string objId, FWAccessModes accessMode, DocAction docAction) { FWSord xsord = null; bool exceptionOccured = false; FWSord tmpSord = null; try { //GetSord(objId); LockZ lockZ = FWLockMode.MakeLockZ(FWAccessModes.MustExist); Sord sord = Conn.Ix.checkoutDoc(objId, null, EditZ, lockZ).sord; sord.changedMembers = EditZ.bset; if (sord.id == 1 || sord.type < SordC.LBT_DOCUMENT) { tmpSord = ClassFactory.NewFolder(sord); } else { tmpSord = ClassFactory.NewDocument(sord); } } catch (Exception e) { exceptionOccured = true; if ((accessMode & FWAccessModes.MustExist) != 0) { throw e; } if (e.Message.IndexOf("[ELOIX:" + IXExceptionC.NOT_FOUND) < 0) { throw e; } } if (tmpSord != null && tmpSord.IsDocument() && docAction == DocAction.EditDocument) { CheckoutResult result = checkedOutDocumentsManagerVal.Checkout(tmpSord as FWDocument); if (result.Success) { xsord = result.FWDocument; } } else if (!exceptionOccured) { try { LockZ lockZ = FWLockMode.MakeLockZ(accessMode); Sord sord = Conn.Ix.checkoutDoc(objId, null, EditZ, lockZ).sord; sord.changedMembers = EditZ.bset; if (sord.id == 1 || sord.type < SordC.LBT_DOCUMENT) { xsord = ClassFactory.NewFolder(sord); } else { xsord = ClassFactory.NewDocument(sord); } } catch (Exception e) { if ((accessMode & FWAccessModes.MustExist) != 0) { throw e; } if (e.Message.IndexOf("[ELOIX:" + IXExceptionC.NOT_FOUND) < 0) { throw e; } } } return(xsord); }
/// <summary> /// Try to read a Sord object. /// </summary> /// <param name="objId">Object ID</param> /// <param name="accessMode">A combination of the FWAccessMode constants.</param> /// <returns>Sord object or null, if the object does not exist and accessMode does not include MustExist.</returns> /// <exception>IOException: object already locked, access denied, etc.</exception> public virtual FWSord TryGetSord(String objId, FWAccessModes accessMode) { return(TryGetSord(objId, accessMode, DocAction.EditOnlyIndexData)); }