Example #1
0
        /// <summary>
        /// Checks if a Url belongs to the part of the web we wish to crawl.
        /// </summary>
        /// <param name="targetUrl">The url to examine</param>
        /// <returns>
        /// A <see cref="DomainFlagValue"/> indicating whether the input Url belongs to the
        /// part of the web we wish to crawl.
        /// </returns>
        /// <remarks>
        /// Since it is possible for a url that belongs to a non-greek domain (e.g. .com) to
        /// contain greek content, all Urls that do not belong to the .gr domain will get the
        /// value of <see cref="DomainFlagValue.Unknown"/>. This allows the system to assign
        /// them at a later time to a client who will visit them and check their content-type
        /// encoding, in order to determine whether they are of interest to the system.
        /// </remarks>
        public DomainFlagValue FilterUrl(ref string targetUrl)
        {
            DomainFlagValue retVal = DomainFlagValue.Unknown;

            try
            {
                mutex.WaitOne();
                string targetHost = InternetUtils.HostName(targetUrl);
                if (targetHost.EndsWith(".gr") || targetHost.Contains("ebay.com"))
                {
                    retVal = DomainFlagValue.MustVisit;
                }
                else
                {
                    if (IsIPAddress(ref targetHost))
                    {
                        if (ipTable.GetCountry(targetHost) == "GR")
                        {
                            retVal = DomainFlagValue.MustVisit;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                globals.FileLog.LogWarning(e.ToString());
            }
            finally
            {
                mutex.ReleaseMutex();
            }
            return(retVal);
        }
Example #2
0
        static void Main(string[] args)
        {
            /* Prüfen, ob eine Internetverbindung nach www.google.de möglich ist */
            string address = "www.google.de";

            InternetUtils.PingResult pingResult = InternetUtils.Ping(address, 1000);
            switch (pingResult)
            {
            case InternetUtils.PingResult.OK:
                Console.WriteLine("Ping an {0} war erfolgreich", address);
                break;

            case InternetUtils.PingResult.Timeout:
                Console.WriteLine("Timeout beim Ping an {0}", address);
                break;

            case InternetUtils.PingResult.ChecksumError:
                Console.WriteLine("Daten wurden empfangen, aber es ist ein " +
                                  "Prüfsummenfehler aufgetreten {0}", address);
                break;
            }

            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #3
0
 /// <summary>
 /// Loads the IP addresses from the APNIC, ARIN, LACNIC and RIPENCC registry files.
 /// If the files are more than 1 month old then a fresh copy is downloaded.
 /// </summary>
 private void LoadIPAddresses()
 {
     //Check if the files are too old.
     try
     {
         if (File.Exists(globals.AppDataPath + FileNames[0]))
         {
             if (File.GetLastWriteTime(globals.AppDataPath + FileNames[0]).AddMonths(1) < DateTime.Now)
             {
                 //They are more than a month old, we need to download a fresh copy.
                 InternetUtils.UpdateIPAddressFiles(globals.AppDataPath);
             }
         }
     }
     catch (Exception e)
     {
         globals.FileLog.LogWarning(e.ToString());
     }
     //Load the files into the cache. [just from ripe]
     for (int i = 3; i < FileNames.Length; i++)
     {
         try
         {
             ipTable.LoadStatisticsFile(globals.AppDataPath + FileNames[i], true);
         }
         catch
         {
             globals.FileLog.LogWarning("DomainFilter failed to load IP addresses from " + FileNames[i]);
             continue;
         }
     }
     GC.Collect();
 }
Example #4
0
        public void atualizarEndereco()
        {
            if (InternetUtils.estarConectado())
            {
                var percursos = _percursoDB.listarEnderecoNulo();
                if (percursos.Count > 0)
                {
                    int idPercurso = percursos[0].Id;
                    var pontos     = _pontoDB.listar(idPercurso);
                    if (pontos.Count() > 0)
                    {
                        float lat = (float)(from p in pontos select p.Latitude).Last();
                        float lon = (float)(from p in pontos select p.Longitude).Last();

                        GeocoderUtils.pegarAsync(lat, lon, (sender, e) =>
                        {
                            var endereco          = e.Endereco;
                            PercursoInfo percurso = new PercursoInfo()
                            {
                                Id       = idPercurso,
                                Endereco = endereco.Logradouro + " " + endereco.Complemento + " " + endereco.Bairro + " " + endereco.Cidade + " " + endereco.Uf + " " + endereco.CEP
                            };
                            gravar(percurso);
                            atualizarEndereco();
                        });
                    }
                }
            }
        }
 public virtual void cadastrarRadar(Object sender, EventArgs e)
 {
     if (InternetUtils.estarConectado())
     {
         LocalizacaoInfo local     = GPSUtils.UltimaLocalizacao;
         float           latitude  = (float)local.Latitude;
         float           longitude = (float)local.Longitude;
         GeocoderUtils.pegarAsync(latitude, longitude, (send, ev) =>
         {
             var endereco = ev.Endereco;
             Emagine.Utils.MensagemUtils.avisar(endereco.Logradouro);
         });
     }
     try
     {
         LocalizacaoInfo local = GPSUtils.UltimaLocalizacao;
         if (local != null)
         {
             RadarBLL regraRadar = RadarFactory.create();
             regraRadar.inserir(local);
             MensagemUtils.avisar("Radar incluído com sucesso.");
         }
         else
         {
             MensagemUtils.avisar("Nenhum movimento registrado pelo GPS.");
         }
     }
     catch (Exception e2)
     {
         MensagemUtils.avisar(e2.Message);
     }
 }
Example #6
0
        static void Main(string[] args)
        {
            try
            {
                // Internetverbindungs-Status abfragen
                InternetUtils.InternetConnectionState ics = InternetUtils.GetInternetConnectionState();

                // Ergebnis ausgeben
                Console.WriteLine("Name: {0}", ics.Name);
                Console.WriteLine("Online: {0}", ics.Online);
                Console.WriteLine("Configured: {0}", ics.Configured);
                Console.WriteLine("Lan: {0}", ics.Lan);
                Console.WriteLine("ModemConnection: {0}", ics.ModemConnection);
                Console.WriteLine("Offline: {0}", ics.Offline);
                Console.WriteLine("ProxyConnection: {0}", ics.ProxyConnection);
                Console.WriteLine("RASInstalled: {0}", ics.RASInstalled);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fehler bei der Abfrage des Internet-Verbindungsstatus: {0}", ex.Message);
            }

            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #7
0
        static void Main(string[] args)
        {
            // Byte-Array für das die Prüfsumme berechnet werden soll
            byte[] buffer = { 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            // IP-Prüfsumme berechnen
            ushort checkSum = InternetUtils.GetTCPCheckSum(buffer);

            // Low- und High-Byte extrahieren
            byte lowByte  = (byte)(checkSum & 0xFF);
            byte highByte = (byte)(checkSum >> 8);

            // Prüfsumme als Hex-Werte ausgeben
            Console.WriteLine("{0:X} {1:X} ", highByte, lowByte);

            // Prüfsumme in die Daten schreiben
            buffer[2] = highByte;
            buffer[3] = lowByte;

            // Prüfsumme mit diesen Daten noch einmal berechnen (muss 0 ergeben)
            checkSum = InternetUtils.GetTCPCheckSum(buffer);
            lowByte  = (byte)(checkSum & 0xFF);
            highByte = (byte)(checkSum >> 8);
            Console.WriteLine("{0:X} {1:X} ", highByte, lowByte);


            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #8
0
        static void Main(string[] args)
        {
            // Internetverbindung öffnen
            try
            {
                InternetUtils.OpenLocalConnection(false, 0);

                Console.WriteLine("Internetverbindung ist geöffnet");
                Console.WriteLine("Schließen mit Return");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            // Internetverbindung schließen
            try
            {
                InternetUtils.CloseLocalConnection();

                Console.WriteLine("Internetverbindung ist geschlossen");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #9
0
        public static string GetItemName(int itemId, string lang = null)
        {
            if (lang == null)
            {
                lang = PwVer;
            }
            string page = InternetUtils.FetchPage(string.Format("http://pwdatabase.com/{0}/items/{1}", lang, itemId));

            return(page.GetBetween("<title>Perfect World Item Database - ", "</title>"));
        }
Example #10
0
        /// <summary>
        /// Performs the update of the Client's version. It queries an available server for
        /// the latest version and if a new version exists it goes on with the update.
        /// </summary>
        private void UpdateClient()
        {
            try
            {
                while (!InternetUtils.ConnectedToInternet())
                {
                    Thread.Sleep(updateBackoff.Next());
                }
                //proxy = WebServiceProxy.Instance();
                proxy = CrawlWaveServerProxy.Instance(globals);


                string latest          = String.Empty;
                SerializedException sx = proxy.SendLatestVersion(globals.Client_Info, out latest);
                if (sx != null)
                {
                    globals.SystemLog.LogError("CrawlWave Client Scheduler failed to retrieve the latest version of the Client:" + sx.Message);
                    return;
                }

                Version latestVersion = new Version(latest);
                if (GetClientVersion() < latestVersion)
                {
                    //we must update the client. First of all download the update.
                    updating = true;
                    byte [] buffer = new byte[0];
                    sx = proxy.SendUpdatedVersion(globals.Client_Info, latest, out buffer);
                    if (sx != null || buffer.Length == 0)
                    {
                        globals.SystemLog.LogError("CrawlWave Client Scheduler failed to retrieve the latest version of the Client: " + sx.Message);
                        updating = false;
                        return;
                    }
                    //save the compressed file to disk. If necessary launch the installer.
                    string     updateFileName = globals.AppPath + latest + ".zip";
                    FileStream outputStream   = new FileStream(updateFileName, FileMode.Create);
                    outputStream.Write(buffer, 0, buffer.Length);
                    outputStream.Close();

                    string mustLaunchInstaller = ExtractUpdatedFiles(updateFileName);
                    if (mustLaunchInstaller != String.Empty)
                    {
                        //Launch Installer and exit
                        Process.Start(mustLaunchInstaller);
                    }
                }
            }
            catch
            {}
            finally
            {
                updating = false;
            }
        }
Example #11
0
        private void pegaEndereco()
        {
            if (InternetUtils.estarConectado())
            {
                LocalizacaoInfo localEndereco = GPSUtils.UltimaLocalizacao;
                float           latitude      = (float)localEndereco.Latitude;
                float           longitude     = (float)localEndereco.Longitude;

                GeocoderUtils.pegarAsync(latitude, longitude, async(send, ev) =>
                {
                    var endereco = ev.Endereco;
                    mostraEndereco(endereco.Logradouro);
                });
            }
        }
Example #12
0
        private void regMsgConsumer(object sender, RoutedEventArgs e)
        {
            TextRange textRange = new TextRange(jsonContext.Document.ContentStart, jsonContext.Document.ContentEnd);

            if (!textRange.Text.Trim().Equals(""))
            {
                Consumer consumer = Newtonsoft.Json.JsonConvert.DeserializeObject <Consumer>(textRange.Text.Trim());
                string   url      = "http://" + InternetUtils.GetAddressIP() + ":" + consumer.port + consumer.uri;
                Console.WriteLine(url);
                Console.WriteLine(url.Substring(url.Length - 1));
                if (!url.Substring(url.Length - 1).Equals("/"))
                {
                    url = url + "/";
                }
                HttpServer server = new HttpServer(url);
                server.start();
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            /* Prüfen, ob eine Internetverbindung nach www.google.de möglich ist */
            // string address = "http://www.google.de";
            string address = null;
            string error;

            if (InternetUtils.CheckConnection(address, out error))
            {
                Console.WriteLine("Verbindung nach {0} ist möglich", address);
            }
            else
            {
                Console.WriteLine("Verbindung nach {0} ist nicht möglich: {1}", address, error);
            }

            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #14
0
        public void atualizarEndereco(PercursoInfo percurso)
        {
            if (!InternetUtils.estarConectado())
            {
                return;
            }
            if (percurso.Pontos.Count == 0)
            {
                return;
            }

            var ponto = percurso.Pontos.Last();

            GeocoderUtils.pegarAsync((float)ponto.Latitude, (float)ponto.Longitude, (sender, e) =>
            {
                var endereco      = e.Endereco;
                percurso.Endereco = endereco.Logradouro + " " + endereco.Complemento + " " + endereco.Bairro + " " + endereco.Cidade + " " + endereco.Uf + " " + endereco.CEP;
                gravar(percurso);
            });
        }
Example #15
0
 private void pegaEndereco()
 {
     if (InternetUtils.estarConectado())
     {
         /*
          * LocalizacaoInfo localEndereco = GPSUtils.UltimaLocalizacao;
          * float latitude = (float)localEndereco.Latitude;
          * float longitude = (float)localEndereco.Longitude;
          */
         var gasto = (GastoInfo)BindingContext;
         if (string.IsNullOrEmpty(_LocalEntry.Text))
         {
             GeocoderUtils.pegarAsync(gasto.Latitude, gasto.Longitude, (send, e) => {
                 if (string.IsNullOrEmpty(_LocalEntry.Text))
                 {
                     _LocalEntry.Text = e.Endereco.ToString();
                 }
             });
         }
     }
 }
Example #16
0
        public async void atualizarEndereco()
        {
            if (InternetUtils.estarConectado())
            {
                var radares = _db.listarEnderecoNulo();
                if (radares.Count > 0)
                {
                    var   radar   = radares.FirstOrDefault();
                    int   idRadar = radares[0].Id;
                    float lat     = (float)radar.Latitude;
                    float lon     = (float)radar.Longitude;

                    GeocoderUtils.pegarAsync(lat, lon, (sender, e) =>
                    {
                        radar.UltimaAlteracao = DateTime.Now;
                        radar.Endereco        = e.Endereco.ToString();
                        gravar(radar);
                        atualizarEndereco();
                    });
                }
            }
        }
            /// <summary>
            /// logs internet connectivity status to console.
            /// </summary>
            /// <seealso cref="InternetUtils.IsConnectedToInternet"/>
            /// <param name="commandArguments"></param>
            /// <returns>
            /// <seealso cref="Command.Execute(string[])"/>
            /// </returns>
            protected override bool Execute(string[] commandArguments)
            {
                bool commandExecutedSuccessfuly;

                ConsoleIOManager.Instance.LogNotice(
                    "Checking internet connectivity ..",
                    ConsoleIOManager.eOutputReportType.CommandExecution);

                bool connectedToInternet = InternetUtils.IsConnectedToInternet();

                string notice = connectedToInternet ?
                                "Device is connected to internet."
                    : "No internet connection.";

                ConsoleIOManager.Instance.LogNotice(
                    notice,
                    ConsoleIOManager.eOutputReportType.CommandExecution);

                commandExecutedSuccessfuly = true;

                return(commandExecutedSuccessfuly);
            }
Example #18
0
        public async void atualizarEndereco()
        {
            if (InternetUtils.estarConectado())
            {
                var radares = _db.listarEnderecoNulo();
                if (radares.Count > 0)
                {
                    int   idRadar = radares[0].Id;
                    float lat     = (float)radares[0].Latitude;
                    float lon     = (float)radares[0].Longitude;

                    GeocoderUtils.pegarAsync(lat, lon, (sender, e) =>
                    {
                        var endereco    = e.Endereco;
                        RadarInfo radar = new RadarInfo()
                        {
                            Id           = idRadar,
                            Latitude     = radares[0].Latitude,
                            Longitude    = radares[0].Longitude,
                            LatitudeCos  = radares[0].LatitudeCos,
                            LatitudeSin  = radares[0].LatitudeSin,
                            LongitudeCos = radares[0].LongitudeCos,
                            LongitudeSin = radares[0].LongitudeSin,
                            Direcao      = radares[0].Direcao,
                            Velocidade   = radares[0].Velocidade,
                            Tipo         = radares[0].Tipo,
                            Usuario      = true,
                            DataInclusao = radares[0].DataInclusao,
                            Endereco     = endereco.Logradouro + " " + endereco.Complemento + " " + endereco.Bairro + " " + endereco.Cidade + " " + endereco.Uf + " " + endereco.CEP
                        };

                        gravarEndereco(radar);

                        atualizarEndereco();
                    });
                }
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            // Die eigenen IP-Adressen über Dns herausfinden
            Console.WriteLine("Die IP-Adressen über DNS:");
            IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
            for (int i = 0; i < addressList.Length; i++)
            {
                string ipAddress = addressList[i].ToString();
                Console.WriteLine(ipAddress);
            }
            Console.WriteLine();

            // Die eigenen IP-Adressen über WMI herausfinden
            Console.WriteLine("Die IP-Adressen über WMI:");
            string[] ipAddresses = InternetUtils.GetLocalIPAddresses();
            foreach (string ipAddress in ipAddresses)
            {
                Console.WriteLine(ipAddress);
            }

            Console.WriteLine("Beenden mit Return");
            Console.ReadLine();
        }
Example #20
0
        public static async void StartGame(bool isOffline = false)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game already running!");
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                try
                {
                    var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                        ? Program.UserConfig.GameFilesPath
                        : GameScannerManager.GetGameFilesRootPath();

                    using (var gameScannner = new GameScannerManager(gameFilePath, Program.UserConfig.IsSteamVersion))
                    {
                        await gameScannner.InitializeFromCelesteManifest();

retry:
                        if (!await gameScannner.Scan(true))
                        {
                            bool success;
                            using (var form =
                                       new MsgBoxYesNo(
                                           @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).")
                                   )
                            {
                                var dr = form.ShowDialog();
                                if (dr == DialogResult.OK)
                                {
                                    using (var form2 = new GameScan())
                                    {
                                        form2.ShowDialog();
                                        success = false;
                                    }
                                }
                                else
                                {
                                    success = true;
                                }
                            }
                            if (!success)
                            {
                                goto retry;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(
                        $"Warning: Error during quick scan. Error message: {ex.Message}",
                        @"Celeste Fan Project",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            //isSteam
            if (!Program.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && Program.UserConfig.MpSettings != null)
            {
                if (Program.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip;

                    if (Program.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception)
                        {
                            Program.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            MsgBox.ShowMessage(
                                "Error: Upnp device not found! \"UPnP Port Mapping\" has been disabled.",
                                @"Celeste Fan Project",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
Example #21
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            //CleanUpFiles
            try
            {
                Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old");
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during files clean-up. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (!InternetUtils.IsConnectedToInternet())
            {
                return;
            }

            //Update Check
            try
            {
                if (await Updater.GetGitHubVersion() > Assembly.GetExecutingAssembly().GetName().Version)
                {
                    using (var form =
                               new MsgBoxYesNo(
                                   @"An update is avalaible. Click ""Yes"" to install it, or ""No"" to ignore it (not recommended).")
                           )
                    {
                        var dr = form.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            using (var form2 = new UpdaterForm())
                            {
                                form2.ShowDialog();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during update check. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Auto Login
            if (Program.UserConfig?.LoginInfo == null)
            {
                return;
            }

            if (!Program.UserConfig.LoginInfo.AutoLogin)
            {
                return;
            }

            panelManager1.Enabled = false;
            try
            {
                var response = await Program.WebSocketApi.DoLogin(Program.UserConfig.LoginInfo.Email,
                                                                  Program.UserConfig.LoginInfo.Password);

                if (response.Result)
                {
                    Program.CurrentUser = response.User;

                    gamerCard1.UserName = Program.CurrentUser.ProfileName;
                    gamerCard1.Rank     = $@"{Program.CurrentUser.Rank}";

                    panelManager1.SelectedPanel = managedPanel1;
                }
            }
            catch (Exception)
            {
                //
            }
            panelManager1.Enabled = true;
        }
Example #22
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                MsgBox.ShowMessage(
                    $@"""Celeste Fan Project Launcher"" v{
                            Assembly.GetEntryAssembly()?.GetName().Version
                        } already running!", "Celeste Fan Project",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                }
            }
            catch (Exception)
            {
                //
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                }
            }
            catch (Exception)
            {
                //
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly()?.Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase) ?? false;
            }
            catch (Exception)
            {
                //
            }

            //SslFix (invalid cert)
            InternetUtils.SslFix();

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);

            //Start Gui
            Application.Run(new MainForm());

            GC.KeepAlive(mutex);
        }
Example #23
0
        protected virtual void inicializarComponente()
        {
            _GPSSentidoLabel = new Label
            {
                Text     = "0º",
                FontSize = 16,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            };
            AbsoluteLayout.SetLayoutBounds(_GPSSentidoLabel, new Rectangle(0.9, 0.12, 0.15, 0.15));
            //AbsoluteLayout.SetLayoutBounds(_PrecisaoLabel, new Rectangle(0.11, 0.12, 0.15, 0.15));
            AbsoluteLayout.SetLayoutFlags(_GPSSentidoLabel, AbsoluteLayoutFlags.All);

            _VelocidadeRadarLabel = new Label
            {
                Text     = "Velocidade",
                FontSize = 16,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            };
            if (Device.OS == TargetPlatform.iOS)
            {
            }
            AbsoluteLayout.SetLayoutBounds(_VelocidadeRadarLabel, new Rectangle(1, 0.950, 1, 0.1));
            AbsoluteLayout.SetLayoutFlags(_VelocidadeRadarLabel, AbsoluteLayoutFlags.All);

            _DistanciaRadarLabel = new Label
            {
                Text     = "0 m",
                FontSize = 16,
                //HorizontalTextAlignment = TextAlignment.Center,
                //VerticalTextAlignment = TextAlignment.Center
            };
            //AbsoluteLayout.SetLayoutBounds(_DistanciaRadarLabel, new Rectangle(1, 0.975, 1, 0.1));
            //AbsoluteLayout.SetLayoutFlags(_DistanciaRadarLabel, AbsoluteLayoutFlags.All);


            if (PreferenciaUtils.ExibirBotaoRemover)
            {
                _RemoverRadarButton = new Image
                {
                    Aspect        = Aspect.AspectFit,
                    Source        = ImageSource.FromFile("menos.png"),
                    WidthRequest  = 180,
                    HeightRequest = 180
                };
                AbsoluteLayout.SetLayoutBounds(_RemoverRadarButton, new Rectangle(0.93, 0.975, 0.2, 0.2));
                AbsoluteLayout.SetLayoutFlags(_RemoverRadarButton, AbsoluteLayoutFlags.All);

                _RemoverRadarButton.GestureRecognizers.Add(
                    new TapGestureRecognizer()
                {
                    Command = new Command(() =>
                    {
                        //var regraAviso = new AvisoSonoroBLL();
                        //regraAviso.play(RadarTipoEnum.RadarFixo, 40, 300);
                        //AudioUtils.play(AudioEnum.Alarm001);
                        //MensagemUtils.avisar("teste");
                        //var downloader = new DownloaderAtualizacao();
                        //downloader.download();

                        if (InternetUtils.estarConectado())
                        {
                            LocalizacaoInfo local = GPSUtils.UltimaLocalizacao;
                            float latitude        = (float)local.Latitude;
                            float longitude       = (float)local.Longitude;
                            GeocoderUtils.pegarAsync(latitude, longitude, (sender, e) =>
                            {
                                var endereco = e.Endereco;
                                ClubManagement.Utils.MensagemUtils.avisar(endereco.Logradouro);
                            });
                        }



                        try
                        {
                            LocalizacaoInfo local = GPSUtils.UltimaLocalizacao;
                            if (local != null)
                            {
                                RadarBLL regraRadar = RadarFactory.create();
                                regraRadar.gravar(local, false);
                                MensagemUtils.avisar("Radar incluído com sucesso.");
                            }
                            else
                            {
                                MensagemUtils.avisar("Nenhum movimento registrado pelo GPS.");
                            }
                        }
                        catch (Exception e)
                        {
                            MensagemUtils.avisar(e.Message);
                        }
                    }
                                          )
                });
            }
            if (PreferenciaUtils.ExibirBotaoAdicionar)
            {
                _AdicionarRadarButton = new Image
                {
                    Aspect        = Aspect.AspectFit,
                    Source        = ImageSource.FromFile("mais.png"),
                    WidthRequest  = 180,
                    HeightRequest = 180
                };
                AbsoluteLayout.SetLayoutBounds(_AdicionarRadarButton, new Rectangle(0.93, 0.975, 0.2, 0.2));
                AbsoluteLayout.SetLayoutFlags(_AdicionarRadarButton, AbsoluteLayoutFlags.All);


                if (TelaUtils.Orientacao == "Landscape")
                {
                    AbsoluteLayout.SetLayoutBounds(_AdicionarRadarButton, new Rectangle(1, 0.5, 0.2, 0.2));
                    AbsoluteLayout.SetLayoutFlags(_AdicionarRadarButton, AbsoluteLayoutFlags.All);
                }
                _AdicionarRadarButton.GestureRecognizers.Add(
                    new TapGestureRecognizer()
                {
                    Command = new Command(() =>
                    {
                        //var regraAviso = new AvisoSonoroBLL();
                        //regraAviso.play(RadarTipoEnum.RadarFixo, 40, 300);
                        //AudioUtils.play(AudioEnum.Alarm001);
                        //MensagemUtils.avisar("teste");
                        //var downloader = new DownloaderAtualizacao();
                        //downloader.download();

                        if (InternetUtils.estarConectado())
                        {
                            LocalizacaoInfo local = GPSUtils.UltimaLocalizacao;
                            float latitude        = (float)local.Latitude;
                            float longitude       = (float)local.Longitude;
                            GeocoderUtils.pegarAsync(latitude, longitude, (sender, e) =>
                            {
                                var endereco = e.Endereco;
                                ClubManagement.Utils.MensagemUtils.avisar(endereco.Logradouro);
                            });
                        }



                        try
                        {
                            LocalizacaoInfo local = GPSUtils.UltimaLocalizacao;
                            if (local != null)
                            {
                                RadarBLL regraRadar = RadarFactory.create();
                                regraRadar.gravar(local, false);
                                MensagemUtils.avisar("Radar incluído com sucesso.");
                            }
                            else
                            {
                                MensagemUtils.avisar("Nenhum movimento registrado pelo GPS.");
                            }
                        }
                        catch (Exception e)
                        {
                            MensagemUtils.avisar(e.Message);
                        }
                    }
                                          )
                });
            }


            _BussolaFundo = new Image
            {
                Aspect        = Aspect.AspectFit,
                Source        = ImageSource.FromFile("bussolacorpo.png"),
                WidthRequest  = 180,
                HeightRequest = 180
            };
            AbsoluteLayout.SetLayoutBounds(_BussolaFundo, new Rectangle(0.93, 0, 0.2, 0.2));
            AbsoluteLayout.SetLayoutFlags(_BussolaFundo, AbsoluteLayoutFlags.All);

            _BussolaAgulha = new Image
            {
                Aspect        = Aspect.AspectFit,
                Source        = ImageSource.FromFile("bussolaagulha.png"),
                WidthRequest  = 180,
                HeightRequest = 180
            };
            AbsoluteLayout.SetLayoutBounds(_BussolaAgulha, new Rectangle(0.93, 0, 0.2, 0.2));
            AbsoluteLayout.SetLayoutFlags(_BussolaAgulha, AbsoluteLayoutFlags.All);

            _PrecisaoFundoImage = new Image
            {
                Aspect        = Aspect.AspectFit,
                Source        = ImageSource.FromFile("bussolacorpo.png"),
                WidthRequest  = 180,
                HeightRequest = 180
            };
            AbsoluteLayout.SetLayoutBounds(_PrecisaoFundoImage, new Rectangle(0.07, 0, 0.2, 0.2));
            AbsoluteLayout.SetLayoutFlags(_PrecisaoFundoImage, AbsoluteLayoutFlags.All);

            _PrecisaoImage = new Image
            {
                Aspect        = Aspect.AspectFit,
                Source        = ImageSource.FromFile("sat04.png"),
                WidthRequest  = 180,
                HeightRequest = 180
            };
            AbsoluteLayout.SetLayoutBounds(_PrecisaoImage, new Rectangle(0.11, 0.04, 0.15, 0.15));
            AbsoluteLayout.SetLayoutFlags(_PrecisaoImage, AbsoluteLayoutFlags.All);

            _PrecisaoLabel = new Label
            {
                Text     = "0 m",
                FontSize = 16,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            };
            //AbsoluteLayout.SetLayoutBounds(_PrecisaoLabel, new Rectangle(0.1, 0.025, 0.1, 0.1));
            AbsoluteLayout.SetLayoutBounds(_PrecisaoLabel, new Rectangle(0.11, 0.12, 0.15, 0.15));
            AbsoluteLayout.SetLayoutFlags(_PrecisaoLabel, AbsoluteLayoutFlags.All);
        }
Example #24
0
 /// <summary>
 /// Affiche un champ contenant plusieurs informations, separes par SEPARATEUR_LISTE,
 /// un lien pour chaque morceau d'information
 /// </summary>
 /// <param name="key"></param>
 /// <param name="link"></param>
 /// <param name="texte"></param>
 private void afficheInfoLinks(Label key, LinkLabel link, string texte)
 {
     char[] SEPARATEURS = { ',' };
     if (texte?.Length > 0)
     {
         key.Show();
         link.Show();
         link.Links.Clear();
         string[] valeurs = texte.Split(BaseFilms.SEPARATEUR_LISTES_CHAR);
         string   label   = "";
         int      start   = 0;
         foreach (string url in valeurs)
         {
             label += url + ", ";
             int            length = url.Length;
             LinkLabel.Link lk     = new LinkLabel.Link(start, length, $"https://www.google.com/search?q={InternetUtils.urlRecherche(url)}");
             link.Links.Add(lk);
             start += length + 2;
         }
         link.Text = label;
     }
     else
     {
         key?.Hide();
         link?.Hide();
     }
 }
Example #25
0
        public static async Task StartGame(bool isOffline = false)
        {
            Logger.Information("Preparing to start game, is offline: {@isOffline}", isOffline);

            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                Logger.Information("Game is already started with PID {@PID}", pname.Select(t => t.Id));
                GenericMessageDialog.Show(Properties.Resources.GameAlreadyRunningError, DialogIcon.Warning);
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                Logger.Information("User is online, will perform game scan");
                try
                {
                    var success = false;

                    while (!success)
                    {
                        Logger.Information("Starting quick game scan");
                        var gameFilePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                            ? LegacyBootstrapper.UserConfig.GameFilesPath
                            : GameScannerManager.GetGameFilesRootPath();

                        Logger.Information("Preparing games canner api");

                        var gameScannner = new GameScannerManager(gameFilePath, LegacyBootstrapper.UserConfig.IsSteamVersion);
                        await gameScannner.InitializeFromCelesteManifest();

                        if (!await gameScannner.Scan(true))
                        {
                            Logger.Information("Game scanner did not approve game files");

                            var dialogResult = GenericMessageDialog.Show(
                                Properties.Resources.GameScannerDidNotPassQuickScan,
                                DialogIcon.None,
                                DialogOptions.YesNo);

                            if (dialogResult.Value)
                            {
                                var gamePathSelectionWindow = new GamePathSelectionWindow();
                                gamePathSelectionWindow.ShowDialog();
                            }
                            else
                            {
                                success = true;
                            }
                        }
                        else
                        {
                            Logger.Information("Game files passed file scanner");
                            success = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, ex.Message);
                    GenericMessageDialog.Show(Properties.Resources.GameScannerScanError, DialogIcon.Warning);
                }
            }

            //isSteam
            if (!LegacyBootstrapper.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && LegacyBootstrapper.UserConfig.MpSettings != null)
            {
                if (LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    LegacyBootstrapper.UserConfig.MpSettings.PublicIp = LegacyBootstrapper.CurrentUser.Ip;

                    if (LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                            LegacyBootstrapper.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            GenericMessageDialog.Show(Properties.Resources.UPnPDisabledError, DialogIcon.Error);
                        }
                        finally
                        {
                            NatDiscoverer.TraceSource.Close();
                        }
                    }
                }
            }

            try
            {
                //Launch Game
                var gamePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(gamePath, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Properties.Resources.GameScannerSpartanNotFound, DialogIcon.Error);
                    return;
                }

                string lang;
                switch (LegacyBootstrapper.UserConfig.GameLanguage)
                {
                case GameLanguage.deDE:
                    lang = "de-DE";
                    break;

                case GameLanguage.enUS:
                    lang = "en-US";
                    break;

                case GameLanguage.esES:
                    lang = "es-ES";
                    break;

                case GameLanguage.frFR:
                    lang = "fr-FR";
                    break;

                case GameLanguage.itIT:
                    lang = "it-IT";
                    break;

                case GameLanguage.zhCHT:
                    lang = "zh-CHT";
                    break;

                case GameLanguage.ptBR:
                    lang = "pt-BR";
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(LegacyBootstrapper.UserConfig.GameLanguage),
                                                          LegacyBootstrapper.UserConfig.GameLanguage, null);
                }

                try
                {
                    if (LegacyBootstrapper.UserConfig.IsDiagnosticMode)
                    {
                        Logger.Information("Diagnostics mode is enabled");
                        //
                        try
                        {
                            var killInfo = new ProcessStartInfo("cmd.exe", "/c taskkill /F /IM procdump.exe /T")
                            {
                                WorkingDirectory       = gamePath,
                                CreateNoWindow         = true,
                                UseShellExecute        = false,
                                RedirectStandardError  = true,
                                RedirectStandardOutput = true
                            };

                            Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", killInfo.FileName, killInfo.Arguments);
                            Process.Start(killInfo);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                        }

                        var       procdumpFileName   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe");
                        const int maxNumOfCrashDumps = 30;
                        if (!File.Exists(procdumpFileName))
                        {
                            Logger.Information("Could not find procdump.exe");
                            LegacyBootstrapper.UserConfig.IsDiagnosticMode = false;
                            throw new FileNotFoundException(
                                      Properties.Resources.DiagnosticsModeMissingProcdump,
                                      procdumpFileName);
                        }

                        // First ensure that all directories are set
                        var pathToCrashDumpFolder =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         @"Spartan\MiniDumps");

                        Logger.Information("CrashDumpFolder is set to {@CrashDumpFolder}", pathToCrashDumpFolder);

                        if (!Directory.Exists(pathToCrashDumpFolder))
                        {
                            Directory.CreateDirectory(pathToCrashDumpFolder);
                        }

                        // Check for cleanup
                        Directory.GetFiles(pathToCrashDumpFolder)
                        .OrderByDescending(File.GetLastWriteTime) // Sort by age --> old one last
                        .Skip(maxNumOfCrashDumps)                 // Skip max num crash dumps
                        .ToList()
                        .ForEach(File.Delete);                    // Remove the rest

                        var excludeExceptions = new[]
                        {
                            "E0434F4D.COM", // .NET native exception
                            "E06D7363.msc",
                            "E06D7363.PAVEEFileLoadException@@",
                            "E0434F4D.System.IO.FileNotFoundException" // .NET managed exception
                        };

                        var excludeExcpetionsCmd = string.Join(" ", excludeExceptions.Select(elem => "-fx " + elem));

                        var fullCmdArgs = "-accepteula -mm -e 1 -n 10 " + excludeExcpetionsCmd +
                                          " -g -w Spartan.exe \"" + pathToCrashDumpFolder + "\"";

                        var startInfo = new ProcessStartInfo(procdumpFileName, fullCmdArgs)
                        {
                            WorkingDirectory       = gamePath,
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardError  = true,
                            RedirectStandardOutput = true
                        };

                        Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", startInfo.FileName, startInfo.Arguments);

                        Process.Start(startInfo);
                    }
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, exception.Message);
                    GenericMessageDialog.Show(Properties.Resources.DiagnosticsModeError, DialogIcon.Warning);
                }

                //SymLink CustomScn Folder
                var profileDir        = Path.Combine(Environment.GetEnvironmentVariable("userprofile"));
                var customScnGamePath = Path.Combine(gamePath, "Scenario", "CustomScn");
                var scenarioUserPath  = Path.Combine(profileDir, "Documents", "Spartan", "Scenario");

                Logger.Information("CustomScn directory: {@customScnPath}", customScnGamePath);
                Logger.Information("Scenario directory: {@scenarioPath}", scenarioUserPath);

                if (!Directory.Exists(scenarioUserPath))
                {
                    Directory.CreateDirectory(scenarioUserPath);
                }

                if (Directory.Exists(customScnGamePath) &&
                    (!Misc.IsSymLink(customScnGamePath, Misc.SymLinkFlag.Directory) ||
                     !string.Equals(Misc.GetRealPath(customScnGamePath), scenarioUserPath, StringComparison.OrdinalIgnoreCase)))
                {
                    Directory.Delete(customScnGamePath, true);
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }
                else
                {
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }

                string arg;
                if (isOffline)
                {
                    arg = $"--offline --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else if (LegacyBootstrapper.UserConfig?.MpSettings == null ||
                         LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    arg = LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.NatPunch
                        ? $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033"
                        : $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --no-nat-punchthrough --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else
                {
                    arg =
                        $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --online-ip \"{LegacyBootstrapper.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }

                Logger.Information("Starting game {@GameExecutable} at {@GamePath}", spartanPath, gamePath);
                Process.Start(new ProcessStartInfo(spartanPath, arg)
                {
                    WorkingDirectory = gamePath
                });
            }
            catch (Exception exception)
            {
                Logger.Error(exception, exception.Message);
                GenericMessageDialog.Show(Properties.Resources.StartGameError, DialogIcon.Error);
            }
        }
Example #26
0
        /// <summary>
        /// Updates the Url and the Url Data tables
        /// </summary>
        /// <param name="data">The UrlCrawlData containing the data of the crawled Url.</param>
        /// <param name="transaction">The currently active <see cref="SqlTransaction"/>.</param>
        /// <returns>The ID of the updated url or 0 of something goes wrong.</returns>
        private int UpdateUrl(UrlCrawlData data, SqlTransaction transaction)
        {
            int retVal = 0;

            try
            {
                //build the Sql Command for updating the url table
                SqlCommand urlcmd = new SqlCommand("cw_update_url", dbcon, transaction);
                urlcmd.CommandType    = CommandType.StoredProcedure;
                urlcmd.CommandTimeout = settings.DBActionTimeout;
                urlcmd.Parameters.Add("@url_id", SqlDbType.Int);
                urlcmd.Parameters.Add("@url", SqlDbType.NVarChar, 500);
                urlcmd.Parameters.Add("@url_md5", SqlDbType.UniqueIdentifier);
                urlcmd.Parameters.Add("@url_host_id", SqlDbType.UniqueIdentifier);
                urlcmd.Parameters.Add("@url_priority", SqlDbType.TinyInt);
                urlcmd.Parameters.Add("@crc", SqlDbType.BigInt);
                urlcmd.Parameters.Add("@flag_domain", SqlDbType.TinyInt);
                urlcmd.Parameters.Add("@flag_robots", SqlDbType.TinyInt);
                urlcmd.Parameters.Add("@flag_updated", SqlDbType.TinyInt);
                urlcmd.Parameters.Add("@last_visited", SqlDbType.SmallDateTime);
                urlcmd.Parameters.Add("@flag_redirected", SqlDbType.TinyInt);
                urlcmd.Parameters.Add("@id", SqlDbType.Int);
                urlcmd.Parameters["@id"].Direction = ParameterDirection.Output;

                //Build the SQL Command for updating the hosts table
                SqlCommand hostcmd = new SqlCommand("cw_insert_host", dbcon, transaction);
                hostcmd.CommandType    = CommandType.StoredProcedure;
                hostcmd.CommandTimeout = settings.DBActionTimeout;
                hostcmd.Parameters.Add("@host_id", SqlDbType.UniqueIdentifier);
                hostcmd.Parameters.Add("@host_name", SqlDbType.NVarChar, 100);

                //set their parameters
                urlcmd.Parameters[0].Value = data.ID;
                urlcmd.Parameters[1].Value = data.Url;
                urlcmd.Parameters[2].Value = new Guid(data.MD5);
                Uri    uri       = new Uri(data.Url);
                string host_name = uri.Host;
                Guid   host_id   = new Guid(MD5Hash.md5(host_name));
                urlcmd.Parameters[3].Value = host_id;
                urlcmd.Parameters[5].Value = data.CRC;
                if (data.Redirected)
                {
                    //we must first attempt to insert the host, otherwise the urlcmd will fail
                    hostcmd.Parameters[0].Value = host_id;
                    hostcmd.Parameters[1].Value = host_name;
                    try
                    {
                        hostcmd.ExecuteNonQuery();
                    }
                    catch
                    {
                        //it probably exists already
                    }

                    urlcmd.Parameters[4].Value  = (byte)data.RedirectedPriority;
                    urlcmd.Parameters[6].Value  = (byte)data.RedirectedFlagDomain;
                    urlcmd.Parameters[7].Value  = (data.RedirectedFlagRobots)?1:0;
                    urlcmd.Parameters[8].Value  = (data.Updated)?1:0;
                    urlcmd.Parameters[9].Value  = data.TimeStamp;
                    urlcmd.Parameters[10].Value = 1;
                }
                else
                {
                    urlcmd.Parameters[4].Value = DBNull.Value;
                    urlcmd.Parameters[6].Value = (byte)data.UrlToCrawl.FlagDomain;
                    if (data.FlagFetchRobots)
                    {
                        urlcmd.Parameters[7].Value = (data.RedirectedFlagRobots)?1:0;
                    }
                    else
                    {
                        urlcmd.Parameters[7].Value = 0;
                    }
                    urlcmd.Parameters[8].Value  = (data.Updated)?1:0;
                    urlcmd.Parameters[9].Value  = data.TimeStamp;
                    urlcmd.Parameters[10].Value = 0;
                }
                //retVal = data.ID;
                //make sure the host command is disposed
                hostcmd.Dispose();
                urlcmd.ExecuteNonQuery();
                retVal = (int)urlcmd.Parameters["@id"].Value;
                urlcmd.Dispose();

                if (data.Updated)
                {
                    //if necessary build the sql command for updating the url data tables
                    SqlCommand urldatacmd = new SqlCommand("cw_update_url_data", dbcon, transaction);
                    urldatacmd.CommandType    = CommandType.StoredProcedure;
                    urldatacmd.CommandTimeout = settings.DBActionTimeout;
                    urldatacmd.Parameters.Add("@url_id", SqlDbType.Int);
                    urldatacmd.Parameters.Add("@data", SqlDbType.Image);
                    urldatacmd.Parameters.Add("@length", SqlDbType.Int);
                    urldatacmd.Parameters.Add("@original_length", SqlDbType.Int);
                    urldatacmd.Parameters.Add("@http_code", SqlDbType.SmallInt);
                    urldatacmd.Parameters.Add("@retrieval_time", SqlDbType.Int);

                    urldatacmd.Parameters[0].Value = retVal;
                    //compress the url's data
                    if (data.Data != String.Empty)
                    {
                        byte [] compressed = null;
                        string  urldata    = InternetUtils.Base64Decode(data.Data);
                        CompressionUtils.CompressString(ref urldata, out compressed);
                        urldatacmd.Parameters[1].Value = compressed;
                        urldatacmd.Parameters[2].Value = compressed.Length;
                        urldatacmd.Parameters[3].Value = data.Data.Length;
                    }
                    else
                    {
                        urldatacmd.Parameters[1].Value = new byte[0];
                        urldatacmd.Parameters[2].Value = 0;
                        urldatacmd.Parameters[3].Value = 0;
                    }
                    urldatacmd.Parameters[4].Value = (short)data.HttpStatusCode;
                    urldatacmd.Parameters[5].Value = data.RetrievalTime;
                    urldatacmd.ExecuteNonQuery();
                    urldatacmd.Dispose();
                }
            }
            catch (Exception e)
            {
                AddToReportQueue(CWLoggerEntryType.Warning, "DBUpdater failed to update a Url in the database: " + e.ToString());
                retVal = 0;
            }
            return(retVal);
        }
Example #27
0
        /// <summary>
        /// Checks if at least 30 seconds have passed since the last request to a given host
        /// was made, in order not to slammer it with simultaneous or frequent requests.
        /// </summary>
        /// <param name="targetUrl">A url that is served by a host we wish to check</param>
        /// <returns>An integer containing the number of milliseconds a crawler thread must wait
        /// before visiting this host.</returns>
        public int FilterUrl(ref string targetUrl)
        {
            string hostName = InternetUtils.HostName(targetUrl);

            return(FilterHost(ref hostName));
        }
Example #28
0
        /// <summary>
        /// Selects and returns a set of urls that are ready to be crawled.
        /// </summary>
        /// <param name="ci">The <see cref="ClientInfo"/> of the client requesting urls to crawl.</param>
        /// <param name="data">An array of <see cref="InternetUrlToCrawl"/> objects containing the selected urls.</param>
        /// <returns>Null if the operation succeeds, or <see cref="SerializedException"/>
        /// encapsulating the error that occured if the operation fails.</returns>
        public SerializedException SelectUrlsToCrawl(ClientInfo ci, ref InternetUrlToCrawl[] data)
        {
            SerializedException sx = null;

            try
            {
                if (!ConnectToDatabase())
                {
                    throw new CWDBConnectionFailedException();
                }
                //we must use a transaction to make sure that if something goes wrong the
                //changes to the database will be rolled back.
                SqlTransaction transaction = dbcon.BeginTransaction(IsolationLevel.Serializable);                //perhaps | repeatableread
                try
                {
                    //first select the urls to crawl
                    SqlCommand cmd = new SqlCommand("cw_select_urls_to_crawl", dbcon, transaction);
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.CommandTimeout = 120;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet        ds = new DataSet();
                    da.Fill(ds);
                    da.Dispose();
                    cmd.Dispose();
                    //now delete them from the table of urls to crawl
                    data = new InternetUrlToCrawl[ds.Tables[0].Rows.Count];
                    if (data.Length > 0)
                    {
                        int i = 0;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            try
                            {
                                InternetUrlToCrawl url = new InternetUrlToCrawl((int)dr[0], (string)dr[1]);
                                if (dr[2] != DBNull.Value)
                                {
                                    url.CRC = (long)dr[2];
                                }
                                if (dr[3] != DBNull.Value)
                                {
                                    url.FlagDomain = (DomainFlagValue)((byte)dr[3]);
                                }
                                if (dr[4] != DBNull.Value)
                                {
                                    url.RobotsDisallowedPaths = (string)dr[4];
                                }
                                else
                                {
                                    RobotsTxtEntry entry = settings.Robots.GetEntry(InternetUtils.HostName(url));
                                    if (entry != null)
                                    {
                                        url.RobotsDisallowedPaths = ConcatenatePaths(entry.DisallowedPaths);
                                    }
                                    else
                                    {
                                        url.FlagFetchRobots = true;
                                    }
                                }
                                data[i++] = url;
                            }
                            catch
                            {
                                continue;
                            }
                        }
                        SqlCommand statscmd = new SqlCommand("cw_update_client_statistics", dbcon, transaction);
                        statscmd.CommandType    = CommandType.StoredProcedure;
                        statscmd.CommandTimeout = 120;
                        statscmd.Parameters.Add("@client_id", SqlDbType.UniqueIdentifier);
                        statscmd.Parameters.Add("@assigned", SqlDbType.BigInt);
                        statscmd.Parameters.Add("@returned", SqlDbType.BigInt);
                        statscmd.Parameters.Add("@type", SqlDbType.TinyInt);
                        statscmd.Parameters[0].Value = ci.ClientID;
                        statscmd.Parameters[1].Value = data.Length;
                        statscmd.Parameters[2].Value = DBNull.Value;
                        statscmd.Parameters[3].Value = 0;
                        statscmd.ExecuteNonQuery();
                        statscmd.Dispose();
                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    if (settings.LogLevel <= CWLogLevel.LogWarning)
                    {
                        settings.Log.LogWarning("SelectUrlsToCrawl failed, Transaction was rolled back: " + ex.ToString());
                    }
                    throw ex;
                }
                finally
                {
                    UpdateClientLastActive(ci);
                    LogClientAction(ci, CWClientActions.LogSendUrlsToCrawl);
                    if (!DisconnectFromDatabase())
                    {
                        throw new CWDBConnectionFailedException("Disconnect from database failure.");
                    }
                }
            }
            catch (Exception e)
            {
                sx = new SerializedException(e.GetType().ToString(), e.Message, e.ToString());
                if (settings.LogLevel <= CWLogLevel.LogWarning)
                {
                    settings.Log.LogWarning("SelectUrlsToCrawl failed: " + e.ToString());
                }
            }
            return(sx);
        }
Example #29
0
        /// <summary>
        /// Stores the results that the clients return after crawling a set of Urls.
        /// </summary>
        /// <param name="ci">The <see cref="ClientInfo"/> of the client returning the data.</param>
        /// <param name="data">An array of <see cref="UrlCrawlData"/> objects containing the data of the crawled urls.</param>
        /// <returns>Null if the operation succeeds, or <see cref="SerializedException"/>
        /// encapsulating the error that occured if the operation fails.</returns>
        public SerializedException StoreCrawlResults(ClientInfo ci, UrlCrawlData[] data)
        {
            SerializedException sx = null;

            try
            {
                if (!ConnectToDatabase())
                {
                    throw new CWDBConnectionFailedException();
                }
                try
                {
                    //store the new robots.txt files in the database, nothing else needs to
                    //be done since the urls will be marked as not assigned when their data
                    //is processed by DBUpdater
                    if ((data != null) && (data.Length > 0))
                    {
                        SqlCommand cmd = new SqlCommand("cw_update_or_insert_robot", dbcon);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@host_id", SqlDbType.UniqueIdentifier);
                        cmd.Parameters.Add("@disallowed", SqlDbType.NVarChar, 1000);
                        foreach (UrlCrawlData urlData in data)
                        {
                            if ((urlData.FlagFetchRobots) || (urlData.Redirected))
                            {
                                string url = urlData.Url;
                                cmd.Parameters[0].Value = new Guid(MD5Hash.md5(InternetUtils.HostName(url)));
                                cmd.Parameters[1].Value = urlData.RobotsDisallowedPaths;
                                try
                                {
                                    cmd.ExecuteNonQuery();
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                        }
                        cmd.Dispose();
                        SqlCommand statscmd = new SqlCommand("cw_update_client_statistics", dbcon);
                        statscmd.CommandType = CommandType.StoredProcedure;
                        statscmd.Parameters.Add("@client_id", SqlDbType.UniqueIdentifier);
                        statscmd.Parameters.Add("@assigned", SqlDbType.BigInt);
                        statscmd.Parameters.Add("@returned", SqlDbType.BigInt);
                        statscmd.Parameters.Add("@type", SqlDbType.TinyInt);
                        statscmd.Parameters[0].Value = ci.ClientID;
                        statscmd.Parameters[1].Value = DBNull.Value;
                        statscmd.Parameters[2].Value = data.Length;
                        statscmd.Parameters[3].Value = 1;
                        statscmd.ExecuteNonQuery();
                        statscmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    if (settings.LogLevel <= CWLogLevel.LogWarning)
                    {
                        settings.Log.LogWarning("StoreCrawlResults failed: " + ex.ToString());
                    }
                    throw ex;
                }
                finally
                {
                    //save xml file on disk
                    try
                    {
                        SaveXMLFile(ci, data);
                    }
                    catch (Exception se)
                    {
                        sx = new SerializedException(se.GetType().ToString(), se.Message, se.ToString());
                        if (settings.LogLevel <= CWLogLevel.LogWarning)
                        {
                            settings.Log.LogWarning("StoreCrawlResults failed to save XML data on disk: " + se.ToString());
                        }
                    }
                }
                if (!DisconnectFromDatabase())
                {
                    throw new CWDBConnectionFailedException("Disconnect from database failure.");
                }
            }
            catch (Exception e)
            {
                sx = new SerializedException(e.GetType().ToString(), e.Message, e.ToString());
            }
            finally
            {
                UpdateClientLastActive(ci);
                LogClientAction(ci, CWClientActions.LogGetCrawlResults);
            }
            return(sx);
        }
Example #30
0
        /// <summary>
        /// Checks if a url is served by a host that belongs to the list of banned hosts.
        /// </summary>
        /// <param name="targetUrl">A <see cref="InternetUrlToIndex"/> to check.</param>
        /// <returns>True if the host is banned, false otherwise.</returns>
        public bool FilterUrl(ref InternetUrlToIndex targetUrl)
        {
            string hostName = InternetUtils.HostName(targetUrl);

            return(FilterHost(ref hostName));
        }