예제 #1
0
        /// <summary>
        /// Defines a SSH transaction
        /// </summary>
        /// <param name="_cred">The SSH transaction credentials</param>
        /// <param name="task">The Transaction task</param>
        /// <param name="remotePath">Changes how the remote path is transformed before
        /// it is passed to the scp command on the remote server.
        /// DoubleQuote, ShellQuote, None</param>
        /// <returns>The transaction result</returns>
        public static Object SSHTransaction(SiteCredentials _cred, Func <AuraSftpClient, Object> task, IRemotePathTransformation remotePath = null)
        {
            Object result = null;

            using (var client = new AuraSftpClient(_cred))
            {
                try
                {
                    if (remotePath == null)
                    {
                        client.RemotePathTransformation = ShellQuote;
                    }
                    else
                    {
                        client.RemotePathTransformation = remotePath;
                    }
                    client.Connect();
                    result = task(client);
                    client.Disconnect();
                }
                catch (System.Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Maps a directory to the project file
        /// </summary>
        /// <param name="prj">The project file</param>
        /// <param name="path">The mapped directory data</param>
        private void MapDirectory(Project prj, MappedPath path)
        {
            String error_msg = null;
            var    result    = AuraSftpClient.SFTPTransactionGen <MappedPath> (prj.Connection.Data,
                                                                               (RenCiSftpClient client) => {
                String rPth = path.GetFullRemotePath();
                if (client.Exists(rPth))
                {
                    var entry          = client.Get(rPth);
                    path.RemoteVersion = entry.LastAccessTime;
                    Boolean mapExist   = prj.Data.Map.Directories.FirstOrDefault(x => x.GetFullRemotePath() == entry.FullName) != null;
                    if (entry.IsDirectory && !mapExist)
                    {
                        if (!Directory.Exists(path.GetFullProjectCopy()))
                        {
                            Directory.CreateDirectory(path.GetFullProjectCopy());
                        }
                        if (!Directory.Exists(path.GetFullServerCopy()))
                        {
                            Directory.CreateDirectory(path.GetFullServerCopy());
                        }
                    }
                    else if (!entry.IsDirectory)
                    {
                        error_msg = String.Format(MSG_ERR_MAP_REM_PTH_NOT_DIR, rPth, HelpCommand, "dir");
                    }
                    else if (mapExist)
                    {
                        error_msg = String.Format(MSG_ERR_MAP_AlREADY_MAPPED, rPth);
                    }
                }
                else
                {
                    error_msg = String.Format(MSG_ERR_MAP_REM_PTH, rPth);
                }
                return(path);
            });

            if (result != null && error_msg == null)
            {
                prj.Data.Map.Directories = prj.Data.Map.Directories.Union(new MappedPath[] { result }).ToArray();
                prj.SaveProject(this.ConfigFile);
                Console.WriteLine(String.Format(MSG_INF_MAP_CREATED, result.GetFullRemotePath(), result.GetFullProjectCopy()));
            }
            else if (error_msg != null)
            {
                Console.WriteLine(error_msg);
            }
        }
예제 #3
0
        /// <summary>
        /// Test the connection to a given site
        /// </summary>
        /// <param name="siteName">The name of the site</param>
        private void TestSite(string siteName)
        {
            var    site = Program.Settings.Sites.FirstOrDefault(x => x.Site.ToLower() == siteName.ToLower());
            String errMsg;

            if (site == null)
            {
                Console.WriteLine(MSG_ERR_SITE_NOT_FOUND, siteName);
            }
            else
            {
                if (AuraSftpClient.TestConnection(site.Data, out errMsg))
                {
                    Console.WriteLine(MSG_INF_SITE_CONN_SUCCEED, siteName);
                }
                else
                {
                    Console.WriteLine(MSG_INF_SITE_CONN_FAIL, siteName, errMsg);
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Defines a SSH transaction
 /// </summary>
 /// <param name="_cred">The SSH transaction credentials</param>
 /// <param name="task">The Transaction task</param>
 /// <param name="remotePath">Changes how the remote path is transformed before
 /// it is passed to the scp command on the remote server.
 /// DoubleQuote, ShellQuote, None</param>
 public static void SSHTransactionVoid(SiteCredentials _cred, Action <AuraSftpClient> task, IRemotePathTransformation remotePath = null)
 {
     using (var client = new AuraSftpClient(_cred))
     {
         try
         {
             if (remotePath == null)
             {
                 client.RemotePathTransformation = ShellQuote;
             }
             else
             {
                 client.RemotePathTransformation = remotePath;
             }
             client.Connect();
             task(client);
             client.Disconnect();
         }
         catch (System.Exception exc)
         {
             Console.WriteLine(exc.Message);
         }
     }
 }
예제 #5
0
 /// <summary>
 /// Pull the files from the server that are defined on the project
 /// configuration file Map
 /// </summary>
 /// <param name="prj">The current project</param>
 /// <param name="replace">True if the pulled files will remove the local ones</param>
 /// <param name="silentDownload">Download the files without listing everything</param>
 private void PullFromServer(Project prj, Boolean replace, Boolean silentDownload = false)
 {
     if (prj.Data.Map.Files.Count() > 0 || prj.Data.Map.Directories.Count() > 0)
     {
         AuraSftpClient.SFTPTransactionVoid(prj.Connection.Data, (RenciSftpClient client) =>
         {
             var dirs          = prj.Data.Map.Directories;
             var files         = prj.Data.Map.Files;
             SftpFilter filter = prj.Filter;
             foreach (var dir in dirs)
             {
                 client.Download(prj.Connection.Data, dir, filter, replace, silentDownload);
             }
             foreach (var file in files)
             {
                 prj.Connection.Data.Download(file, replace);
             }
         });
     }
     else
     {
         throw new Exception(MSG_ERR_PRJ_PULL_EMPTY_MAP);
     }
 }
예제 #6
0
        /// <summary>
        /// Check the files from the current cached and list the files that has
        /// differences
        /// </summary>
        /// <param name="prj">The current project</param>
        private void CheckFiles(Project prj)
        {
            String msg = null;

            if ((prj.Data.Map.Files.Count() > 0 || prj.Data.Map.Directories.Count() > 0) && AuraSftpClient.TestConnection(prj.Connection.Data, out msg))
            {
                this.PullFromServer(prj, false, true);
                List <MappedPath> files = new List <MappedPath>();
                foreach (var file in prj.Data.Map.Files)
                {
                    if (files.Count(x => x.ProjectCopy == file.ProjectCopy) == 0)
                    {
                        files.Add(file);
                    }
                }
                foreach (var dir in prj.Data.Map.Directories)
                {
                    this.GetPaths(ref files, new DirectoryInfo(dir.ProjectCopy), prj, dir);
                }
                diff_match_patch dmp = new diff_match_patch();
                //Only uploads files with diff
                String[] cExt = Program.Settings.ComparableFilesExt;
                Boolean  isComparable;
                var      filesToUpload = files.Where(x =>
                {
                    isComparable = x.ProjectCopy.IsComparable(cExt);
                    return(!isComparable || (isComparable && !dmp.AreFilesEquals(x.ProjectCopy, x.ServerCopy)));
                });
                if (filesToUpload.Count() > 0)
                {
                    Console.WriteLine(MSG_INF_FILES_WITH_CHANGES);
                    filesToUpload.ToList().ForEach(x =>
                                                   Console.WriteLine(x.ProjectCopy));
                }
                else
                {
                    Console.WriteLine(MSG_INF_PRJ_NO_CHANGES);
                }
            }
            else
            {
                Console.WriteLine(msg == null ? MSG_INF_PRJ_NO_CHANGES : msg);
            }
        }