Наследование: IDisposable
        public override void SaveToDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId, object settings)
        {
            XmlSerializer xs = new XmlSerializer(settings.GetType());
            string objectXML = string.Empty;
            using (StringWriter sw = new StringWriter())
            {
                xs.Serialize(sw, settings);
                objectXML = sw.ToString();
            }

            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("DataStoreSettings");

                Document spec = new Document();
                spec["ExtensionType"] = exType;
                spec["ExtensionId"] = exId;

                var res = new Document();
                res["Settings"] = objectXML;
                res["ExtensionType"] = exType;
                res["ExtensionId"] = exId;

                coll.Update(res, spec, UpdateFlags.Upsert);
            }
        }
 /// <summary>
 /// Inserts a new Post to the data store.
 /// </summary>
 /// <param name="post"></param>
 public override void InsertPost(Post post)
 {
     using (var mongo = new MongoDbWr())
     {
         var coll = mongo.BlogDB.GetCollection("posts");
         coll.Insert(post.ToDocument());
     }
 }
        public override List<BlogEngine.Core.Page> FillPages()
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection(COLLECTION_PAGES);

                return coll.FindAll().Documents.Select(doc => DocumentToPage(doc)).ToList();
            }
        }
        public override void InsertPage(BlogEngine.Core.Page page)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection(COLLECTION_PAGES);

                var record = PageToDocument(page);

                coll.Insert(record);
            }
        }
        /// <summary>
        /// Deletes a post from the data store.
        /// </summary>
        public override void DeletePost(Post post)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("posts");

                Document spec = new Document();
                spec.Add("id", post.Id);
                coll.Delete(spec);
            }
        }
 public override void RemoveFromDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId)
 {
     using (var mongo = new MongoDbWr())
     {
         var coll = mongo.BlogDB.GetCollection("DataStoreSettings");
         
         Document spec = new Document();
         spec["ExtensionType"] = exType;
         spec["ExtensionId"] = exId;
         
         coll.Delete(spec);
     }
 }
        public override BlogEngine.Core.Page SelectPage(Guid id)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection(COLLECTION_PAGES);

                var spec = new Document();
                spec["Id"] = id;

                var doc = coll.FindOne(spec);

                return DocumentToPage(doc);
            }
        }
        /// <summary>
        /// Retrieves all posts from the data store
        /// </summary>
        /// <returns>List of Posts</returns>
        public override List<Post> FillPosts()
        {
            List<Post> posts = new List<Post>();

            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("posts");

                foreach (Document doc in coll.FindAll().Documents)
                {
                    posts.Add(doc.ToPost());
                }
            }
            return posts;
        }
        public override void SaveSettings(System.Collections.Specialized.StringDictionary settings)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("settings");

                foreach (string key in settings.Keys)
                {
                    Document doc = new Document();
                    doc.Append("name", key);
                    doc.Append("value", settings[key]);

                    coll.Insert(doc);
                }
            }
        }
        public override object LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId)
        {
            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("DataStoreSettings");

                Document spec = new Document();
                spec["ExtensionType"] = exType;
                spec["ExtensionId"] = exId;

                var res = coll.FindOne(spec);
                if (res == null)
                    return null;

                return res["Settings"];
            }
        }
Пример #11
0
        /// <summary>
        /// Retrieves a post based on the specified Id.
        /// </summary>
        public override Post SelectPost(Guid id)
        {
            Post post;

            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("settings");

                Document spec = new Document();
                spec.Add("id", id);

                Document docPost = coll.FindOne(spec);
                post = docPost.ToPost();
            }

            return post;
        }
        public override System.Collections.Specialized.StringDictionary LoadSettings()
        {
            StringDictionary dic;

            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("settings");

                dic = new StringDictionary();

                foreach (var el in coll.FindAll().Documents)
                {
                    dic.Add((string)el["name"], (string)el["value"]);
                }
            }

            // ensure defaults

            if (dic["Theme"] == null)
                dic["Theme"] = "Standard";

            return dic;
        }