HOME hai 8 meses
pai
achega
cc3887850b

+ 5 - 18
Rac.Core/Crawler.cs

@@ -10,18 +10,6 @@ using System.Threading;
 
 
 namespace Rac
 namespace Rac
 {
 {
-    //public enum CrawlTaskEventType
-    //{
-    //    Started,
-    //    Stopped,
-    //}
-
-    //public class CrawlTaskEventArgs : EventArgs
-    //{
-    //    public string Url { get; set; }
-    //    public CrawlTaskEventType Type { get; set; }
-    //}
-
     //TODO: CHECK AFFECT OF `Error loading type Typespec 0x1b000044 from  due to Could not resolve typespec token 1b000044'
     //TODO: CHECK AFFECT OF `Error loading type Typespec 0x1b000044 from  due to Could not resolve typespec token 1b000044'
 
 
     public class Crawler : BaseService
     public class Crawler : BaseService
@@ -31,10 +19,9 @@ namespace Rac
 
 
         public bool IsRunning { get; private set; }
         public bool IsRunning { get; private set; }
 
 
-        public Crawler(string dbFilename)
-
+        public Crawler(string dbFilePath)
         {
         {
-            _db = new DataAccess(dbFilename);
+            _db = new DataAccess(dbFilePath);
         }
         }
 
 
         public override void Start()
         public override void Start()
@@ -142,7 +129,7 @@ namespace Rac
 
 
                 var hssExtractedLinks = new HashSet<string>();
                 var hssExtractedLinks = new HashSet<string>();
 
 
-                ArchiveEntry PageProce(string url)
+                ArchiveEntry PageProc(string url)
                 {
                 {
                     ArchiveEntry entry;
                     ArchiveEntry entry;
                     Response resp;
                     Response resp;
@@ -208,7 +195,7 @@ namespace Rac
 #if !DEBUG
 #if !DEBUG
                     .AsParallel().WithDegreeOfParallelism(conf.Parallel)
                     .AsParallel().WithDegreeOfParallelism(conf.Parallel)
 #endif
 #endif
-                    .Select(PageProce)
+                    .Select(PageProc)
                     .ToArray();
                     .ToArray();
 
 
                 LogInfo($"Saving extracted {hssExtractedLinks.Count} new link...");
                 LogInfo($"Saving extracted {hssExtractedLinks.Count} new link...");
@@ -224,4 +211,4 @@ namespace Rac
             LogInfo("Finished!");
             LogInfo("Finished!");
         }
         }
     }
     }
-}
+}

+ 15 - 3
Rac.Core/FileBrowseServer.cs

@@ -1,22 +1,34 @@
 using Rac.Common;
 using Rac.Common;
 using System;
 using System;
+using System.IO;
+using Rac.Tools;
 
 
 namespace Rac
 namespace Rac
 {
 {
     public class FileBrowseServer : BaseService
     public class FileBrowseServer : BaseService
     {
     {
-        public FileBrowseServer(string db)
+        private readonly string _dbFilePath;
+        private DataAccess _db;
+
+        public FileBrowseServer(string dbFilePath)
         {
         {
+            _dbFilePath = dbFilePath;
         }
         }
 
 
         public override void Start()
         public override void Start()
         {
         {
-            throw new NotImplementedException();
+            if (false == File.Exists(_dbFilePath))
+            {
+                LogFatal($"Can not find database file:{_dbFilePath}");
+                return;
+            }
+            _db = new DataAccess(_dbFilePath);
+
+            var urls = _db.GetAllUrl();
         }
         }
 
 
         public override void Stop()
         public override void Stop()
         {
         {
-            throw new NotImplementedException();
         }
         }
     }
     }
 }
 }

+ 6 - 6
Rac.Core/OfflineWebServer.cs

@@ -12,7 +12,7 @@ namespace Rac
 {
 {
     public class OfflineWebServer : BaseService
     public class OfflineWebServer : BaseService
     {
     {
-        private readonly string _dbFilename;
+        private readonly string _dbFilePath;
         private DataAccess _db;
         private DataAccess _db;
         private HttpListener _server;
         private HttpListener _server;
 
 
@@ -22,19 +22,19 @@ namespace Rac
 
 
         private Encoding _defaultEncoding;
         private Encoding _defaultEncoding;
 
 
-        public OfflineWebServer(string dbFilename)
+        public OfflineWebServer(string dbFilePath)
         {
         {
-            _dbFilename = dbFilename;
+            _dbFilePath = dbFilePath;
         }
         }
 
 
         public override void Start()
         public override void Start()
         {
         {
-            if (false == File.Exists(_dbFilename))
+            if (false == File.Exists(_dbFilePath))
             {
             {
-                LogFatal($"Can not find database file:{_dbFilename}");
+                LogFatal($"Can not find database file:{_dbFilePath}");
                 return;
                 return;
             }
             }
-            _db = new DataAccess(_dbFilename);
+            _db = new DataAccess(_dbFilePath);
             var conf = new ConfigAdapter(_db.GetConfigs());
             var conf = new ConfigAdapter(_db.GetConfigs());
 
 
             _defaultEncoding = null != conf.DefaultCharset ? Encoding.GetEncoding(conf.DefaultCharset) : Encoding.UTF8;
             _defaultEncoding = null != conf.DefaultCharset ? Encoding.GetEncoding(conf.DefaultCharset) : Encoding.UTF8;

+ 16 - 5
Rac.Core/Tools/DataAccess.cs

@@ -12,18 +12,18 @@ namespace Rac.Tools
 {
 {
     internal class DataAccess
     internal class DataAccess
     {
     {
-        private readonly string _filename;
+        private readonly string _dbFilePath;
 
 
-        public DataAccess(string filename)
+        public DataAccess(string dbFilePath)
         {
         {
-            _filename = filename;
+            _dbFilePath = dbFilePath;
 
 
             CreateDatabaseIfNotExist();
             CreateDatabaseIfNotExist();
         }
         }
 
 
         private void CreateDatabaseIfNotExist()
         private void CreateDatabaseIfNotExist()
         {
         {
-            if (File.Exists(_filename)) return;
+            if (File.Exists(_dbFilePath)) return;
 
 
             using (var conn = GetConnection())
             using (var conn = GetConnection())
             {
             {
@@ -82,7 +82,7 @@ namespace Rac.Tools
 
 
         private DbConnection GetConnection()
         private DbConnection GetConnection()
         {
         {
-            var conn = new SqliteConnection("Data Source=" + _filename);
+            var conn = new SqliteConnection("Data Source=" + _dbFilePath);
             conn.Open();
             conn.Open();
             return conn;
             return conn;
         }
         }
@@ -200,5 +200,16 @@ namespace Rac.Tools
                 return conn.Query<ArchiveEntry>($"SELECT * FROM Archives WHERE {nameof(ArchiveEntry.Url)}=@url", new { url }).FirstOrDefault();
                 return conn.Query<ArchiveEntry>($"SELECT * FROM Archives WHERE {nameof(ArchiveEntry.Url)}=@url", new { url }).FirstOrDefault();
             }
             }
         }
         }
+
+        // --- for file browser ---
+
+        public string[] GetAllUrl()
+        {
+            using (var conn = GetConnection())
+            {
+                return conn.Query<string>($"SELECT {nameof(ArchiveEntry.Url)} FROM Archives").ToArray();
+            }
+        }
+
     }
     }
 }
 }