/// <summary> /// Get all database information /// </summary> public BsonObject GetDatabaseInfo() { this.Transaction.AvoidDirtyRead(); var info = new BsonObject(); var param = new BsonObject(); info["filename"] = this.ConnectionString.Filename; info["journal"] = this.ConnectionString.JournalEnabled; info["timeout"] = this.ConnectionString.Timeout.TotalSeconds; info["version"] = this.Cache.Header.UserVersion; info["changeID"] = this.Cache.Header.ChangeID; info["fileLength"] = (this.Cache.Header.LastPageID + 1) * BasePage.PAGE_SIZE; info["lastPageID"] = this.Cache.Header.LastPageID; info["pagesInCache"] = this.Cache.PagesInCache; info["dirtyPages"] = this.Cache.GetDirtyPages().Count(); // parameters info param[MAX_FILE_LENGTH] = this.Cache.Header.MaxFileLength == long.MaxValue ? BsonValue.Null : new BsonValue(this.Cache.Header.MaxFileLength); param[INDEX_IGNORE_CASE] = true; param[INDEX_WHITESPACE_TO_NULL] = true; info["parameters"] = param; return(info); }
internal FileEntry(LiteEngine engine, BsonDocument doc) { _engine = engine; this.Id = doc.Id.ToString(); this.Filename = doc["filename"].AsString; this.MimeType = doc["mimeType"].AsString; this.Length = doc["length"].AsLong; this.UploadDate = doc["uploadDate"].AsDateTime; this.Metadata = doc["metadata"].AsObject; }
public BsonObject Stats() { _engine.Transaction.AvoidDirtyRead(); var col = this.GetCollectionPage(false); if (col == null) { return(new BsonObject()); } var stats = new BsonObject(); stats["name"] = col.CollectionName; stats["documents"] = col.DocumentCount; //TODO: Não tenho como fazer de forma eficiente. // Não tenho um link de todas as paginas de uma mesma colecao // Somente quando implementar os Drop/DropCollection corretos vou conseguir isso // // db.collection.dataSize(): data size in bytes for the collection. // db.collection.storageSize(): allocation size in bytes, including unused space. // db.collection.totalSize(): the data size plus the index size in bytes. // db.collection.totalIndexSize(): the index size in bytes. // indexes stats["indexes"] = new BsonArray(); for (var i = 0; i < col.Indexes.Length; i++) { var index = col.Indexes[i]; if (index.IsEmpty) { continue; } var idx = new BsonObject(); idx["field"] = index.Field; idx["unique"] = index.Unique; // nullCount // avg key size // % (0.00-1.00) distinct > quanto mais proximo do 1 melhor, mais seletivo stats["indexes"].AsArray.Add(idx); } return(stats); }
public FileEntry(string id, string filename) { if (!Regex.IsMatch(id, ID_PATTERN)) { throw new LiteException("Invalid file id format."); } this.Id = id; this.Filename = Path.GetFileName(filename); this.MimeType = MimeTypeConverter.GetMimeType(this.Filename); this.Length = 0; this.UploadDate = DateTime.Now; this.Metadata = new BsonObject(); }
/// <summary> /// Get all database information /// </summary> public BsonObject GetDatabaseInfo() { this.Transaction.AvoidDirtyRead(); var info = new BsonObject(); info["filename"] = this.ConnectionString.Filename; info["journal"] = this.ConnectionString.JournalEnabled; info["timeout"] = this.ConnectionString.Timeout.TotalSeconds; info["version"] = this.Cache.Header.UserVersion; info["changeID"] = this.Cache.Header.ChangeID; info["fileLength"] = (this.Cache.Header.LastPageID + 1) * BasePage.PAGE_SIZE; info["lastPageID"] = this.Cache.Header.LastPageID; info["pagesInCache"] = this.Cache.PagesInCache; info["dirtyPages"] = this.Cache.GetDirtyPages().Count(); return(info); }
private void WriteObject(BsonObject obj, object docId) { var hasData = obj.Keys.Length > 0; this.WriteStartBlock("{", hasData); if (docId != null) { this.WriteKeyValue("_id", new BsonValue(docId), hasData); } var index = 0; foreach (var key in obj.Keys) { this.WriteKeyValue(key, obj[key], index++ < obj.Keys.Length - 1); } this.WriteEndBlock("}", hasData); }
private BsonObject ReadObject(StringScanner s) { var obj = new BsonObject(); s.Scan(@"\s*{"); while (!s.Match(@"\s*}")) { s.Scan(@"\s*"); // accept key without " var key = s.Match(@"[\w$]+") ? s.Scan(@"[\w$]+") : this.ReadString(s); if (key.Trim().Length == 0) { throw new ArgumentException("Invalid json object key"); } s.Scan(@"\s*:\s*"); var value = this.ReadValue(s); obj[key] = value; if (s.Scan(@"\s*,").Length == 0) { break; } } if (s.Scan(@"\s*}").Length == 0) { throw new ArgumentException("Missing close json object symbol"); } return(obj); }