예제 #1
0
        public void AddAtPath(string path, MetaData meta)
        {
            // this is add or update action (file)
            // lookup file Id
            DocumentStateItem documentAtPath;

            if (_currentState.TryGetValue(path, out documentAtPath))
            {
                documentAtPath.IsDeleted = false;
                _pendingChanges.EnqueueUpdate(documentAtPath, meta);
            }
            else
            {
                // in case this is a file replacing a folder with sub-items, we need to check to
                // ensure the sub-items are removed
                if (AnyFilesUnderPath(path))
                {
                    RemoveItemsUnderPath(path);
                }

                // new path, generate new Id
                documentAtPath = new DocumentStateItem
                {
                    Id       = Guid.NewGuid(),
                    FilePath = path
                };

                Add(path, documentAtPath);

                _pendingChanges.EnqueueAdd(documentAtPath, meta);
            }
        }
예제 #2
0
        /// <summary>
        /// Adds specified document to the local state at the specified path
        /// </summary>
        private void Add(string path, DocumentStateItem documentAtPath)
        {
            Debug.Assert(!_currentState.ContainsKey(path), "Specified path already exists in the local state.");

            var insertPos = _pathIndex.BinarySearch(path, StringComparer.InvariantCulture);

            Debug.Assert(insertPos < 0 && ~insertPos <= _pathIndex.Count, "Specified path already exists in the path index.");

            if (insertPos < 0)
            {
                insertPos = ~insertPos;

                if (insertPos < _pathIndex.Count)
                {
                    // insert in the middle
                    _pathIndex.Insert(insertPos, path);
                }
                else
                {
                    // append to the end
                    _pathIndex.Add(path);
                }

                _currentState.Add(path, documentAtPath);
            }
        }
예제 #3
0
        public void AddAtPath(string path, MetaData meta)
        {
            // this is add or update action (file)
            // lookup file Id
            DocumentStateItem documentAtPath;
            if (_currentState.TryGetValue(path, out documentAtPath))
            {
                documentAtPath.IsDeleted = false;
                _pendingChanges.EnqueueUpdate(documentAtPath, meta);
            }
            else
            {
                // in case this is a file replacing a folder with sub-items, we need to check to
                // ensure the sub-items are removed
                if (AnyFilesUnderPath(path))
                {
                    RemoveItemsUnderPath(path);
                }

                // new path, generate new Id
                documentAtPath = new DocumentStateItem
                {
                    Id = Guid.NewGuid(),
                    FilePath = path
                };

                Add(path, documentAtPath);

                _pendingChanges.EnqueueAdd(documentAtPath, meta);
            }
        }
예제 #4
0
        /// <summary>
        /// Adds specified document to the local state at the specified path
        /// </summary>
        private void Add(string path, DocumentStateItem documentAtPath)
        {
            Debug.Assert(!_currentState.ContainsKey(path), "Specified path already exists in the local state.");

            var insertPos = _pathIndex.BinarySearch(path, StringComparer.InvariantCulture);

            Debug.Assert(insertPos < 0 && ~insertPos <= _pathIndex.Count, "Specified path already exists in the path index.");

            if (insertPos < 0)
            {
                insertPos = ~insertPos;

                if (insertPos < _pathIndex.Count)
                {
                    // insert in the middle
                    _pathIndex.Insert(insertPos, path);
                }
                else
                {
                    // append to the end
                    _pathIndex.Add(path);
                }

                _currentState.Add(path, documentAtPath);
            }
        }