Exemple #1
0
 private void StartNewProcess(string projectPath, int timeout)
 {
     _busyService.ShowBusyIndicator(() =>
     {
         Process process = Process.Start(Assembly.GetEntryAssembly().Location, string.Format("\"{0}\"", projectPath));
         Debug.Assert(process != null);
         var stopwatch = new Stopwatch();
         stopwatch.Start();
         while (process.MainWindowHandle == IntPtr.Zero && stopwatch.ElapsedMilliseconds < timeout)
         {
             Thread.Sleep(100);
             process.Refresh();
         }
         stopwatch.Stop();
     });
 }
Exemple #2
0
 private bool Export(object ownerViewModel, string fileName, Action <Stream> exportAction)
 {
     try
     {
         _busyService.ShowBusyIndicator(() =>
         {
             using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                 exportAction(stream);
         });
         return(true);
     }
     catch (Exception e)
     {
         _dialogService.ShowError(ownerViewModel, string.Format("Error exporting file:\n{0}", e.Message), "Cog");
         return(false);
     }
 }
Exemple #3
0
        private void SaveElement(FrameworkElement elem, string path, Action <double> scaleUpdate)
        {
            _busyService.ShowBusyIndicator(() =>
            {
                RenderTargetBitmap rtb;
                if (!elem.IsLoaded)
                {
                    using (var temporaryPresentationSource = new HwndSource(new HwndSourceParameters())
                    {
                        RootVisual = elem
                    })
                    {
                        temporaryPresentationSource.Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() => { }));
                        double width  = elem.ActualWidth;
                        double height = elem.ActualHeight;
                        double maxDim = Math.Max(elem.ActualWidth, elem.ActualHeight);
                        if (maxDim > MaxDimension)
                        {
                            double scale = MaxDimension / maxDim;
                            if (scaleUpdate != null)
                            {
                                scaleUpdate(scale);
                                temporaryPresentationSource.Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() => { }));
                            }
                            width  = elem.ActualWidth * scale;
                            height = elem.ActualHeight * scale;
                            elem.RenderTransform = new ScaleTransform(scale, scale);
                            temporaryPresentationSource.Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() => { }));
                        }
                        rtb = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32);
                        rtb.Render(elem);
                    }
                }
                else
                {
                    double width           = elem.ActualWidth;
                    double height          = elem.ActualHeight;
                    double maxDim          = Math.Max(elem.ActualWidth, elem.ActualHeight);
                    Transform oldTransform = elem.RenderTransform;
                    if (maxDim > MaxDimension)
                    {
                        double scale         = MaxDimension / maxDim;
                        width               *= scale;
                        height              *= scale;
                        elem.RenderTransform = new ScaleTransform(scale, scale);
                    }
                    elem.Measure(elem.RenderSize);
                    elem.Arrange(new Rect(elem.DesiredSize));
                    rtb = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32);
                    rtb.Render(elem);
                    if (maxDim > MaxDimension)
                    {
                        elem.RenderTransform = oldTransform;
                    }
                    elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    elem.Arrange(new Rect(elem.DesiredSize));
                }

                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(rtb));
                using (var file = File.Create(path))
                    encoder.Save(file);
            });
        }