{"id":996,"date":"2023-06-30T14:06:31","date_gmt":"2023-06-30T14:06:31","guid":{"rendered":"https:\/\/doc.bim.fm\/?post_type=docs&#038;p=996"},"modified":"2023-06-30T14:06:34","modified_gmt":"2023-06-30T14:06:34","slug":"lock-file","status":"publish","type":"docs","link":"https:\/\/doc.bim.fm\/index.php\/en\/docs\/api-3\/lock-file\/","title":{"rendered":"Lock file"},"content":{"rendered":"\n<p>To<strong> <\/strong>prevent multiple users from changing the same file at the same time, user must check out or lock a file before updating it. (The checkout and checkin operations are equivalent to lock and unlock, respectively)<\/p>\n\n\n\n<p>Checking out a file grants exclusive update rights to the user who has the item checked out. When users check out a file, they hold a persistent write-lock on that file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>We have 3 lock types:<\/strong><\/p>\n\n\n\n<ul><li><strong>Persistent lock<\/strong><\/li><\/ul>\n\n\n\n<p>A persistent-lock is persistent and tied to a username, not a connected session. A persistent-lock remains in effect until either user with the SuperCheckIn privilege unlocks your item. Furthermore, the same user is allowed to make changes in any authenticated session. If you connect using the same user name to multiple connections, each connection has permission to update the write-lock.<\/p>\n\n\n\n<ul><li><strong>Transient lock<\/strong><\/li><\/ul>\n\n\n\n<p>A Transient lock is volatil (expire after 30minutes unless refreshed &#8211; See RefreshLock), a transient lock like a persistent lock, prevents anyone that does not have a valid lock ID from making changes to a file.<\/p>\n\n\n\n<ul><li><strong>And read only lock<\/strong><\/li><\/ul>\n\n\n\n<p>Read only is a special lock to prevent anyone from making change to a file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Please find bellow the possible actions depending of the lock type:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Action<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Lock: Persistent or Transient<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Readonly<\/strong><\/td><\/tr><tr><td>Upload a new version<\/td><td class=\"has-text-align-center\" data-align=\"center\">Yes if owner<\/td><td class=\"has-text-align-center\" data-align=\"center\">No<\/td><\/tr><tr><td>Rename file<\/td><td class=\"has-text-align-center\" data-align=\"center\">No<\/td><td class=\"has-text-align-center\" data-align=\"center\">No<\/td><\/tr><tr><td>Move file<\/td><td class=\"has-text-align-center\" data-align=\"center\">Yes<\/td><td class=\"has-text-align-center\" data-align=\"center\">Yes<\/td><\/tr><tr><td>Delete file<\/td><td class=\"has-text-align-center\" data-align=\"center\">No<\/td><td class=\"has-text-align-center\" data-align=\"center\">No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/doc.bim.fm\/wp-content\/uploads\/2021\/10\/LockSeq.png\" alt=\"\" class=\"wp-image-575\" width=\"292\" height=\"342\"\/><figcaption>Typical checkout\/checkin sequence<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/doc.bim.fm\/wp-content\/uploads\/2021\/11\/TypicalLockSeqError.png\" alt=\"\" class=\"wp-image-601\" width=\"430\" height=\"440\"\/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<h2>CheckOut<\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-column\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-top has-luminous-vivid-orange-color has-text-color\">\n<div class=\"wp-block-buttons\">\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link\" href=\"https:\/\/localhost:8445\/apidoc\/index.html#\/Project\/Project_CheckOut\" target=\"_blank\" rel=\"noreferrer noopener\">API reference<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<p>The Lock operation locks a file for editing by client application instance that requested the lock. When locked, a file should not be writable by other applications.<\/p>\n\n\n\n<p><strong>Parameters<\/strong><\/p>\n\n\n\n<ul><li>projectId (string) A string that represent the unique identifier for the project, using 32 hexadecimal characters.<\/li><li>inodeId (string) A string that represent the unique file identifier, using 32 hexadecimal characters.<\/li><\/ul>\n\n\n\n<p><strong>Response<\/strong><\/p>\n\n\n\n<p>If the file is currently unlocked, the server should lock the file and return an HTTP status code 200 OK.<\/p>\n\n\n\n<p>If the file is currently locked, the server return an HTTP status 401 Unauthorized with an error code 22.<\/p>\n\n\n\n<p>In all other cases, the server must return a \u201clock conflict\u201d response (500). <\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<h2>CheckIn<\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-column\"><\/div>\n\n\n\n<div class=\"wp-block-column\">\n<div class=\"wp-block-buttons\">\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link has-luminous-vivid-orange-color has-text-color\" href=\"https:\/\/localhost:8445\/apidoc\/index.html#\/Project\/Project_CheckIn\" target=\"_blank\" rel=\"noreferrer noopener\">API reference<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<p>The Unlock operation releases the lock on a file.<\/p>\n\n\n\n<p>Clients will usually make a Lock request to lock a file prior to calling this operation. The client will pass the Inode ID previously locked in the lock request.<\/p>\n\n\n\n<p><strong>Parameters<\/strong><\/p>\n\n\n\n<ul><li>projectId (string) A string that represent the unique identifier for the project, using 32 hexadecimal characters.<\/li><li>inodeId (string) A string that represent the unique file identifier, using 32 hexadecimal characters.<\/li><\/ul>\n\n\n\n<p><strong>Response<\/strong><\/p>\n\n\n\n<p>If the file is currently lock by the request user, the server should unlock the file and return an HTTP status code 200.<\/p>\n\n\n\n<p>If the file is lock by another user, the server return an HTTP status 401 Un authorized with an error code 22. <\/p>\n\n\n\n<p>In all other case, the server must return a &#8220;lock conflict&#8221; response (HTTP status 500).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<h2>StealLock<\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-column\"><\/div>\n\n\n\n<div class=\"wp-block-column\">\n<div class=\"wp-block-buttons\">\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link has-luminous-vivid-orange-color has-text-color\">API reference<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<p>The steal-lock operation force a file to be unlock and relock it for the current logged on user. This operation can be request only on a PERSISTENT lock.<\/p>\n\n\n\n<p><strong>Parameters<\/strong><\/p>\n\n\n\n<ul><li>projectId (string) A string that represent the unique identifier for the project, using 32 hexadecimal characters.<\/li><li>inodeId (string) A string that represent the unique file identifier, using 32 hexadecimal characters.<\/li><\/ul>\n\n\n\n<p>Response<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2>C# API example<\/h2>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>\/\/ Login to the server\nBimfmApi bimfmapi = new BimfmApi();\nbimfmapi.mHttpRqs.BimFmUrl = \"https:\/\/dev.edifycad.com\/api\";\nTokens myToken = bimfmapi.token(\n    new Login() {\n        username = id,\n        password = password,\n        grant_type = \"password\"\n    }).Result;\n\n...\n\n\/\/ Lock a file\ntry\n{\n    ResponseApi&lt;ProjectInodeLockDto&gt; lock = <strong>bimfmapi.project.Checkout(projectId, inodeId);<\/strong>\n    if (folders.Status != 200)\n    {\n         switch (folders.ErrorCode)\n         {\n              case ERROR_CODE.FILE_ALREADY_LOCK:\n                   logger.Error(\"File already lock by another user.\");\n                   break;\n              case ERROR_CODE.LOCK_CONFLICT:\n                   logger.Error(\"File can be lock.\");\n\n                   break;\n              default:\n                    logger.Error(\"Un-managed exception.\");\n              }\n          }\n\n     }\n}\ncatch (Exception ex)\n{\n     ...\n}\n\n\n...\n\n\/\/ Upload a new version\nbimfmapi.project.UploadNewVersionRequest(\"myfile.qsp\", filecontent, projectId, folderId, inodeId);\n\n...\n\n\/\/ Unlock file\ntry\n{\n    ResponseApi&lt;ProjectInodeLockDto&gt; lock = <strong>bimfmapi.project.Checkin(projectId, inodeId)<\/strong>;\n    if (folders.Status != 200)\n    {\n         switch (folders.ErrorCode)\n         {\n              case ERROR_CODE.FILE_NOT_LOCK:\n                   logger.Error(\"File not lock. Please checkout file before checkin.\");\n                   break;\n              case ERROR_CODE.LOCK_CONFLICT:\n                   logger.Error(\"File can be lock.\");\n                   break;\n              default:\n                    logger.Error(\"Un-managed exception.\");\n              }\n          }\n\n     }\n}\ncatch (Exception ex)\n{\n     ...\n}\n\n<\/code><\/pre>\n\n\n\n<p> <\/p>\n","protected":false},"featured_media":0,"parent":992,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"_links":{"self":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/996"}],"collection":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/comments?post=996"}],"version-history":[{"count":1,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/996\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/996\/revisions\/997"}],"up":[{"embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/992"}],"prev":[{"title":"Authentificate","link":"https:\/\/doc.bim.fm\/index.php\/en\/docs\/api-3\/authentificate\/","href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/994"}],"wp:attachment":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/media?parent=996"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/doc_tag?post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}