public static void MoveObjects(IRestClient restClient, long[] pFileIds, long pFromId, long pToId,
            TransactionResponse transaction = null)
        {
            if (pFileIds == null || pFileIds.Length == 0)
                return;

            var createRequest = new RestRequest("api/rest/object/move/{id}", Method.POST);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);

            for (var i = 0; i < pFileIds.Length; i++)
            {
                if (i == 0)
                    createRequest.AddUrlSegment("id", pFileIds[i].ToString("D"));
                else
                    createRequest.AddParameter("id", pFileIds[i].ToString("D"));
            }
            createRequest.AddParameter("target", pToId.ToString("D"));
            createRequest.AddParameter("parameters", createRequest.JsonSerializer.Serialize(new
            {
                parent = new[] {pFromId.ToString("D")},
                inheritAcl = true
            }));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }
        public static void CreateLinks(IRestClient restClient, long sourceFileId, long[] destFolderId,
                                      TransactionResponse transaction = null)
        {
            if (destFolderId == null || destFolderId.Length == 0)
                return;

            var createRequest = new RestRequest("api/rest/object/link/{id}", Method.POST);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);

            createRequest.AddUrlSegment("id", sourceFileId.ToString("D"));

            foreach (var value in destFolderId)
            {
                createRequest.AddParameter("target", value.ToString("D"));
            }
            createRequest.AddParameter("parameters", createRequest.JsonSerializer.Serialize(new {aclfromtarget = true}));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse, "duplicate entry");

            //var createRequest = new RestRequest("/api/rest/parse/xml", Method.POST);
            //if (transaction != null)
            //    createRequest.AddParameter("transactionId", transaction.TransactionId);
            //createRequest.AddParameter("xml", AgorumFile.GenerateLinkObjectToFolderXml(sourceFileId, destFolderId));

            //var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);

            //ThrowIfNotSuccessful(tmpResponse, "duplicate");
        }
        public static void CreateFolder(IRestClient restClient, AgorumFolder folder,
                                        TransactionResponse transaction = null)
        {
            var createRequest = new RestRequest("api/rest/object", Method.POST);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);
            createRequest.AddParameter("handler", "object");

            createRequest.AddParameter("data", createRequest.JsonSerializer.Serialize(new Data
                {
                    classname = folder.Classname,
                    name = AgorumObject.RemoveIllegalChars(folder.Name),
                    target = folder.AnyFolderPathId != 0 ? folder.AnyFolderPathId.ToString() : GetAgorumAbsolutePath(folder.AnyFolderPath),
                    createtarget = folder.AnyFolderPathId == 0
                }));

            foreach (var property in folder.GetProperties())
            {
                createRequest.AddParameter("properties", property);
            }

            var tmpResponse = restClient.Execute<RestResponseBaseExt<AgorumFolder>>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);

            folder.FillFromObject(tmpResponse.Data.Data);
        }
 public static void CreateLinks(IRestClient restClient, long[] sourceFileIds, long[] destFolderId,
                               TransactionResponse transaction = null)
 {
     foreach (var sourceFileId in sourceFileIds)
     {
         CreateLinks(restClient, sourceFileId, destFolderId, transaction);
     }
 }
        public static void UpdateAndRenameObject(IRestClient restClient, AgorumObject agObject, TransactionResponse transaction = null)
        {
            //Angabe von Id nicht nötig, da XML ObjectZuweisungen in XML-Anweisung hat und nicht zu einem bestimmten Object hochgeladen wird.
            var createRequest = new RestRequest("/api/rest/parse/xml", Method.POST);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);
            createRequest.AddParameter("xml", agObject.GenerateUpdateObjectXml());

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }
        public static void DeleteObject(IRestClient restClient, long id, TransactionResponse transaction = null)
        {
            var createRequest = new RestRequest("api/rest/object/{id}", Method.DELETE);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);
            createRequest.AddParameter("handler", "object");
            createRequest.AddUrlSegment("id", id.ToString("D"));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }
        public static void DeleteLinks(IRestClient restClient, long fileId, long[] parentId,
                                       TransactionResponse transaction = null)
        {
            if (parentId == null || parentId.Length == 0)
                return;

            foreach (var tmpParent in parentId)
            {
                DeleteLink(restClient, fileId, tmpParent, transaction);
            }
        }
        public static void CommitTransaction(IRestClient restClient, TransactionResponse transaction, bool abortTransaction = false)
        {
            var request = new RestRequest("api/rest/session/transaction/{id}", Method.DELETE);
            //request.AddParameter("id", transaction.TransactionId);
            request.AddUrlSegment("id", transaction.TransactionId);
            request.AddParameter("rollback", abortTransaction); //If true, Transaction gets aborted

            // execute the request
            var responseData = restClient.Execute<RestResponseBaseExt>(request);
            ThrowIfNotSuccessful(responseData);
        }
        public static void DeleteLink(IRestClient restClient, long fileId, long parentId,
                                       TransactionResponse transaction = null)
        {
            var createRequest = new RestRequest("api/rest/object/{id}", Method.DELETE);
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);
            createRequest.AddUrlSegment("id", fileId.ToString("D"));
            createRequest.AddParameter("parameters", createRequest.JsonSerializer.Serialize(new { parent = parentId.ToString("D") }));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }
        public static void RenameObject(IRestClient restClient, AgorumFile agObject, TransactionResponse transaction = null)
        {
            var createRequest = new RestRequest("/api/rest/object/{id}", Method.PUT);
            createRequest.AddUrlSegment("id", agObject.Id.ToString("D"));
            if (transaction != null)
                createRequest.AddParameter("transactionId", transaction.TransactionId);
            createRequest.AddParameter("updatehandler", "object");

            createRequest.AddParameter("data", createRequest.JsonSerializer.Serialize(new
            {
                name = agObject.Name
            }));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }
        public static void UploadFile(IRestClient restClient, AgorumFile file,
                                      byte[] rawFile, TransactionResponse transaction = null)
        {
            //workaround, because agorum wont regognize if "target" is set in body
            var createRequest = new RestRequest("api/rest/object/upload?target={target}", Method.POST);
            if (transaction != null)
            {
                createRequest.Resource = createRequest.Resource + "&transactionId={transId}";
                createRequest.AddUrlSegment("transId", transaction.TransactionId);
            }
            createRequest.AddUrlSegment("target", file.AnyFolderPathId != 0 ? file.AnyFolderPathId.ToString() : GetAgorumAbsolutePath(file.AnyFolderPath));
            createRequest.AddFile("parameters", rawFile, GetValidAgorumFileName(file.Name));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);

            file.Id = tmpResponse.Data.Id;
        }
        public static void UploadFileAndUpdateExisting(IRestClient restClient,
                                                       AgorumFile file,
                                                       byte[] rawFile, TransactionResponse transaction = null)
        {
            var createRequest = new RestRequest("api/rest/object/upload/{id}", Method.POST);
            if (transaction != null)
            {
                createRequest.Resource = createRequest.Resource + "?transactionId={transId}";
                createRequest.AddUrlSegment("transId", transaction.TransactionId);
            }
            createRequest.AddUrlSegment("id", file.Id.ToString("D"));
            createRequest.AddFile("parameters", rawFile, GetValidAgorumFileName(file.Name));

            var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest);
            ThrowIfNotSuccessful(tmpResponse);
        }