コード例 #1
0
ファイル: PathItem.cs プロジェクト: zyj0021/TracerX
        /// <summary>
        /// This ctor is for a REMOTE file/folder.
        /// </summary>
        public PathItem(TXFileInfo remoteTXInfo, ViewedPath viewedPath = null)
        {
            IsFolder = remoteTXInfo.IsFolder;
            FullPath = remoteTXInfo.FullPath;
            IsFromRecentlyCreatedList = remoteTXInfo.FoundInRecentFiles;

            if (IsFolder)
            {
                ItemName      = Path.GetFileName(remoteTXInfo.FullPath);
                ContainerName = Path.GetDirectoryName(remoteTXInfo.FullPath);
            }
            else
            {
                ItemName      = Path.GetFileNameWithoutExtension(remoteTXInfo.FullPath);
                ContainerName = Path.GetDirectoryName(remoteTXInfo.FullPath);
            }

            WriteTime  = remoteTXInfo.LastModified;
            CreateTime = remoteTXInfo.Created;
            Size       = remoteTXInfo.Size;

            if (viewedPath != null)
            {
                ViewTime = viewedPath.ViewTime;
            }

            Init();
        }
コード例 #2
0
ファイル: PathItem.cs プロジェクト: zyj0021/TracerX
        /// <summary>
        /// This ctor is for a local file/folder.  It will throw an exception if
        /// the path is not well-formed.
        /// </summary>
        public PathItem(ViewedPath viewedPath, bool isFolder)
            : this(viewedPath.Path, isFolder, false)
        {
            ViewTime = viewedPath.ViewTime;

            // Do not reference path.Exists, path.LastModified, or other properties
            // that depend on the actual existence of the file/folder, because it
            // may take a long time if the file/folder is on a remote share or is unreachable.
            // It will be done by a worker thread.
        }
コード例 #3
0
        /// <summary>
        /// Calls the TracerX-Service on the remote server to
        /// get the files in the specified folder.  Returns
        /// only the .tx1 files, if any.
        /// </summary>
        public List <PathItem> GetFilesInFolder(string folder)
        {
            var result = new List <PathItem>();
            List <TXFileInfo> files = null;

            using (var proxy = new ProxyFileEnum())
            {
                proxy.SetHost(HostAndPort);
                proxy.SetCredentials(GetCreds());

                Log.Info("Getting remote files from ", HostAndPort);
                files = proxy.GetFilesInFolder(folder);
            }

            foreach (TXFileInfo file in files)
            {
                ViewedPath viewedFile = _savedViewedFiles.FirstOrDefault(svf => svf.Path.Equals(file.FullPath, StringComparison.OrdinalIgnoreCase));
                PathItem   pathItem;

                if (_dictFiles.TryGetValue(file.FullPath, out pathItem))
                {
                    // We already know about this file so just update the properties that might have changed.

                    pathItem.WriteTime  = file.LastModified;
                    pathItem.CreateTime = file.Created;
                    pathItem.Size       = file.Size;

                    if (viewedFile != null)
                    {
                        pathItem.ViewTime = viewedFile.ViewTime;
                    }
                }
                else
                {
                    pathItem = new PathItem(file, viewedFile);
                    _dictFiles.Add(pathItem.FullPath, pathItem);
                }

                // Create a new PathItem to return to the caller.
                // We never return an existing item from _dictFiles because that can cause the same
                // PathItem to be associated with two PathGridRows, which causes problems.

                pathItem = new PathItem(file, viewedFile);
                result.Add(pathItem);
            }

            return(result);
        }
コード例 #4
0
        // Called when the user views the specified file so we can keep track of which files
        // have been viewed and when.
        public void UpdateViewedFiles(string viewedFile)
        {
            // First, add/update the file in both file collections (_savedViewedFiles and _dictFiles).

            DateTime   now           = DateTime.Now;
            ViewedPath viewedFileObj = _savedViewedFiles.Find(item => item.Path.Equals(viewedFile, StringComparison.OrdinalIgnoreCase));

            if (viewedFileObj == null)
            {
                viewedFileObj = new ViewedPath {
                    Path = viewedFile, ViewTime = now
                };
                _savedViewedFiles.Add(viewedFileObj);
            }
            else
            {
                viewedFileObj.ViewTime = now;
            }

            PathItem filePathItem;

            if (!_dictFiles.TryGetValue(viewedFile, out filePathItem))
            {
                // We assume the file exists because it was just loaded into the viewer.

                var txInfo = new TXFileInfo()
                {
                    IsFolder = false,
                    FullPath = viewedFile,
                };

                filePathItem           = new PathItem(txInfo);
                _dictFiles[viewedFile] = filePathItem;
            }

            filePathItem.ViewTime = now;

            // Now add/update the folder in both folder collections (_savedViewedFolders and _dictFolders).

            string     folder          = System.IO.Path.GetDirectoryName(viewedFile);
            ViewedPath viewedFolderObj = _savedViewedFolders.Find(item => item.Path.Equals(folder, StringComparison.OrdinalIgnoreCase));

            if (viewedFolderObj == null)
            {
                viewedFolderObj = new ViewedPath {
                    Path = folder, ViewTime = now
                };
                _savedViewedFolders.Add(viewedFolderObj);
            }
            else
            {
                viewedFolderObj.ViewTime = now;
            }

            PathItem folderPathItem;

            if (!_dictFolders.TryGetValue(folder, out folderPathItem))
            {
                var txInfo = new TXFileInfo()
                {
                    IsFolder = true,
                    FullPath = folder
                };

                folderPathItem       = new PathItem(txInfo);
                _dictFolders[folder] = folderPathItem;
            }

            folderPathItem.ViewTime = now;
        }