예제 #1
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;
            }
        }
예제 #2
0
 private void PerformExtraction()
 {
     try
     {
         events.Enqueue(new EventLoggerEntry(CWLoggerEntryType.Info, DateTime.Now, "CrawlWave Word Extraction Plugin thread has started with ID 0x" + Thread.CurrentThread.GetHashCode().ToString("x4")));
         //the user may have enabled database just before starting the plugin
         if (settings.UseDatabase)
         {
             if (dbcon == null)
             {
                 dbProvider = DBConnectionStringProvider.Instance();
                 settings.DBConnectionString = dbProvider.ProvideDBConnectionString(name);
                 dbcon = new SqlConnection(settings.DBConnectionString);
             }
         }
         while (!mustStop)
         {
             //Select a page from the database, perform word extraction and store the
             //results back in the database
             int    UrlID       = 0;
             string data        = String.Empty;
             int    waitSeconds = 0;
             SelectUrlForWordExtraction(out UrlID, out data);
             if (UrlID != 0)
             {
                 try
                 {
                     backoff.Reset();
                     SortedList words = wordExtractor.ExtractWords(data);
                     if (words.Count != 0)
                     {
                         //add all the words to the database if they don't exist already
                         string word       = String.Empty;
                         short  word_count = 0;
                         int    word_id    = -1;
                         foreach (DictionaryEntry de in words)
                         {
                             word = (string)de.Key;
                             cache.AddStemmedWord(word);
                         }
                         //remove all the old words related to this url from the database
                         RemoveUrlWords(UrlID);
                         //now add relationships between the url and its words
                         foreach (DictionaryEntry d in words)
                         {
                             word       = (string)d.Key;
                             word_count = (short)((int)d.Value);
                             word_id    = cache[word];
                             AddUrlWord(UrlID, word_id, word_count);
                         }
                     }
                     UpdateUrlDataLastProcess(UrlID);
                 }
                 catch (Exception e)
                 {
                     events.Enqueue(new EventLoggerEntry(CWLoggerEntryType.Warning, DateTime.Now, "WordExtractionPlugin failed to extract words from Url with ID " + UrlID.ToString() + ": " + e.ToString()));
                     continue;
                 }
             }
             else
             {
                 waitSeconds = backoff.Next() / 1000;
                 for (int i = 0; i < waitSeconds; i++)
                 {
                     Thread.Sleep(1000);
                     if (mustStop)
                     {
                         break;
                     }
                 }
             }
             Report();
             if (settings.PauseBetweenOperations)
             {
                 waitSeconds = PauseInSeconds();
                 for (int i = 0; i < waitSeconds; i++)
                 {
                     Thread.Sleep(1000);
                     if (mustStop)
                     {
                         break;
                     }
                 }
             }
         }
     }
     catch (ThreadAbortException)
     {
         //The thread was asked to abort, which means it must return at once
         return;
     }
     catch (ThreadInterruptedException)
     {
         //The thread has been asked to Join. We have nothing to do but return.
         return;
     }
     finally
     {
         events.Enqueue(new EventLoggerEntry(CWLoggerEntryType.Info, DateTime.Now, Thread.CurrentThread.Name + " has stopped."));
     }
 }