Beispiel #1
0
        /// <summary>
        /// Method to create a new validation file with default values at the default location
        /// Checks if the file already exists. If it does, nothing will happen.
        /// </summary>
        internal static void CreateDummyJsonConfigurationFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                var validationFile = new StringBuilder();

                validationFile.AppendLine("/* TEAM Json Export File Settings */");

                validationFile.AppendLine("GenerateDataObjectConnection|True");
                validationFile.AppendLine("GenerateDatabaseAsExtension|True");
                validationFile.AppendLine("GenerateSchemaAsExtension|True");
                validationFile.AppendLine("GenerateTypeAsClassification|True");

                validationFile.AppendLine("GenerateSourceDataItemTypes|True");
                validationFile.AppendLine("GenerateTargetDataItemTypes|True");

                validationFile.AppendLine("AddMetadataAsRelatedDataObject|True");
                validationFile.AppendLine("AddUpstreamDataObjectsAsRelatedDataObject|True");

                validationFile.AppendLine("/* End of file */");

                using (var outfile = new StreamWriter(fileName))
                {
                    outfile.Write(validationFile.ToString());
                    outfile.Close();
                }

                FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"A new Json extract configuration file was created for {fileName}."));
            }
            else
            {
                FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The existing Json extract configuration file {fileName} was detected."));
            }
        }
        // Save the root path file (configuration path, output path and working environment).
        private void UpdateRootPathFile()
        {
            // Update the root path file, part of the core solution to be able to store the config and output path
            var rootPathConfigurationFile = new StringBuilder();

            rootPathConfigurationFile.AppendLine("/* TEAM File Path Settings */");
            rootPathConfigurationFile.AppendLine("/* Saved at " + DateTime.Now + " */");
            rootPathConfigurationFile.AppendLine("ConfigurationPath|" + GlobalParameters.ConfigurationPath + "");
            rootPathConfigurationFile.AppendLine("OutputPath|" + GlobalParameters.OutputPath + "");
            rootPathConfigurationFile.AppendLine("WorkingEnvironment|" + GlobalParameters.WorkingEnvironment + "");
            rootPathConfigurationFile.AppendLine("/* End of file */");

            try
            {
                using (var outfile = new StreamWriter(GlobalParameters.CorePath + GlobalParameters.PathFileName + GlobalParameters.FileExtension))
                {
                    outfile.Write(rootPathConfigurationFile.ToString());
                    outfile.Close();
                }
            }
            catch (Exception ex)
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"The configuration file {GlobalParameters.CorePath +GlobalParameters.PathFileName + GlobalParameters.FileExtension} could not be updated. The error message is: \r\n\r\b\n{ex}"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Return the full TeamConnection object for a given (TeamConnection) connection Id string.
        /// </summary>
        /// <param name="connectionId"></param>
        /// <returns></returns>
        public static TeamConnection GetTeamConnectionByConnectionId(string connectionId)
        {
            if (!TeamConfiguration.ConnectionDictionary.TryGetValue(connectionId, out var teamConnection))
            {
                // The key isn't in the dictionary.
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Warning, $"The connection could not be matched for Connection Id {connectionId}."));
            }

            return(teamConnection);
        }
        public FormManageConfiguration(FormMain parent) : base(parent)
        {
            this.parentFormMain = parent;
            InitializeComponent();

            //Paths
            textBoxOutputPath.Text        = GlobalParameters.OutputPath;
            textBoxConfigurationPath.Text = GlobalParameters.ConfigurationPath;

            // Adding tab pages to the Environment tabs.
            IntPtr localHandle = tabControlEnvironments.Handle;

            foreach (var environment in TeamEnvironmentCollection.EnvironmentDictionary)
            {
                // Adding tabs on the Tab Control
                var lastIndex = tabControlEnvironments.TabCount - 1;
                CustomTabPageEnvironment localCustomTabPage = new CustomTabPageEnvironment(environment.Value);
                localCustomTabPage.OnDeleteEnvironment += DeleteEnvironment;
                localCustomTabPage.OnSaveEnvironment   += SaveEnvironment;
                localCustomTabPage.OnChangeMainText    += UpdateMainInformationTextBox;
                tabControlEnvironments.TabPages.Insert(lastIndex, localCustomTabPage);
                tabControlEnvironments.SelectedIndex = 0;

                // Adding items in the drop down list
                comboBoxEnvironments.Items.Add(new KeyValuePair <TeamWorkingEnvironment, string>(environment.Value, environment.Value.environmentKey));
                comboBoxEnvironments.DisplayMember = "Value";
            }

            comboBoxEnvironments.SelectedIndex = comboBoxEnvironments.FindStringExact(GlobalParameters.WorkingEnvironment);

            // Load the configuration file using the paths retrieved from the application root contents (configuration path)
            try
            {
                LocalInitialiseConnections(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
            }
            catch (Exception ex)
            {
                richTextBoxInformation.AppendText("Errors occurred trying to load the configuration file, the message is " + ex + ". No default values were loaded. \r\n\r\n");
            }

            // Connection tabs for the specific environment.
            AddConnectionTabPages();

            if (TeamConfiguration.MetadataConnection is null)
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Warning, $"No metadata connection is set."));
            }
            else
            {
                comboBoxMetadataConnection.SelectedIndex = comboBoxMetadataConnection.FindStringExact(TeamConfiguration.MetadataConnection.ConnectionKey);
            }

            _formLoading = false;
        }
 internal static void CreateBackupPath()
 {
     try
     {
         FileHandling.InitialisePath(FormBase.GlobalParameters.BackupPath);
         FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The TEAM directory {FormBase.GlobalParameters.BackupPath} is available."));
     }
     catch
     {
         FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error,
                                                                         "The directories required to operate TEAM are not available and can not be created. Do you have administrative privileges in the installation directory to create these additional directories?"));
     }
 }
Beispiel #6
0
        /// <summary>
        ///    Create a file backup for the configuration file at the provided location
        /// </summary>
        internal static void CreateFileBackup(string fileName, string filePath = "")
        {
            var localFileName = Path.GetFileName(fileName);

            // Manage that the backup path can be defaulted or derived.
            if (filePath == "")
            {
                filePath = FormBase.GlobalParameters.BackupPath;
            }
            else
            {
                filePath = Path.GetDirectoryName(fileName);
            }

            try
            {
                if (File.Exists(fileName))
                {
                    var targetFilePathName = filePath + string.Concat("Backup_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_", localFileName);

                    if (fileName != null)
                    {
                        File.Copy(fileName, targetFilePathName);
                    }
                    else
                    {
                        FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"The file cannot be backed up because it cannot be identified."));
                    }
                }
                else
                {
                    MessageBox.Show(
                        "TEAM couldn't locate a configuration file! Can you check the paths and existence of directories?",
                        "An issue has been encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred while creating a file backup. The error message is " + ex,
                                "An issue has been encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #7
0
        /// <summary>
        /// This method reads a file (using filePath) and populates a Dictionary collection using the individual commands and provided Connection String
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="commandDictionary"></param>
        /// <param name="connString"></param>
        private void PopulateSqlCommandDictionaryFromFile(string filePath, Dictionary <string, string> commandDictionary, string connString)
        {
            try
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    var sqlCommands = sr.ReadToEnd()
                                      .Split(new string[] { Environment.NewLine + Environment.NewLine },
                                             StringSplitOptions.RemoveEmptyEntries);

                    foreach (var command in sqlCommands)
                    {
                        commandDictionary.Add(command, connString);
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An error occurred: {ex}"));
            }
        }
Beispiel #8
0
        internal static Event SaveTextToFile(string targetFile, string textContent)
        {
            Event localEvent = new Event();

            try
            {
                //Output to file
                using (var outfile = new StreamWriter(targetFile))
                {
                    outfile.Write(textContent);
                    outfile.Close();
                }

                localEvent = Event.CreateNewEvent(EventTypes.Information, "The file was successfully saved to disk.\r\n");
            }
            catch (Exception ex)
            {
                localEvent = Event.CreateNewEvent(EventTypes.Error, "There was an issue saving the output to disk. The message is: " + ex + ".\r\n");
            }

            return(localEvent);
        }
Beispiel #9
0
        /// <summary>
        /// Method to create a new validation file with default values at the default location
        /// Checks if the file already exists. If it does, nothing will happen.
        /// </summary>
        internal void CreateDummyValidationFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                var validationFile = new StringBuilder();

                validationFile.AppendLine("/* TEAM Validation Settings */");

                // Object existence validation
                validationFile.AppendLine("DataObjectExistence|True");
                validationFile.AppendLine("BusinessKeyExistence|True");

                validationFile.AppendLine("DataItemExistence|True");

                // Consistency validation
                validationFile.AppendLine("LogicalGroup|True");
                validationFile.AppendLine("LinkKeyOrder|True");
                validationFile.AppendLine("BusinessKeySyntax|True");
                validationFile.AppendLine("LinkCompletion|True");

                validationFile.AppendLine("BasicDataVaultValidation|True");

                validationFile.AppendLine("/* End of file */");

                using (var outfile = new StreamWriter(fileName))
                {
                    outfile.Write(validationFile.ToString());
                    outfile.Close();
                }

                FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"A new configuration file was created for {fileName}."));
            }
            else
            {
                FormBase.GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The existing configuration file {fileName} was detected."));
            }
        }
Beispiel #10
0
        /// <summary>
        /// /// Run a SQL command against the provided database connection, capture any errors and report feedback to the Sample data screen.
        /// </summary>
        /// <param name="connString"></param>
        /// <param name="createStatement"></param>
        /// <param name="worker"></param>
        /// <param name="progressCounter"></param>
        /// <param name="targetForm"></param>
        private static void RunSqlCommandSampleDataForm(string connString, string createStatement, BackgroundWorker worker, int progressCounter, Form_Alert targetForm)
        {
            using (var connectionVersion = new SqlConnection(connString))
            {
                var commandVersion = new SqlCommand(createStatement, connectionVersion);

                try
                {
                    connectionVersion.Open();
                    commandVersion.ExecuteNonQuery();

                    worker.ReportProgress(progressCounter);
                    targetForm.SetTextLogging(createStatement);
                }
                catch (Exception ex)
                {
                    string errorMessage = $"An error has occurred with the following query: \r\n\r\n{createStatement}.\r\n\r\nThe error message is {ex}.";
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));

                    targetForm.SetTextLogging(errorMessage + "\r\n\r\n");
                    targetForm.SetTextLogging("This occurred with the following query: " + createStatement + "\r\n\r\n");
                }
            }
        }
Beispiel #11
0
        public FormMain()
        {
            InitializeComponent();

            // Instantiate the logging
            EventLog eventLog = new EventLog();

            // Set the version of the build for everything
            const string versionNumberForTeamApplication = "v1.6.0";

            Text = "TEAM - Taxonomy for ETL Automation Metadata " + versionNumberForTeamApplication;

            //richTextBoxInformation.AppendText("Starting from "+GlobalParameters.RootPath+"\r\n\r\n");
            //richTextBoxInformation.AppendText("Script path is " + GlobalParameters.ScriptPath + "\r\n\r\n");

            richTextBoxInformation.AppendText("Initialising the application.\r\n\r\n");

            // Make sure the application and custom location directories exist
            try
            {
                EnvironmentConfiguration.InitialiseRootPath();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The TEAM directories are available and initialised.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The directories required to operate TEAM are not available and can not be created. Do you have administrative priviliges in the installation directory to create these additional directories?"));
            }

            // Set the root path, to be able to locate the customisable configuration file
            try
            {
                EnvironmentConfiguration.LoadRootPathFile();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The core configuration file has been loaded.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The core configuration file could not be loaded. Is there a Configuration directory in the TEAM installation location?"));
            }

            // Make sure the configuration file is in memory
            try
            {
                EnvironmentConfiguration.InitialiseConfigurationPath();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The user configuration paths are available.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered creating or detecting the configuration paths."));
            }

            // Load the available configuration file
            try
            {
                EnvironmentConfiguration.LoadConfigurationFile(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The user configuration settings (file) have been loaded.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered loading the user configuration file."));
            }

            // Load the pattern definition file
            try
            {
                ConfigurationSettings.patternDefinitionList = LoadPatternDefinition.DeserializeLoadPatternDefinition(GlobalParameters.LoadPatternPath + GlobalParameters.LoadPatternDefinitionFile);
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The pattern definition file was loaded successfully.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered loading the pattern definition file."));
            }


            // Report the events (including errors) back to the user
            int errorCounter = 0;

            foreach (Event individualEvent in eventLog)
            {
                if (individualEvent.eventCode == (int)EventTypes.Error)
                {
                    errorCounter++;
                }

                richTextBoxInformation.AppendText(individualEvent.eventDescription);
            }

            richTextBoxInformation.AppendText($"\r\n{errorCounter} error(s) have been found at startup.\r\n\r\n");


            TestConnections();

            //Startup information
            richTextBoxInformation.AppendText("\r\nApplication initialised - the Taxonomy of ETL Automation Metadata (TEAM). \r\n");
            richTextBoxInformation.AppendText("Welcome to version " + versionNumberForTeamApplication + ".\r\n\r\n");

            labelWorkingEnvironment.Text = "The working environment is: " + GlobalParameters.WorkingEnvironment;
        }
Beispiel #12
0
        /// <summary>
        /// Check the ordinal position of Link Keys against their business key definitions.
        /// </summary>
        /// <param name="validationObject"></param>
        /// <param name="inputDataTable"></param>
        /// <param name="physicalModelDataTable"></param>
        /// <param name="evaluationMode"></param>
        /// <returns></returns>
        internal static Dictionary <string, bool> ValidateLinkKeyOrder(Tuple <string, string, string, string> validationObject, DataTable inputDataTable, DataTable physicalModelDataTable, EnvironmentModes evaluationMode)
        {
            // First, the Hubs need to be identified using the Business Key information. This, for the Link, is the combination of Business keys separated by a comma.
            // Every business key needs to be iterated over to query the individual Hub information
            List <string> hubBusinessKeys = validationObject.Item3.Split(',').ToList();

            // Now iterate over each Hub, as identified by the business key.
            // Maintain the ordinal position of the business key
            var hubKeyOrder = new Dictionary <int, string>();

            int businessKeyOrder = 0;

            foreach (string hubBusinessKey in hubBusinessKeys)
            {
                // Determine the order in the business key array
                businessKeyOrder++;

                // Query the Hub information
                DataRow[] selectionRows = inputDataTable.Select(TableMappingMetadataColumns.SourceTable + " = '" + validationObject.Item1 + "' AND " + TableMappingMetadataColumns.BusinessKeyDefinition + " = '" + hubBusinessKey.Replace("'", "''").Trim() + "' AND " + TableMappingMetadataColumns.TargetTable + " NOT LIKE '" + FormBase.TeamConfiguration.SatTablePrefixValue + "_%'");

                try
                {
                    // Derive the Hub surrogate key name, as this can be compared against the Link
                    string hubTableName         = selectionRows[0][TableMappingMetadataColumns.TargetTable.ToString()].ToString();
                    string hubTableConnectionId = selectionRows[0][TableMappingMetadataColumns.TargetConnection.ToString()].ToString();
                    var    hubTableConnection   = GetTeamConnectionByConnectionId(hubTableConnectionId);

                    string hubSurrogateKeyName = MetadataHandling.GetSurrogateKey(hubTableName, hubTableConnection, FormBase.TeamConfiguration);

                    // Add to the dictionary that contains the keys in order.
                    hubKeyOrder.Add(businessKeyOrder, hubSurrogateKeyName);
                }
                catch
                {
                    //
                }
            }

            // Derive the Hub surrogate key name, as this can be compared against the Link
            var linkKeyOrder = new Dictionary <int, string>();

            if (evaluationMode == EnvironmentModes.PhysicalMode)
            {
                var connTarget = new SqlConnection {
                    ConnectionString = validationObject.Item4
                };
                var connDatabase = connTarget.Database;

                var sqlStatementForLink = new StringBuilder();
                sqlStatementForLink.AppendLine("SELECT");
                sqlStatementForLink.AppendLine("   OBJECT_NAME([object_id]) AS [TABLE_NAME]");
                sqlStatementForLink.AppendLine("  ,[name] AS [COLUMN_NAME]");
                sqlStatementForLink.AppendLine("  ,[column_id] AS [ORDINAL_POSITION]");
                sqlStatementForLink.AppendLine("  ,ROW_NUMBER() OVER(PARTITION BY object_id ORDER BY column_id) AS [HUB_KEY_POSITION]");
                sqlStatementForLink.AppendLine("FROM [" + connDatabase + "].sys.columns");
                sqlStatementForLink.AppendLine("    WHERE OBJECT_NAME([object_id]) LIKE '" + FormBase.TeamConfiguration.LinkTablePrefixValue + "_%'");
                sqlStatementForLink.AppendLine("AND column_id > 4");
                sqlStatementForLink.AppendLine("AND OBJECT_NAME([object_id]) = '" + validationObject.Item2 + "'");

                // The hubKeyOrder contains the order of the keys in the Hub, now we need to do the same for the (target) Link so we can compare.

                connTarget.Open();
                var linkList = Utility.GetDataTable(ref connTarget, sqlStatementForLink.ToString());
                connTarget.Close();

                foreach (DataRow row in linkList.Rows)
                {
                    var linkHubSurrogateKeyName     = row["COLUMN_NAME"].ToString();
                    int linkHubSurrogateKeyPosition = Convert.ToInt32(row["HUB_KEY_POSITION"]);

                    if (linkHubSurrogateKeyName.Contains(FormBase.TeamConfiguration.DwhKeyIdentifier)
                        ) // Exclude degenerate attributes from the order
                    {
                        linkKeyOrder.Add(linkHubSurrogateKeyPosition, linkHubSurrogateKeyName);
                    }
                }
            }
            else // virtual
            {
                int linkHubSurrogateKeyPosition = 1;

                var workingTable = new DataTable();

                try
                {
                    // Select only the business keys in a link table.
                    // Excluding all non-business key attributes
                    workingTable = physicalModelDataTable
                                   .Select($"{PhysicalModelMappingMetadataColumns.TableName} LIKE '%{FormBase.TeamConfiguration.LinkTablePrefixValue}%' " +
                                           $"AND {PhysicalModelMappingMetadataColumns.TableName} = '{validationObject.Item2}' " +
                                           $"AND {PhysicalModelMappingMetadataColumns.OrdinalPosition} > 4", $"{PhysicalModelMappingMetadataColumns.OrdinalPosition} ASC").CopyToDataTable();
                }
                catch (Exception ex)
                {
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An error occurred during validation of the metadata. The errors is {ex}."));
                }

                if (workingTable.Rows.Count > 0)
                {
                    foreach (DataRow row in workingTable.Rows)
                    {
                        var linkHubSurrogateKeyName = row[PhysicalModelMappingMetadataColumns.ColumnName.ToString()].ToString();

                        if (linkHubSurrogateKeyName.Contains(FormBase.TeamConfiguration.DwhKeyIdentifier)
                            ) // Exclude degenerate attributes from the order
                        {
                            linkKeyOrder.Add(linkHubSurrogateKeyPosition, linkHubSurrogateKeyName);
                            linkHubSurrogateKeyPosition++;
                        }
                    }
                }
            }

            // Check for duplicates, which indicate a Same-As Link or Hierarchical Link
            var duplicateValues = hubKeyOrder.Where(i => hubKeyOrder.Any(t => t.Key != i.Key && t.Value == i.Value)).ToDictionary(i => i.Key, i => i.Value);


            // Run the comparison, test for equality.
            // Only if there are no duplicates, as this indicates the SAL / HLINK which is not currently supported
            bool equal = false;

            if (duplicateValues.Count == 0)
            {
                if (hubKeyOrder.Count == linkKeyOrder.Count) // Require equal count.
                {
                    equal = true;
                    foreach (var pair in hubKeyOrder)
                    {
                        string value;
                        if (linkKeyOrder.TryGetValue(pair.Key, out value))
                        {
                            // Require value be equal.
                            if (value != pair.Value)
                            {
                                equal = false;
                                break;
                            }
                        }
                        else
                        {
                            // Require key be present.
                            equal = false;
                            break;
                        }
                    }
                }
            }
            else
            {
                equal = true;
            }

            // return the result of the test;
            Dictionary <string, bool> result = new Dictionary <string, bool>();

            result.Add(validationObject.Item2, equal);
            return(result);
        }
Beispiel #13
0
        public void SaveConnection(object sender, EventArgs e)
        {
            if (_localConnection.ConnectionKey != "New")
            {
                // Save the connection to global memory (the shared variables across the application).
                // If the connection key (also the dictionary key) already exists, then update the values.
                // If the key does not exist then insert a new row in the connection dictionary.

                if (FormBase.TeamConfiguration.ConnectionDictionary.ContainsKey(_localConnection.ConnectionInternalId))
                {
                    FormBase.TeamConfiguration.ConnectionDictionary[_localConnection.ConnectionInternalId] = _localConnection;
                }
                else
                {
                    FormBase.TeamConfiguration.ConnectionDictionary.Add(_localConnection.ConnectionInternalId, _localConnection);
                }

                // Update the connection on disk

                if (!File.Exists(_connectionFileName))
                {
                    File.Create(_connectionFileName).Close();
                }

                // Check if the value already exists in the file.
                var jsonKeyLookup = new TeamConnection();

                TeamConnection[] jsonArray = JsonConvert.DeserializeObject <TeamConnection[]>(File.ReadAllText(_connectionFileName));

                // If the Json file already contains values (non-empty) then perform a key lookup.
                if (jsonArray != null)
                {
                    jsonKeyLookup = jsonArray.FirstOrDefault(obj => obj.ConnectionInternalId == _localConnection.ConnectionInternalId);
                }

                // If nothing yet exists in the file, the key lookup is NULL or "" then the record in question does not exist in the Json file and should be added.
                if (jsonArray == null || jsonKeyLookup == null || jsonKeyLookup.ConnectionKey == "")
                {
                    //  There was no key in the file for this connection, so it's new.
                    var list = new List <TeamConnection>();
                    if (jsonArray != null)
                    {
                        list = jsonArray.ToList();
                    }
                    list.Add(_localConnection);
                    jsonArray = list.ToArray();
                }
                else
                {
                    // Update the values in an existing JSON segment
                    jsonKeyLookup.ConnectionInternalId = _localConnection.ConnectionInternalId;
                    jsonKeyLookup.ConnectionName       = _localConnection.ConnectionName;
                    jsonKeyLookup.ConnectionKey        = _localConnection.ConnectionKey;
                    jsonKeyLookup.ConnectionType       = GetSelectedConnectionTypesRadioButtonFromForm();
                    jsonKeyLookup.ConnectionNotes      = _localConnection.ConnectionNotes;
                    jsonKeyLookup.DatabaseServer       = _localConnection.DatabaseServer;
                    jsonKeyLookup.FileConnection       = _localConnection.FileConnection;
                }

                try
                {
                    // Save the updated file to disk.
                    TeamUtility.CreateFileBackup(_connectionFileName);
                    string output = JsonConvert.SerializeObject(jsonArray, Formatting.Indented);
                    File.WriteAllText(_connectionFileName, output);

                    UpdateRichTextBoxInformation(
                        $"The connection {_localConnection.ConnectionKey} was saved to {_connectionFileName}. A backup was made in the Backups directory also.\r\n");
                }
                catch (Exception ex)
                {
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An error occurred: {ex}"));
                }

                // The name of the tab page is passed back to the original control (the tab control).
                OnSaveConnection(this, new MyStringEventArgs(this.Name));
            }
            else
            {
                UpdateRichTextBoxInformation("Please update the connection information before saving. The 'new' profile is not meant to be saved.\r\n");
            }
        }
        /// <summary>
        /// Manage the event when the environment selection changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxEnvironments_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_formLoading == false)
            {
                // Retrieve the object from the event.
                var localComboBox = (ComboBox)sender;

                var localComboBoxSelection = (KeyValuePair <TeamWorkingEnvironment, string>)localComboBox.SelectedItem;

                var selectedItem = localComboBoxSelection.Key;

                // Get the full environment from the in-memory dictionary.
                var localEnvironment = TeamEnvironmentCollection.EnvironmentDictionary[selectedItem.environmentInternalId];

                // Set the working environment in memory.
                GlobalParameters.WorkingEnvironment           = localEnvironment.environmentKey;
                GlobalParameters.WorkingEnvironmentInternalId = localEnvironment.environmentInternalId;

                // Update the root path file with the new working directory.
                UpdateRootPathFile();

                // Initialise new environment in configuration settings.
                UpdateEnvironment(localEnvironment);

                foreach (TabPage customTabPage in tabControlConnections.TabPages)
                {
                    if ((customTabPage.Name == "tabPageConnectionMain") || (customTabPage.Name == "tabPageConnectionNewTab"))
                    {
                        // Do nothing, as only the two standard Tab Pages exist.
                    }
                    else
                    {
                        // Remove the Tab Page from the Tab Control
                        tabControlConnections.Controls.Remove((customTabPage));
                    }
                }

                var connectionFileName =
                    GlobalParameters.ConfigurationPath +
                    GlobalParameters.JsonConnectionFileName + '_' +
                    GlobalParameters.WorkingEnvironment +
                    GlobalParameters.JsonExtension;

                TeamConfiguration.ConnectionDictionary = TeamConnectionFile.LoadConnectionFile(connectionFileName);

                comboBoxMetadataConnection.Items.Clear();
                AddConnectionTabPages();


                try
                {
                    LocalInitialiseConnections(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
                }
                catch (Exception ex)
                {
                    richTextBoxInformation.AppendText("Errors occurred trying to load the configuration file, the message is " + ex + ". No default values were loaded. \r\n\r\n");
                }



                //var selectedItemComboBox = new KeyValuePair<TeamConnectionProfile, string>(TeamConfigurationSettings.MetadataConnection, TeamConfigurationSettings.MetadataConnection.ConnectionKey);

                if (TeamConfiguration.MetadataConnection is null)
                {
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"No metadata connection is set."));
                }
                else
                {
                    comboBoxMetadataConnection.SelectedIndex = comboBoxMetadataConnection.FindStringExact(TeamConfiguration.MetadataConnection.ConnectionKey);
                }

                // Report back to the event log.
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The environment was changed to {localEnvironment.environmentName}."));
            }
        }
        /// <summary>
        /// Check if the last tab rectangle contains the mouse clicked point, then insert a tab before the last tab.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControlConnections_MouseDown(object sender, MouseEventArgs e)
        {
            var lastIndex = tabControlConnections.TabCount - 1;

            if (tabControlConnections.GetTabRect(lastIndex).Contains(e.Location))
            {
                //tabControlConnections.TabPages.Insert(lastIndex, "New Tab");
                TeamConnection connectionProfile = new TeamConnection();
                connectionProfile.ConnectionInternalId = Utility.CreateMd5(new[] { Utility.GetRandomString(100) }, " % $@");
                connectionProfile.ConnectionName       = "New connection";
                connectionProfile.ConnectionKey        = "New";
                connectionProfile.ConnectionType       = ConnectionTypes.Database;

                TeamDatabaseConnection connectionDatabase = new TeamDatabaseConnection();
                connectionDatabase.SchemaName         = "<Schema Name>";
                connectionDatabase.ServerName         = "<Server Name>";
                connectionDatabase.DatabaseName       = "<Database Name>";
                connectionDatabase.NamedUserName      = "******";
                connectionDatabase.NamedUserPassword  = "******";
                connectionDatabase.authenticationType = ServerAuthenticationTypes.NamedUser;

                TeamFileConnection connectionFile = new TeamFileConnection();
                connectionFile.FilePath = @"<File Path>";
                connectionFile.FileName = @"<File Name>";

                connectionProfile.DatabaseServer = connectionDatabase;
                connectionProfile.FileConnection = connectionFile;


                //localCustomTabPage.OnChangeMainText += UpdateMainInformationTextBox;
                //localCustomTabPage.OnClearMainText += (ClearMainInformationTextBox);

                bool newTabExists = false;
                foreach (TabPage customTabPage in tabControlConnections.TabPages)
                {
                    if (customTabPage.Name == "New")
                    {
                        newTabExists = true;
                    }
                    else
                    {
                        // Do nothing
                    }
                }

                if (newTabExists == false)
                {
                    // Create a new tab page using the connection profile (a TeamConnection class object) as input.
                    CustomTabPageConnection localCustomTabPage = new CustomTabPageConnection(connectionProfile);
                    localCustomTabPage.OnDeleteConnection += DeleteConnection;
                    localCustomTabPage.OnChangeMainText   += UpdateMainInformationTextBox;
                    localCustomTabPage.OnSaveConnection   += SaveConnection;
                    tabControlConnections.TabPages.Insert(lastIndex, localCustomTabPage);
                    tabControlConnections.SelectedIndex = lastIndex;

                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"A new connection was created."));
                }
                else
                {
                    richTextBoxInformation.AppendText("There is already a 'new connection' tab open. Please close or save this first.\r\n");
                }
            }
        }
Beispiel #16
0
        public FormMain()
        {
            InitializeComponent();

            // Set the version of the build for everything
            const string versionNumberForTeamApplication = "v1.6.3";

            Text = "TEAM - Taxonomy for ETL Automation Metadata " + versionNumberForTeamApplication;

            GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The TEAM root path is {GlobalParameters.RootPath}."));
            GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The TEAM script path is {GlobalParameters.ScriptPath}."));

            richTextBoxInformation.AppendText("Initialising the application.\r\n\r\n");

            // Root paths (mandatory TEAM directories)
            // Make sure the application and custom location directories exist as per the start-up default.
            try
            {
                LocalTeamEnvironmentConfiguration.InitialiseEnvironmentPaths();
            }
            catch (Exception ex)
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An error was encountered while creating the standard TEAM paths: \r\n\r\n{ex}"));
            }

            #region Load the root path configuration settings (user defined paths and working environment)

            // Load the root file, to be able to locate the (customisable) configuration file.
            // This file contains the configuration directory, the output directory and the working environment.
            string rootPathFileName = GlobalParameters.CorePath + GlobalParameters.PathFileName + GlobalParameters.FileExtension;
            try
            {
                LocalTeamEnvironmentConfiguration.LoadRootPathFile(rootPathFileName, GlobalParameters.ConfigurationPath, GlobalParameters.OutputPath);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information,
                                                                       $"The core configuration file {rootPathFileName} has been loaded."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error,
                                                                       $"The core configuration file {rootPathFileName} could not be loaded. Is there a Configuration directory in the TEAM installation location?"));
            }

            // Environments file
            string environmentFile = GlobalParameters.CorePath + GlobalParameters.JsonEnvironmentFileName + GlobalParameters.JsonExtension;
            try
            {
                TeamEnvironmentCollection.LoadTeamEnvironmentCollection(environmentFile);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information,
                                                                       $"The environment file {environmentFile} has been loaded."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error,
                                                                       $"The environment file {environmentFile} could not be loaded. Does the file exists in the designated (root) location?"));
            }

            #endregion

            #region Check if user configured paths exists (now that they have been loaded from the root file), and create dummy Configuration and Validation files if necessary
            // Configuration Path
            try
            {
                FileHandling.InitialisePath(GlobalParameters.ConfigurationPath);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The user defined configuration path {GlobalParameters.ConfigurationPath} is available."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The directories required to operate TEAM are not available and can not be created. Do you have administrative privileges in the installation directory to create these additional directories?"));
            }

            // Output Path
            try
            {
                FileHandling.InitialisePath(GlobalParameters.OutputPath);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The user defined output path {GlobalParameters.OutputPath} is available."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The directories required to operate TEAM are not available and can not be created. Do you have administrative privileges in the installation directory to create these additional directories?"));
            }

            // Create a dummy configuration file if it does not exist.
            var configurationFileName =
                GlobalParameters.ConfigurationPath +
                GlobalParameters.ConfigFileName + '_' +
                GlobalParameters.WorkingEnvironment +
                GlobalParameters.FileExtension;

            try
            {
                if (!File.Exists(configurationFileName))
                {
                    TeamConfiguration.CreateDummyEnvironmentConfigurationFile(configurationFileName);
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"A new configuration file {configurationFileName} was created."));
                }
                else
                {
                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The existing configuration file {configurationFileName} was detected."));
                }
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An issue was encountered creating or detecting the configuration paths for {configurationFileName}."));
            }

            // Create a default validation file if the file does not exist as expected.
            var validationFileName =
                GlobalParameters.ConfigurationPath +
                GlobalParameters.ValidationFileName + '_' +
                GlobalParameters.WorkingEnvironment +
                GlobalParameters.FileExtension;

            try
            {
                ValidationSetting.CreateDummyValidationFile(validationFileName);
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An issue was encountered creating or detecting the configuration paths for {validationFileName}."));
            }

            // Create a default json configuration file if the file does not exist as expected.
            var jsonConfigurationFileName =
                GlobalParameters.ConfigurationPath +
                GlobalParameters.JsonExportConfigurationFileName + '_' +
                GlobalParameters.WorkingEnvironment +
                GlobalParameters.FileExtension;

            try
            {
                JsonExportSetting.CreateDummyJsonConfigurationFile(jsonConfigurationFileName);
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An issue was encountered creating or detecting the configuration paths for {jsonConfigurationFileName}."));
            }
            #endregion

            // Load the connections file for the respective environment.
            var connectionFileName =
                GlobalParameters.ConfigurationPath +
                GlobalParameters.JsonConnectionFileName + '_' +
                GlobalParameters.WorkingEnvironment +
                GlobalParameters.JsonExtension;

            TeamConfiguration.ConnectionDictionary = TeamConnectionFile.LoadConnectionFile(connectionFileName);

            #region Load configuration file
            // Load the available configuration file into memory.
            var configurationFile = GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension;
            try
            {
                // Load the configuration file.
                TeamConfiguration.LoadTeamConfigurationFile(configurationFile);
                GlobalParameters.EnvironmentMode = TeamConfiguration.EnvironmentMode;
                // Retrieve the events into the main event log.
                GlobalParameters.TeamEventLog.MergeEventLog(TeamConfiguration.ConfigurationSettingsEventLog);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The user configuration settings ({configurationFile}) have been loaded."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An issue was encountered loading the user configuration file ({configurationFile})."));
            }
            #endregion

            //FormBase.EnvironmentVersion.GetEnvironmentVersionsFromFile(Path.GetDirectoryName(configurationFile));

            TeamVersionList.LoadVersionList(GlobalParameters.CorePath + GlobalParameters.VersionFileName + GlobalParameters.JsonExtension);

            // Load the pattern definition file.
            try
            {
                GlobalParameters.PatternDefinitionList = LoadPatternDefinition.DeserializeLoadPatternDefinition(GlobalParameters.LoadPatternPath + GlobalParameters.LoadPatternDefinitionFile);
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, "The pattern definition file was loaded successfully."));
            }
            catch
            {
                GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered loading the pattern definition file."));
            }

            // Report the events (including errors) back to the user
            int errorCounter = 0;
            foreach (Event individualEvent in GlobalParameters.TeamEventLog)
            {
                if (individualEvent.eventCode == (int)EventTypes.Error)
                {
                    errorCounter++;
                }
            }

            if (errorCounter > 0)
            {
                richTextBoxInformation.AppendText(
                    $"{errorCounter} error(s) have been found at startup. Please check the Event Log in the menu.\r\n\r\n");
            }

            TestConnections();

            //Startup information
            richTextBoxInformation.AppendText("\r\nApplication initialised - the Taxonomy of ETL Automation Metadata (TEAM). \r\n");
            richTextBoxInformation.AppendText("Welcome to version " + versionNumberForTeamApplication + ".\r\n\r\n");

            labelWorkingEnvironment.Text = GlobalParameters.WorkingEnvironment; //+"("+GlobalParameters.WorkingEnvironmentInternalId+")";
            labelEnvironmentMode.Text    = GlobalParameters.EnvironmentMode.ToString();
        }