Example #1
0
 private void DependeciesForm_Load(object sender, EventArgs e)
 {
     try
     {
         _dependencies = new TableDependencyGraph(_tablesLimit, _onlySelectedTables);
     }
     catch (TableDependencyException exc)
     {
         Debug.WriteLine(exc);
         Cursor.Current = Cursors.Default;
         MessageBox.Show(this, "Dependencies cannot be loaded", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Close();
         return;
     }
     _graph = new Graph("graph");
     graphViewer.CurrentLayoutMethod = LayoutMethod.MDS;
     graphViewer.LayoutAlgorithmSettingsButtonVisible = true;
     foreach (DependencyEdge edge in _dependencies.DependencyEdges)
     {
         _graph.AddEdge(edge.Parent.DbObject.NameWithSchema, edge.Name, edge.Child.DbObject.NameWithSchema);
     }
     foreach (DependencyNode node in _dependencies.NodesWithoutEdges)
     {
         _graph.AddNode(node.DbObject.NameWithSchema);
     }
     foreach (Node node in _graph.Nodes)
     {
         _maxInEdges    = Math.Max(node.InEdges.Count(), _maxInEdges);
         _maxOutEdges   = Math.Max(node.OutEdges.Count(), _maxOutEdges);
         _maxInOutEdges = Math.Max(node.Edges.Count(), _maxInOutEdges);
     }
     SetEdgesCounts();
     CalculateNodesColor();
     graphViewer.Graph = _graph;
     Cursor.Current    = Cursors.Default;
 }
Example #2
0
        private void ArchiveTablesForm_Load(object sender, EventArgs e)
        {
            try
            {
                _dependencies = Optimizer.Instance.DependencyGraph;
            }
            catch (TableDependencyException exc)
            {
                Debug.WriteLine(exc);
                Cursor.Current = Cursors.Default;
                MessageBox.Show(this, "Dependencies cannot be loaded", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return;
            }
            IList <Tuple <DatabaseObject, DatabaseObject> > removedTables = new List <Tuple <DatabaseObject, DatabaseObject> >();

            for (int i = 0; i < _tablesLimit.Count; i++)
            {
                ISet <DatabaseObject> nodes = new HashSet <DatabaseObject>(_dependencies.GetAncestors(_tablesLimit[i]).Select(t => t.DbObject));
                for (int j = 0; j < _tablesLimit.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (nodes.Contains(_tablesLimit[j]))
                    {
                        removedTables.Add(new Tuple <DatabaseObject, DatabaseObject>(_tablesLimit[j], _tablesLimit[i]));
                        _tablesLimit.Remove(_tablesLimit[j]);
                        if (j < i)
                        {
                            i--;
                        }
                        j--;
                    }
                }
            }
            IList <string> errorTableList = new List <string>();

            foreach (DatabaseObject table in _tablesLimit)
            {
                try
                {
                    ArchiveEntryTabPage archiveEntryTabPage = new ArchiveEntryTabPage(table, _dependencies);
                    TabPage             page = new TabPage(table.NameWithSchema);
                    tabControlTables.TabPages.Add(page);
                    page.Controls.Add(archiveEntryTabPage);
                }
                catch (DatabaseException exc)
                {
                    Debug.WriteLine(exc);
                    errorTableList.Add(table.NameWithSchema);
                }
            }
            Cursor.Current = Cursors.Default;
            if (errorTableList.Count > 0)
            {
                MessageBox.Show(this, $"Columns of tables {string.Join(", ", errorTableList)} cannot be loaded", "Loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (removedTables.Count > 0)
            {
                MessageBox.Show(this, $"These tables are dependent on others and there is no need to archive them multiple times.{Environment.NewLine}{string.Join(Environment.NewLine, removedTables.Select(t => t.Item1 + " -> " + t.Item2))}", "Table dependency check", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            TextReader input = Console.In;

            if (args.Length > 2)
            {
                Console.WriteLine("Error: You must provide zero params or up to 2 params (1: connection string do database, 2: filename containg commands (it is mandatory use connection string parameter))");
                input.Read();
                return;
            }
            string connectionString;
            bool   fileCommands = false;

            if (args.Length == 1)
            {
                connectionString = args[0];
            }
            else if (args.Length >= 2)
            {
                connectionString = args[0];
                string commandFile = args[1];
                fileCommands = true;
                if (File.Exists(commandFile))
                {
                    input = File.OpenText(commandFile);
                }
                else
                {
                    Console.WriteLine($"Error: File {commandFile} cannot be open - it does not exists");
                    input.Read();
                    return;
                }
            }
            else
            {
                connectionString = GetConnectionString();
            }
            Console.WriteLine("Connecting to database....");
            if (Database.Instance.Connect(connectionString))
            {
                Console.WriteLine();
                Console.WriteLine("Connection was successful.");
                Console.WriteLine();
                _databaseOperations = new DatabaseOperations(Database.Instance);
                _optimizer          = Optimizer.Instance;
                try
                {
                    foreach (DatabaseObject dbObject in _databaseOperations.GetTables())
                    {
                        _tableByName.Add(dbObject.NameWithSchema.ToLower(), dbObject);
                    }
                    _dependencies = new TableDependencyGraph();
                }
                catch (TableDependencyException exc)
                {
                    Debug.WriteLine(exc);
                    Console.WriteLine("Error: Cannot get table dependencies graph");
                    return;
                }
                catch (DatabaseException exc)
                {
                    Debug.WriteLine(exc);
                    Console.WriteLine("Error: Cannot get tables");
                    return;
                }
                Console.WriteLine("Table dependency graph has been built.");
                if (!fileCommands)
                {
                    ListCommands();
                }
                ProcessCommands(input, fileCommands);
                if (fileCommands)
                {
                    input.Close();
                    Console.WriteLine("All commands have been processed");
                }
            }
            else
            {
                Console.WriteLine("Error: Connection failed. Details: {0}", Database.Instance.ErrorMessage);
                input.Read();
            }
        }