示例#1
0
        //
        public void SaveScreenShot(string filePath)
        {
            Dispatcher.BeginInvoke(new Action(() => {
                if (chart != null && takeShot == true)
                {
                    RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
                    outputFrame = BitmapFrame.Create(screenCapture);

                    if (screenCapture != null)
                    {
                        PngBitmapEncoder png = new PngBitmapEncoder();
                        png.Frames.Add(outputFrame);

                        using (System.IO.Stream stream = System.IO.File.Create(filePath))
                            png.Save(stream);

                        Print("Screenshot saved to " + filePath);
                        takeShot = true;
                    }
                }
            }));
        }
        private void SendMailChart(string Subject, string Body, string From, string To, string Host, int Port, string Username, string Password)
        {
            try
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (chart != null)
                    {
                        RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
                        outputFrame = BitmapFrame.Create(screenCapture);

                        if (screenCapture != null)
                        {
                            PngBitmapEncoder png = new PngBitmapEncoder();
                            png.Frames.Add(outputFrame);
                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            png.Save(stream);
                            stream.Position = 0;

                            MailMessage theMail = new MailMessage(From, To, Subject, Body);
                            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(stream, "image.png");
                            theMail.Attachments.Add(attachment);

                            SmtpClient smtp  = new SmtpClient(Host, Port);
                            smtp.EnableSsl   = true;
                            smtp.Credentials = new System.Net.NetworkCredential(Username, Password);
                            string token     = Instrument.MasterInstrument.Name + ToDay(Time[0]) + " " + ToTime(Time[0]) + CurrentBar.ToString();

                            Print("Sending Mail!");
                            smtp.SendAsync(theMail, token);
                        }
                    }
                }));
            }
            catch (Exception ex) {
                Print("Sending Chart email failed -  " + ex);
            }
        }
        protected override void OnBarUpdate()
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                if (chart != null && takeShot == true)
                {
                    RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
                    outputFrame = BitmapFrame.Create(screenCapture);

                    if (screenCapture != null)
                    {
                        PngBitmapEncoder png = new PngBitmapEncoder();
                        png.Frames.Add(outputFrame);

                        using (Stream stream = File.Create(string.Format(@"{0}\{1}", Core.Globals.UserDataDir, "MyScreenshot.png")))
                            png.Save(stream);

                        Print("Screenshot saved to " + Core.Globals.UserDataDir);
                        takeShot = false;
                    }
                }
            }));
        }