Beispiel #1
0
        /*
         * public void Start()
         * {
         *      T = new System.Threading.Thread(new ThreadStart(this.Run));
         *      T.Priority = ThreadPriority.Lowest;
         *      T.Start();
         * }
         */

        public void Run()
        {
            RouteScope routeScope = null;

            try
            {
                //bool alwaysRun = Engine.Instance.Storage.GetBool("pinger.always"); // 2.6
                routeScope = new RouteScope(Server.IpEntry);

                Int64 result = Platform.Instance.Ping(Server.IpEntry, 3);
                Pinger.Instance.PingResult(Server, result);

                /*
                 *
                 *              // Ping
                 *              Ping pingSender = new Ping();
                 *              PingOptions options = new PingOptions();
                 *
                 *              // Use the default Ttl value which is 128,
                 *              // but change the fragmentation behavior.
                 *              //options.DontFragment = true;
                 *
                 *              // Create a buffer of 32 bytes of data to be transmitted.
                 *              byte[] buffer = RandomGenerator.GetBuffer(32);
                 *              int timeout = 2000;
                 *              PingReply reply = pingSender.Send(Server.IpEntry, timeout, buffer, options);
                 *              Pinger.Instance.PingResult(Server, reply);
                 */
            }
            catch (Exception)
            {
                Pinger.Instance.PingResult(Server, -1);
            }
            finally
            {
                if (routeScope != null)
                {
                    routeScope.End();
                }

                lock (Pinger.Instance.Jobs)
                {
                    Pinger.Instance.Jobs.Remove(this);
                }
            }
        }
Beispiel #2
0
        public static XmlDocument FetchUrls(string title, string authPublicKey, List <string> urls, Dictionary <string, string> parameters)
        {
            parameters["login"]    = Engine.Instance.Storage.Get("login");
            parameters["password"] = Engine.Instance.Storage.Get("password");
            parameters["system"]   = Platform.Instance.GetSystemCode();
            parameters["version"]  = Constants.VersionInt.ToString(CultureInfo.InvariantCulture);

            string firstError = "";
            int    hostN      = 0;

            foreach (string url in urls)
            {
                string host = UtilsCore.HostFromUrl(url);

                hostN++;
                if (IpAddress.IsIP(host) == false)
                {
                    // If locked network are enabled, skip the hostname and try only by IP.
                    // To avoid DNS issue (generally, to avoid losing time).
                    if (Engine.Instance.NetworkLockManager.IsDnsResolutionAvailable(host) == false)
                    {
                        continue;
                    }
                }

                try
                {
                    RouteScope  routeScope = new RouteScope(host);
                    XmlDocument xmlDoc     = FetchUrl(authPublicKey, url, parameters);
                    routeScope.End();
                    if (xmlDoc == null)
                    {
                        throw new Exception("No answer.");
                    }

                    if (xmlDoc.DocumentElement.Attributes["error"] != null)
                    {
                        throw new Exception(xmlDoc.DocumentElement.Attributes["error"].Value);
                    }

                    return(xmlDoc);
                }
                catch (Exception e)
                {
                    string info      = e.Message;
                    string proxyMode = Engine.Instance.Storage.Get("proxy.mode").ToLowerInvariant();
                    string proxyWhen = Engine.Instance.Storage.Get("proxy.when").ToLowerInvariant();
                    string proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant();
                    if (proxyMode != "none")
                    {
                        info += " - with '" + proxyMode + "' (" + proxyWhen + ") proxy and '" + proxyAuth + "' auth";
                    }

                    if (Engine.Instance.Storage.GetBool("advanced.expert"))
                    {
                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.ExchangeTryFailed, title, hostN.ToString(), info));
                    }

                    if (firstError == "")
                    {
                        firstError = info;
                    }
                }
            }

            throw new Exception(firstError);
        }