public DbDipViewModel()
        {
            Corpuses = new ObservableCollection <DipCorpus>();
            foreach (var corpus in CorpusesStorage.AllCorpuses())
            {
                Corpuses.Add(corpus);
            }
            AddCommand = new ActionCommand(() =>
            {
                StartProgress();

                var editor = GenericEdit.Create(new DipCorpus
                {
                    Name          = "Новий корпус",
                    PinCount      = 8,
                    CorpusWidthMm = 6
                }, corpus =>
                {
                    Corpuses.Add(corpus);
                    SaveCorpuses();
                });

                editor.ShowDialog();

                CompleteProgress();
            });

            EditCommand = new ActionCommand <DipCorpus>(item =>
            {
                StartProgress();
                // TODO Should copy instead of modification
                var editor = GenericEdit.Create(item, corpus =>
                {
                    SaveCorpuses();
                });

                editor.ShowDialog();

                CompleteProgress();
            });

            RemoveCommand = new ActionCommand <DipCorpus>(item =>
            {
                StartProgress();

                Corpuses.Remove(item);
                SaveCorpuses();

                CompleteProgress();
            });

            GenerateCommand = new ActionCommand <DipCorpus>(item =>
            {
                StartProgress();

                new DipBuilder(new SwContext()).Build(item);

                CompleteProgress();
            });
        }
        public ComponentsViewModel()
        {
            Components = new ObservableCollection <CircuitComponent>();
            foreach (var component in ComponentsStorage.AllComponents())
            {
                Components.Add(component);
            }
            AddExistingCommand = new ActionCommand(() =>
            {
                StartProgress();

                var editor = GenericEdit.Create(new CircuitComponent(), component =>
                {
                    Components.Add(component);
                    SaveCorpuses();
                });

                editor.ShowDialog();

                CompleteProgress();
            });

            AddDIPCommand = new ActionCommand(() =>
            {
                StartProgress();

                var editor = GenericEdit.Create(new DipCorpus {
                    PinCount = 8, CorpusWidthMm = 6.0
                }, async corpus =>
                {
                    var component = await Task.Run(() =>
                    {
                        var builder = new DipBuilder(new SwContext());
                        return(builder.BuildComponent(corpus));
                    });
                    Components.Add(component);
                    SaveCorpuses();
                });

                editor.ShowDialog();

                CompleteProgress();
            });

            EditCommand = new ActionCommand <CircuitComponent>(item =>
            {
                StartProgress();

                //var editor = new EditDip(item, () =>
                //{
                //    SaveCorpuses();
                //});
                //editor.ShowDialog();

                CompleteProgress();
            });

            RemoveCommand = new ActionCommand <CircuitComponent>(item =>
            {
                StartProgress();

                Components.Remove(item);
                SaveCorpuses();

                CompleteProgress();
            });

            GenerateCommand = new ActionCommand <CircuitComponent>(item =>
            {
                StartProgress();

                var editor = GenericEdit.Create(new PlaceSpec(), async place =>
                {
                    await Task.Run(() =>
                    {
                        var ctx = EnsureAssemblyContext();
                        if (ctx != null)
                        {
                            ctx.Place(place, item);
                        }
                    });
                });

                editor.ShowDialog();

                CompleteProgress();
            });
        }