예제 #1
0
        private void mnuImportScripts_Click(object sender, EventArgs e)
        {
            if (lstFiles.SelectedItems.Count == 0)
            {
                return;
            }

            List <string> files = new List <string>();

            for (int i = 0; i < lstFiles.SelectedItems.Count; i++)
            {
                if (lstFiles.SelectedItems[i].SubItems[3].Text.Length > 0)
                {
                    files.Add(lstFiles.SelectedItems[i].SubItems[3].Text);
                }
            }



            bool   isValid;
            string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            SqlSync.Validator.SchemaValidator validator = new SqlSync.Validator.SchemaValidator();
            string importFileXml = string.Empty;

            if (File.Exists(this.rightTempFilePath + XmlFileNames.MainProjectFile))
            {
                importFileXml = this.rightTempFilePath + XmlFileNames.MainProjectFile;
            }
            string valErrorMessage;

            isValid = SqlBuildFileHelper.ValidateAgainstSchema(importFileXml, out valErrorMessage);
            if (isValid == false)
            {
                MessageBox.Show("Unable to Import. Invalid Build File Schema?");
                return;
            }

            SqlSyncBuildData importData;

            if (File.Exists(importFileXml))
            {
                importData = new SqlSyncBuildData();
                importData.ReadXml(this.rightTempFilePath + XmlFileNames.MainProjectFile);
                importData.AcceptChanges();

                foreach (SqlSyncBuildData.ScriptRow row in importData.Script)
                {
                    if (files.Contains(row.FileName) == false)
                    {
                        row.Delete();
                    }
                }
                importData.Script.AcceptChanges();
                importData.AcceptChanges();
            }
            else
            {
                return;
            }

            string[] arrFiles = new string[files.Count];
            files.CopyTo(arrFiles);

            SqlBuild.ImportListForm frmImport = new SqlBuild.ImportListForm(importData, this.rightTempFilePath, this.buildData, arrFiles);
            if (DialogResult.OK != frmImport.ShowDialog())
            {
                return;
            }

            string[] addedFileNames;
            double   importStartNumber = SqlBuild.SqlBuildFileHelper.ImportSqlScriptFile(ref this.buildData,
                                                                                         importData, this.rightTempFilePath, lastBuildNumber, this.leftTempFilePath, this.leftTempFilePath + XmlFileNames.MainProjectFile, this.leftZipFilePath, false, out addedFileNames);


            if (importStartNumber > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Import Successful\r\n");
                sb.Append("New file indexes start at: " + importStartNumber.ToString() + "\r\n\r\n");
                MessageBox.Show(sb.ToString(), "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.refreshProjectList = true;
                this.lastBuildNumber    = this.lastBuildNumber + addedFileNames.Length;
            }
            else
            {
                if (importStartNumber == (double)ImportFileStatus.Canceled)
                {
                    MessageBox.Show("Import Canceled", "Import Canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (importStartNumber == (double)ImportFileStatus.UnableToImport)
                {
                    MessageBox.Show("Unable to Import the requested file", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (importStartNumber == (double)ImportFileStatus.NoRowsImported)
                {
                    MessageBox.Show("No rows were selected for import", "None selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }


            btnCompare_Click(null, EventArgs.Empty);
        }