Exemplo n.º 1
0
        async static Task <bool> Send(string from, string to, string subject, string body, string host, string[] attachmentFiles = null, string[] signatureImages = null)
        {
            try
            {
                using (var mailMessage = new MailMessage(from, to, subject, body))
                {
                    mailMessage.IsBodyHtml = body.Length > 0 && body.Substring(0, 1) == "<";

                    if (signatureImages != null)
                    {
                        addSignatureImages(body, signatureImages, mailMessage);
                    }

                    if (attachmentFiles != null)
                    {
                        attachmentFiles.Where(r => !string.IsNullOrEmpty(r) && File.Exists(r)).ToList().ForEach(fnm => mailMessage.Attachments.Add(new Attachment(fnm)));
                    }

                    await new SmtpClient {
                        Host = host
                    }.SendMailAsync(mailMessage);
                }

                return(true);
            }
            catch (FormatException ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }
            catch (SmtpException ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }
            catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }

            return(false);
        }
Exemplo n.º 2
0
        public static async Task <bool> TrySend(string from, string to__, string subject, string body, string host, string epName, string epAdrs)
        {
            var isSuccess = false;

            try
            {
                isSuccess = await Emailer.Send(
                    string.IsNullOrEmpty(from)? "*****@*****.**" : from,
                    string.IsNullOrEmpty(to__)? "*****@*****.**" : to__,
                    subject, body, host);
            }
            catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }
            DevOp.SysLogger.LogMessage(string.Format("Send email by App: {0}.", isSuccess ? "SUCCESS" : "FAILURE"));

            if (isSuccess)
            {
                return(isSuccess);
            }

            try
            {
                //using (var svc = new OLServiceReference.OLServiceClient(epName/*, epAdrs*/)) //todo: test epAdrs
                //{
                //  try { isSuccess = await svc.SendEmailAsync(from, to__, subject, body); }
                //  catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }
                //  finally { svc.Close(); }
                //}
            }
            catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); }
            DevOp.SysLogger.LogMessage(string.Format("Send email by WS: {0}.", isSuccess ? "SUCCESS" : "FAILURE"));

            return(isSuccess);
        }
Exemplo n.º 3
0
        public static List <string> GetSheetsFromExcel(string fileForXlsOrFolderForCsv, bool useHeader = true, bool isCsv = false)
        {
            var sw = Stopwatch.StartNew();
            var rv = new List <string>();

            try
            {
                using (var con = new OleDbConnection(getConString(fileForXlsOrFolderForCsv, useHeader, isCsv)))
                {
                    con.Open(); //nogo: var rrrr = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows.OfType<object>();

                    var sheets = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows;
                    foreach (DataRow item in sheets)
                    {
                        rv.Add(item["TABLE_NAME"].ToString().Replace("$", "").ToUpper());
                    }

                    con.Close();
                }
            }
            catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); throw; }
            finally { Trace.WriteLine(string.Format("\tInfo: {0}.{1}()  {2:s\\.f} sec  {3:#,###} rows", MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, sw.Elapsed, rv.Count)); }

            return(rv);
        }
Exemplo n.º 4
0
        public async Task Speak(string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            Debug.WriteLine($"spk:> {msg}");

            var isPlaying = mp_Vm.PlaybackSession.PlaybackState == MediaPlaybackState.Playing;

            if (isPlaying)
            {
                mp_Vm.Pause();
            }

            try
            {
                var wasSpeaking = 0;
                while (sp_Vm.PlaybackSession.PlaybackState == MediaPlaybackState.Playing)
                {
                    Debug.WriteLine($"   wasSpeaking: {++wasSpeaking}"); await Task.Delay(333);
                }                                                                          // aug 2017: trying to resolve speaking conflicts.

                var speechSynthesisStream = await _synth.SynthesizeTextToStreamAsync(msg); // Create a stream from the text. This will be played using a media element.

                sp_Vm.Source = MediaSource.CreateFromStream(speechSynthesisStream, speechSynthesisStream.ContentType);

                TypedEventHandler <MediaPlayer, object> h = null;
                sp_Vm.MediaEnded += h = (s, a) =>
                {
                    sp_Vm.MediaEnded -= h;
                    sp_Vm.Source      = null; // prevent replaying the old message on
                    if (isPlaying)
                    {
                        mp_Vm.Play();
                    }
                };

                sp_Vm.Play();
            }
            catch (FileNotFoundException ex) /**/ { await new MessageDialog(ex.Message, "Media player components unavailable").ShowAsync(); } // If media player components are unavailable, (eg, using a N SKU of windows), we won't be able to start media playback. Handle this gracefully
            catch (Exception ex) { DevOp.ExHrT(ex, GetType().FullName); }
        }
Exemplo n.º 5
0
        public static DataTable GetTableFromExcel(string file, string sheet, bool useHeader = true, bool isCsv = false, string sql = "select * from [{0}]")
        {
            var tbl = new DataTable();
            var sw  = Stopwatch.StartNew();

            try
            {
                using (var con = new OleDbConnection(getConString(file, useHeader, isCsv)))
                {
                    con.Open();

                    var da  = new OleDbDataAdapter(string.Format(sql, isCsv?sheet: (sheet.EndsWith("$") ? sheet : sheet + "$")), con);
                    var qnt = da.Fill(tbl);
                    con.Close();
                }
            }
            catch (Exception ex) { DevOp.ExHrT(ex, System.Reflection.MethodInfo.GetCurrentMethod()); throw; }
            //finally { Trace.WriteLine(string.Format("\tInfo: {0}.{1}()  {2:s\\.f} sec  {3:#,###} rows", MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, sw.Elapsed, tbl.Rows.Count)); }

            return(tbl);
        }