private static void SelectAndSaveImages(string fullText, int newspaperId) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(fullText); HtmlNodeCollection images = doc.DocumentNode.SelectNodes("//img"); if (images != null) { foreach (HtmlNode image in images) { string url = image.Attributes.AttributesWithName("src").First().Value; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; string localPath = LoadImageGetLocalPath(url); ImageDB img = new ImageDB(); img.i_newspaper_id = newspaperId; img.s_url = url; img.s_path = localPath; DataBase.SaveImage(img); } } }
public static void SaveImage(ImageDB image) { SQLiteConnection connection = DatabaseConnectionHandler.InvokeMultiple(); string sql = $"insert into {TableNames.NetworkAddress} (s_url) values ('{image.s_url}')"; connection.Execute(sql); int networkId = connection.QueryFirst <int>( $"select id from {TableNames.NetworkAddress} where s_url='{image.s_url}'"); connection.Execute($"insert into {TableNames.LocalFileAddress} " + $"(s_path) values ('{image.s_path}')"); int localId = connection.QueryFirst <int>( $"select id from {TableNames.LocalFileAddress} where s_path='{image.s_path}'"); connection.Execute($"insert into {TableNames.Images} (i_newspaper_id, " + $"i_local_address_id, i_network_address_id) values " + $"({image.i_newspaper_id}, {localId}, {networkId})"); }