Esempio n. 1
0
 public static bool TryGetConnectionInfoOrDefault(
     ConnectionInfoStore store,
     string remoteTargetStringOrId,
     out StoredConnectionInfo connectionInfo)
 {
     return(RemoteTargetUtils.TryGetConnectionInfoOrDefault(store, remoteTargetStringOrId, RetrieveMode.All, out connectionInfo));
 }
Esempio n. 2
0
 public static bool TryGetDefaultConnectionInfo(
     ConnectionInfoStore store,
     StoredConnectionInfo[] excludedConnections,
     out StoredConnectionInfo connectionInfo)
 {
     return(RemoteTargetUtils.TryGetDefaultConnectionInfo(store, RetrieveMode.All, excludedConnections, out connectionInfo));
 }
Esempio n. 3
0
        public static bool TryGetConnectionInfoOrDefault(
            ConnectionInfoStore store,
            string remoteTargetStringOrId,
            RetrieveMode mode,
            out StoredConnectionInfo connectionInfo)
        {
            connectionInfo = (StoredConnectionInfo)null;
            if (string.IsNullOrWhiteSpace(remoteTargetStringOrId))
            {
                return(RemoteTargetUtils.TryGetDefaultConnectionInfo(store, mode, new StoredConnectionInfo[0], out connectionInfo));
            }
            RemoteTarget result1 = (RemoteTarget)null;
            int          result2 = -1;

            if (RemoteTargetUtils.TryParseRemoteTarget(remoteTargetStringOrId, out result1))
            {
                if (!store.TryGetById(result1.Id, mode, out connectionInfo))
                {
                    return(false);
                }
            }
            else
            {
                if (!int.TryParse(remoteTargetStringOrId, out result2))
                {
                    return(store.TryGetByName(remoteTargetStringOrId, out connectionInfo));
                }
                if (!store.TryGetById(result2, out connectionInfo))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 4
0
        public static SSHConnection GetSSHConnection(string name)
        {
            ConnectionInfoStore store          = new ConnectionInfoStore();
            ConnectionInfo      connectionInfo = null;

            StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection =>
            {
                return(name.Equals(SSHPortSupplier.GetFormattedSSHConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase));
            });

            if (storedConnectionInfo != null)
            {
                connectionInfo = (ConnectionInfo)storedConnectionInfo;
            }

            if (connectionInfo == null)
            {
                IVsConnectionManager     connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));
                IConnectionManagerResult result;
                if (string.IsNullOrWhiteSpace(name))
                {
                    result = connectionManager.ShowDialog();
                }
                else
                {
                    string userName;
                    string hostName;

                    int atSignIndex = name.IndexOf('@');
                    if (atSignIndex > 0)
                    {
                        userName = name.Substring(0, atSignIndex);

                        int hostNameStartPos = atSignIndex + 1;
                        hostName = hostNameStartPos < name.Length ? name.Substring(hostNameStartPos) : StringResources.HostName_PlaceHolder;
                    }
                    else
                    {
                        userName = string.Format(CultureInfo.CurrentCulture, StringResources.UserName_PlaceHolder);
                        hostName = name;
                    }
                    result = connectionManager.ShowDialog(new PasswordConnectionInfo(hostName, userName, new System.Security.SecureString()));
                }

                if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded)
                {
                    // Retrieve the newly added connection
                    store.Load();
                    connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId);
                }
            }

            return(SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo));
        }
Esempio n. 5
0
        public static bool TryGetConnectionIdByName(string name, out int id)
        {
            ConnectionInfoStore  connectionInfoStore  = new ConnectionInfoStore();
            StoredConnectionInfo storedConnectionInfo = (StoredConnectionInfo)null;

            if (connectionInfoStore.TryGetByName(name, RetrieveMode.All, out storedConnectionInfo))
            {
                id = storedConnectionInfo.Id;
                return(true);
            }
            id = 0;
            return(false);
        }
Esempio n. 6
0
        public int EnumPorts(out IEnumDebugPorts2 ppEnum)
        {
            ConnectionInfoStore store = new ConnectionInfoStore();
            IDebugPort2[] ports = new IDebugPort2[store.Connections.Count];

            for (int i = 0; i < store.Connections.Count; i++)
            {
                ConnectionInfo connectionInfo = (ConnectionInfo)store.Connections[i];
                ports[i] = new AD7Port(this, ConnectionManager.GetFormattedConnectionName(connectionInfo), isInAddPort: false);
            }

            ppEnum = new AD7PortEnum(ports);
            return HR.S_OK;
        }
Esempio n. 7
0
        public int EnumPorts(out IEnumDebugPorts2 ppEnum)
        {
            ConnectionInfoStore store = new ConnectionInfoStore();

            IDebugPort2[] ports = new IDebugPort2[store.Connections.Count];

            for (int i = 0; i < store.Connections.Count; i++)
            {
                ConnectionInfo connectionInfo = (ConnectionInfo)store.Connections[i];
                ports[i] = new AD7Port(this, ConnectionManager.GetFormattedConnectionName(connectionInfo), isInAddPort: false);
            }

            ppEnum = new AD7PortEnum(ports);
            return(HR.S_OK);
        }
Esempio n. 8
0
 public static bool TryGetDefaultConnectionInfo(
     ConnectionInfoStore store,
     RetrieveMode mode,
     StoredConnectionInfo[] excludedConnections,
     out StoredConnectionInfo connectionInfo)
 {
     connectionInfo = (StoredConnectionInfo)null;
     if (store.Connections.Count == 0)
     {
         return(false);
     }
     StoredConnectionInfo[] connectionsByAddedDate = RemoteTargetUtils.GetAvailableConnectionsByAddedDate(store);
     connectionInfo = store.Connections.Where <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(c => !((IEnumerable <StoredConnectionInfo>)excludedConnections).Any <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(e => e.Id == c.Id)))).Where <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(c => c.LastSuccessful != DateTime.MinValue)).DefaultIfEmpty <StoredConnectionInfo>(((IEnumerable <StoredConnectionInfo>)connectionsByAddedDate).FirstOrDefault <StoredConnectionInfo>()).FirstOrDefault <StoredConnectionInfo>();
     return(connectionInfo != null);
 }
Esempio n. 9
0
        public static SSHConnection GetSSHConnection(string name)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            ConnectionInfoStore store          = new ConnectionInfoStore();
            ConnectionInfo      connectionInfo = null;

            StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection =>
            {
                return(string.Equals(name, SSHPortSupplier.GetFormattedSSHConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase));
            });

            if (storedConnectionInfo != null)
            {
                connectionInfo = (ConnectionInfo)storedConnectionInfo;
            }

            if (connectionInfo == null)
            {
                IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));
                if (connectionManager != null)
                {
                    IConnectionManagerResult result;
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        result = connectionManager.ShowDialog();
                    }
                    else
                    {
                        ParseSSHConnectionString(name, out string userName, out string hostName, out int port);

                        result = connectionManager.ShowDialog(new PasswordConnectionInfo(hostName, port, Timeout.InfiniteTimeSpan, userName, new System.Security.SecureString()));
                    }

                    if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded)
                    {
                        // Retrieve the newly added connection
                        store.Load();
                        connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Why is IVsConnectionManager null?");
                }
            }

            return(SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo));
        }
Esempio n. 10
0
        public static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Invalid command line");
                return((int)Result.InvalidCommandLine);
            }

            var command = args[0];

            if (string.Compare(command, "add", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (args.Length < 5)
                {
                    Console.WriteLine("Invalid command line");
                    return((int)Result.InvalidCommandLine);
                }

                var host     = args[1];
                var port     = int.Parse(args[2]);
                var user     = args[3];
                var password = args[4];

                Console.WriteLine($"Adding credentials for {host}");

                var cis            = new ConnectionInfoStore();
                var passwordSecure = new SecureString();
                foreach (var c in password)
                {
                    passwordSecure.AppendChar(c);
                }

                cis.Add(new PasswordConnectionInfo(host, port, TimeSpan.MaxValue, user, passwordSecure));

                Console.WriteLine($"Saving credentials");
                cis.Save();
                Console.WriteLine($"Credentials saved successfully");

                return((int)Result.Success);
            }
            return((int)Result.UnsupportedCommand);
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command2"/> 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 Command2(AsyncPackage package, OleMenuCommandService commandService)
        {
            this.package   = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

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

            commandService.AddCommand(menuItem);

            try
            {
                ConnectionInfoStore connectionInfoStore = new ConnectionInfoStore();
                connectionInfoStore.Load();
                if (connectionInfoStore.Connections.Count > 0)
                {
                    remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
                    directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
                }
            }
            catch { }
        }
Esempio n. 12
0
        public override bool Execute()
        {
            ConnectionInfoStore  store          = new ConnectionInfoStore();
            StoredConnectionInfo connectionInfo = (StoredConnectionInfo)null;

            if (RemoteTargetUtils.TryGetConnectionInfoOrDefault(store, this.RemoteTarget, RetrieveMode.PropertiesOnly, out connectionInfo))
            {
                this.ResolvedRemoteTarget     = RemoteTargetUtils.ConnectionToString(connectionInfo);
                this.ResolvedRemoteTargetId   = connectionInfo.Id.ToString();
                this.RemoteTargetArchitecture = connectionInfo.Properties["Platform"] ?? "";
                this.ResolvedRemoteUserName   = RemoteTargetUtils.ConnectionToUserName(connectionInfo);
            }
            else
            {
                if (store.Connections.Count == 0 && !this.DesignTimeBuild)
                {
                    this.Log.LogErrorFromResources("Error.NoRemoteTargets");
                    return(false);
                }
                this.ResolvedRemoteTarget = this.RemoteTarget;
            }
            this.RemoteTargetHash = this.RemoteTarget?.GetHashCode().ToString();
            return(true);
        }
Esempio n. 13
0
        public static IEnumerable <ConnectionInfo> GetAvailableSSHConnectionInfos()
        {
            ConnectionInfoStore store = new ConnectionInfoStore();

            return(store.Connections.ToList().Select(item => (ConnectionInfo)item));
        }
Esempio n. 14
0
        internal static Connection GetInstance(string name, ConnectionReason reason)
        {
            UnixSystem remoteSystem = null;
            ConnectionInfoStore store = new ConnectionInfoStore();
            ConnectionInfo connectionInfo = null;

            StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection =>
                {
                    return name.Equals(GetFormattedConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase);
                });

            if (storedConnectionInfo != null)
                connectionInfo = (ConnectionInfo)storedConnectionInfo;

            if (connectionInfo == null)
            {
                IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));

                string userName;
                string hostName;

                int atSignIndex = name.IndexOf('@');
                if (atSignIndex > 0)
                {
                    userName = name.Substring(0, atSignIndex);
                    hostName = name.Substring(atSignIndex + 1);
                }
                else
                {
                    userName = string.Format(CultureInfo.CurrentCulture, StringResources.UserName_PlaceHolder);
                    hostName = name;
                }

                PasswordConnectionInfo newConnectionInfo = new PasswordConnectionInfo(hostName, userName, new System.Security.SecureString());

                IConnectionManagerResult result = connectionManager.ShowDialog(newConnectionInfo);

                if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded)
                {
                    // Retrieve the newly added connection
                    store.Load();
                    connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId);
                }
            }

            if (connectionInfo != null)
            {
                remoteSystem = new UnixSystem();

                while (true)
                {
                    try
                    {
                        VSOperationWaiter.Wait(string.Format(CultureInfo.CurrentCulture, StringResources.WaitingOp_Connecting, name), throwOnCancel: false, action: () =>
                        {
                            remoteSystem.Connect(connectionInfo);
                        });
                        break;
                    }
                    catch (RemoteAuthenticationException)
                    {
                        IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));
                        IConnectionManagerResult result = connectionManager.ShowDialog(StringResources.AuthenticationFailureHeader, StringResources.AuthenticationFailureDescription, connectionInfo);

                        if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded)
                        {
                            connectionInfo = result.ConnectionInfo;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    catch (Exception ex)
                    {
                        VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, ex.Message, null,
                            OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        return null;
                    }
                }

                // NOTE: This will be null if connect is canceled
                if (remoteSystem != null)
                {
                    return new Connection(remoteSystem);
                }
            }

            return null;
        }
Esempio n. 15
0
 public static StoredConnectionInfo[] GetAvailableConnectionsByAddedDate(
     ConnectionInfoStore store)
 {
     return(store.Connections.OrderBy <StoredConnectionInfo, DateTime>((Func <StoredConnectionInfo, DateTime>)(c => c.DateAdded)).ToArray <StoredConnectionInfo>());
 }
Esempio n. 16
0
        internal static Connection GetInstance(string name, ConnectionReason reason)
        {
            UnixSystem          remoteSystem   = null;
            ConnectionInfoStore store          = new ConnectionInfoStore();
            ConnectionInfo      connectionInfo = null;

            StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection =>
            {
                return(name.Equals(GetFormattedConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase));
            });

            if (storedConnectionInfo != null)
            {
                connectionInfo = (ConnectionInfo)storedConnectionInfo;
            }

            if (connectionInfo == null)
            {
                IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));

                string userName;
                string hostName;

                int atSignIndex = name.IndexOf('@');
                if (atSignIndex > 0)
                {
                    userName = name.Substring(0, atSignIndex);
                    hostName = name.Substring(atSignIndex + 1);
                }
                else
                {
                    userName = string.Format(CultureInfo.CurrentCulture, StringResources.UserName_PlaceHolder);
                    hostName = name;
                }

                PasswordConnectionInfo newConnectionInfo = new PasswordConnectionInfo(hostName, userName, new System.Security.SecureString());

                IConnectionManagerResult result = connectionManager.ShowDialog(newConnectionInfo);

                if (result.DialogResult == ConnectionManagerDialogResult.Succeeded)
                {
                    // Retrieve the newly added connection
                    store.Load();
                    connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId);
                }
            }

            if (connectionInfo != null)
            {
                remoteSystem = new UnixSystem();

                while (true)
                {
                    try
                    {
                        VSOperationWaiter.Wait(string.Format(CultureInfo.CurrentCulture, StringResources.WaitingOp_Connecting, name), throwOnCancel: false, action: () =>
                        {
                            remoteSystem.Connect(connectionInfo);
                        });
                        break;
                    }
                    catch (RemoteAuthenticationException)
                    {
                        IVsConnectionManager     connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager));
                        IConnectionManagerResult result            = connectionManager.ShowDialog(StringResources.AuthenticationFailureHeader, StringResources.AuthenticationFailureDescription, connectionInfo);

                        if (result.DialogResult == ConnectionManagerDialogResult.Succeeded)
                        {
                            // Update the credentials in the store
                            store.Load();
                            store.RemoveById(result.StoredConnectionId);
                            store.Add(result.ConnectionInfo);
                            store.Save();

                            connectionInfo = result.ConnectionInfo;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch (Exception ex)
                    {
                        VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, ex.Message, null,
                                                        OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        return(null);
                    }
                }

                // NOTE: This will be null if connect is canceled
                if (remoteSystem != null)
                {
                    return(new Connection(remoteSystem));
                }
            }

            return(null);
        }
Esempio n. 17
0
 public void ScpToRemote(List <string> files, string dir_path, string dir, IVsOutputWindowPane outputWindowPane)
 {
     try
     {
         lock (lock_obj)
         {
             // ThreadHelper.ThrowIfNotOnUIThread();
             var dte = Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
             dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Activate();
             if (files.Count == 0)
             {
                 outputWindowPane.OutputStringThreadSafe("No file can be copied");
                 return;
             }
             ConnectionInfoStore connectionInfoStore = new ConnectionInfoStore();
             connectionInfoStore.Load();
             if (connectionInfoStore.Connections.Count < 1)
             {
                 outputWindowPane.OutputStringThreadSafe("No connection found. Add connection in [Tools] / [Options] / [Cross Platform]");
                 return;
             }
             outputWindowPane.OutputStringThreadSafe("Connecting...\n");
             if (remoteSystem == null)
             {
                 remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
                 directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
             }
             using (var concurrencySemaphore = new System.Threading.SemaphoreSlim(8))
             {
                 int         num    = 0;
                 int         length = files.Count;
                 List <Task> tasks  = new List <Task>();
                 foreach (string file in files)
                 {
                     concurrencySemaphore.Wait();
                     var t = Task.Run(() =>
                     {
                         string str2           = file.Substring(dir_path.Length);
                         string remoteFileName = directory.FullPath + "/projects/" + dir + str2.Replace('\\', '/');
                         string remotePath     = remoteFileName.Substring(0, remoteFileName.LastIndexOf('/'));
                         try
                         {
                             if (File.Exists(file))
                             {
                                 remoteSystem.FileSystem.UploadFile(file, remoteFileName);
                                 outputWindowPane.OutputStringThreadSafe("[" + Interlocked.Increment(ref num) + "/" + length + "] " + remoteFileName + "\n");
                             }
                             else
                             {
                                 Interlocked.Increment(ref num);
                                 outputWindowPane.OutputStringThreadSafe("Skip " + file + " (file not exists)\n");
                             }
                         }
                         catch (liblinux.IO.IOException ex1)
                         {
                             if (ex1.Message.Contains("No such file"))
                             {
                                 remoteSystem.FileSystem.CreateDirectories(remotePath);
                                 remoteSystem.FileSystem.UploadFile(file, remoteFileName);
                                 outputWindowPane.OutputStringThreadSafe("[" + Interlocked.Increment(ref num) + "/" + length + "] " + remoteFileName + "\n");
                             }
                             else
                             {
                                 Interlocked.Increment(ref num);
                                 outputWindowPane.OutputStringThreadSafe("Upload failed: " + file + "\n");
                             }
                         }
                         catch (Exception ex)
                         {
                             Interlocked.Increment(ref num);
                             outputWindowPane.OutputStringThreadSafe("Upload failed: " + file + ", ex: " + ex.ToString() + "\n");
                         }
                         finally
                         {
                             concurrencySemaphore.Release();
                         }
                     });
                     tasks.Add(t);
                 }
                 Task.WaitAll(tasks.ToArray());
             }
             remoteSystem.Disconnect();
             remoteSystem.Dispose();
             outputWindowPane.OutputStringThreadSafe("Copy to " + remoteSystem.ConnectionInfo.HostNameOrAddress + " done.\n");
             // prepare for next time
             remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
             directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
         }
     }
     catch (Exception ex)
     {
         remoteSystem = null;
         throw ex;
     }
 }