Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }