Example #1
0
        /// <summary>
        ///		同步创建连接
        /// </summary>
        /// <param name="timeout"></param>
        public void Connect(int timeout)
        {
            var a = new SyncInvoker <Exception>();

            BeginConnect(a.Callback);
            if (!a.Wait(timeout))
            {
                throw new RpcException(RpcErrorCode.ConnectionTimeout, RemoteUri.ToString(), "Connection timeout", null);
            }
        }
        public override void ExecuteAsync()
        {
            SetStatus(TaskStatus.Running);
            TorrentService s = Banshee.ServiceStack.ServiceManager.Get <TorrentService> ();

            downloader = s.Download(RemoteUri.ToString(), Path.GetDirectoryName(LocalPath));
            torrent    = TorrentService.Bus.GetObject <ITorrent> (TorrentService.BusName, downloader.GetTorrent());

            downloader.StateChanged += OnDownloaderStateChanged;

            // There are no events on the torrent IDownloader to indicate when the stats have updated
            // Manually ping the SetProgress event, otherwise migo never notices progress changing
            System.Threading.ThreadPool.QueueUserWorkItem(UpdateProgress);
        }
Example #3
0
        public IEnumerable <string> GetSettingValues(string envarName, string section, string property)
        {
            string envarValue = null;

            if (Environment?.Variables.TryGetValue(envarName, out envarValue) ?? false)
            {
                yield return(envarValue);
            }

            foreach (string scope in RemoteUri.GetGitConfigurationScopes())
            {
                string key = $"{section}.{scope}.{property}";

                IEnumerable <string> configValues = GitConfiguration.GetAll(key);
                foreach (string value in configValues)
                {
                    yield return(value);
                }
            }
        }
Example #4
0
        public IEnumerable <string> GetSettingValues(string envarName, string section, string property)
        {
            string envarValue = null;

            if (Environment?.Variables.TryGetValue(envarName, out envarValue) ?? false)
            {
                yield return(envarValue);
            }

            foreach (string scope in RemoteUri.GetGitConfigurationScopes())
            {
                string key = $"{section}.{scope}.{property}";

                IList <string> configValues = null;
                if (GitConfiguration?.Dictionary.TryGetValue(key, out configValues) ?? false)
                {
                    if (configValues.Count > 0)
                    {
                        yield return(configValues[0]);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Try and get the all values of a specified setting as specified in the environment and Git configuration,
        /// in the correct order or precedence.
        /// </summary>
        /// <param name="envarName">Optional environment variable name.</param>
        /// <param name="section">Optional Git configuration section name.</param>
        /// <param name="property">Git configuration property name. Required if <paramref name="section"/> is set, optional otherwise.</param>
        /// <returns>All values for the specified setting, in order of precedence, or an empty collection if no such values are set.</returns>
        public IEnumerable <string> GetSettingValues(string envarName, string section, string property)
        {
            string value;

            if (envarName != null)
            {
                if (_environment.Variables.TryGetValue(envarName, out value))
                {
                    yield return(value);
                }
            }

            if (section != null && property != null)
            {
                IGitConfiguration config = GetGitConfiguration();

                if (RemoteUri != null)
                {
                    /*
                     * Look for URL scoped "section" configuration entries, starting from the most specific
                     * down to the least specific (stopping before the TLD).
                     *
                     * In a divergence from standard Git configuration rules, we also consider matching URL scopes
                     * without a scheme ("protocol://").
                     *
                     * For each level of scope, we look for an entry with the scheme included (the default), and then
                     * also one without it specified. This allows you to have one configuration scope for both "http" and
                     * "https" without needing to repeat yourself, for example.
                     *
                     * For example, starting with "https://foo.example.com/bar/buzz" we have:
                     *
                     *   1a. [section "https://foo.example.com/bar/buzz"]
                     *          property = value
                     *
                     *   1b. [section "foo.example.com/bar/buzz"]
                     *          property = value
                     *
                     *   2a. [section "https://foo.example.com/bar"]
                     *          property = value
                     *
                     *   2b. [section "foo.example.com/bar"]
                     *          property = value
                     *
                     *   3a. [section "https://foo.example.com"]
                     *          property = value
                     *
                     *   3b. [section "foo.example.com"]
                     *          property = value
                     *
                     *   4a. [section "https://example.com"]
                     *          property = value
                     *
                     *   4b. [section "example.com"]
                     *          property = value
                     *
                     */

                    // Enumerate all configuration entries with the correct section and property name
                    // and make a local copy of them here to avoid needing to call `TryGetValue` on the
                    // IGitConfiguration object multiple times in a loop below.
                    var configEntries = new Dictionary <string, string>();
                    config.Enumerate((entryName, entryValue) =>
                    {
                        string entrySection  = entryName.TruncateFromIndexOf('.');
                        string entryProperty = entryName.TrimUntilLastIndexOf('.');

                        if (StringComparer.OrdinalIgnoreCase.Equals(entrySection, section) &&
                            StringComparer.OrdinalIgnoreCase.Equals(entryProperty, property))
                        {
                            configEntries[entryName] = entryValue;
                        }

                        // Continue the enumeration
                        return(true);
                    });

                    foreach (string scope in RemoteUri.GetGitConfigurationScopes())
                    {
                        string queryName = $"{section}.{scope}.{property}";
                        // Look for a scoped entry that includes the scheme "protocol://example.com" first as this is more specific
                        if (configEntries.TryGetValue(queryName, out value))
                        {
                            yield return(value);
                        }

                        // Now look for a scoped entry that omits the scheme "example.com" second as this is less specific
                        string scopeWithoutScheme  = scope.TrimUntilIndexOf(Uri.SchemeDelimiter);
                        string queryWithSchemeName = $"{section}.{scopeWithoutScheme}.{property}";
                        if (configEntries.TryGetValue(queryWithSchemeName, out value))
                        {
                            yield return(value);
                        }
                    }
                }

                /*
                 * Try to look for an un-scoped "section" property setting:
                 *
                 *    [section]
                 *        property = value
                 *
                 */
                if (config.TryGetValue($"{section}.{property}", out value))
                {
                    yield return(value);
                }
            }
        }
        public IEnumerable <string> GetSettingValues(string envarName, string section, string property, bool isPath)
        {
            string value;

            if (envarName != null)
            {
                if (_environment.Variables.TryGetValue(envarName, out value))
                {
                    yield return(value);
                }
            }

            if (section != null && property != null)
            {
                IGitConfiguration config = _git.GetConfiguration();

                if (RemoteUri != null)
                {
                    /*
                     * Look for URL scoped "section" configuration entries, starting from the most specific
                     * down to the least specific (stopping before the TLD).
                     *
                     * In a divergence from standard Git configuration rules, we also consider matching URL scopes
                     * without a scheme ("protocol://").
                     *
                     * For each level of scope, we look for an entry with the scheme included (the default), and then
                     * also one without it specified. This allows you to have one configuration scope for both "http" and
                     * "https" without needing to repeat yourself, for example.
                     *
                     * For example, starting with "https://foo.example.com/bar/buzz" we have:
                     *
                     *   1a. [section "https://foo.example.com/bar/buzz"]
                     *          property = value
                     *
                     *   1b. [section "foo.example.com/bar/buzz"]
                     *          property = value
                     *
                     *   2a. [section "https://foo.example.com/bar"]
                     *          property = value
                     *
                     *   2b. [section "foo.example.com/bar"]
                     *          property = value
                     *
                     *   3a. [section "https://foo.example.com"]
                     *          property = value
                     *
                     *   3b. [section "foo.example.com"]
                     *          property = value
                     *
                     *   4a. [section "https://example.com"]
                     *          property = value
                     *
                     *   4b. [section "example.com"]
                     *          property = value
                     *
                     * It is also important to note that although the section and property names are NOT case
                     * sensitive, the "scope" part IS case sensitive! We must be careful when searching to ensure
                     * we follow Git's rules.
                     *
                     */

                    // Enumerate all configuration entries with the correct section and property name
                    // and make a local copy of them here to avoid needing to call `TryGetValue` on the
                    // IGitConfiguration object multiple times in a loop below.
                    var configEntries = new Dictionary <string, string>(GitConfigurationKeyComparer.Instance);
                    config.Enumerate(section, property, entry =>
                    {
                        configEntries[entry.Key] = entry.Value;

                        // Continue the enumeration
                        return(true);
                    });

                    foreach (string scope in RemoteUri.GetGitConfigurationScopes())
                    {
                        string queryName = $"{section}.{scope}.{property}";
                        // Look for a scoped entry that includes the scheme "protocol://example.com" first as
                        // this is more specific. If `isPath` is true, then re-get the value from the
                        // `GitConfiguration` with `isPath` specified.
                        if (configEntries.TryGetValue(queryName, out value) &&
                            (!isPath || config.TryGet(queryName, isPath, out value)))
                        {
                            yield return(value);
                        }

                        // Now look for a scoped entry that omits the scheme "example.com" second as this is less
                        // specific. As above, if `isPath` is true, get the configuration setting again with
                        // `isPath` specified.
                        string scopeWithoutScheme  = scope.TrimUntilIndexOf(Uri.SchemeDelimiter);
                        string queryWithSchemeName = $"{section}.{scopeWithoutScheme}.{property}";
                        if (configEntries.TryGetValue(queryWithSchemeName, out value) &&
                            (!isPath || config.TryGet(queryWithSchemeName, isPath, out value)))
                        {
                            yield return(value);
                        }
                    }
                }

                /*
                 * Try to look for an un-scoped "section" property setting:
                 *
                 *    [section]
                 *        property = value
                 *
                 */
                if (config.TryGet($"{section}.{property}", isPath, out value))
                {
                    yield return(value);
                }

                // Check for an externally specified default value
                if (TryGetExternalDefault(section, property, out string defaultValue))
                {
                    yield return(defaultValue);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Try and get the all values of a specified setting as specified in the environment and Git configuration,
        /// in the correct order or precedence.
        /// </summary>
        /// <param name="envarName">Optional environment variable name.</param>
        /// <param name="section">Optional Git configuration section name.</param>
        /// <param name="property">Git configuration property name. Required if <paramref name="section"/> is set, optional otherwise.</param>
        /// <returns>All values for the specified setting, in order of precedence, or an empty collection if no such values are set.</returns>
        public IEnumerable <string> GetSettingValues(string envarName, string section, string property)
        {
            string value;

            if (envarName != null)
            {
                if (_environment.TryGetValue(envarName, out value))
                {
                    yield return(value);
                }
            }

            if (section != null && property != null)
            {
                using (var config = _git.GetConfiguration(RepositoryPath))
                {
                    if (RemoteUri != null)
                    {
                        /*
                         * Look for URL scoped "section" configuration entries, starting from the most specific
                         * down to the least specific (stopping before the TLD).
                         *
                         * In a divergence from standard Git configuration rules, we also consider matching URL scopes
                         * without a scheme ("protocol://").
                         *
                         * For each level of scope, we look for an entry with the scheme included (the default), and then
                         * also one without it specified. This allows you to have one configuration scope for both "http" and
                         * "https" without needing to repeat yourself, for example.
                         *
                         * For example, starting with "https://foo.example.com/bar/buzz" we have:
                         *
                         *   1a. [section "https://foo.example.com/bar/buzz"]
                         *          property = value
                         *
                         *   1b. [section "foo.example.com/bar/buzz"]
                         *          property = value
                         *
                         *   2a. [section "https://foo.example.com/bar"]
                         *          property = value
                         *
                         *   2b. [section "foo.example.com/bar"]
                         *          property = value
                         *
                         *   3a. [section "https://foo.example.com"]
                         *          property = value
                         *
                         *   3b. [section "foo.example.com"]
                         *          property = value
                         *
                         *   4a. [section "https://example.com"]
                         *          property = value
                         *
                         *   4b. [section "example.com"]
                         *          property = value
                         *
                         */
                        foreach (string scope in RemoteUri.GetGitConfigurationScopes())
                        {
                            // Look for a scoped entry that includes the scheme "protocol://example.com" first as this is more specific
                            if (config.TryGetValue(section, scope, property, out value))
                            {
                                yield return(value);
                            }

                            // Now look for a scoped entry that omits the scheme "example.com" second as this is less specific
                            string scopeWithoutScheme = scope.TrimUntilIndexOf(Uri.SchemeDelimiter);
                            if (config.TryGetValue(section, scopeWithoutScheme, property, out value))
                            {
                                yield return(value);
                            }
                        }
                    }

                    /*
                     * Try to look for an un-scoped "section" property setting:
                     *
                     *    [section]
                     *        property = value
                     *
                     */
                    if (config.TryGetValue(section, property, out value))
                    {
                        yield return(value);
                    }
                }
            }
        }