private void loadArchives() { using (Model m = new Model()) { archives = new ObservableCollection<archive>(m.archives); archiveListView.ItemsSource = archives; } }
private void savePassword(string pw) { archive.Password = passwordBox.Text; using (Model m = new Model()) { m.archives.FirstOrDefault(i => i.Id == archive.Id).Password = archive.Password; m.SaveChanges(); } }
//static void SendMail(string mailContent) //{ // return; // Task.Run(new Action(() => // { // using (SmtpClient sc = new SmtpClient("smtp-mail.outlook.com", 25)) // { // MailMessage mm; // sc.EnableSsl = true; // sc.Credentials = new NetworkCredential("*****@*****.**", "password"); // mm = new MailMessage(new MailAddress("*****@*****.**", "包布丁"), new MailAddress("*****@*****.**", "包布丁")); // mm.Subject = "First answer published!"; // mm.Body = mailContent; // try // { // Logging.WriteLine("Sending a mail."); // sc.Send(mm); // Logging.WriteLine("Mail sent."); // } // catch (Exception ex) // { // Logging.WriteLine("Error while sending a mail:" + ex.ToString()); // } // Logging.WriteLine("Press enter to continue..."); // Console.ReadLine(); // } // })); //} static void ProcessArchive(KeyCrawler.Attachment archive) { Interlocked.Increment(ref taskLeftCount); taskProcessingHandle.Reset(); string path = Properties.Settings.Default.pathPrefix + @"\archive\" + archive.Name; httpClient.GetByteArrayAsync(archive.Url).ContinueWith(new Action<Task<byte[]>>(async (result) => { System.IO.File.WriteAllBytes(path, await result); Logging.WriteLine("Download done: " + archive.Name); Logging.WriteLine("Saved at: " + path); Logging.WriteLine("Writing to db: " + archive.Name); using (Model m = new Model()) { m.archives.Add(new archive() { Path = path, CreateTime = DateTime.Now }); await m.SaveChangesAsync(); } Logging.WriteLine("db written: " + archive.Name); if (Interlocked.Decrement(ref taskLeftCount) == 0) { taskProcessingHandle.Set(); } })); Logging.WriteLine("Download started: " + archive.Name); }