Exemplo n.º 1
0
 /// <summary>
 /// Opens an existing tree in the page store
 /// </summary>
 /// <param name="pageStore"></param>
 /// <param name="rootPageId">The page ID of the BTree root node</param>
 /// <param name="keySize"></param>
 /// <param name="dataSize"></param>
 /// <param name="profiler"></param>
 public BPlusTree(IPageStore pageStore, ulong rootPageId, int keySize = 8, int dataSize = 64, BrightstarProfiler profiler = null)
 {
     _config = new BPlusTreeConfiguration(keySize, dataSize, pageStore.PageSize);
     _pageStore = pageStore;
     _modifiedNodes = new Dictionary<ulong, INode>();
     _nodeCache = new WeakReferenceNodeCache();
     _root = GetNode(rootPageId, profiler);
     _nodeCache.Add(_root);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Opens an existing tree in the page store
 /// </summary>
 /// <param name="pageStore"></param>
 /// <param name="rootPageId">The page ID of the BTree root node</param>
 /// <param name="keySize"></param>
 /// <param name="dataSize"></param>
 /// <param name="profiler"></param>
 public BPlusTree(IPageStore pageStore, ulong rootPageId, int keySize = 8, int dataSize = 64, BrightstarProfiler profiler = null)
 {
     _config        = new BPlusTreeConfiguration(keySize, dataSize, pageStore.PageSize);
     _pageStore     = pageStore;
     _modifiedNodes = new Dictionary <ulong, INode>();
     _nodeCache     = new WeakReferenceNodeCache();
     _root          = GetNode(rootPageId, profiler);
     _nodeCache.Add(_root);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new tree in the page store
 /// </summary>
 /// <param name="txnId">The transaction id for the update</param>
 /// <param name="pageStore"></param>
 /// <param name="keySize">The size of the B+ tree's key (in bytes)</param>
 /// <param name="dataSize">The size of the values stored in leaf nodes (in bytes)</param>
 public BPlusTree(ulong txnId, IPageStore pageStore, int keySize = 8, int dataSize = 64) 
 {
     _config = new BPlusTreeConfiguration(pageStore, keySize, dataSize, pageStore.PageSize);
     _pageStore = pageStore;
     var root = MakeLeafNode(txnId);
     _rootId = root.PageId;
     _nodeCache = new WeakReferenceNodeCache();
     _nodeCache.Add(root);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Opens an existing tree in the page store
 /// </summary>
 /// <param name="pageStore"></param>
 /// <param name="rootPageId">The page ID of the BTree root node</param>
 /// <param name="keySize"></param>
 /// <param name="dataSize"></param>
 /// <param name="profiler"></param>
 public BPlusTree(IPageStore pageStore, ulong rootPageId, int keySize = 8, int dataSize = 64, BrightstarProfiler profiler = null)
 {
     _config = new BPlusTreeConfiguration(pageStore, keySize, dataSize, pageStore.PageSize);
     _pageStore = pageStore;
     _nodeCache = new WeakReferenceNodeCache();
     var root = GetNode(rootPageId, profiler);
     _nodeCache.Add(root);
     _rootId = root.PageId;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new tree in the page store
 /// </summary>
 /// <param name="pageStore"></param>
 /// <param name="keySize">The size of the B+ tree's key (in bytes)</param>
 /// <param name="dataSize">The size of the values stored in leaf nodes (in bytes)</param>
 public BPlusTree(IPageStore pageStore, int keySize = 8, int dataSize = 64) 
 {
     _config = new BPlusTreeConfiguration(keySize, dataSize, pageStore.PageSize);
     _pageStore = pageStore;
     _modifiedNodes = new Dictionary<ulong, INode>();
     _root = new LeafNode(pageStore.Create(), 0, 0, _config);
     _nodeCache = new WeakReferenceNodeCache();
     _modifiedNodes[_root.PageId] = _root;
     _nodeCache.Add(_root);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new tree in the page store
 /// </summary>
 /// <param name="pageStore"></param>
 /// <param name="keySize">The size of the B+ tree's key (in bytes)</param>
 /// <param name="dataSize">The size of the values stored in leaf nodes (in bytes)</param>
 public BPlusTree(IPageStore pageStore, int keySize = 8, int dataSize = 64)
 {
     _config        = new BPlusTreeConfiguration(keySize, dataSize, pageStore.PageSize);
     _pageStore     = pageStore;
     _modifiedNodes = new Dictionary <ulong, INode>();
     _root          = new LeafNode(pageStore.Create(), 0, 0, _config);
     _nodeCache     = new WeakReferenceNodeCache();
     _modifiedNodes[_root.PageId] = _root;
     _nodeCache.Add(_root);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Opens an existing tree in the page store
        /// </summary>
        /// <param name="pageStore"></param>
        /// <param name="rootPageId">The page ID of the BTree root node</param>
        /// <param name="keySize"></param>
        /// <param name="dataSize"></param>
        /// <param name="profiler"></param>
        public BPlusTree(IPageStore pageStore, ulong rootPageId, int keySize = 8, int dataSize = 64, BrightstarProfiler profiler = null)
        {
            _config    = new BPlusTreeConfiguration(pageStore, keySize, dataSize, pageStore.PageSize);
            _pageStore = pageStore;
            _nodeCache = new WeakReferenceNodeCache();
            var root = GetNode(rootPageId, profiler);

            _nodeCache.Add(root);
            _rootId = root.PageId;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new tree in the page store
        /// </summary>
        /// <param name="txnId">The transaction id for the update</param>
        /// <param name="pageStore"></param>
        /// <param name="keySize">The size of the B+ tree's key (in bytes)</param>
        /// <param name="dataSize">The size of the values stored in leaf nodes (in bytes)</param>
        public BPlusTree(ulong txnId, IPageStore pageStore, int keySize = 8, int dataSize = 64)
        {
            _config    = new BPlusTreeConfiguration(pageStore, keySize, dataSize, pageStore.PageSize);
            _pageStore = pageStore;
            var root = MakeLeafNode(txnId);

            _rootId    = root.PageId;
            _nodeCache = new WeakReferenceNodeCache();
            _nodeCache.Add(root);
        }
Exemplo n.º 9
0
 private static object GetValueForField(QualifiedName[] browsePath, INodeCache nodeCache, object value)
 {
     if (browsePath != null && browsePath.Length == 1 && (string.Compare(browsePath[0].namespaceUrl, "http://opcfoundation.org/UA/") == 0))
     {
         var fieldName = browsePath[0].name;
         if (_converter.TryGetValue(fieldName, out Func <INodeCache, object, object> conv))
         {
             return(conv(nodeCache, value));
         }
     }
     return(value);
 }
Exemplo n.º 10
0
        public void NodeCache_LoadUaDefinedTypes()
        {
            INodeCache nodeCache = Session.NodeCache;

            Assert.IsNotNull(nodeCache);

            // load the predefined types
            nodeCache.LoadUaDefinedTypes(Session.SystemContext);

            // reload the predefined types
            nodeCache.LoadUaDefinedTypes(Session.SystemContext);
        }
        /// <summary>
        /// Initializes the file system with the supplied <c>rootAddress</c>, <c>parentLayer</c> and <c>options</c>.
        /// </summary>
        /// <param name="rootAddress">
        /// The rootAddress for the file system.  All nodes in the file system are relative to the root name.</param>
        /// <param name="parentLayer">
        /// The parent layer for this file system or <c>null</c> if this <see cref="IFileSystem"/> is not layered.
        /// </param>
        /// <param name="options">
        /// The options for creating this <c>FileSystem.</c>
        /// </param>
        protected AbstractFileSystem(INodeAddress rootAddress, IFile parentLayer, FileSystemOptions options)
        {
            this.cache       = (INodeCache)Activator.CreateInstance(options.NodeCacheType);
            this.ParentLayer = parentLayer;
            this.rootAddress = rootAddress;
            this.Options     = options;
            this.autoLock    = new AutoLock(this);

            InitializeConstruction(rootAddress, parentLayer, options);

            this.Extenders = CreateExtenders();
            CreateSecurityManager();
        }
Exemplo n.º 12
0
 private static object NodeToBrowseName(INodeCache nodeCache, NodeId nodeId)
 {
     try
     {
         var node = nodeCache.GetBrowseName(nodeId);
         if (node != null)
         {
             return(node.ToString());
         }
     }
     catch {
     }
     return(nodeId.ToString());
 }
Exemplo n.º 13
0
        public void NodeCache_References()
        {
            INodeCache nodeCache = Session.NodeCache;

            Assert.IsNotNull(nodeCache);

            // ensure the predefined types are loaded
            nodeCache.LoadUaDefinedTypes(Session.SystemContext);

            // check on all reference type ids
            var refTypeDictionary = typeof(ReferenceTypeIds).GetFields(BindingFlags.Public | BindingFlags.Static)
                                    .Where(f => f.FieldType == typeof(NodeId))
                                    .ToDictionary(f => f.Name, f => (NodeId)f.GetValue(null));

            TestContext.Out.WriteLine("Testing {0} references", refTypeDictionary.Count);
            foreach (var property in refTypeDictionary)
            {
                TestContext.Out.WriteLine("FindReferenceTypeName({0})={1}", property.Value, property.Key);
                // find the Qualified Name
                var qn = nodeCache.FindReferenceTypeName(property.Value);
                Assert.NotNull(qn);
                Assert.AreEqual(property.Key, qn.Name);
                // find the node by name
                var refId = nodeCache.FindReferenceType(new QualifiedName(property.Key));
                Assert.NotNull(refId);
                Assert.AreEqual(property.Value, refId);
                // is the node id known?
                var isKnown = nodeCache.IsKnown(property.Value);
                Assert.IsTrue(isKnown);
                // is it a reference?
                var isTypeOf = nodeCache.IsTypeOf(
                    NodeId.ToExpandedNodeId(refId, Session.NamespaceUris),
                    NodeId.ToExpandedNodeId(ReferenceTypeIds.References, Session.NamespaceUris));
                Assert.IsTrue(isTypeOf);
                // negative test
                isTypeOf = nodeCache.IsTypeOf(
                    NodeId.ToExpandedNodeId(refId, Session.NamespaceUris),
                    NodeId.ToExpandedNodeId(DataTypeIds.Byte, Session.NamespaceUris));
                Assert.IsFalse(isTypeOf);
                var subTypes = nodeCache.FindSubTypes(NodeId.ToExpandedNodeId(refId, Session.NamespaceUris));
                Assert.NotNull(subTypes);
            }
        }
Exemplo n.º 14
0
 public Result <DataResponse> CreateEventDataResponse(Result <HistoryEvent> historyEventResult, OpcUAQuery query, INodeCache nodeCache)
 {
     if (historyEventResult.Success)
     {
         var historyEvent = historyEventResult.Value;
         var dataResponse = new DataResponse();
         var dataFrame    = new DataFrame(query.refId);
         var fields       = AddEventFields(dataFrame, query);
         if (historyEvent.Events.Count > 0)
         {
             foreach (var e in historyEvent.Events)
             {
                 FillEventDataFrame(fields, e.EventFields, query, nodeCache);
             }
         }
         dataResponse.Frames.Add(dataFrame.ToGprcArrowFrame());
         return(new Result <DataResponse>(dataResponse));
     }
     else
     {
         return(new Result <DataResponse>(historyEventResult.StatusCode, historyEventResult.Error));
     }
 }
Exemplo n.º 15
0
        public Result <DataResponse> CreateEventSubscriptionDataResponse(ICollection <VariantCollection> events, OpcUAQuery query, INodeCache nodeCache)
        {
            var dataResponse = new DataResponse();
            var dataFrame    = new DataFrame(query.refId);
            var fields       = AddEventFields(dataFrame, query);

            foreach (var ev in events)
            {
                FillEventDataFrame(fields, ev, query, nodeCache);
            }
            dataResponse.Frames.Add(dataFrame.ToGprcArrowFrame());
            return(new Result <DataResponse>(dataResponse));
        }
Exemplo n.º 16
0
 internal static void FillEventDataFrame(Dictionary <int, Field> fields, VariantCollection eventFields, OpcUAQuery query, INodeCache nodeCache)
 {
     for (int k = 0; k < eventFields.Count; k++)
     {
         var field = eventFields[k];
         if (fields.TryGetValue(k, out Field dataField))
         {
             var path = query.eventQuery.eventColumns[k].browsePath;
             dataField.Append(GetDataFieldValue(dataField, GetValueForField(path, nodeCache, field.Value)));
         }
     }
 }