Exemple #1
0
        public override IDock CreateLayout()
        {
            var objectExplorer = new ObjectExplorerViewModel
            {
                Id    = "ObjectExplorer",
                Title = "ObjectExplorer",
            };

            var documentsWindows = new DocumentDock
            {
                Id               = "DocumentsPane",
                Title            = "DocumentsPane",
                Proportion       = double.NaN,
                VisibleDockables = CreateList <IDockable>()
            };

            _context
            .Queries
            .ToObservableChangeSet()
            .Transform(x =>
            {
                return(new QueryViewModel(x, _context));
            })
            .ObserveOn(RxApp.MainThreadScheduler)
            .ActOnEveryObject(
                added =>
            {
                bool exists = documentsWindows.VisibleDockables
                              .Select(x => (QueryViewModel)x)
                              .Any(x => x.Id == added.Id);
                if (exists == false)
                {
                    if (documentsWindows.ActiveDockable != null)
                    {
                        documentsWindows.VisibleDockables.Insert(
                            documentsWindows.VisibleDockables.IndexOf(documentsWindows.ActiveDockable) + 1,
                            added);
                    }
                    else
                    {
                        documentsWindows.VisibleDockables.Add(added);
                    }
                    this.InitLayout(added);
                    this.InitLayout(documentsWindows);
                    documentsWindows.ActiveDockable = added;
                }
            },
                removed =>
            {
                bool exists = documentsWindows.VisibleDockables
                              .Select(x => (QueryViewModel)x)
                              .Any(x => x.Id == removed.Id);
                if (exists)
                {
                    documentsWindows.VisibleDockables.Remove(removed);
                }
            }
                );

            ((INotifyCollectionChanged)documentsWindows.VisibleDockables).CollectionChanged += new NotifyCollectionChangedEventHandler(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                if (e.OldItems != null)
                {
                    foreach (QueryViewModel view in e.OldItems)
                    {
                        var queryModel = _context.Queries.FirstOrDefault(x => x.Id == view.Id);
                        if (queryModel != null)
                        {
                            _context.Queries.Remove(queryModel);
                        }
                    }
                }
            });

            documentsWindows
            .WhenAnyValue(x => x.ActiveDockable)
            .Subscribe(x => {
                if (x != null)
                {
                    _context.SelectedQueryIndex = documentsWindows.VisibleDockables.IndexOf(x);
                }
                else
                {
                    _context.SelectedQueryIndex = -1;
                }
            });
            _context
            .WhenAnyValue(x => x.SelectedQueryIndex)
            .Subscribe(x => {
                var view = documentsWindows.VisibleDockables.ElementAtOrDefault(x);
                if (view != null)
                {
                    documentsWindows.ActiveDockable = view;
                }
            });


            var bodyLayout = new ProportionalDock
            {
                Id               = "BodyLayout",
                Title            = "BodyLayout",
                Proportion       = double.NaN,
                Orientation      = Orientation.Horizontal,
                ActiveDockable   = null,
                VisibleDockables = CreateList <IDockable>
                                   (
                    new ProportionalDock
                {
                    Id               = "LeftPane",
                    Title            = "LeftPane",
                    Proportion       = double.NaN,
                    Orientation      = Orientation.Vertical,
                    ActiveDockable   = null,
                    VisibleDockables = CreateList <IDockable>
                                       (
                        new ToolDock
                    {
                        Id               = "LeftPaneTop",
                        Title            = "LeftPaneTop",
                        Proportion       = double.NaN,
                        ActiveDockable   = objectExplorer,
                        VisibleDockables = CreateList <IDockable>
                                           (
                            objectExplorer
                                           )
                    }
                                       )
                },
                    new SplitterDock()
                {
                    Id    = "LeftSplitter",
                    Title = "LeftSplitter"
                },
                    documentsWindows
                                   )
            };

            var root = CreateRootDock();

            root.Id               = "Root";
            root.Title            = "Root";
            root.ActiveDockable   = bodyLayout;
            root.DefaultDockable  = bodyLayout;
            root.VisibleDockables = CreateList <IDockable>(bodyLayout);
            root.Top              = CreatePinDock();
            root.Top.Alignment    = Alignment.Top;
            root.Bottom           = CreatePinDock();
            root.Bottom.Alignment = Alignment.Bottom;
            root.Left             = CreatePinDock();
            root.Left.Alignment   = Alignment.Left;
            root.Right            = CreatePinDock();
            root.Right.Alignment  = Alignment.Right;

            return(root);
        }
Exemple #2
0
 public MainWindowViewModel()
 {
     _objectExplorer = new ObjectExplorerViewModel();
 }
        public static DataBaseViewModel BuildDataBaseObject(string path, ObjectExplorerViewModel objectExplorer)
        {
            string            connectionString  = string.Format("Data source= {0} ;", path);
            string            fileName          = path.Split('\\').Last().ToString();
            DataBaseViewModel dataBaseViewModel = new DataBaseViewModel(objectExplorer);

            dataBaseViewModel.Name = fileName;
            dataBaseViewModel.Path = path;
            var tables   = SQLiteCore.GetTablesNames(connectionString);
            var views    = SQLiteCore.GetViewsNames(connectionString);
            var triggers = SQLiteCore.GetTriggersNames(connectionString);

            //Create Tables
            foreach (DataRow tableRow in tables.Rows)
            {
                var table = new TableViewModel();
                table.Name = tableRow[0].ToString();
                var columns     = SQLiteCore.GetCulumnsByTable(connectionString, table.Name);
                var indexs      = SQLiteCore.GetIndexByTable(connectionString, table.Name);
                var foreignkeys = SQLiteCore.GetForeignKeysByTable(connectionString, table.Name);
                //Create ForeignKeys
                foreach (DataRow foreignKeyRow in foreignkeys.Rows)
                {
                    table.ForeignKeys.Add(new ForeignKeyViewModel()
                    {
                        Name        = foreignKeyRow[3].ToString(),
                        Description = string.Format(" To {0}({1})", foreignKeyRow[2].ToString(), foreignKeyRow[4].ToString())
                    });
                }
                //Create Columns
                foreach (DataRow columnRow in columns.Rows)
                {
                    var column = new ColumnViewModel();
                    column.Name = columnRow[1].ToString();
                    string description = string.Format(" {0} ", columnRow[2].ToString());
                    if (columnRow[3].ToString() != "0")
                    {
                        description += ", NOT Null ";
                    }
                    if (!columnRow.IsNull(4))
                    {
                        description += string.Format(",Default= {0}", columnRow[4].ToString());
                    }
                    if (columnRow[5].ToString() != "0")
                    {
                        column.IsPrimaryKey = true;
                    }
                    column.Description = description;
                    if (table.ForeignKeys.Where(e => e.Name == column.Name).Count() != 0)
                    {
                        column.IsForeignKey = true;
                    }
                    table.Columns.Add(column);
                }
                //Create Indexs
                foreach (DataRow indexRow in indexs.Rows)
                {
                    table.Indexs.Add(indexRow[1].ToString());
                }

                dataBaseViewModel.Tables.Add(table);
            }
            //Create Views
            foreach (DataRow viewRow in views.Rows)
            {
                dataBaseViewModel.Views.Add(
                    new ViewViewModel()
                {
                    Name = viewRow[0].ToString()
                }
                    );
            }
            //Create Triggers
            foreach (DataRow triggerRow in triggers.Rows)
            {
                dataBaseViewModel.Triggers.Add(
                    new TriggerViewModel()
                {
                    Name      = triggerRow[0].ToString(),
                    TableName = triggerRow[1].ToString()
                });
            }

            return(dataBaseViewModel);
        }