Esempio n. 1
0
        private void btnSave_Image_Click(object sender, RoutedEventArgs e)
        {
            TimeSpan        scaleDuration     = new TimeSpan(0, 0, 0, 0, 1000);
            DoubleAnimation ProgressAnimation = new DoubleAnimation(0, 100, scaleDuration, FillBehavior.Stop);

            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ProgressAnimation);


            DataTable dataTable = ds.Tables[0];

            foreach (DataRow row in dataTable.Rows)
            {
                if (row[0].ToString() == lvPictureResult.SelectedItem.ToString())
                {
                    //Store binary data read from the database in a byte array
                    byte[]       blob   = (byte[])row[1];
                    MemoryStream stream = new MemoryStream();
                    stream.Write(blob, 0, blob.Length);
                    stream.Position = 0;

                    System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
                    BitmapImage          bi  = new BitmapImage();
                    bi.BeginInit();

                    MemoryStream ms = new MemoryStream();
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    ms.Seek(0, SeekOrigin.Begin);
                    bi.StreamSource = ms;
                    bi.EndInit();
                    image2.Source = bi;
                    //save file image to directory
                    try
                    {
                        if (img != null)
                        {
                            img.Save("..\\..\\PhotosSaved\\" + lvPictureResult.SelectedItem.ToString());
                            MessageBox.Show("Image saved successfully.");
                            Window1.Editor.ClearPhotoList();
                            Window1.Editor.Photos.Update();
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("There was a problem saving the file." +
                                        "Check the file permissions.");
                    }
                }
            }
        }
Esempio n. 2
0
        public void startrun1()
        {
            OnRun++;
            sd1.Visibility = System.Windows.Visibility.Visible;
            sp1.Visibility = System.Windows.Visibility.Visible;

            this.Height += 74;
            ProcessStartInfo startUWG = new ProcessStartInfo();

            //startUWG.FileName = "C:\\Users\\anakano\\Documents\\Research\\UWG2.1\\For_Installer\\UWGv2.0.exe";
            startUWG.FileName = "UWGEngine.exe";
            //make sure there is space in between each of the four inputs and that folder extension ends with \\
            startUWG.Arguments = ep + "\\ " + ef1 + " " + xp1 + "\\ " + xf1 + " " + rp + "\\ " + rf1 + " " + mon + " " + day + " " + dur;
            //startUWG.Arguments = this.epwPath + this.epwFileName + this.xmlPath + this.xmlFilename;
            startUWG.UseShellExecute        = false;
            startUWG.CreateNoWindow         = true;
            startUWG.RedirectStandardOutput = true;
            double maxx = System.Convert.ToDouble(dur);

            ProgressBar1.Maximum = System.Convert.ToDouble(dur);
            UWGs1  = Process.Start(startUWG);
            UWGst1 = 1;
            UWGs1.EnableRaisingEvents = true;
            UWGs1.Exited += new EventHandler(onClose);
            StreamReader UWGreader = UWGs1.StandardOutput;

            new Thread(() =>
            {
                String UWGreaderst;
                int value = 0;
                while (!UWGreader.EndOfStream)
                {
                    UWGreaderst = UWGreader.ReadLine();
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        if (UWGreaderst == "le")
                        {
                            ProgressBar1.IsIndeterminate = false;
                            RunningInfo1.Text            = "Loading EPW file...";
                            DoubleAnimation ani          = new DoubleAnimation(maxx, TimeSpan.FromSeconds(15));
                            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ani);
                        }
                        if (UWGreaderst == "lx")
                        {
                            RunningInfo1.Text    = "Loading XML file...";
                            DoubleAnimation ani1 = new DoubleAnimation(0, TimeSpan.FromSeconds(0));
                            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ani1);
                            DoubleAnimation ani2 = new DoubleAnimation(maxx, TimeSpan.FromSeconds(15));
                            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ani2);
                        }
                        if (UWGreaderst == "start")
                        {
                            DoubleAnimation ani1 = new DoubleAnimation(0, TimeSpan.FromSeconds(0));
                            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ani1);
                            ProgressBar1.Value = 0;
                            RunningInfo1.Text  = "Generating Day " + System.Convert.ToString(1) + "...";
                        }
                        if (UWGreaderst == "+")
                        {
                            value++;
                            ProgressBar1.Visibility = System.Windows.Visibility.Visible;
                            //                   ProgressBar.Value = value;
                            DoubleAnimation ani = new DoubleAnimation(value, TimeSpan.FromSeconds(.5));
                            ProgressBar1.BeginAnimation(ProgressBar.ValueProperty, ani);
                            if (value == System.Convert.ToDouble(dur))
                            {
                                value = value - 1;
                            }
                            RunningInfo1.Text = "Generating Day " + System.Convert.ToString(value + 1) + "...";
                        }
                        if (UWGreaderst == "end")
                        {
                            RunningInfo1.Text = "Writing new EPW file";
                        }
                        if (UWGreaderst == "over")
                        {
                            UWGst1            = 0;
                            RunningInfo1.Text = "Generating finished!";
                            System.IO.File.Delete(System.IO.Path.Combine(ep, ef1));
                        }
                    }));
                }
            }).Start();
        }