Beispiel #1
0
 /// <summary>
 /// Push the files to the server only the mapped files are push to the server
 /// </summary>
 /// <param name="prj">The current project</param>
 /// <param name="silentMode">if true push changes without confirmation</param>
 private void PushToServer(Project prj, Boolean silentMode = false)
 {
     if (prj.Data.Map.Files.Count() > 0 || prj.Data.Map.Directories.Count() > 0)
     {
         List <MappedPath> files = new List <MappedPath>();
         foreach (var file in prj.Data.Map.Files)
         {
             if (files.Count(x => x.GetFullProjectCopy() == file.GetFullProjectCopy()) == 0)
             {
                 files.Add(file);
             }
         }
         foreach (var dir in prj.Data.Map.Directories)
         {
             this.GetPaths(ref files, new DirectoryInfo(dir.GetFullProjectCopy()), 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.GetFullProjectCopy().IsComparable(cExt);
             return(isComparable && !dmp.AreFilesEquals(x.GetFullProjectCopy(), x.GetFullServerCopy() + ".copy"));
         }).ToArray();
         if (filesToUpload.Length > 0)
         {
             SftpUtils.UploadFiles(filesToUpload, prj, silentMode);
         }
         else
         {
             Console.WriteLine(MSG_INF_PRJ_PUSH_NO_CHANGES);
         }
     }
     else
     {
         throw new Exception(MSG_ERR_PRJ_PULL_EMPTY_MAP);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Adds a file or a directory to the server
        /// </summary>
        /// <param name="prj">The current project</param>
        /// <param name="localPath">The local path</param>
        /// <param name="remotePath">The remote path</param>
        private void AddToServer(Project prj, string localPath, string remotePath)
        {
            String prjPath    = Environment.CurrentDirectory;
            String configFile = Path.Combine(prjPath, ".ssh", "config.json");

            localPath  = Path.Combine(prj.Data.ProjectCopy, localPath);
            remotePath = Path.Combine(prj.Connection.Data.RootDir, remotePath);
            if (File.Exists(localPath)) //is a file
            {
                var mapped = prj.Data.Map.Files.FirstOrDefault(x => x.ProjectCopy == localPath);
                if (mapped == null)
                {
                    // File.Copy (localPath, localPath.Replace (prj.Data.ProjectCopy, prj.Data.ServerCopy), true);
                    MappedPath newMap = new MappedPath()
                    {
                        ProjectCopy   = localPath,
                        ServerCopy    = localPath.Replace(prj.Data.ProjectCopy, prj.Data.ServerCopy),
                        RemotePath    = remotePath,
                        RemoteVersion = DateTime.Now,
                        LocalVersion  = DateTime.Now
                    };
                    SftpUtils.UploadFiles(new MappedPath[] { newMap }, prj, true);
                    prj.Data.Map.Files = prj.Data.Map.Files.Union(new MappedPath[] { newMap }).ToArray();
                    prj.SaveProject(configFile);
                    Console.WriteLine(String.Format(MSG_INF_MAP_CREATED, localPath, remotePath));
                }
                else
                {
                    throw new Exception(String.Format(MSG_ERR_MAP_AlREADY_MAPPED, localPath));
                }
            }
            else if (Directory.Exists(localPath))
            {
                var mapped = prj.Data.Map.Files.FirstOrDefault(x => x.ProjectCopy == localPath);
                if (mapped == null)
                {
                    var files = prj.Filter.FilesInDirectory(localPath);
                    foreach (String file in files)
                    {
                        File.Copy(file, file.Replace(prj.Data.ProjectCopy, prj.Data.ServerCopy + ".copy"));
                    }
                    SftpUtils.UploadFiles(files.Select(x =>
                                                       new MappedPath()
                    {
                        ProjectCopy   = x,
                        ServerCopy    = x.Replace(prj.Data.ProjectCopy, prj.Data.ServerCopy),
                        RemotePath    = remotePath + "/" + x.Substring(x.LastIndexOf('\\')),
                        RemoteVersion = DateTime.Now,
                        LocalVersion  = DateTime.Now
                    }
                                                       ), prj);
                    MappedPath newMap = new MappedPath()
                    {
                        ProjectCopy   = localPath,
                        ServerCopy    = localPath.Replace(prj.Data.ProjectCopy, prj.Data.ServerCopy),
                        RemotePath    = remotePath,
                        RemoteVersion = DateTime.Now,
                        LocalVersion  = DateTime.Now
                    };
                    prj.Data.Map.Directories = prj.Data.Map.Directories.Union(new MappedPath[] { newMap }).ToArray();
                    prj.SaveProject(configFile);
                    Console.WriteLine(String.Format(MSG_INF_MAP_CREATED, localPath, remotePath));
                }
            }
            else
            {
                throw new Exception(MSG_ERR_PRJ_BAD_LOC_PTH);
            }
        }