コード例 #1
0
        public void Insert(MarklogicContent[] marklogicContent, MlTransactionScope transaction)
        {
            foreach (var doc in marklogicContent)
            {
                var collections = doc.Collections?.Length > 0
                    ? $", ( {string.Join(", ", doc.Collections.Where(x => !string.IsNullOrEmpty(x)).Select(x => $"'{x}'"))} )"
                    : string.Empty;

                var content = "";
                switch (doc.Media)
                {
                case MediaType.Xml:
                    content = $"xdmp:unquote('{EscapeXml(RemoveXmlHeader(doc.Content))}')";
                    break;

                case MediaType.Json:
                    content = $"xdmp:unquote('{doc.Content}')";
                    break;

                default:
                    throw new ArgumentException("Unknown mime type");
                }

                var query = "xdmp:document-insert(" +
                            $"'{doc.DocumentName}'," +
                            $"{content}, " +
                            "xdmp:default-permissions()" +
                            $"{collections})";

                var resp = transaction == null?Submit(query) : Submit(query, transaction);
            }
        }
コード例 #2
0
        public void RollbackTransaction(MlTransactionScope transaction)
        {
            var result = Submit("xdmp:rollback()", transaction);

            if (!result.IsSuccessStatusCode)
            {
                throw new HttpRequestException(result.Content.ReadAsStringAsync().Result);
            }
        }
コード例 #3
0
        public void AcquireLocks(MlTransactionScope transaction, params string[] lockFiles)
        {
            var batchLock = new MultiStatement();

            foreach (var lockValue in lockFiles)
            {
                var query = new XdmpLockForUpdate(new MlUri(lockValue, MlUriDocumentType.Xml));
                batchLock.Add(query);
            }

            Submit(batchLock.Query, transaction);
        }
コード例 #4
0
        public HttpResponseMessage Submit(string query, MlTransactionScope transaction)
        {
            HttpResponseMessage result = null;

            for (var i = 0; i < _maxTries; i++)
            {
                var content = new StringContent(WebUtility.UrlEncode("xquery") + "=" + WebUtility.UrlEncode(query), null, "application/x-www-form-urlencoded");
                result = Post(_client, $"eval?txid={transaction.TransactionId}", content, transaction.Cookies);

                if (result.IsSuccessStatusCode)
                {
                    transaction.Cookies = GetCookies(result);
                    return(result);
                }
            }

            throw new HttpRequestException(result.Content.ReadAsStringAsync().Result);
        }
コード例 #5
0
        public MlTransactionScope BeginTransaction()
        {
            //https://docs.marklogic.com/REST/POST/v1/transactions
            var response = Post(_client, $"LATEST/transactions?timeLimit={TransactionTimeLimit}", new StringContent("", Encoding.UTF8));

            if (response.StatusCode != HttpStatusCode.SeeOther)
            {
                throw new HttpRequestException(response.Content.ReadAsStringAsync().Result);
            }

            var transaction = new MlTransactionScope
            {
                TransactionId = response.Headers.Location.OriginalString.Split('/').Last(),
                Cookies       = GetCookies(response)
            };

            Submit($"xquery version '1.0-ml'; declare option xdmp:transaction-mode 'update'; xdmp:set-transaction-time-limit({TransactionTimeLimit});", transaction);

            return(transaction);
        }
コード例 #6
0
 public void Insert(MarklogicContent marklogicContent, MlTransactionScope transaction)
 {
     Insert(new[] { marklogicContent }, transaction);
 }