예제 #1
0
파일: Database.cs 프로젝트: wushian/Nxdb
 internal void SetNode(int pre, Node.Node node)
 {
     if (_nodes == null)
     {
         throw new ObjectDisposedException("Database");
     }
     _nodes[pre] = new WeakReference(node);
 }
예제 #2
0
파일: Conversions.cs 프로젝트: wushian/Nxdb
        //Converts potential sequences into item lists, while flattening to a single dimension
        private static IEnumerable <Item> GetItems(object obj)
        {
            //It it a Node?
            Node.Node node = obj as Node.Node;
            if (node != null)
            {
                return(new[] { node.ANode });
            }

            //Is it a Database?
            Database database = obj as Database;

            if (database != null)
            {
                return(database.Documents.Select(d => d.ANode).Cast <Item>());
            }

            //Is it enumerable (list, array, etc. - but not a string!)
            //This is recursive and results in flattening any nested sequences
            IEnumerable enumerable = obj as IEnumerable;

            if (!(obj is string) && enumerable != null)
            {
                return(enumerable.Cast <object>().Select(GetItems).SelectMany(x => x));
            }

            // Clean up non-.NET values
            if (obj is Decimal)
            {
                obj = new BigDecimal(obj.ToString());
            }
            else if (obj is DateTime)
            {
                obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(
                    ((DateTime)obj).ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"));
            }
            else if (obj is TimeSpan)
            {
                obj = DatatypeFactory.newInstance().newDuration(
                    Convert.ToInt64(((TimeSpan)obj).TotalMilliseconds));
            }
            else if (obj is XmlQualifiedName)
            {
                XmlQualifiedName qname = (XmlQualifiedName)obj;
                obj = new QName(qname.Namespace, qname.Name);
            }

            //Get the item
            return(new [] { JavaMapping.type(obj).cast(obj, null) });
        }
예제 #3
0
파일: Database.cs 프로젝트: wushian/Nxdb
 // Only called from the Node.Get() static methods - use those to get new nodes
 internal Node.Node GetNode(int pre)
 {
     if (_nodes == null)
     {
         throw new ObjectDisposedException("Database");
     }
     if (_nodes[pre] != null)
     {
         Node.Node node = (Node.Node)_nodes[pre].Target;
         if (node != null)
         {
             return(node);
         }
     }
     return(null);
 }
예제 #4
0
파일: Database.cs 프로젝트: wushian/Nxdb
        // Called by Updates.Apply()
        internal void Update()
        {
            if (_nodes == null)
            {
                throw new ObjectDisposedException("Database");
            }

            // Grow the nodes cache if needed (but never shrink it)
            if (_data.meta.size > _nodes.Length)
            {
                Array.Resize(ref _nodes, _data.meta.size);
            }

            // Check validity and reposition nodes
            LinkedList <Node.Node> reposition = new LinkedList <Node.Node>();

            for (int c = 0; c < _nodes.Length; c++)
            {
                if (_nodes[c] != null)
                {
                    Node.Node node = (Node.Node)_nodes[c].Target;
                    if (node != null)
                    {
                        if (!node.Validate())
                        {
                            // The node is now invalid, remove it from the cache
                            _nodes[c] = null;
                        }
                        else
                        {
                            // The node is still valid, but if it moved add it to the reposition list
                            if (node.Index != c)
                            {
                                reposition.AddLast(node);
                                _nodes[c] = null;
                            }
                        }
                    }
                    else
                    {
                        _nodes[c] = null;
                    }
                }
            }

            // Reposition any nodes that moved
            foreach (Node.Node node in reposition)
            {
                _nodes[node.Index] = new WeakReference(node);
            }

            //Raise the Updated event, but avoid recursivly raising it
            EventHandler <EventArgs> handler = Updated;

            if (handler == null)
            {
                return;
            }
            do
            {
                if (!_inUpdated)
                {
                    _recursiveUpdated = false;
                    _inUpdated        = true;
                    handler(this, EventArgs.Empty);
                    _inUpdated = false;
                }
                else
                {
                    _recursiveUpdated = true;
                    break;
                }
            } while (_recursiveUpdated);
        }