Beispiel #1
0
 /// <summary>
 /// In this current version of our example, we don't know what our user data looks like - we just know we have a string
 /// representation of Xml. Let's take that data and save it in the database, so we can perform analysis on it later.
 /// </summary>
 /// <param name="itemData">The string we pulled from the Users file.</param>
 /// <param name="category">The item category, used for sorting/querying later.</param>
 public void InsertItem(string itemData, string category)
 {
     // set up to retry 20 times
     while (true)
     {
         if (disposing)
         {
             return;
         }
         using (var tx = Manager.CreateTransaction(TransactionType.SnapshotTransaction))
         {
             try
             {
                 var doc = Manager.CreateDocument();
                 doc.SetContent(itemData);
                 doc.SetMetadata(META_URI, "category", new XmlValue(category));
                 doc.Name = category;
                 using (var uc = Manager.CreateUpdateContext()) { BeerDb.PutDocument(tx, doc, uc, PutDocumentOptions.GenerateFileName); }
                 //using (var uc = Manager.CreateUpdateContext()) { BeerDb.PutDocument(doc, uc,PutDocumentOptions.GenerateFileName); }
                 tx.Commit();
                 doc.Dispose();
                 break;
             }
             catch (Exception ex)
             {
                 tx.Abort();
                 Console.WriteLine("{0} {1}: write error: {2}", DateTime.Now, ex.GetType(), ex.Message);
                 //give the reader a chance to retry before resuming writes
                 Thread.Sleep(300);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Inserts an XML record pulled from a URL.
        /// </summary>
        /// <param name="url">The URL to extract XML from.</param>
        /// <returns>The name of the record.</returns>
        public string InsertRecordFromUrl(string url)
        {
            var name = "record" + DateTime.Now.ToFileTimeUtc();
            var stm  = Manager.CreateUrlInputStream(string.Empty, url);
            var doc  = Manager.CreateDocument();

            doc.SetContentAsInputStream(stm);
            doc.Name = name;

            //add metadata to the record.
            doc.SetMetadata("http://schemas.bdbxml.net/metadata", "CreatedDate",
                            new XmlValue(DateTime.Now.ToString()));
            using (var uc = Manager.CreateUpdateContext()) { BeerDb.PutDocument(doc, uc); }
            return(name);
        }
Beispiel #3
0
        /// <summary>
        /// Insert a System.Xml.XmlDocument into the database.
        /// </summary>
        /// <param name="doc">The document to insert.</param>
        /// <returns>The document name, for lookup purposes.</returns>
        public string InsertRecord(System.Xml.XmlDocument doc)
        {
            if (disposing)
            {
                return(string.Empty);
            }
            var name = "record" + DateTime.Now.ToFileTimeUtc();
            var xml  = Manager.CreateDocument(doc);

            xml.Name = name;
            //add metadata to the record.
            xml.SetMetadata("http://schemas.bdbxml.net/metadata", "CreatedDate",
                            new XmlValue(DateTime.Now.ToString()));
            using (var uc = Manager.CreateUpdateContext()) { BeerDb.PutDocument(xml, uc); }
            return(name);
        }