/// <summary>
 /// Append the specified collection.
 /// </summary>
 /// <param name="collection">The collection.</param>
 public void Append(SchemaCollection collection)
 {
     foreach (SchemaData data in collection)
     {
         this.list.Add(data.Type.ToString() + ";" + data.Name + ";" + data.ModifyDate.ToString("s"));
     }
 }
示例#2
0
        /// <summary>
        /// Shows the processed list.
        /// </summary>
        protected void ShowProcessedList()
        {
            // Prepare the list store
            TreeStore list = new TreeStore(typeof(string), typeof(string), typeof(bool), typeof(string), typeof(SchemaData));
            TreeIter iterTable1 = list.AppendValues("Tables");
            TreeIter iterProcedure1 = list.AppendValues("Stored Procedures");
            this.treeviewDB.Model = list;

            TreeStore list2 = new TreeStore(typeof(string), typeof(string), typeof(bool), typeof(string), typeof(SchemaData));
            TreeIter iterTable2 = list2.AppendValues("Tables");
            TreeIter iterProcedure2 = list2.AppendValues("Stored Procedures");
            this.treeviewFile.Model = list2;

            SchemaCollection cache = new SchemaCollection();

            // Render to the tree view
            foreach (SchemaData file in this.combinedFile)
            {
                if (comboShow.Active == 1 && file.Status == SchemaDataStatus.None)
                {
                    continue;
                }

                if (comboType.Active == 1 && file.Type != SchemaDataType.Table)
                {
                    continue;
                }

                if (comboType.Active == 2 && file.Type != SchemaDataType.StoredProcedure)
                {
                    continue;
                }

                // Compare current file to the SQL Schema
                string color = "#ffffff";
                bool check = false;
                string status = string.Empty;
                if (file.Status == SchemaDataStatus.Added)
                {
                    color = "#99ff99";
                    check = true;
                    status = "+";
                }
                else if (file.Status == SchemaDataStatus.Modified)
                {
                    color = "#ffff99";
                    check = true;
                    status = "#";
                }
                else if (file.Status == SchemaDataStatus.Conflicted)
                {
                    color = "#ff9999";
                    check = false;
                    status = "?";
                }

                TreeIter localIter = iterTable2;
                if (file.Type == SchemaDataType.StoredProcedure)
                {
                    localIter = iterProcedure2;
                }

                list2.AppendValues(localIter, file.Name, color, check, status, file);
            }

            foreach (SchemaData str in this.combinedDB)
            {
                if (comboShow.Active == 1 && str.Status == SchemaDataStatus.None)
                {
                    continue;
                }

                if (comboType.Active == 1 && str.Type != SchemaDataType.Table)
                {
                    continue;
                }

                if (comboType.Active == 2 && str.Type != SchemaDataType.StoredProcedure)
                {
                    continue;
                }

                // Compare the current SQL Schema to the file
                string color = "#ffffff";
                bool check = false;
                string status = string.Empty;
                if (str.Status == SchemaDataStatus.Added)
                {
                    color = "#99ff99";
                    check = true;
                    status = "+";
                }
                else if (str.Status == SchemaDataStatus.Modified)
                {
                    color = "#ffff99";
                    check = true;
                    status = "#";
                }
                else if (str.Status == SchemaDataStatus.Conflicted)
                {
                    color = "#ff9999";
                    check = false;
                    status = "?";
                }

                TreeIter localIter = iterTable1;
                if (str.Type == SchemaDataType.StoredProcedure)
                {
                    localIter = iterProcedure1;
                }

                list.AppendValues(localIter, str.Name, color, check, status, str);
            }
        }
示例#3
0
        /// <summary>
        /// Raises the button start diff clicked event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Event arguments.</param>
        protected void OnButtonStartDiffClicked(object sender, EventArgs e)
        {
            string dir = this.entryFolder.Text;
            string tableDir = dir + "/" + AppSettings.TableDir;
            string procedureDir = dir + "/" + AppSettings.ProcedureDir;

            this.SaveConfiguration();

            this.Sql = new SqlServerAccess(entryHost.Text, entryUser.Text, entryPassword.Text, entryDatabase.Text);
            this.listDBTables = this.Sql.GetTables();
            this.listDBProcedures = this.Sql.GetStoredProcedure();

            int id = 0;

            // Prepare the file list
            this.listFileTables = new SchemaCollection();
            foreach (string file in Directory.GetFiles(tableDir))
            {
                id++;
                string tableName = file.Replace("\\", "/").Substring(tableDir.Length + 1);
                tableName = tableName.Replace(".Table.sql", string.Empty);
                this.listFileTables.Add(new SchemaData { Name = tableName, ObjectID = id, Type = SchemaDataType.Table, FilePath = file, Data = File.ReadAllText(file).Replace("\r\n", "\n") });
            }

            this.listFileProcedures = new SchemaCollection();
            foreach (string file in Directory.GetFiles(procedureDir))
            {
                id++;
                string procedureName = file.Replace("\\", "/").Substring(procedureDir.Length + 1);
                procedureName = procedureName.Replace(".StoredProcedure.sql", string.Empty);
                this.listFileProcedures.Add(new SchemaData { Name = procedureName, ObjectID = id, Type = SchemaDataType.StoredProcedure, FilePath = file, Data = File.ReadAllText(file) });
            }

            if (!Directory.Exists(dir))
            {
                GtkLogService.Instance.Write(string.Concat("Failed to get directory ", dir));
                return;
            }

            if (!Directory.Exists(tableDir))
            {
                GtkLogService.Instance.Write(string.Concat("Failed to get table directory ", tableDir));
                return;
            }

            SchemaCollection modifiedDBTables = new SchemaCollection();
            SchemaCollection modifiedDBProcedure = new SchemaCollection();
            SchemaCollection modifiedFileTables = new SchemaCollection();
            SchemaCollection modifiedFileProcedure = new SchemaCollection();

            // Add status to the list
            foreach (SchemaData table in this.listFileTables)
            {
                if (!this.listDBTables.ContainsName(table))
                {
                    table.Status = SchemaDataStatus.Added;
                    continue;
                }

                if (this.listDBTables.IsModified(table))
                {
                    table.Status = SchemaDataStatus.Modified;
                }
            }

            foreach (SchemaData table in this.listDBTables)
            {
                if (!this.listFileTables.ContainsName(table))
                {
                    table.Status = SchemaDataStatus.Added;
                    continue;
                }

                if (this.listFileTables.IsModified(table))
                {
                    table.Status = SchemaDataStatus.Modified;
                    modifiedDBTables.Add(table);
                }
            }

            // SP list
            foreach (SchemaData sp in this.listFileProcedures)
            {
                if (!this.listDBProcedures.ContainsName(sp))
                {
                    sp.Status = SchemaDataStatus.Added;
                    continue;
                }

                if (this.listDBProcedures.IsModified(sp))
                {
                    sp.Status = SchemaDataStatus.Modified;
                }
            }

            foreach (SchemaData sp in this.listDBProcedures)
            {
                if (!this.listFileProcedures.ContainsName(sp))
                {
                    sp.Status = SchemaDataStatus.Added;
                    continue;
                }

                if (this.listFileProcedures.IsModified(sp))
                {
                    sp.Status = SchemaDataStatus.Modified;
                    modifiedDBProcedure.Add(sp);
                }
            }

            SchemaCollection cache = this.ReadSyncLog();

            // Get list for conflicted data
            foreach (SchemaData table in modifiedDBTables)
            {
                if (cache.ContainsName(table) && cache[table.Name].ModifyDate.ToString("s") != table.ModifyDate.ToString("s"))
                {
                    table.Status = SchemaDataStatus.Conflicted;

                    if (this.listFileTables.ContainsName(table))
                    {
                        this.listFileTables[table.Name].Status = SchemaDataStatus.Conflicted;
                    }
                }
            }

            foreach (SchemaData sp in modifiedDBProcedure)
            {
                if (cache.ContainsName(sp) && cache[sp.Name].ModifyDate.ToString("s") != sp.ModifyDate.ToString("s"))
                {
                    sp.Status = SchemaDataStatus.Conflicted;

                    if (this.listFileProcedures.ContainsName(sp))
                    {
                        this.listFileProcedures[sp.Name].Status = SchemaDataStatus.Conflicted;
                    }
                }
            }

            // Reset the combined file and database variables
            this.combinedFile = new SchemaCollection();
            this.combinedDB = new SchemaCollection();

            this.combinedFile.AppendCollection(this.listFileTables);
            this.combinedFile.AppendCollection(this.listFileProcedures);
            this.combinedDB.AppendCollection(this.listDBTables);
            this.combinedDB.AppendCollection(this.listDBProcedures);

            this.ShowProcessedList();
        }
 /// <summary>
 /// Appends the collection.
 /// </summary>
 /// <param name="collection">The collection.</param>
 public void AppendCollection(SchemaCollection collection)
 {
     foreach (SchemaData single in collection)
     {
         this.Add(single);
     }
 }
        /// <summary>
        /// Reads the log.
        /// </summary>
        /// <returns>The log.</returns>
        /// <param name="path">The path.</param>
        public SchemaCollection ReadLog(string path)
        {
            SchemaCollection collection = new SchemaCollection();
            foreach (string line in System.IO.File.ReadAllLines(path + "/" + this.baseFileName + "_" + this.databaseName.ToString()))
            {
                string[] split = line.Split(';');
                SchemaData schema = new SchemaData();
                schema.Name = split[1];
                schema.Type = (SchemaDataType)Enum.Parse(typeof(SchemaDataType), split[0]);
                schema.ModifyDate = DateTime.Parse(split[2]);
                collection.Add(schema);
            }

            return collection;
        }