Пример #1
0
        /// <summary>
        /// Retrieve the external ip of this pc from one of n external websites
        ///
        /// Currently available and processed in this order:
        /// 1) whatismyip.com (url for automated access)
        /// 2) dyndns.com (checkip.dyndns.com)
        /// 3) agentgatech.appspot.com (google app engine)
        /// </summary>
        /// <param name="forceUpdate">If true, cache is ignored</param>
        /// <returns>External ip of pc</returns>
        public static IPAddress GetIP(bool forceUpdate)
        {
            if (!forceUpdate && CachedIP != null && (DateTime.Now - CacheLastUpdated).TotalSeconds < CACHE_LIFETIME)
            {
                return(CachedIP);
            }

            WebClient client = new WebClient();

            client.Headers[HttpRequestHeader.UserAgent] = VersionUtil.GetUserAgent();

            var methods = new Func <WebClient, string>[] { RetrieveFromDynDNS, RetrieveFromAppEngine };

            foreach (var method in methods)
            {
                string result = method.Invoke(client);
                if (result == null)
                {
                    continue;
                }

                if (!IPAddress.TryParse(result, out CachedIP))
                {
                    Log.Warn("Failed to parse retrieved external address '{0}'", result);
                    continue;
                }

                CacheLastUpdated = DateTime.Now;
                return(CachedIP);
            }

            Log.Warn("Couldn't retrieve external IP from any of the external websites. Is your network functioning and the firewall configured correctly?");
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Retrieve the external ip of this pc from one of n external websites
        ///
        /// Currently available and processed in this order:
        /// 1) whatismyip.com (url for automated access)
        /// 2) dyndns.com (checkip.dyndns.com)
        /// 3) agentgatech.appspot.com (google app engine)
        /// </summary>
        /// <param name="forceUpdate">If true, cache is ignored</param>
        /// <returns>External ip of pc</returns>
        public static IPAddress GetIP(bool forceUpdate)
        {
            if (!forceUpdate && CachedIP != null &&
                (DateTime.Now - CacheLastUpdated).TotalSeconds < CACHE_LIFETIME)
            {
                return(CachedIP);
            }

            WebClient client = new WebClient();

            client.Headers[HttpRequestHeader.UserAgent] = VersionUtil.GetUserAgent();

            string ip = RetrieveFromWhatsMyIp(client) ??
                        RetrieveFromDynDNS(client) ??
                        RetrieveFromAppEngine(client);

            if (ip != null)
            {
                CacheLastUpdated = DateTime.Now;
                if (!IPAddress.TryParse(ip, out CachedIP))
                {
                    Log.Warn("Failed to parse retrieved external address '{0}'", ip);
                    return(null);
                }

                return(CachedIP);
            }
            else
            {
                Log.Warn("Couldn't retrieve external IP from any of the external websites. Is a firewall blocking outgoing traffic?");
                return(null);
            }
        }
Пример #3
0
        public void Run()
        {
            WebClient client = new WebClient();

            client.Headers[HttpRequestHeader.UserAgent] = VersionUtil.GetUserAgent("DevTool");
            client.Encoding    = Encoding.UTF8;
            client.Credentials = new NetworkCredential(Answers["username"], Answers["password"]);

            foreach (var resource in resources)
            {
                var details  = client.DownloadString(String.Format("https://www.transifex.com/api/2/project/mpextended/resource/{0}/?details", resource.Key));
                var response = JObject.Parse(details);
                foreach (var code in response["available_languages"].Select(x => (string)x["code"]))
                {
                    var resx = client.DownloadString(String.Format("https://www.transifex.com/api/2/project/mpextended/resource/{0}/translation/{1}/?file", resource.Key, code));
                    var path = Path.Combine(Installation.GetSourceRootDirectory(), String.Format(resource.Value, code));
                    using (StreamWriter writer = new StreamWriter(path, false, Encoding.UTF8))
                    {
                        writer.Write(resx);
                    }
                    OutputStream.WriteLine("Got translation of resource '{0}' for language '{1}'", resource.Key, code);
                }
            }
        }