private static IEnumerable BSonToIEnumerable(this BSonDoc doc) { #if WINDOWS_PHONE List <object> list = new List <object>(); foreach (var p in doc.Properties) { var val = doc[p]; if (val is IBSonNode) { list.Add(((IBSonNode)val)); } else { list.Add(val); } } return(list); #else ArrayList list = new ArrayList(); foreach (var p in doc.Properties) { var val = doc[p]; if (val is IBSonNode) { list.Add(((IBSonNode)val)); } else { list.Add(val); } } return(list); #endif }
public override void OnHandle(IStore store, string collection, BSonDoc command, BSonDoc document) { IObjectStore st = store.GetCollection(collection); st.Set(document); }
public static BSonDoc Deserialize(this byte[] data) { MemoryStream ms = new MemoryStream(data); BinaryReader br = new BinaryReader(ms); BSonDoc result = NavigateStream(br) as BSonDoc; return(result); }
private static void UpdateSingleDocument(BSonDoc document, IObjectStore store) { var obj = store.GetById((string)document[DocumentMetadata.IdPropertyName]); BSonDoc val = GetValue(document); foreach (var p in GetRealProperties(val)) // remove properties starting with if (document.HasProperty(p)) obj[p] = val[p]; store.Set(obj); }
private static BSonDoc IDictionaryToBSon(this IDictionary entities) { BSonDoc doc = new BSonDoc(BSonDocumentType.BSON_Dictionary); foreach (DictionaryEntry item in entities) { doc[item.Key.ToString()] = item.Value.ToBSon(); } return(doc); }
private static BSonDoc IEnumerableToBSon(this IEnumerable entities) { BSonDoc doc = new BSonDoc(BSonDocumentType.BSON_DocumentArray); int x = 0; foreach (var item in entities) { doc[string.Format("i{0}", x++)] = item.ToBSon(); } return(doc); }
protected static string[] GetRealProperties(BSonDoc document) { string[] invalidproperties = new string[] { CommandKeyword.Action, CommandKeyword.Collection, CommandKeyword.Filter, CommandKeyword.Id, CommandKeyword.Type, CommandKeyword.Value, DocumentMetadata.IdPropertyName, DocumentMetadata.TimeStampPropertyName }; return document.Properties.Except(invalidproperties).ToArray(); }
private static BSonDoc IDictionaryToBSonG <TK, T>(this IDictionary <TK, T> entities) where T : class { BSonDoc doc = new BSonDoc(BSonDocumentType.BSON_Dictionary); var tt = typeof(T); //doc["_type_"] = tt.FullName; foreach (var item in entities) { doc[item.Key.ToString()] = item.Value.ToBSon(); } return(doc); }
//#region Constructor //internal ObjectStore() // : this(ObjectStoreKeyType.Integer) //{ } //internal ObjectStore(ObjectStoreKeyType keytype) //{ // KeyType = keytype; // switch (KeyType) // { // case ObjectStoreKeyType.Integer: // newIdFunction = () => ++_storeintuid; // currentIdFunction = () => _storeintuid; // break; // case ObjectStoreKeyType.LongInteger: // newIdFunction = () => ++_storelonguid; // currentIdFunction = () => _storelonguid; // break; // case ObjectStoreKeyType.GlobalUniqueIdentifier: // newIdFunction = () => { _storeGuid = Guid.NewGuid(); return _storeGuid; }; // currentIdFunction = () => _storeGuid; // break; // default: // break; // } //} //#endregion #region Public methods for storing objects public void Set(BSonDoc entity) { ChangesFromLastSave++; //var lastid = currentIdFunction(); var uid = GetEntityUI(entity); if (dContains(uid)) { dUpdate(uid, entity); return; } dSet(uid, entity); }
private static BSonDoc IEnumerableToBSonG <T>(this IEnumerable <T> entities) where T : class { BSonDoc doc = new BSonDoc(BSonDocumentType.BSON_DocumentArray); var tt = typeof(T); //doc["_type_"] = tt.FullName; int x = 0; foreach (var item in entities) { doc[string.Format("i{0}", x++)] = (item.GetBSonType() == BSonTypeEnum.BSON_Document ? (object)item.ToBSon() : (object)item); } return(doc); }
public override void OnHandle(IStore store, string collection, BSonDoc command, BSonDoc document) { IObjectStore st = store.GetCollection(collection); if (command.HasProperty(CommandKeyword.Id)) { var ent = st.GetById((string)command[CommandKeyword.Id]); if (ent != null) st.Remove(ent); } if (document != null && document.HasProperty(DocumentMetadata.IdPropertyName)) { var ent = st.GetById((string)document[DocumentMetadata.IdPropertyName]); if (ent != null) st.Remove(ent); } }
public override void OnHandle(IStore store, string collection, BSonDoc command, BSonDoc document) { if (document == null || string.IsNullOrEmpty(collection)) return; IObjectStore st = store.GetCollection(collection); if (document.HasProperty(DocumentMetadata.IdPropertyName)) { UpdateSingleDocument(document, st); return; } if (document.HasProperty(CommandKeyword.Filter)) { UpdateCollection(document, st); return; } st.Set(document); }
public override void OnHandle(IStore store, string collection, BSonDoc command, BSonDoc document) { if (document == null || string.IsNullOrEmpty(collection)) return; IObjectStore st = store.GetCollection(collection); if (document.DocType == BSonDocumentType.BSON_DocumentArray || document.DocType == BSonDocumentType.BSON_Dictionary) { var documents = document.ToList(); if (documents != null) foreach (var d in documents) { //if(d is BSonDoc && ((BSonDoc)d).HasProperty(CommandKeyword.Id)) } } }
private static BSonDoc DeserializeDocument(BinaryReader reader, BSonDocumentType doctype) { var doc = new BSonDoc(doctype); doc.Name = reader.ReadString(); var size = reader.ReadInt32(); var endposition = reader.BaseStream.Position + size; while (reader.BaseStream.Position < endposition) { var res = NavigateStream(reader); var pp = res as IBSonNode; if (pp != null) { doc[pp.Name] = pp.Value; } } return(doc); }
private static IEnumerable <T> BSonToIEnumerableG <T>(this BSonDoc doc) { List <T> list = new List <T>(); foreach (var p in doc.Properties) { var val = doc[p]; T rval = default(T); if (val is IBSonNode) { rval = ((IBSonNode)val).FromBSon <T>(); } else if (typeof(T).IsAssignableFrom(val.GetType())) { rval = (T)val; } list.Add(rval); } return(list); }
public override void OnHandle(IStore store, string collection, BSonDoc command, BSonDoc document) { IObjectStore st = store.GetCollection(collection); if (document.DocType == BSonDocumentType.BSON_DocumentArray || document.DocType == BSonDocumentType.BSON_Dictionary) { var documents = document.ToList(); if (documents != null) foreach (var d in documents) if (d is BSonDoc) st.Set(d as BSonDoc); } else { st.Set(document); } }
private static BSonDoc DocumentToBSon <T>(this T entity, bool includetype = true) where T : class { if (entity is BSonDoc) { return(entity as BSonDoc); } BSonDoc doc = new BSonDoc(); var tt = entity.GetType(); //if (includetype) // doc["_type_"] = tt.FullName; var properties = tt.GetProperties(); foreach (var p in properties) { if (p.GetCustomAttributes(typeof(IgnorePropertyAttribute), false).Length == 0) { doc[p.Name] = entity.NavigateProperty <T>(p.Name); } } return(doc); }
public abstract void OnHandle(IStore store, string collection , BSonDoc command, BSonDoc document);
private void dSet(string key, BSonDoc doc) { lock (_primarystore) { if (!dUpdate(key, doc)) dInsert(key, doc); } }
private string GetEntityUI(BSonDoc entity) { if (entity.HasProperty(DocumentMetadata.IdPropertyName) && entity[DocumentMetadata.IdPropertyName] != null) return (string)entity[DocumentMetadata.IdPropertyName]; entity[DocumentMetadata.IdPropertyName] = newIdFunction(); return (string)entity[DocumentMetadata.IdPropertyName]; }
protected static BSonDoc GetValue(BSonDoc document) { if (document.HasProperty(CommandKeyword.Value)) return document[CommandKeyword.Value] as BSonDoc; return document; }
private void dInsert(string key, BSonDoc doc) { //doc["@ts#" Dictionary<string, byte[]> freedictionary = null; foreach (var d in _primarystore) if (d.Count < Configuration.DictionarySplitSize) { freedictionary = d; break; } if (freedictionary == null) { freedictionary = new Dictionary<string, byte[]>(); _primarystore.Add(freedictionary); } if (!freedictionary.ContainsKey(key)) freedictionary.Add(key, doc.Serialize()); }
private static void UpdateCollection(BSonDoc document, IObjectStore store) { // TODO: completely to do. }
private bool dUpdate(string key, BSonDoc doc) { lock (_primarystore) foreach (var d in _primarystore) if (d.ContainsKey(key)) { d[key] = doc.Serialize(); return true; } return false; }
private static ICommandHandler[] ChechHandlers(BSonDoc command) { string actionname = string.Empty; if (command.HasProperty(CommandKeyword.Action)) actionname = (command[CommandKeyword.Action] ?? string.Empty).ToString(); LogWriter.LogInformation(string.Format("Executing action {0}", string.Empty), LogEntryType.Information); if (_commandHandlers.ContainsKey(actionname)) return _commandHandlers[actionname].ToArray(); return null; }
public void Remove(BSonDoc entity) { //var lastid = currentIdFunction(); var uid = GetEntityUI(entity); if (dContains(uid)) if (dRemove(uid)) ChangesFromLastSave++; }