/// <summary> /// Deploys files to an FTP site. /// </summary> internal void Deploy(DeploymentProject project, DeploymentStructure structure) { // Init FTP client // FtpServerSettings settings = project.FtpServer; // _ftp = new FTPClient(settings.Address, settings.Port); // _ftp.CommandSent += new FTPMessageHandler(Ftp_CommandSent); // _ftp.ReplyReceived += new FTPMessageHandler(Ftp_ReplyReceived); // _ftp.BytesTransferred += new BytesTransferredHandler(Ftp_BytesTransferred); // _ftp.Login(settings.Login, settings.Password); // _ftp.TransferType = FTPTransferType.BINARY; // // // Deploy the structure // DeployStructure(structure, settings.Path); // // _ftp.Quit(); }
/// <summary> /// Scans a directory and all subdirectory and returns all the files found that match the scan filter. /// If we are to use project filter, files are read from project instead of directory. /// </summary> /// <param name="project">The current project settings.</param> /// <param name="modifiedSince">Only return files modified after this date.</param> /// <returns>A structure with the files that were found.</returns> internal DeploymentStructure FindFiles(DeploymentProject project, DateTime modifiedSince) { // These members are used for easy access during scanning _project = project; _config = project.ActiveDeployConfig; if (_config == null) throw new ApplicationException("The project has no active deploy configuration."); // Build structure of matching files _structure = new DeploymentStructure(); if (_config.UseProjectFilter) { string projectFilename = project.GetVisualStudioProjectFileName(); if (projectFilename == null) throw new ApplicationException("Could not find a Visual Studio project file in the root directory."); ScanProjectFile(projectFilename, project.LocalPathAbsolute, modifiedSince); } else ScanDirectoryRecurse(project.LocalPathAbsolute, string.Empty, modifiedSince); return _structure; }
/// <summary> /// Deploys a structure recursively. Works in the current remote directory. /// </summary> /// <param name="structure"></param> private void DeployStructure(DeploymentStructure structure, string remoteBasePath) { // Deploy files string currentRemotePath = null; foreach(DeploymentFile file in structure.Files) { if(currentRemotePath != file.RemotePath) { ChangeRemoteDirectory(Path.Combine(remoteBasePath, file.RemotePath)); // Will create the directory if not existing currentRemotePath = file.RemotePath; } // // Get files in directory // string[] remoteFiles = _ftp.Dir(); // Signal that transfer started _currentTransferEventArgs = new TransferEventArgs(file.LocalPath); EventManager.OnTransferBegin(_currentTransferEventArgs); // Start transferring (FTPClient will raise events about the progress) _ftp.Put(file.LocalPath, file.Name); // Signal that transfer is complete EventManager.OnTransferComplete(_currentTransferEventArgs); } // Verify that directories exist // foreach(DeploymentStructure dir in structure.Directories) { // // Create directory? // if(Array.IndexOf(remoteFiles, dir.Name) == -1) // _ftp.MkDir(dir.Name); // } // Deploy each directory (will change the current remote directory) // foreach(DeploymentStructure dir in structure.Directories) { // DeployStructure(dir, string.Format("{0}/{1}", remotePath, dir.Name)); // } }
/// <summary> /// /// </summary> /// <param name="currentStructure"></param> /// <param name="relativePath"></param> /// <param name="localPath"></param> /// <param name="modifiedSince"></param> private void AddFolderFromRelativePath(DeploymentStructure currentStructure, string relativePath, string localPath, DateTime modifiedSince) { string folderPath = Path.Combine(localPath, relativePath); if(CanIncludeDirectory(relativePath, true) && Directory.Exists(folderPath)) { string[] files = Directory.GetFiles(folderPath); foreach(string file in files) { //Try to add file AddFile(file, relativePath, modifiedSince); } } }
/// <summary> /// /// </summary> /// <param name="currentStructure"></param> /// <param name="relativePath"></param> /// <param name="localPath"></param> /// <param name="modifiedSince"></param> private void AddFileFromRelativePath(DeploymentStructure currentStructure, string relativePath, string localPath, DateTime modifiedSince) { string virtualPath = string.Empty; try { int endpos = relativePath.LastIndexOf('\\'); if(endpos != -1) virtualPath = relativePath.Substring(0, endpos); } catch {} string filePath = Path.Combine(localPath, relativePath); if(CanIncludeDirectory(virtualPath, true)) { //Try to add file AddFile(filePath, virtualPath, modifiedSince); } }
/// <summary> /// Resets variables and UI when a project is loaded or created. /// </summary> private void ResetProjectState() { _filelist.Items.Clear(); _fileQueueList.Items.Clear(); _databaselist.Items.Clear(); _folderTree.Nodes.Clear(); _lastUploadTime = DateTime.MinValue; _deployStructure = null; _scannedDbStructure = null; _databaseComparison = null; }
/// <summary> /// Rescan the deployment file structure. /// </summary> private void RescanStructure() { //AddToLog(string.Format("Scanning directory \"{0}\"...", _currentProject.LocalPathAbsolute)); _deployStructure = DeploymentManager.Instance.ScanFiles(_currentProject, DateTime.MinValue); //AddToLog(string.Format("Found {0} file(s) to deploy.", _deployStructure.Files.Count)); }