Example #1
0
        private bool SameGroup(RelPath sourcepath, RelPath targetpath)
        {
            string srcDir = MainPath.ExtractSubfolderName(sourcepath);
            string tarDir = MainPath.ExtractSubfolderName(targetpath);

            if (srcDir == tarDir)
            {
                return true;
            }
            if (FileIndex.ChooseTable(sourcepath)
                != FileIndex.ChooseTable(targetpath))
            {
                return false;
            }
            return true;
        }
Example #2
0
        //        private class SyncObject : ISynchronizeInvoke
        //        {
        //            public bool TimerStopped;
        //        }
        public IndexingJob(AbsPath absDirPath, RelPath relDirPath, List<IndexedObjects> folderList, TimerCallback callback, long dueTime, QueingThread queue)
            : base(new FsFolder<RelPath>(relDirPath), callback, dueTime, Timeout.Infinite)
        {
            _absDirPath = absDirPath;
            _queue = queue;
            _indexedObjects = new IndexedObjects(relDirPath);
            _tokenSource = new CancellationTokenSource();

            _eventQueue = new BlockingCollection<FileEvent>();
            DeletedContentList = folderList;

            _toRemove = new Queue<RelPath>();

            _startDelayTimer = new Timer();
            _startDelayTimer.Elapsed += FireDeepScan;
            _startDelayTimer.AutoReset = false;
            _startDelayTimer.Interval = FinishDelay;

            _endingTimer = new Timer();
            _endingTimer.Elapsed += Finish2;
            _endingTimer.AutoReset = false;
            _endingTimer.Interval = FinishDelay;
        }
Example #3
0
 public FsObject<AbsPath> GetFile(RelPath fileName)
 {
     AbsPath path = fileName.AbsoluteIn(MainPath);
     return MainFileIndex.GetObjectAbs(path);
 }
Example #4
0
 public bool Equals(RelPath other)
 {
     return Equals(other._relativePath, _relativePath);
 }
Example #5
0
        private DirNode GetParentDir(RelPath dirPath)
        {
            var folders = dirPath.GetAncestorFolders();

            return GetNode(folders);
        }
Example #6
0
 public bool TryGetObject(RelPath path, out FsObject<RelPath> fsObject)
 {
     throw new NotImplementedException();
 }
Example #7
0
 public bool TryGetFile(RelPath path, out FsFile<RelPath> file)
 {
     try
     {
         file = GetFile(path);
         return true;
     }
     catch (KeyNotFoundException )
     {
         file = default(FsFile<RelPath>);
         return false;
     }
 }
Example #8
0
 public bool Remove(RelPath relPath)
 {
     try
     {
         DirNode node = GetNode(relPath.GetAncestorFolders());
         return node.Remove(relPath.FileName());
     }
     catch (KeyNotFoundException)
     {
         // Looks like its already removed.
         return false;
     }
 }
Example #9
0
        public void MoveDirectory(RelPath sourcePath, RelPath targetPath)
        {
            DirNode parent = GetParentDir(sourcePath);
            DirNode node = parent.RemoveDirNode(sourcePath.FileName());

            DirNode target = EnsureNode(targetPath.GetAncestorFolders());

            target.AddDirNode(targetPath.FileName(), node);
        }
Example #10
0
        public FsObject<RelPath> GetObject(RelPath path)
        {
            var folders = path.GetAncestorFolders();
            DirNode current = GetNode(folders);
            Name fName = path.FileName();
            folders.Add(fName);

            FsFile<Name> fsFile;
            if (current.Files.TryGetValue(fName, out fsFile))
            {
                return fsFile.WithNewPath(RelPath.FromNames(folders));
            }

            return current.Directories[fName].FolderInfo.WithNewPath(RelPath.FromNames(folders));
        }
Example #11
0
        public FsFile<RelPath> GetFile(RelPath path)
        {
            var folders = path.GetAncestorFolders();
            DirNode parent = GetNode(folders);

            Name fName = path.FileName();
            folders.Add(fName);
            return parent.Files[fName].WithNewPath(RelPath.FromNames(folders));
        }
Example #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rootPath">Path relative to rootDirectory</param>
        /// <param name="relativeTo">First part of the path of returned files </param>
        /// <returns></returns>
        public FileTree CloneSubTree(RelPath rootPath, IPath relativeTo)
        {
            var tree = new FileTree(relativeTo);

            Stack<DirNode> targetNodes = new Stack<DirNode>();
            Stack<DirNode> sourceNodes = new Stack<DirNode>();

            DirNode localRoot = GetNode(rootPath.SplitPath());

            tree._rootDirectory = localRoot.Clone(null);

            sourceNodes.Push(localRoot);
            targetNodes.Push(tree._rootDirectory);

            while (sourceNodes.Count != 0)
            {
                DirNode currentSource = sourceNodes.Pop();
                DirNode currentTarget = targetNodes.Pop();

                foreach (DirNode sourceChild in currentSource.Directories.Values)
                {
                    var cloned = sourceChild.Clone(currentTarget);
                    currentTarget.Directories.Add(cloned.Name,cloned);

                    sourceNodes.Push(sourceChild);
                    targetNodes.Push(cloned);
                }
            }
            return tree;
        }
Example #13
0
 public FileEvent(RelPath path, FileEvents eventType)
 {
     _path = path;
     _eventType = eventType;
 }
Example #14
0
        /*

        [ForeignThreadEntryPoint]
        private void Finish(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _queue.Add(() =>
            {
                if(!_startDelayTimerFired)
                {
                    _startDelayTimerFired = true;

                    foreach (FileEvent fileEvent in _eventQueue)
                    {
                        switch (fileEvent.EventType)
                        {
                            case FileEvents.Created:
                            {
                                try
                                {
                                    _indexedObjects.AddObject(LoadFile(fileEvent.Path));
                                }
                                catch (FileNotFoundException)
                                {
                                    // it was probably already deleted
                                }

                                break;
                            }
                            case FileEvents.Changed:
                            {

                                try
                                {
                                    _indexedObjects.ChangeFile((FsFile<RelPath>) LoadFile(fileEvent.Path));
                                }
                                catch (FileNotFoundException)
                                {
                                    // it was probably already deleted
                                }
                                break;
                            }
                            case FileEvents.Deleted:
                            {
                                _indexedObjects.Remove(fileEvent.Path);
                                break;
                            }
                        }
                    }

                    _endingTimer.Start();

                }

            });

        }
        */
        private FsObject<RelPath> LoadFile(RelPath path)
        {
            AbsPath absPath = path.AbsoluteIn(_absDirPath);
            return FsObject<AbsPath>.ReadFrom(absPath).RelativeTo(_absDirPath);
        }
Example #15
0
        /// <summary>
        ///   Adds to the queue an event that happened inside the folder while indexing.
        ///  Warning: Should be invoked on _queue thread.
        /// </summary>
        /// <param name = "path">Path to an object, relative to indexing root.</param>
        /// <param name = "eventType"></param>
        public bool AddEvent(RelPath path, FileEvents eventType)
        {
            if (!_startDelayTimerFired)
            {

                //_eventQueue.Add(new FileEvent(path, eventType));
                // refresh timer.
                _startDelayTimer.Interval = FinishDelay;
                return true;
            }
            if (!_endingTimerFired)
            {
                _toRemove.Enqueue(path);
                return false;
            }
            return false;
        }