Beispiel #1
0
        //[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        public static void Main(string[] args)
        {
            InvocationTime = DateTime.UtcNow;
            Console.WriteLine($"Processor Count: {Environment.ProcessorCount}");

            var options = PublishSshOptions.ParseArgs(args);

            if (options.PrintHelp)
            {
                PrintHelp();
                return;
            }

            PrepareOptions(options);

            var arguments = string.Join(" ", options.Args);
            var localPath = Path.GetFullPath(options.LocalPath);

            Directory.CreateDirectory(localPath);

            using (FileSystemWatcher watcher = new FileSystemWatcher())
            {
                watcher.Path         = localPath;
                watcher.NotifyFilter = NotifyFilters.LastAccess
                                       | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName
                                       | NotifyFilters.DirectoryName;

                // Add event handlers.
                watcher.Changed += OnChanged;
                watcher.Created += OnChanged;
                watcher.Deleted += OnChanged;
                watcher.Renamed += OnRenamed;

                // Begin watching.
                watcher.EnableRaisingEvents = true;

                // Wait for the user to quit the program.
                if (!PublishLocal(arguments))
                {
                    return;
                }
            }

            var path = options.Path;

            if (!path.EndsWith("/"))
            {
                path = path + "/";
            }
            localPath += Path.DirectorySeparatorChar;

            var localFiles = ChangedFiles;             // GetLocalFiles(localPath);

            if (localFiles.Count <= 0)
            {
                Console.WriteLine($"No files needs to be uploaded!");
            }
            else
            {
                Console.WriteLine($"\nUploading {localFiles.Count} files to {options.User}@{options.Host}:{options.Port}{options.Path}");

                try
                {
                    var runner = new Runner(options);
                    runner.RunBefore();
                    var uploader = new Uploader(options);
                    uploader.UploadFiles(path, localFiles.Select(f => new LocalFile(localPath, f)).ToList());
                    runner.RunAfter();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error uploading files to server: {ex.Message}");
                }
            }
            //Directory.Delete(localPath, true);
            Console.WriteLine($"\nPublished in {TimeSpan.FromSeconds((int)(DateTime.UtcNow - InvocationTime).TotalSeconds):g} !\nThanks for using dotnet publish-ssh!");
        }
Beispiel #2
0
 public Runner(PublishSshOptions publishSshOptions)
 {
     connectionInfo = Uploader.CreateConnectionInfo(publishSshOptions);
     cmdBefore      = publishSshOptions.CmdBefore;
     cmdAfter       = publishSshOptions.CmdAfter;
 }