Exemplo n.º 1
0
        /// <summary>
        ///    This method will load an existing configuration file and display the values on the form, or create a new dummy one if not available
        /// </summary>
        /// <param name="chosenFile"></param>
        private void LocalInitialiseConnections(string chosenFile)
        {
            // If the config file does not exist yet, create it by calling the EnvironmentConfiguration Class
            if (!File.Exists(chosenFile))
            {
                var newEnvironmentConfiguration = new ClassEnvironmentConfiguration();
                newEnvironmentConfiguration.CreateDummyEnvironmentConfiguration(chosenFile);
            }


            // Open the configuration file
            var configList = new Dictionary <string, string>();
            var fs         = new FileStream(chosenFile, FileMode.Open, FileAccess.Read);
            var sr         = new StreamReader(fs);

            try
            {
                string textline;
                while ((textline = sr.ReadLine()) != null)
                {
                    if (textline.IndexOf(@"/*", StringComparison.Ordinal) == -1)
                    {
                        var line = textline.Split('|');
                        configList.Add(line[0], line[1]);
                    }
                }

                sr.Close();
                fs.Close();


                ////Replace values for formatting and connection string layout
                //var connectionStringOmd = configList["connectionStringMetadata"];
                //connectionStringOmd = connectionStringOmd.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");

                //var connectionStringSource = configList["connectionStringSource"];
                //connectionStringSource = connectionStringSource.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");

                //var connectionStringStg = configList["connectionStringStaging"];
                //connectionStringStg = connectionStringStg.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");

                //var connectionStringHstg = configList["connectionStringPersistentStaging"];
                //connectionStringHstg = connectionStringHstg.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");

                //var connectionStringInt = configList["connectionStringIntegration"];
                //connectionStringInt = connectionStringInt.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");

                //var connectionStringPres = configList["connectionStringPresentation"];
                //connectionStringPres = connectionStringPres.Replace("Provider=SQLNCLI10;", "").Replace("Provider=SQLNCLI11;", "").Replace("Provider=SQLNCLI12;", "");


                ////Connections
                //textBoxIntegrationConnection.Text = connectionStringInt;
                //textBoxPSAConnection.Text = connectionStringHstg;
                //textBoxSourceConnection.Text = connectionStringSource;
                //textBoxStagingConnection.Text = connectionStringStg;
                //textBoxMetadataConnection.Text = connectionStringOmd;
                //textBoxPresentationConnection.Text = connectionStringPres;

                //DWH settings
                textBoxHubTablePrefix.Text             = configList["HubTablePrefix"];
                textBoxSatPrefix.Text                  = configList["SatTablePrefix"];
                textBoxLinkTablePrefix.Text            = configList["LinkTablePrefix"];
                textBoxLinkSatPrefix.Text              = configList["LinkSatTablePrefix"];
                textBoxDWHKeyIdentifier.Text           = configList["KeyIdentifier"];
                textBoxSchemaName.Text                 = configList["SchemaName"];
                textBoxEventDateTime.Text              = configList["EventDateTimeStamp"];
                textBoxLDST.Text                       = configList["LoadDateTimeStamp"];
                textBoxExpiryDateTimeName.Text         = configList["ExpiryDateTimeStamp"];
                textBoxChangeDataCaptureIndicator.Text = configList["ChangeDataIndicator"];
                textBoxRecordSource.Text               = configList["RecordSourceAttribute"];
                textBoxETLProcessID.Text               = configList["ETLProcessID"];
                textBoxETLUpdateProcessID.Text         = configList["ETLUpdateProcessID"];
                textBoxSourcePrefix.Text               = configList["SourceSystemPrefix"];
                textBoxStagingAreaPrefix.Text          = configList["StagingAreaPrefix"];
                textBoxPSAPrefix.Text                  = configList["PersistentStagingAreaPrefix"];
                textBoxSourceRowId.Text                = configList["RowID"];

                // Databases
                textBoxSourceDatabase.Text       = configList["SourceDatabase"];
                textBoxStagingDatabase.Text      = configList["StagingDatabase"];
                textBoxPSADatabase.Text          = configList["PersistentStagingDatabase"];
                textBoxIntegrationDatabase.Text  = configList["IntegrationDatabase"];
                textBoxPresentationDatabase.Text = configList["PresentationDatabase"];
                textBoxMetadataDatabaseName.Text = configList["MetadataDatabase"];

                textBoxRecordChecksum.Text                    = configList["RecordChecksum"];
                textBoxCurrentRecordAttributeName.Text        = configList["CurrentRecordAttribute"];
                textBoxAlternativeRecordSource.Text           = configList["AlternativeRecordSource"];
                textBoxHubAlternativeLDTSAttribute.Text       = configList["AlternativeHubLDTS"];
                textBoxSatelliteAlternativeLDTSAttribute.Text = configList["AlternativeSatelliteLDTS"];
                textBoxLogicalDeleteAttributeName.Text        = configList["LogicalDeleteAttribute"];

                // Servers (instances)
                textBoxPhysicalModelServerName.Text = configList["PhysicalModelServerName"];
                textBoxMetadataServerName.Text      = configList["MetadataServerName"];

                //Checkbox setting based on loaded configuration
                CheckBox myConfigurationCheckBox;

                if (configList["AlternativeRecordSourceFunction"] == "False")
                {
                    myConfigurationCheckBox                = checkBoxAlternativeRecordSource;
                    myConfigurationCheckBox.Checked        = false;
                    textBoxAlternativeRecordSource.Enabled = false;
                }
                else
                {
                    myConfigurationCheckBox         = checkBoxAlternativeRecordSource;
                    myConfigurationCheckBox.Checked = true;
                }

                if (configList["AlternativeHubLDTSFunction"] == "False")
                {
                    myConfigurationCheckBox                    = checkBoxAlternativeHubLDTS;
                    myConfigurationCheckBox.Checked            = false;
                    textBoxHubAlternativeLDTSAttribute.Enabled = false;
                }
                else
                {
                    myConfigurationCheckBox         = checkBoxAlternativeHubLDTS;
                    myConfigurationCheckBox.Checked = true;
                }

                if (configList["AlternativeSatelliteLDTSFunction"] == "False")
                {
                    myConfigurationCheckBox         = checkBoxAlternativeSatLDTS;
                    myConfigurationCheckBox.Checked = false;
                    textBoxSatelliteAlternativeLDTSAttribute.Enabled = false;
                }
                else
                {
                    myConfigurationCheckBox         = checkBoxAlternativeSatLDTS;
                    myConfigurationCheckBox.Checked = true;
                }


                //Radiobutton setting for prefix / suffix
                RadioButton myTableRadioButton;

                if (configList["TableNamingLocation"] == "Prefix")
                {
                    myTableRadioButton         = tablePrefixRadiobutton;
                    myTableRadioButton.Checked = true;
                }
                else
                {
                    myTableRadioButton         = tableSuffixRadiobutton;
                    myTableRadioButton.Checked = true;
                }

                //Radiobutton settings for on key location
                RadioButton myKeyRadioButton;

                if (configList["KeyNamingLocation"] == "Prefix")
                {
                    myKeyRadioButton         = keyPrefixRadiobutton;
                    myKeyRadioButton.Checked = true;
                }
                else
                {
                    myKeyRadioButton         = keySuffixRadiobutton;
                    myKeyRadioButton.Checked = true;
                }

                //Radiobutton settings for PSA Natural Key determination
                RadioButton myPsaBusinessKeyLocation;

                if (configList["PSAKeyLocation"] == "PrimaryKey")
                {
                    myPsaBusinessKeyLocation         = radioButtonPSABusinessKeyPK;
                    myPsaBusinessKeyLocation.Checked = true;
                }
                else
                {
                    myPsaBusinessKeyLocation         = radioButtonPSABusinessKeyIndex;
                    myPsaBusinessKeyLocation.Checked = true;
                }

                //Radiobutton settings for repository type
                RadioButton myMetadatarepositoryType;

                if (configList["metadataRepositoryType"] == "JSON")
                {
                    myMetadatarepositoryType         = radioButtonJSON;
                    myMetadatarepositoryType.Checked = true;
                }
                else
                {
                    myMetadatarepositoryType         = radioButtonSQLServer;
                    myMetadatarepositoryType.Checked = true;
                }


                // Authentication approach for metadata
                var myRadioButtonMetadataSSPI  = radioButtonMetadataSSPI;
                var myRadioButtonMetadataNamed = radioButtonMetadataNamed;

                if (configList["MetadataSSPI"] == "True")
                {
                    myRadioButtonMetadataSSPI.Checked  = true;
                    myRadioButtonMetadataNamed.Checked = false;
                    groupBoxMetadataNamedUser.Visible  = false;
                }
                else
                {
                    myRadioButtonMetadataSSPI.Checked = false;
                }

                if (configList["MetadataNamed"] == "True")
                {
                    myRadioButtonMetadataNamed.Checked = true;
                    myRadioButtonMetadataSSPI.Checked  = false;
                    groupBoxMetadataNamedUser.Visible  = true;
                }
                else
                {
                    myRadioButtonMetadataNamed.Checked = false;
                    groupBoxMetadataNamedUser.Visible  = false;
                }

                // Authentication approach for the physical model
                var myRadioButtonPhysicalModelSSPI  = radioButtonPhysicalModelSSPI;
                var myRadioButtonPhysicalModelNamed = radioButtonPhysicalModelNamed;

                if (configList["PhysicalModelSSPI"] == "True")
                {
                    myRadioButtonPhysicalModelSSPI.Checked  = true;
                    myRadioButtonPhysicalModelNamed.Checked = false;
                    groupBoxMetadataNamedUser.Visible       = false;
                }
                else
                {
                    myRadioButtonPhysicalModelSSPI.Checked = false;
                }

                if (configList["PhysicalModelNamed"] == "True")
                {
                    myRadioButtonPhysicalModelNamed.Checked = true;
                    myRadioButtonPhysicalModelSSPI.Checked  = false;
                    groupBoxPhysicalModelNamedUser.Visible  = true;
                }
                else
                {
                    myRadioButtonPhysicalModelNamed.Checked = false;
                    groupBoxPhysicalModelNamedUser.Visible  = false;
                }

                textBoxMetadataUserName.Text      = configList["MetadataUserName"];
                textBoxMetadataPassword.Text      = configList["MetadataPassword"];
                textBoxPhysicalModelUserName.Text = configList["PhysicalModelUserName"];
                textBoxPhysicalModelPassword.Text = configList["PhysicalModelPassword"];

                // Also commit the values to memory
                UpdateConfigurationInMemory();

                richTextBoxInformation.AppendText(@"The file " + chosenFile + " was uploaded successfully. \r\n\r\n");
            }
            catch (Exception ex)
            {
                richTextBoxInformation.AppendText("\r\n\r\nAn error occured while loading the configuration file. The original error is: '" + ex.Message + "'");
            }
        }
        /// <summary>
        ///    Check if the paths exists and create them if necessary
        /// </summary>
        internal static void InitialiseConfigurationPath()
        {
            // Create the configuration directory if it does not exist yet
            try
            {
                if (!Directory.Exists(FormBase.GlobalParameters.ConfigurationPath))
                {
                    Directory.CreateDirectory(FormBase.GlobalParameters.ConfigurationPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Error creation default directory at " + FormBase.GlobalParameters.ConfigurationPath +
                    " the message is " + ex, "An issue has been encountered", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            // Create the output directory if it does not exist yet
            try
            {
                if (!Directory.Exists(FormBase.GlobalParameters.OutputPath))
                {
                    Directory.CreateDirectory(FormBase.GlobalParameters.OutputPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Error creation default directory at " + FormBase.GlobalParameters.OutputPath +
                    " the message is " + ex, "An issue has been encountered", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            // Create a new dummy configuration file
            try
            {
                // Create a default configuration file if the file does not exist as expected
                if (File.Exists(FormBase.GlobalParameters.ConfigurationPath +
                                FormBase.GlobalParameters.ConfigfileName + '_' +
                                FormBase.GlobalParameters.WorkingEnvironment +
                                FormBase.GlobalParameters.FileExtension))
                {
                    return;
                }
                var newEnvironmentConfiguration = new ClassEnvironmentConfiguration();
                newEnvironmentConfiguration.CreateDummyEnvironmentConfiguration(
                    FormBase.GlobalParameters.ConfigurationPath + FormBase.GlobalParameters.ConfigfileName + '_' +
                    FormBase.GlobalParameters.WorkingEnvironment + FormBase.GlobalParameters.FileExtension);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "An error occurred while creation the default Configuration File. The error message is " + ex,
                    "An issue has been encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Create a new dummy validation file
            try
            {
                // Create a default configuration file if the file does not exist as expected
                if (File.Exists(FormBase.GlobalParameters.ConfigurationPath +
                                FormBase.GlobalParameters.ValidationFileName + '_' +
                                FormBase.GlobalParameters.WorkingEnvironment +
                                FormBase.GlobalParameters.FileExtension))
                {
                    return;
                }
                var newEnvironmentConfiguration = new ClassEnvironmentConfiguration();
                newEnvironmentConfiguration.CreateDummyEnvironmentConfiguration(
                    FormBase.GlobalParameters.ConfigurationPath + FormBase.GlobalParameters.ValidationFileName +
                    '_' + FormBase.GlobalParameters.WorkingEnvironment + FormBase.GlobalParameters.FileExtension);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "An error occurred while creation the default Configuration File. The error message is " + ex,
                    "An issue has been encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }