/// <summary>
        /// Commit the changes to memory, save the configuration settings to disk and create a backup.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveConfigurationFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            #region root path file
            // Update the paths in memory
            GlobalParameters.OutputPath        = textBoxOutputPath.Text;
            GlobalParameters.ConfigurationPath = textBoxConfigurationPath.Text;

            var localEnvironment = (KeyValuePair <TeamWorkingEnvironment, string>)comboBoxEnvironments.SelectedItem;
            GlobalParameters.WorkingEnvironment           = localEnvironment.Key.environmentKey;
            GlobalParameters.WorkingEnvironmentInternalId = localEnvironment.Key.environmentInternalId;

            // Save the paths from memory to disk.
            UpdateRootPathFile();
            #endregion

            // Make sure the new paths as updated are available upon save for backup etc.
            // Check if the paths and files are available, just to be sure.
            FileHandling.InitialisePath(GlobalParameters.ConfigurationPath);
            FileHandling.InitialisePath(GlobalParameters.OutputPath);
            TeamConfiguration.CreateDummyEnvironmentConfigurationFile(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
            ValidationSetting.CreateDummyValidationFile(GlobalParameters.ConfigurationPath + GlobalParameters.ValidationFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
            JsonExportSetting.CreateDummyJsonConfigurationFile(GlobalParameters.ConfigurationPath + GlobalParameters.JsonExportConfigurationFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);

            // Create a file backup for the configuration file
            try
            {
                TeamUtility.CreateFileBackup(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
                richTextBoxInformation.Text = "A backup of the current configuration was made at " + DateTime.Now + " in " + textBoxConfigurationPath.Text + ".\r\n";
            }
            catch (Exception)
            {
                richTextBoxInformation.Text = "TEAM was unable to create a backup of the configuration file.";
            }


            // Update the in-memory variables for use throughout the application, to commit the saved changes for runtime use.
            // This is needed before saving to disk, as the EnvironmentConfiguration Class retrieves the values from memory.
            UpdateConfigurationInMemory();


            // Save the information
            LocalTeamEnvironmentConfiguration.SaveConfigurationFile();
            parentFormMain.RevalidateFlag = true;
        }
Example #2
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");
            }
        }
Example #3
0
        private void SetStandardConfigurationSettings()
        {
            if (checkBoxConfigurationSettings.Checked)
            {
                TeamUtility.CreateFileBackup(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + FormBase.GlobalParameters.FileExtension);

                // Shared values (same for all samples)
                var stagingAreaPrefix           = "STG";
                var persistentStagingAreaPrefix = "PSA";

                var    hubTablePrefix     = "HUB_";
                var    satTablePrefix     = "SAT_";
                var    linkTablePrefix    = "LNK_";
                var    linkSatTablePrefix = "LSAT_";
                string psaKeyLocation     = "PrimaryKey";

                string keyIdentifier;
                string sourceRowId;
                string eventDateTime;
                string loadDateTime;
                string expiryDateTime;
                string changeDataIndicator;
                string recordSource;
                string etlProcessId;
                string etlUpdateProcessId;
                string logicalDeleteAttribute;
                string tableNamingLocation;
                string keyNamingLocation;
                string recordChecksum;
                string currentRecordIndicator;
                string alternativeRecordSource;
                string alternativeHubLoadDateTime;
                string alternativeSatelliteLoadDateTime;
                string alternativeRecordSourceFunction;
                string alternativeHubLoadDateTimeFunction;
                string alternativeSatelliteLoadDateTimeFunction;



                keyIdentifier = "_SK";

                sourceRowId                              = "SOURCE_ROW_ID";
                eventDateTime                            = "EVENT_DATETIME";
                loadDateTime                             = "LOAD_DATETIME";
                expiryDateTime                           = "LOAD_END_DATETIME";
                changeDataIndicator                      = "CDC_OPERATION";
                recordSource                             = "RECORD_SOURCE";
                etlProcessId                             = "MODULE_INSTANCE_ID";
                etlUpdateProcessId                       = "MODULE_UPDATE_INSTANCE_ID";
                logicalDeleteAttribute                   = "DELETED_RECORD_INDICATOR";
                tableNamingLocation                      = "Prefix";
                keyNamingLocation                        = "Suffix";
                recordChecksum                           = "HASH_FULL_RECORD";
                currentRecordIndicator                   = "CURRENT_RECORD_INDICATOR";
                alternativeRecordSource                  = "N/A";
                alternativeHubLoadDateTime               = "N/A";
                alternativeSatelliteLoadDateTime         = "N/A";
                alternativeRecordSourceFunction          = "False";
                alternativeHubLoadDateTimeFunction       = "False";
                alternativeSatelliteLoadDateTimeFunction = "False";


                TeamConfiguration.EnvironmentMode = EnvironmentModes.PhysicalMode;

                TeamConfiguration.StgTablePrefixValue = stagingAreaPrefix;
                TeamConfiguration.PsaTablePrefixValue = persistentStagingAreaPrefix;

                TeamConfiguration.HubTablePrefixValue  = hubTablePrefix;
                TeamConfiguration.SatTablePrefixValue  = satTablePrefix;
                TeamConfiguration.LinkTablePrefixValue = linkTablePrefix;
                TeamConfiguration.LsatTablePrefixValue = linkSatTablePrefix;
                TeamConfiguration.DwhKeyIdentifier     = keyIdentifier;
                TeamConfiguration.PsaKeyLocation       = psaKeyLocation;
                TeamConfiguration.TableNamingLocation  = tableNamingLocation;
                TeamConfiguration.KeyNamingLocation    = keyNamingLocation;

                TeamConfiguration.EventDateTimeAttribute                          = eventDateTime;
                TeamConfiguration.LoadDateTimeAttribute                           = loadDateTime;
                TeamConfiguration.ExpiryDateTimeAttribute                         = expiryDateTime;
                TeamConfiguration.ChangeDataCaptureAttribute                      = changeDataIndicator;
                TeamConfiguration.RecordSourceAttribute                           = recordSource;
                TeamConfiguration.EtlProcessAttribute                             = etlProcessId;
                TeamConfiguration.EtlProcessUpdateAttribute                       = etlUpdateProcessId;
                TeamConfiguration.RowIdAttribute                                  = sourceRowId;
                TeamConfiguration.RecordChecksumAttribute                         = recordChecksum;
                TeamConfiguration.CurrentRowAttribute                             = currentRecordIndicator;
                TeamConfiguration.LogicalDeleteAttribute                          = logicalDeleteAttribute;
                TeamConfiguration.EnableAlternativeRecordSourceAttribute          = alternativeRecordSourceFunction;
                TeamConfiguration.AlternativeRecordSourceAttribute                = alternativeRecordSource;
                TeamConfiguration.EnableAlternativeLoadDateTimeAttribute          = alternativeHubLoadDateTimeFunction;
                TeamConfiguration.AlternativeLoadDateTimeAttribute                = alternativeHubLoadDateTime;
                TeamConfiguration.EnableAlternativeSatelliteLoadDateTimeAttribute = alternativeSatelliteLoadDateTimeFunction;
                TeamConfiguration.AlternativeSatelliteLoadDateTimeAttribute       = alternativeSatelliteLoadDateTime;

                LocalTeamEnvironmentConfiguration.SaveConfigurationFile();
            }
        }
Example #4
0
        public void SaveEnvironment(object sender, EventArgs e)
        {
            if (_localEnvironment.environmentKey != "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.TeamEnvironmentCollection.EnvironmentDictionary.ContainsKey(_localEnvironment.environmentInternalId))
                {
                    FormBase.TeamEnvironmentCollection.EnvironmentDictionary[_localEnvironment.environmentInternalId] = _localEnvironment;
                }
                else
                {
                    FormBase.TeamEnvironmentCollection.EnvironmentDictionary.Add(_localEnvironment.environmentInternalId, _localEnvironment);
                }

                // Update the environment on disk
                if (!File.Exists(_environmentFileName))
                {
                    File.Create(_environmentFileName).Close();
                }

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

                TeamWorkingEnvironment[] jsonArray = JsonConvert.DeserializeObject <TeamWorkingEnvironment[]>(File.ReadAllText(_environmentFileName));

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

                // 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.environmentInternalId == "")
                {
                    //  There was no key in the file for this connection, so it's new.
                    var list = new List <TeamWorkingEnvironment>();
                    if (jsonArray != null)
                    {
                        list = jsonArray.ToList();
                    }

                    list.Add(_localEnvironment);
                    jsonArray = list.ToArray();
                }
                else
                {
                    // Update the values in an existing JSON segment
                    jsonKeyLookup.environmentInternalId = _localEnvironment.environmentInternalId;
                    jsonKeyLookup.environmentKey        = _localEnvironment.environmentKey;
                    jsonKeyLookup.environmentName       = _localEnvironment.environmentName;
                    jsonKeyLookup.environmentNotes      = _localEnvironment.environmentNotes;
                }

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

                UpdateRichTextBoxInformation($"The environment {_localEnvironment.environmentKey} was saved to {_environmentFileName}. A backup was made in the Backups directory also.\r\n");


                // The name of the tab page is passed back to the original control (the tab control).
                OnSaveEnvironment(this, new MyStringEventArgs(this.Name));
            }
            else
            {
                UpdateRichTextBoxInformation("Please update the environment information before saving. The 'new' profile is not meant to be saved.\r\n");
            }
        }