示例#1
0
        /// <summary>
        /// Determines if the client should be switched out after the specific command has
        /// executed. If it is switched out, the old client should be disposed of, and a new client
        /// should be returned. If it is not switched out, the current client should be simply returned.
        /// This method is only called upon successful execution of the command.
        /// </summary>
        /// <param name="command">
        /// The command that was successfully executed.
        /// </param>
        /// <param name="currentClient">
        /// The current <see cref="IClient"/> implementation.
        /// </param>
        /// <returns>
        /// The <see cref="IClient"/> to use from now on.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="command"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="currentClient"/> is <c>null</c>.</para>
        /// </exception>
        public IClient SwitchAfterCommand(IMercurialCommand command, IClient currentClient)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (currentClient == null)
            {
                throw new ArgumentNullException("currentClient");
            }

            if (!(command is InitCommand))
            {
                return(currentClient);
            }
            if (!(currentClient is NonPersistentClient))
            {
                return(currentClient);
            }

            if (PersistentClient.IsSupported(currentClient.RepositoryPath))
            {
                string repositoryPath = currentClient.RepositoryPath;
                var    disposable     = currentClient as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                return(new PersistentClient(repositoryPath));
            }

            return(currentClient);
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="IClient"/> object for use by the <see cref="Repository"/>.
        /// </summary>
        /// <param name="repositoryPath">
        /// The path to the repository to manage by the <see cref="IClient"/> and the
        /// <see cref="Repository"/>.
        /// </param>
        /// <returns>
        /// The <see cref="IClient"/> implementation to use.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="repositoryPath"/> is <c>null</c> or empty.</para>
        /// </exception>
        public IClient CreateClient(string repositoryPath)
        {
            if (PersistentClient.IsSupported(repositoryPath))
            {
                return(new PersistentClient(repositoryPath));
            }

            return(new NonPersistentClient(repositoryPath));
        }