Exemplo n.º 1
0
 protected override bool InitClient(ConnectEntryData ci, ref SFTPSyncClient client)
 {
     try
     {
         client = SFTPSyncClient.Create(ci.ce);
     }
     catch (Exception eClient)
     {
         ClouderSyncPackage.Log(eClient.Message);
         return(false);
     }
     try
     {
         if (!client.Connect())
         {
             client.Log("Connection has failed" + '\n');
             return(false);
         }
     }
     catch (Exception eConnect)
     {
         ClouderSyncPackage.WriteToOutputWindow(eConnect.Message + '\n');
         string testResult = client.getLogMessages();
         ClouderSyncPackage.WriteToOutputWindow(testResult);
         client.clearLogMessages();
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        protected override bool ProcessTask()
        {
            ci.ReadEntry();


            ZipArchive archive     = null;
            string     archiveFile = string.Empty;

            if (!InitArchive(ref archive, ref ci, ref archiveFile))
            {
                return(false);
            }

            Array arrInfo = arrItems;

            ProcessCompression(archive, arrInfo, ci);
            ClouderSyncPackage.WriteToOutputWindow(string.Format("Compression complete: file {0}\n", archiveFile));
            try
            {
                archive.Dispose();
            }
            catch { }
            archive = null;
            return(true);
        }
Exemplo n.º 3
0
        private async void Launch()
        {
            //CompressTask task = null;

            ClouderSyncPackage.WriteToOutputWindow("-----\n", "ClouderSync", null, true);

            if (!ConnectEntryData.SettingsExist())
            {
                ShowMessageBox(@"It does not appear that SFTP connection has been configured. Please configure in the next step", "ClouderSync SSH");
                cmdConfigureSSH.ConfigureSSH(this);
                return;
            }
            if (CompressTask.GetIsRunning())
            {
                ShowMessageBox(@"It appears that a compression task is running. Please cancel, or wait, or restart Visual Studio", "ClouderSync Compress");
                return;
            }
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       token       = tokenSource.Token;

            CompressTask task = new CompressTask(this);
            await Task.Run(() =>
            {
                task.Execute(tokenSource);
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// VS Package that provides this command, not null.
        /// </summary>
        //private readonly CloudSyncPackage package;

        /// <summary>
        /// Initializes a new instance of the <see cref="cmdCloudDeploy"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private cmdCloudDeploy(ClouderSyncPackage package, OleMenuCommandService commandService)
            : base(package, commandService, _commandSet, _commandId)
        {
            CommandID      commandID0   = CreateCommandID(CommandSet, CommandId);
            OleMenuCommand menuCommand0 = CreateMenuCommand(commandID0, this.Execute);
            CommandID      commandID1   = CreateCommandID(ClouderSyncIDs.guidSSHDeployCmdSet, CommandId);
            OleMenuCommand menuCommand1 = CreateMenuCommand(commandID1, this.Execute);

#if BEFORE_V199
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem      = new MenuCommand(this.ExecuteAsync, menuCommandID);
            commandService.AddCommand(menuItem);

            menuCommandID = new CommandID(CloudSyncIDs.guidSSHDeployCmdSet, CommandId);
            menuItem      = new MenuCommand(this.ExecuteAsync, menuCommandID);
            commandService.AddCommand(menuItem);

/*
 *          menuCommandID = new CommandID(CloudSyncIDs.guidSSHDeployCmdSet, 0x200);
 *          menuItem = new MenuCommand(this.ExecuteAsync, menuCommandID);
 *          commandService.AddCommand(menuItem);
 */
            /*
             * menuCommandID = new CommandID(CloudSyncIDs.guidVSStd2k, CommandId);
             * menuItem = new MenuCommand(this.ExecuteAsync, menuCommandID);
             * commandService.AddCommand(menuItem);
             */
#endif
#if USE_BKG_WORKER
            InitBackgroundWorker();
#endif
        }
Exemplo n.º 5
0
        static Guid _commandSet = ClouderSyncIDs.guidCloudSyncCmdSet;// new Guid("d10c84e7-2237-4b60-85eb-e0e1864f929e");

        /// <summary>
        /// Initializes a new instance of the <see cref="cmdCommandWindow"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private cmdCommandWindow(ClouderSyncPackage package, OleMenuCommandService commandService)
            : base(package, commandService, _commandSet, _commandId)
        {
            CommandID      commandID0   = CreateCommandID(CommandSet, CommandId);
            OleMenuCommand menuCommand0 = CreateMenuCommand(commandID0, this.ExecuteCommand);
            CommandID      commandID1   = CreateCommandID(ClouderSyncIDs.guidCommandWndCmdSet, CommandId);
            OleMenuCommand menuCommand1 = CreateMenuCommand(commandID1, this.ExecuteCommand);

#if BEFORE_208
            OleMenuCommand menuCommand0 = CreateMenuCommand(CommandSet, CommandId, this.ExecuteCommand);
            OleMenuCommand menuCommand1 = CreateMenuCommand(ClouderSyncIDs.guidCommandWndCmdSet, CommandId, this.ExecuteCommand);
#endif

            /*
             *
             *          commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
             *
             *          var menuCommandID = new CommandID(CommandSet, base.CommandId);
             *          //var menuItem = new MenuCommand(this.Execute, menuCommandID);
             *          var menuItem = new OleMenuCommand(this.Execute, menuCommandID);
             *          commandService.AddCommand(menuItem);
             */
            /*
             * var menuItem = new OleMenuCommand
             * menuItem.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatus);
             */
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="cmdCloudDeploy"/> class.
 /// Adds our command handlers for menu (commands must exist in the command table file)
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 /// <param name="commandService">Command service to add command to, not null.</param>
 protected BaseCommand(ClouderSyncPackage package, OleMenuCommandService commandService, Guid commandSet, int commandId)
 {
     if (_package == null)
     {
         _package = package ?? throw new ArgumentNullException(nameof(package));
     }
     CommandSet      = commandSet;
     CommandId       = commandId;
     _commandService = commandService;
 }
Exemplo n.º 7
0
        public static SettingsManager GetAppSettings(ClouderSyncPackage package)
        {
            var dte = package.GetServiceOfType(typeof(EnvDTE.DTE));

            if (dte is DTE)
            {
                return(SettingsManagerCreator.GetSettingsManager((DTE)dte));
            }
            return(SettingsManagerCreator.GetSettingsManager(package));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static async Task InitializeAsync(ClouderSyncPackage package)
        {
            // Switch to the main thread - the call to AddCommand in cmdCloudDeploy's constructor requires
            // the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;

            Instance = new cmdCloudCompress(package, commandService);
        }
Exemplo n.º 9
0
        protected override bool ProcessTask()
        {
            SFTPSyncClient client = null;

            ci.ReadEntry();

            Array arrInfo = arrItems;

            ProcessTransfer(arrInfo, ref client, ref ci);
            ClouderSyncPackage.WriteToOutputWindow("Transfer complete" + "\n");
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// VS Package that provides this command, not null.
        /// </summary>
        //private readonly CloudSyncPackage package;

        /// <summary>
        /// Initializes a new instance of the <see cref="cmdCloudDeploy"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private cmdCloudCompress(ClouderSyncPackage package, OleMenuCommandService commandService)
            : base(package, commandService, _commandSet, _commandId)
        {
            CommandID      commandID0   = CreateCommandID(CommandSet, CommandId);
            OleMenuCommand menuCommand0 = CreateMenuCommand(commandID0, this.Execute);
            CommandID      commandID1   = CreateCommandID(ClouderSyncIDs.guidSSHDeployCmdSet, CommandId);
            OleMenuCommand menuCommand1 = CreateMenuCommand(commandID1, this.Execute);

#if USE_BKG_WORKER
            InitBackgroundWorker();
#endif
        }
Exemplo n.º 11
0
        public static Guid _commandSet = ClouderSyncIDs.guidCloudSyncConfigureSSHSet;//new Guid("d10c84e7-2237-4b60-85eb-e0e1864f929e");

        /// <summary>
        /// VS Package that provides this command, not null.
        /// </summary>
        //private readonly AsyncPackage package;
        //private CloudSyncPackage package;

        /// <summary>
        /// Initializes a new instance of the <see cref="cmdConfigureSSH"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private cmdConfigureSSH(ClouderSyncPackage package, OleMenuCommandService commandService)
            : base(package, commandService, _commandSet, _commandId)
        {
            CommandID      commandID0   = CreateCommandID(CommandSet, CommandId);
            OleMenuCommand menuCommand0 = CreateMenuCommand(commandID0, this.Execute);

/*
 *          commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
 *
 *          var menuCommandID = new CommandID(CommandSet, CommandId);
 *          var menuItem = new MenuCommand(this.Execute, menuCommandID);
 *          commandService.AddCommand(menuItem);
 */
        }
Exemplo n.º 12
0
 public void Execute(CancellationTokenSource cancellationTokenSource = null)
 {
     _cancelTokenSrc = cancellationTokenSource;
     try
     {
         ExecuteInternal();
     }
     catch (OperationCanceledException eCxl)
     {
         SetIsRunning(false);
         ClouderSyncPackage.WriteToOutputWindow("Transfer cancelled, " + eCxl.Message + "\n");
     }
     finally
     {
         cancellationTokenSource.Dispose();
     }
 }
Exemplo n.º 13
0
        protected void ExecuteInternal()
        {
            SetIsRunning(true);
            if (_cancelTokenSrc != null)
            {
                _cancelToken = _cancelTokenSrc.Token;
            }
            if (_cancelToken.IsCancellationRequested)
            {
                _cancelToken.ThrowIfCancellationRequested();
            }
            SFTPSyncClient client = null;

            ci.ReadEntry();

            Array arrInfo = arrItems;

            ProcessTransfer(arrInfo, ref client, ref ci);
            ClouderSyncPackage.WriteToOutputWindow("Transfer complete" + "\n");
            SetIsRunning(false);
        }
Exemplo n.º 14
0
        /*
         * protected virtual void ExecuteInternal()
         * {
         *  SetIsRunning(true);
         *  if (_cancelTokenSrc != null)
         *  {
         *      _cancelToken = _cancelTokenSrc.Token;
         *  }
         *  if (_cancelToken.IsCancellationRequested)
         *  {
         *      _cancelToken.ThrowIfCancellationRequested();
         *  }
         *  SFTPSyncClient client = null;
         *
         *  ci.ReadEntry();
         *
         *  Array arrInfo = arrItems;
         *
         *  ProcessTask(arrInfo, ref client, ref ci);
         *  ClouderSyncPackage.WriteToOutputWindow("Transfer complete" + "\n");
         *  SetIsRunning(false);
         * }
         */
        protected virtual bool InitArchive(ref ZipArchive archive, ref ConnectEntryData ci, ref string _archiveFileName)
        {
            //string archiveName = Path.ChangeExtension(selectedDir, "zip");
            string archiveName  = selectedFullFilePath + ".zip";
            string errorMessage = string.Empty;

            if (!FileTools.DeleteFile(archiveName, ref errorMessage))
            {
                try
                {
                    if (File.Exists(archiveName))
                    {
                        File.Delete(archiveName);
                    }
                }
                catch (Exception eDelete)
                {
                    ClouderSyncPackage.WriteToOutputWindow(String.Format("Failed to delete {0}:{1}\n", archiveName, eDelete.Message));
                    return(false);
                }
            }
            try
            {
                archive = ZipFile.Open(archiveName, ZipArchiveMode.Create);
            }
            catch (Exception eCreate)
            {
                ClouderSyncPackage.WriteToOutputWindow(String.Format("Failed to create {0}:{1}\n", archiveName, eCreate.Message));
                return(false);
            }
            if (_archiveFileName != null)
            {
                _archiveFileName = archiveName;
            }
            //archive.CreateEntryFromFile()
            return(true);
        }
Exemplo n.º 15
0
        protected bool ProcessCompression(ZipArchive archive, Array arrInfo, ConnectEntryData ci)
        {
            if ((arrInfo == null) || (arrInfo.Length < 1))
            {
                ClouderSyncPackage.WriteToOutputWindow("Nothing selected, nothing to do \n");
                return(false);
            }

            int iItem      = 0;
            int iItemCount = arrInfo.Length;

            if ((_cancelToken != null) && _cancelToken.IsCancellationRequested)
            {
                _cancelToken.ThrowIfCancellationRequested();
            }

            foreach (ItemInfo item in arrInfo)
            {
                iItem++;
                if (!item.HasPath)
                {
                    continue;
                }
                if (ci.ce.ignoreexcludedfiles)
                {
                    if (!item.IncludedInProject)
                    {
                        ClouderSyncPackage.WriteToOutputWindow("Skipping item excluded from project " + item.FilePath + "...\n");
                        continue;
                    }
                }
                string pathTrail  = FileTools.MapRoots(item.FilePath, projectDirectory);
                string szFileName = Path.Combine(projectDirectory, pathTrail);
                if (!File.Exists(szFileName))
                {
                    ClouderSyncPackage.WriteToOutputWindow("Entering local directory " + szFileName + "\n");
                    continue;
                }
                string          fileName          = Path.GetFileName(item.FilePath);
                string          localDir          = Path.GetDirectoryName(pathTrail);
                string          remoteRelativeDir = FileTools.NormalizeDirName(localDir);
                string          archiveRoot       = remoteRelativeDir;
                ZipArchiveEntry archiveEntry      = null;

                remoteRelativeDir = remoteRelativeDir.TrimStart(FileTools.DirectorySeparators);
                if (NeedsNewArchiveEntry(archiveEntry, remoteRelativeDir))
                {
                    ClouderSyncPackage.WriteToOutputWindow("Entering local directory " + Path.GetDirectoryName(item.FilePath) + "\n");
                    archiveRoot = remoteRelativeDir;
                    if (string.IsNullOrEmpty(archiveRoot))
                    {
                        archiveRoot = "/";
                    }
                    if (!string.IsNullOrEmpty(archiveRoot))
                    {
                        try
                        {
                            archiveEntry = archive.CreateEntry(archiveRoot);
                        }
                        catch (Exception eFile)
                        {
                            ClouderSyncPackage.WriteToOutputWindow(string.Format(CultureInfo.CurrentCulture, "Failed to create archive entry {0}: {1}\n", remoteRelativeDir, eFile.Message));
                        }
                    }
                    if (fileName == string.Empty)
                    {
                        continue;
                    }
                }
                string message = string.Format(CultureInfo.CurrentCulture, "{0}/{1} {2}=>{3}", iItem, iItemCount, pathTrail, remoteRelativeDir + fileName);
                ClouderSyncPackage.WriteToOutputWindow(message + "\n");
#if !TEST_MODE
                try
                {
                    string remoteFile = Path.Combine(remoteRelativeDir, fileName);
                    if (archiveEntry != null)
                    {
//                        remoteFile = archiveEntry.FullName + "/" + fileName;
                    }
                    ZipArchiveEntry fileZipEntry = archive.CreateEntryFromFile(szFileName, remoteFile, CompressionLevel.Optimal);
                }
                catch (Exception eAddFile)
                {
                    ClouderSyncPackage.WriteToOutputWindow(string.Format(CultureInfo.CurrentCulture, "Skipping file {0}: {1}", szFileName, eAddFile.Message));
                }
#endif
                if ((_cancelToken != null) && _cancelToken.IsCancellationRequested)
                {
                    _cancelToken.ThrowIfCancellationRequested();
                }
            }
            return(true);
        }
Exemplo n.º 16
0
 private async void Cancel()
 {
     ClouderSyncPackage.WriteToOutputWindow("\nCancellation requested \n", "ClouderSync", null, false);
     CompressTask.Cancel();
 }
Exemplo n.º 17
0
        protected bool ProcessTransfer(Array arrInfo, ref SFTPSyncClient client, ref ConnectEntryData ci)
        {
            if ((arrInfo == null) || (arrInfo.Length < 1))
            {
                ClouderSyncPackage.WriteToOutputWindow("Nothing selected, nothing to do \n");
                return(false);
            }
            if (!InitClient(ci, ref client))
            {
                return(false);
            }
            string remoteSrcPath = FileTools.NormalizeDirName(ci.ce.remotesrcpath);
            int    iItem         = 0;
            int    iItemCount    = arrInfo.Length;

            if ((_cancelToken != null) && _cancelToken.IsCancellationRequested)
            {
                _cancelToken.ThrowIfCancellationRequested();
            }

#if !TEST_MODE
            if (!client.EnterDirectory(remoteSrcPath))
            {
                ClouderSyncPackage.WriteToOutputWindow("Failed to enter remote directory " + remoteSrcPath + "\n");
            }
            else
#endif
            {
                ClouderSyncPackage.WriteToOutputWindow("Entering remote directory " + remoteSrcPath + "...\n");
            }

            foreach (ItemInfo item in arrInfo)
            {
                iItem++;
                if (!item.HasPath)
                {
                    continue;
                }
                if (ci.ce.ignoreexcludedfiles)
                {
                    if (!item.IncludedInProject)
                    {
                        ClouderSyncPackage.WriteToOutputWindow("Skipping item excluded from project " + item.FilePath + "...\n");
                        continue;
                    }
                }
                if (!FileTools.CanMapRoots(item.FilePath, projectDirectory))
                {
                    int iMinLen = projectDirectory.Length;
                    if (item.FilePath.Length < iMinLen)
                    {
                        iMinLen = item.FilePath.Length;
                    }
                    ClouderSyncPackage.WriteToOutputWindow("Can not map " + item.FilePath.Substring(0, iMinLen) + " to " + projectDirectory + "\n");
                    continue;
                }
                string pathTrail  = FileTools.MapRoots(item.FilePath, projectDirectory);
                string szFileName = Path.Combine(projectDirectory, pathTrail);
                if (!File.Exists(szFileName))
                {
                    ClouderSyncPackage.WriteToOutputWindow("Entering local directory " + szFileName + "\n");
                    continue;
                }
                string fileName          = Path.GetFileName(item.FilePath);
                string localDir          = Path.GetDirectoryName(pathTrail);
                string remoteRelativeDir = FileTools.NormalizeDirName(localDir);

                if (fileName == string.Empty)
                {
                    ClouderSyncPackage.WriteToOutputWindow("Entering local directory " + item.FilePath + "\n");
                    client.EnterDirectory(FileTools.CombinePaths(remoteSrcPath, remoteRelativeDir));
                    continue;
                }


                string message = string.Format(CultureInfo.CurrentCulture, "{0}/{1} {2}=>{3}", iItem, iItemCount, pathTrail, remoteRelativeDir + fileName);
                ClouderSyncPackage.WriteToOutputWindow(message + "\n");
#if !TEST_MODE
                FileStream fs = null;
                try
                {
                    fs = new FileStream(szFileName, FileMode.Open, FileAccess.Read);
                }
                catch (Exception eFile)
                {
                    ClouderSyncPackage.WriteToOutputWindow(string.Format(CultureInfo.CurrentCulture, "Failed to open local file {0}: {1}\n", szFileName, eFile.Message));
                }
                if (fs != null)
                {
                    client.BufferSize = 1024;
                    client.UploadAndCreateFile(fs, remoteSrcPath, remoteRelativeDir, fileName, _cancelToken);
                    fs.Close();
                    fs.Dispose();
                    fs = null;
                }
#endif
                if ((_cancelToken != null) && _cancelToken.IsCancellationRequested)
                {
                    _cancelToken.ThrowIfCancellationRequested();
                }
            }
            if (client != null)
            {
                client.Disconnect();
                client.Dispose();
            }

            return(true);
        }
Exemplo n.º 18
0
 private void Cancel()
 {
     ClouderSyncPackage.WriteToOutputWindow("\nCancellation requested \n", "ClouderSync", null, false);
     DeploymentTask.Cancel();
 }