public void TestFillRemove() { INodeProvider <Guid, object, EdgeData> nodes = new DirectNodeProviderSafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false); Guid rootId = Guid.NewGuid(); Node <Guid, object, EdgeData> node = BPlusTreeOperations.CreateRootNode(NodeType.Collection, rootId); nodes.SetNode(rootId, node); Collection <Guid> references = new Collection <Guid>(); for (int i = 0; i < 1000; i++) { references.Add(Guid.NewGuid()); } int count = 0; foreach (var reference in references) { Assert.AreEqual(count, BPlusTreeOperations.Count(nodes, rootId, EdgeType.ListItem)); BPlusTreeOperations.InsertEdge(nodes, rootId, new Edge <Guid, EdgeData>(reference, new EdgeData(EdgeType.ListItem, reference)), TreeOrder); count++; } foreach (var reference in references) { Assert.AreEqual(count, BPlusTreeOperations.Count(nodes, rootId, EdgeType.ListItem)); BPlusTreeOperations.RemoveEdge(nodes, rootId, new EdgeData(EdgeType.ListItem, reference), TreeOrder); count--; } }
private void InitializeProvider(IKeyValueStorage <Guid, object> storage) { if (storage is ISerializingStorage) { (storage as ISerializingStorage).Serializer = objectSerializationService; } var storageProvider = new DirectNodeProviderSafe <Guid, object, EdgeData>(storage, storage is IForceUpdateStorage); provider = new CachedReadNodeProvider <Guid, object, EdgeData>(storageProvider, new DirectNodeProviderSafe <Guid, object, EdgeData>(new LimitedMemoryStorageSafe <Guid, object>(Properties.Settings.Default.DataCacheMinimumCount, Properties.Settings.Default.DataCacheMaximumCount), false)); }
/// <summary> /// Constructor /// </summary> /// <param name="storage">The storage from which the types needed for visualisation are loaded</param> public TypesVisualisationService(IKeyValueStorage<Guid, object> storage) { if (storage is ISerializingStorage) { (storage as ISerializingStorage).Serializer = objectSerializationService; } var storageProvider = new DirectNodeProviderSafe<Guid, object, EdgeData>(storage, storage is IForceUpdateStorage); provider = new CachedReadNodeProvider<Guid, object, EdgeData>(storageProvider, new DirectNodeProviderSafe<Guid, object, EdgeData>(new LimitedMemoryStorageSafe<Guid, object>(Properties.Settings.Default.DataCacheMinimumCount, Properties.Settings.Default.DataCacheMaximumCount), false)); typesService = new TypesService(provider); typesService.InitializeTypeSystem(null); objectSerializationService.TypesService = typesService; }
/// <summary> /// Constructor /// </summary> /// <param name="storage">The storage from which the types needed for visualisation are loaded</param> public TypesVisualisationService(IKeyValueStorage <Guid, object> storage) { if (storage is ISerializingStorage) { (storage as ISerializingStorage).Serializer = objectSerializationService; } var storageProvider = new DirectNodeProviderSafe <Guid, object, EdgeData>(storage, storage is IForceUpdateStorage); provider = new CachedReadNodeProvider <Guid, object, EdgeData>(storageProvider, new DirectNodeProviderSafe <Guid, object, EdgeData>(new LimitedMemoryStorageSafe <Guid, object>(Properties.Settings.Default.DataCacheMinimumCount, Properties.Settings.Default.DataCacheMaximumCount), false)); typesService = new TypesService(provider); typesService.InitializeTypeSystem(null); objectSerializationService.TypesService = typesService; }
public void TestConsistency() { INodeProvider <Guid, object, EdgeData> nodes = new DirectNodeProviderSafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false); Guid rootId = Guid.NewGuid(); Node <Guid, object, EdgeData> node = BPlusTreeOperations.CreateRootNode(NodeType.Collection, rootId); nodes.SetNode(rootId, node); Collection <Guid> references = new Collection <Guid>(); Collection <Guid> referencesAdded = new Collection <Guid>(); for (int i = 0; i < 1000; i++) { references.Add(Guid.NewGuid()); } foreach (var reference in references) { var data = new EdgeData(EdgeType.ListItem, reference); BPlusTreeOperations.InsertEdge(nodes, rootId, new Edge <Guid, EdgeData>(reference, data), TreeOrder); referencesAdded.Add(reference); foreach (var addedReference in referencesAdded) { var dataAdded = new EdgeData(EdgeType.ListItem, addedReference); Edge <Guid, EdgeData> edge; Assert.IsTrue(BPlusTreeOperations.TryFindEdge(nodes, rootId, dataAdded, out edge)); Assert.AreEqual(addedReference, edge.Data.Data); } } foreach (var reference in references) { var data = new EdgeData(EdgeType.ListItem, reference); Edge <Guid, EdgeData> edge; Assert.IsTrue(BPlusTreeOperations.TryFindEdge(nodes, rootId, data, out edge)); Assert.AreEqual(reference, edge.Data.Data); Assert.AreEqual(reference, edge.ToNodeId); } }
/// <summary> /// Method is used for parsing Nodes in change set. /// </summary> /// <param name="dictForParsing">Dictionary from ChangeSet which should contain Nodes</param> /// <returns></returns> private static DirectNodeProviderSafe<Guid, object, EdgeData> ParseNodes(Dictionary<String, Object> dictForParsing) { DirectNodeProviderSafe<Guid, object, EdgeData> nodes = new DirectNodeProviderSafe<Guid, object, EdgeData>(new MemoryStorageSafe<Guid, object>(), false); Dictionary<String, Object> dictFromObject = dictForParsing; //parsing nodes from objectForParsing if (dictFromObject.ContainsKey(NODES)) { Object oNodes = dictFromObject[NODES]; if (oNodes is Dictionary<String, Object>) { Dictionary<String, Object> dNodes = oNodes as Dictionary<String, Object>; if (dNodes.ContainsKey(STORAGE)) { Object oStorage = dNodes[STORAGE]; if (oStorage is Dictionary<String, Object>) { Dictionary<String, Object> dStorage = oStorage as Dictionary<String, Object>; Object oDictionary = dStorage[DICTIONARY]; if (oDictionary is Dictionary<String, Object>) { Dictionary<String, Object> dDictionary = oDictionary as Dictionary<String, Object>; Object oArray = dDictionary[ARRAY]; if (oArray is Object[]) { Object[] dArray = oArray as Object[]; foreach (Object o in dArray) { if (o is Dictionary<String, Object>) { Dictionary<String, Object> dNode = o as Dictionary<String, Object>; if (dNode.ContainsKey(KEY) && dNode.ContainsKey(VALUE)) { Guid key = Guid.Empty; if (dNode[KEY] is Dictionary<String, Object>) { Dictionary<String, Object> dKey = (dNode[KEY] as Dictionary<String, Object>); if (dKey.ContainsKey(VALUE) && dKey[VALUE] is String) { key = new Guid((String)dKey[VALUE]); } else { //case when there is not right properties in Dictionary continue; } } else { //case when dNode[KEY] is not Dictionary continue; } Node<Guid, object, EdgeData> node = NodeWrapper.ParseNode(dNode[VALUE]); nodes.SetNode(key, node); } } else { continue; } } } } } } } } else { throw new Exception("Node object is not valid!"); } return nodes; }
/// <summary> /// Method is used for parsing Nodes in change set. /// </summary> /// <param name="dictForParsing">Dictionary from ChangeSet which should contain Nodes</param> /// <returns></returns> private static DirectNodeProviderSafe <Guid, object, EdgeData> ParseNodes(Dictionary <String, Object> dictForParsing) { DirectNodeProviderSafe <Guid, object, EdgeData> nodes = new DirectNodeProviderSafe <Guid, object, EdgeData>(new MemoryStorageSafe <Guid, object>(), false); Dictionary <String, Object> dictFromObject = dictForParsing; //parsing nodes from objectForParsing if (dictFromObject.ContainsKey(NODES)) { Object oNodes = dictFromObject[NODES]; if (oNodes is Dictionary <String, Object> ) { Dictionary <String, Object> dNodes = oNodes as Dictionary <String, Object>; if (dNodes.ContainsKey(STORAGE)) { Object oStorage = dNodes[STORAGE]; if (oStorage is Dictionary <String, Object> ) { Dictionary <String, Object> dStorage = oStorage as Dictionary <String, Object>; Object oDictionary = dStorage[DICTIONARY]; if (oDictionary is Dictionary <String, Object> ) { Dictionary <String, Object> dDictionary = oDictionary as Dictionary <String, Object>; Object oArray = dDictionary[ARRAY]; if (oArray is Object[]) { Object[] dArray = oArray as Object[]; foreach (Object o in dArray) { if (o is Dictionary <String, Object> ) { Dictionary <String, Object> dNode = o as Dictionary <String, Object>; if (dNode.ContainsKey(KEY) && dNode.ContainsKey(VALUE)) { Guid key = Guid.Empty; if (dNode[KEY] is Dictionary <String, Object> ) { Dictionary <String, Object> dKey = (dNode[KEY] as Dictionary <String, Object>); if (dKey.ContainsKey(VALUE) && dKey[VALUE] is String) { key = new Guid((String)dKey[VALUE]); } else { //case when there is not right properties in Dictionary continue; } } else { //case when dNode[KEY] is not Dictionary continue; } Node <Guid, object, EdgeData> node = NodeWrapper.ParseNode(dNode[VALUE]); nodes.SetNode(key, node); } } else { continue; } } } } } } } } else { throw new Exception("Node object is not valid!"); } return(nodes); }
/// <summary> /// Method is used for getting data from object to IsolatedChangeSet. /// Object containing dictionaries that contain data. If object is not /// formated in right way, this method is throwing exception. /// </summary> /// <param name="objectForParsing">object that is containg data that is commited from client</param> /// <returns>IsolatedChangeSet that is created from objectForParsing</returns> public static IsolatedChangeSet <Guid, object, EdgeData> Parse(Object objectForParsing) { Guid sourceSnapshotId = Guid.Empty; if (objectForParsing == null) { throw new Exception("Object is not valid!"); } Dictionary <Guid, NodeState> nodeState = null; DirectNodeProviderSafe <Guid, object, EdgeData> nodes = null; if (objectForParsing is Dictionary <String, Object> ) { Dictionary <String, Object> dictFromObject = (Dictionary <String, Object>)objectForParsing; //finding sourceSnapshotId property from dictionary if (dictFromObject.ContainsKey(SOURCE_SNAPSHOT_ID)) { Object objectSourceId = dictFromObject[SOURCE_SNAPSHOT_ID]; if (objectSourceId is Dictionary <String, Object> ) { Dictionary <String, Object> dSourceId = objectSourceId as Dictionary <String, Object>; if (dSourceId != null) { Object sSourceId = dSourceId[VALUE]; //checking if object is string. If it is then this is guid if (sSourceId is String) { sourceSnapshotId = new Guid(sSourceId as String); } else { //sSourceId is not string so this is not right type and object that is being //parsed is not formated as he should. throw new Exception("Field SourceSnapshotId is not in right format!"); } } else { throw new Exception("Field SourceSnapshotId is not in right format!"); } } } else { //case when SourceSnapshotId is missing in objectForParsing throw new Exception("There is not field SourceSnapshotId!"); } nodes = ParseNodes(dictFromObject); nodeState = ParseNodeStates(dictFromObject); } else { throw new Exception("Object is not valid!"); } //in case some data is missing here we will throw exception if (sourceSnapshotId == null || nodes == null || nodeState == null) { throw new ArgumentNullException(); } // creating IsolatedChangeSet object with parsed data IsolatedChangeSet <Guid, object, EdgeData> result = new IsolatedChangeSet <Guid, object, EdgeData>(sourceSnapshotId, nodes, nodeState); return(result); }