public override void Insert(SearchModel entity, ITransaction transaction)
 {
     using (var writer = new StringWriter())
         using (var xmlWriter = XmlWriter.Create(writer))
         {
             new XmlSerializer(entity.GetType()).Serialize(writer, entity);
             var serializedModel = writer.GetStringBuilder().ToString();
             var content         = MarklogicContent.Xml($"{entity.Id}", serializedModel, new[] { SearchModelConstants.CollectionName });
             RestConnector.Insert(content, transaction.GetScope());
         }
 }
Beispiel #2
0
        public override void Insert(MarklogicDataLayer.DataStructs.Utility entity, ITransaction transaction)
        {
            var utilityKind = entity.Type == OfferType.Olx ? OfferTypeConstants.Olx : OfferTypeConstants.OtoDom;

            using (var writer = new StringWriter())
                using (var xmlWriter = XmlWriter.Create(writer))
                {
                    new XmlSerializer(entity.GetType()).Serialize(writer, entity);
                    var serializedOffer = writer.GetStringBuilder().ToString();
                    var content         = MarklogicContent.Xml($"utility_{utilityKind}", serializedOffer);
                    RestConnector.Insert(content, transaction.GetScope());
                }
        }
        private void InsertEntity(ICommand entity, ITransaction transaction)
        {
            var commandType = entity.GetType().ToString().Split(".").Last();

            using (var writer = new StringWriter())
                using (var xmlWriter = XmlWriter.Create(writer))
                {
                    new XmlSerializer(entity.GetType()).Serialize(writer, entity);
                    var serializedCommand = writer.GetStringBuilder().ToString();
                    var content           = MarklogicContent.Xml($"{commandType}_{entity.GetId()}", serializedCommand, new[] { commandType, CommandConstants.CollectionName });
                    RestConnector.Insert(content, transaction.GetScope());
                }
        }
Beispiel #4
0
 public override void Insert(Offer entity, ITransaction transaction)
 {
     entity.DateOfScraping = DateTime.Now.ToShortDateString();
     entity.TotalCost      = entity.Cost + entity.BonusCost;
     using (var writer = new StringWriter())
         using (var xmlWriter = XmlWriter.Create(writer))
         {
             new XmlSerializer(entity.GetType()).Serialize(writer, entity);
             var serializedOffer = writer.GetStringBuilder().ToString();
             var content         = MarklogicContent.Xml($"offer_{entity.Id}", serializedOffer, new[] { OfferConstants.CollectionName });
             RestConnector.Insert(content, transaction.GetScope());
         }
 }
Beispiel #5
0
        public override void Insert(HtmlData entity, ITransaction transaction)
        {
            entity.LastUpdate = DateTime.Now;
            var offerType = entity.OfferType == OfferType.Olx ? HtmlDataConstants.OlxHtmlData : HtmlDataConstants.OtoDomHtmlData;

            using (var writer = new StringWriter())
                using (var xmlWriter = XmlWriter.Create(writer))
                {
                    new XmlSerializer(entity.GetType()).Serialize(writer, entity);
                    var serializedHtmlData = writer.GetStringBuilder().ToString();
                    var content            = MarklogicContent.Xml($"{offerType}_{entity.Id}", serializedHtmlData, new[] { offerType, HtmlDataConstants.CollectionName });
                    RestConnector.Insert(content, transaction.GetScope());
                }
        }
Beispiel #6
0
        public override void Insert(Link entity, ITransaction transaction)
        {
            entity.LastUpdate = DateTime.Now;
            var linkKind = entity.LinkSourceKind == OfferType.Olx ? OfferTypeConstants.Olx : OfferTypeConstants.OtoDom;

            using (var writer = new StringWriter())
                using (var xmlWriter = XmlWriter.Create(writer))
                {
                    new XmlSerializer(entity.GetType()).Serialize(writer, entity);
                    var serializedLink = writer.GetStringBuilder().ToString();
                    var content        = MarklogicContent.Xml($"{linkKind}_link_{entity.Id}", serializedLink, new[] { linkKind, LinkConstants.CollectionName });
                    RestConnector.Insert(content, transaction.GetScope());
                }
        }
        public void Rollback_Marklogic_content_transaction_does_not_change_document()
        {
            var documentName = "test_02";
            var content      = "test_02_value";
            var doc          = MarklogicContent.Xml(documentName, GetTestDocument(documentName, content));

            var rest = new RestConnector(DbConnectionSettings);

            rest.Insert(doc);

            var transaction = rest.BeginTransaction();

            doc = MarklogicContent.Xml(documentName, GetTestDocument(documentName, $"{content}_changed"));
            rest.Insert(doc, transaction);
            rest.RollbackTransaction(transaction);

            var query    = $"xquery version '1.0-ml'; fn:doc('/{documentName}.xml')";
            var response = rest.Submit(query);
            var actual   = response.Content.ReadAsMultipartAsync().Result.Contents[0].ReadAsStringAsync().Result;
            var expected = MarklogicContent.Xml(documentName, GetTestDocumentXml(documentName, content)).Content;

            Assert.IsTrue(actual.Equals(expected));
        }