Ejemplo n.º 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
            {
                IpAddress ip = Server.IpsEntry.FirstPreferIPv4;
                if ((ip == null) || (ip.Valid == false))
                {
                    throw new Exception("Invalid ip");
                }
                routeScope = new RouteScope(ip.ToString());
                Int64 result = Platform.Instance.Ping(ip, 3);
                Engine.Instance.JobsManager.Latency.PingResult(Server, result);
            }
            catch (Exception)
            {
                Engine.Instance.JobsManager.Latency.PingResult(Server, -1);
            }
            finally
            {
                if (routeScope != null)
                {
                    routeScope.End();
                }

                lock (Engine.Instance.JobsManager.Latency.Jobs)
                {
                    Engine.Instance.JobsManager.Latency.Jobs.Remove(this);
                }
            }
        }
Ejemplo n.º 2
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
            {
                IpAddress ip = Server.IpsEntry.FirstPreferIPv4;
                if ((ip == null) || (ip.Valid == false))
                {
                    throw new Exception("Invalid ip");
                }
                routeScope = new RouteScope(ip.ToString());
                Int64 result = Platform.Instance.Ping(ip, Engine.Instance.Storage.GetInt("pinger.timeout"));

                if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null))
                {
                    return;                     // Avoid unidentified crash
                }
                Engine.Instance.JobsManager.Latency.PingResult(Server, result);
            }
            catch (Exception)
            {
                if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null))
                {
                    return;                     // Avoid unidentified crash
                }
                Engine.Instance.JobsManager.Latency.PingResult(Server, -1);
            }
            finally
            {
                if (routeScope != null)
                {
                    routeScope.End();
                }

                if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null))
                {
                    // Avoid unidentified crash
                }
                else
                {
                    lock (Engine.Instance.JobsManager.Latency.Jobs)
                    {
                        Engine.Instance.JobsManager.Latency.Jobs.Remove(this);
                    }
                }
            }
        }
Ejemplo n.º 3
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
            {
                IpAddress ip = Server.IpsEntry.OnlyIPv4.First;

                /*
                 * if (Server.DisplayName == "Castor") // ClodoTemp
                 *      ip = Server.IpsEntry.OnlyIPv6.First;
                 */
                if ((ip == null) || (ip.Valid == false))
                {
                    throw new Exception("Invalid ip");
                }
                routeScope = new RouteScope(ip.ToString());
                Int64 result = Platform.Instance.Ping(ip, 3);
                Pinger.Instance.PingResult(Server, result);
            }
            catch (Exception)
            {
                Pinger.Instance.PingResult(Server, -1);
            }
            finally
            {
                if (routeScope != null)
                {
                    routeScope.End();
                }

                lock (Pinger.Instance.Jobs)
                {
                    Pinger.Instance.Jobs.Remove(this);
                }
            }
        }
Ejemplo n.º 4
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 = Utils.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     = AirExchange.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 proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant();
                    if (proxyMode != "none")
                    {
                        info += " - with '" + proxyMode + "' 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);
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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 = Utils.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 = AirExchange.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 proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant();
                    if (proxyMode != "none")
                        info += ", with '" + proxyMode + "' 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);
        }