Example #1
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);
        }
Example #2
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);
        }
Example #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);
        }
        public AbrMainPg()
        {
            this.InitializeComponent();
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }

            _abrVM = ViewModelDispatcher.AbrVM;
            btnPinTile.Visibility = /*WinTileHelper.IsPinned ? Visibility.Collapsed : */ Visibility.Visible;

#if DEBUG
            ApplicationView.GetForCurrentView().Title = /*tbVer.Text =*/ $@"Dbg: built {(DateTime.Now - DevOp.BuildTime(typeof(App))).TotalDays:N1} days ago";
#else
            ApplicationView.GetForCurrentView().Title = /*tbVer.Text =*/ $@"Rls: {DevOp.BuildTime(typeof(App))}";
#endif
        }
Example #5
0
        public MainPage()
        {
            this.InitializeComponent();

            _vm              = MainVM.Instance;
            DataContext      = _vm;
            _vm.MediaElement = pl1;

            var bt = DevOp.BuildTime(typeof(App));

#if DEBUG
            ApplicationView.GetForCurrentView().Title = tbVer.Text = $@"Dbg: {(DateTime.Now - bt):d\ h\:mm} ago";
#else
            ApplicationView.GetForCurrentView().Title = tbVer.Text = $@"Rls: {bt}";
#endif

            this.NavigationCacheMode = NavigationCacheMode.Required; // I want this page to be always cached so that we don't have to add logic to save/restore state for the checkbox. //C:\gh\Windows - universal - samples\Samples\BackButton\cs\Scenario1.xaml.cs
        }
Example #6
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); }
        }
Example #7
0
        void onMediaOpened(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine(DevOp.GetCaller());

            try
            {
                if (_mid != null && me_Xm.CanSeek && me_Xm.NaturalDuration > _mid.PlayPosn)
                {
                    me_Xm.Position = _mid.PlayPosn; //              me1.Position = new TimeSpan(0, 1, 0, 0, 0);
                }
            }
            catch (Exception ex) { Debug.WriteLine(ex.Message); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       throw;
                                   } }
        }
Example #8
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);
        }
Example #9
0
 void onMediaPmfd(MediaElement sender, PartialMediaFailureDetectedEventArgs args)
 {
     Debug.WriteLine(DevOp.GetCaller());
 }
Example #10
0
 void onMediaCoStChd(object sender, RoutedEventArgs e)
 {
     Debug.WriteLine(DevOp.GetCaller());
 }
Example #11
0
 void onMediaFailed(object sender, ExceptionRoutedEventArgs e)
 {
     Debug.WriteLine(DevOp.GetCaller());
 }