public static void Imap(string password, HlidacStatu.Api.V2.Dataset.Typed.Dataset <NemocniceData> ds) { string obsazenostFile = null; Devmasters.Logging.Logger.Root.Info("connection to uzisbackupmbx@"); using (ImapClient Client = new ImapClient("imap.gmail.com", 993, "*****@*****.**", password, AuthMethod.Login, true)) { // This returns all messages sent since August 23rd 2012. IEnumerable <uint> uids = Client.Search( SearchCondition.Unseen() ); Devmasters.Logging.Logger.Root.Info($"found {uids.Count()} email"); // The expression will be evaluated for every MIME part // of every mail message in the uids collection. IEnumerable <MailMessage> messages = Client.GetMessages(uids, true); foreach (var msg in messages) { string reportDir = uzisRoot + msg.Date()?.ToString("yyyy-MM-dd") + "\\"; if (System.IO.Directory.Exists(reportDir) == false) { System.IO.Directory.CreateDirectory(reportDir); } Devmasters.Logging.Logger.Root.Info($"saving {msg.Attachments?.Count()} files"); foreach (var att in msg.Attachments) { if (att.ContentDisposition.Inline == false) { var attfn = MakeValidFileName(att.Name); using (var fs = System.IO.File.Create(reportDir + attfn)) { att.ContentStream.Seek(0, System.IO.SeekOrigin.Begin); att.ContentStream.CopyTo(fs); } if (attfn.Contains("hosp04_KRAJE")) { obsazenostFile = reportDir + attfn; Obsazenost.ProcessExcelObsazenost(obsazenostFile, ds); } } } } } }
public static void LastObsazenost(HlidacStatu.Api.V2.Dataset.Typed.Dataset <NemocniceData> ds) { for (int i = 0; i < 10; i++) { DateTime dt = DateTime.Now.Date.AddDays(-1 * i); string reportDir = uzisRoot + dt.ToString("yyyy-MM-dd") + "\\"; if (System.IO.Directory.Exists(reportDir)) { foreach (var fn in System.IO.Directory.EnumerateFiles(reportDir, "*.xlsx")) { if (fn.Contains("hosp04_KRAJE")) { Devmasters.Logging.Logger.Root.Info($"Process lastObsazenost {fn}"); Obsazenost.ProcessExcelObsazenost(fn, ds); return; } } } } }