Exemple #1
0
        private void UpdateDBConnectionString(string exePath, SQLServerInfo sqlServerInfo)
        {
            Configuration sipeImporterConfiguration = ConfigurationManager.OpenExeConfiguration(exePath);

            sipeImporterConfiguration.ConnectionStrings.ConnectionStrings[Constants.SIPEIMPORT_DB_CONNECTION_STRING_NAME].ConnectionString = string.Format(@"Data Source={0};Initial Catalog={1};User ID={2};Password={3}", sqlServerInfo.ServerAddress, sqlServerInfo.DatabaseName, sqlServerInfo.UserId, sqlServerInfo.Password);
            sipeImporterConfiguration.Save(ConfigurationSaveMode.Modified, true);
        }
Exemple #2
0
        private void btnRunValidationAndImport_Click(object sender, EventArgs e)
        {
            if (isInterfaceDevExtracted && isGTFSExtracted && !string.IsNullOrEmpty(comboBoxAgency.Text.Trim()) && !string.IsNullOrEmpty(txtSQLServerAddress.Text.Trim()) && !string.IsNullOrEmpty(txtSQLUserId.Text.Trim()) && !string.IsNullOrEmpty(txtSQLPassword.Text.Trim()))
            {
                DisableAll();
                Agency agency = new Agency();
                agency.Name        = comboBoxAgency.Text.Trim();
                agency.ContextName = Constants.AGENCY_CONTEXTE_PREFIX + "_" + comboBoxAgency.Text.Trim();
                //agency.EmailAddress = txtAgencyEmail.Text.Trim();

                SQLServerInfo sQLServerInfo = new SQLServerInfo();
                sQLServerInfo.ServerAddress = txtSQLServerAddress.Text.Trim();
                sQLServerInfo.DatabaseName  = agency.ContextName;
                sQLServerInfo.UserId        = txtSQLUserId.Text.Trim();
                sQLServerInfo.Password      = txtSQLPassword.Text.Trim();

                object[] parameters = new object[] { Operation.RunValidation, agency, sQLServerInfo };
                bgWorker.RunWorkerAsync(parameters);
                // run the sipeimporter.exe process and wait it to finish
                // after finishing run
                //IsFilesExist
            }
            else
            {
                MessageBox.Show("Required fields are missing! Please fill all the fields in the form before proceed.");
            }
        }
        public MemoryClerks(HttpContext context, SQLServerInfo sqlServerInfo)
        {
            this.SQLServerInfo = sqlServerInfo;
            logger             = context.RequestServices.GetRequiredService <ILogger <MemoryClerks> >();

            TSQLQuery = TSQLStore.ProbeTSQL("memory_clerks", this.SQLServerInfo);
        }
Exemple #4
0
        private void _SQLServerInfo(SqlInstances sqlInstances)
        {
            SQLServerInfo sSI = new SQLServerInfo(credentials);

            sSI.SetComputerName(sqlInstances.Server);
            sSI.SetInstance(sqlInstances.ServerInstance);
            sSI.Query();
            _PrintOutput(sSI.GetResults());
        }
        public WaitStats(HttpContext context, SQLServerInfo sqlServerInfo)
        {
            this.SQLServerInfo = sqlServerInfo;
            logger             = context.RequestServices.GetRequiredService <ILogger <WaitStats> >();

            // in theory we should guard this code against concurrent access. It is possibile that
            // two or more threads will work on the same HashSet concurrently because the all
            // tested Waits == null to be true. In practice this will never happen as long as it's only
            // one Prometheus calling our method. For now we will avoid the cost of a mutex, if bugs
            // arise it will be included here.
            if (Waits == null)
            {
                Waits = new HashSet <string>();

                foreach (var file in Program.CommandLineOptions.WaitStats.TemplateFiles)
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(file);
                    logger.LogInformation($"Loading wait stats template to include from {fi.FullName}...");

                    using (System.IO.StreamReader sr = new System.IO.StreamReader(new System.IO.FileStream(fi.FullName,
                                                                                                           System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)))
                    {
                        string str;
                        while ((str = sr.ReadLine()) != null)
                        {
                            if (str.StartsWith("#"))
                            {
                                continue;
                            }

                            Waits.Add(str);
                        }
                    }
                }

                string tsql = TSQLStore.ProbeTSQL("wait_stats", this.SQLServerInfo);
                logger.LogDebug($"Probing wait statistics for {this.SQLServerInfo.Name}, version {this.SQLServerInfo.Version} returned {tsql}");

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                bool fFirst = true;
                foreach (string str in Waits)
                {
                    if (!fFirst)
                    {
                        sb.Append(",\n");
                    }
                    else
                    {
                        fFirst = false;
                    }
                    sb.Append($"  N'{str}'");
                }

                TSQLQuery = tsql.Replace("%%WAITS%%", sb.ToString());
            }
        }
Exemple #6
0
        public PerformanceCounters(HttpContext context, SQLServerInfo sqlServerInfo)
        {
            this.SQLServerInfo = sqlServerInfo;
            logger             = context.RequestServices.GetRequiredService <ILogger <PerformanceCounters> >();

            // in theory we should guard this code against concurrent access. It is possibile that
            // two or more threads will work on the same HashSet concurrently because the all
            // tested Waits == null to be true. In practice this will never happen as long as it's only
            // one Prometheus calling our method. For now we will avoid the cost of a mutex, if bugs
            // arise it will be included here.
            if (EnabledCounters == null)
            {
                EnabledCounters = new HashSet <string>();

                foreach (var file in Program.CommandLineOptions !.PerformanceCounters.TemplateFiles)
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(file);
                    logger.LogInformation($"Loading performance counter template to include from {fi.FullName}...");

                    using (System.IO.StreamReader sr = new System.IO.StreamReader(new System.IO.FileStream(fi.FullName,
                                                                                                           System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)))
                    {
                        string?str;
                        while ((str = sr.ReadLine()) != null)
                        {
                            if (str.StartsWith("#"))
                            {
                                continue;
                            }

                            EnabledCounters.Add(str);
                        }
                    }
                }
            }
        }
 public CustomCounter(HttpContext context, SQLServerInfo sqlServerInfo, CustomCounterConfiguration configuration)
 {
     this.SQLServerInfo = sqlServerInfo;
     logger             = context.RequestServices.GetRequiredService <ILogger <CustomCounter> >();
     this.Configuration = configuration;
 }
Exemple #8
0
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bgWorker.ReportProgress(0);

            object[] parameters = e.Argument as object[];

            //Check if there is a request to cancel the process
            if (bgWorker.CancellationPending)
            {
                e.Cancel = true;
                bgWorker.ReportProgress(0);
                return;
            }

            switch ((Operation)parameters[0])
            {
            case Operation.ExtractInterfaceDev:
                if (parameters.Length == 2)
                {
                    bgWorker.ReportProgress(25);

                    if (DirectoryHelper.RemoveTemporaryWorkSpaceDir(new string[] { Constants.INTERFACEDEV_EXTRACTED_PATH }))
                    {
                        bgWorker.ReportProgress(50);
                        try
                        {
                            ZipFile.ExtractToDirectory(parameters[1].ToString(), Constants.INTERFACEDEV_EXTRACTION_ROOT_PATH);
                            isInterfaceDevExtracted = true;
                        }
                        catch (Exception ex)
                        {
                            currentCompletedOperation = CompletedOperation.InterfaceDevExtractionFailed;
                        }
                    }
                    else
                    {
                        currentCompletedOperation = CompletedOperation.FailedToRemoveExistingInterfaceDevExtractionPath;
                    }

                    bgWorker.ReportProgress(75);
                    e.Result = e.Argument;
                    bgWorker.ReportProgress(100);
                }
                break;

            case Operation.ExtractGTFS:
                if (parameters.Length == 3)
                {
                    bgWorker.ReportProgress(25);
                    string SuperClientPath    = string.Format(Constants.SUPERCLIENT_EXTRACTION_PATH, parameters[2].ToString());
                    string GTFSExtractionPath = string.Format(Constants.GTFS_EXTRACTION_PATH, parameters[2].ToString());
                    if (DirectoryHelper.CleanDirectory(SuperClientPath) && DirectoryHelper.CleanDirectory(GTFSExtractionPath))
                    {
                        bgWorker.ReportProgress(50);
                        try
                        {
                            ZipFile.ExtractToDirectory(parameters[1].ToString(), GTFSExtractionPath);
                            isGTFSExtracted = true;
                        }
                        catch (Exception ex) {
                            currentCompletedOperation = CompletedOperation.GTFSExtractionFailed;
                        }
                        bgWorker.ReportProgress(75);
                    }

                    e.Result = e.Argument;
                    bgWorker.ReportProgress(100);
                }
                break;

            case Operation.RunValidation:
                if (parameters.Length == 3)
                {
                    bgWorker.ReportProgress(20);
                    Agency        agency             = (Agency)parameters[1];
                    SQLServerInfo sQLServerInfo      = (SQLServerInfo)parameters[2];
                    string        sipeImporteExePath = string.Format(Constants.SIPEIMPORT_EXE_PATH, agency.Name);

                    UpdateDBConnectionString(sipeImporteExePath, sQLServerInfo);

                    ProcessHelper sipeImportProcess = new ProcessHelper(sipeImporteExePath);
                    bgWorker.ReportProgress(40);
                    //sipeImportProcess.RunProcess();
                    if (sipeImportProcess.RunProcess())
                    {
                        bgWorker.ReportProgress(60);
                        string SuperClientPath = string.Format(Constants.SUPERCLIENT_EXTRACTION_PATH, agency.Name);
                        string Index_Pour_Calsule_Audio_File_Path = DirectoryHelper.GetIndexPourCapsulesAudioFileLocation(SuperClientPath, agency.Name);
                        bgWorker.ReportProgress(80);
                        if (!string.IsNullOrEmpty(Index_Pour_Calsule_Audio_File_Path))
                        {
                            try
                            {
                                string validatedAudioFileOutputRootPath = string.Format(Constants.VALIDATED_AUDIO_FILE_OUTPUT_PATH, agency.Name);
                                string validatedAudioFileOutputPath     = Path.Combine(validatedAudioFileOutputRootPath, Path.GetFileName(Index_Pour_Calsule_Audio_File_Path));
                                DirectoryHelper.FileCopy(Index_Pour_Calsule_Audio_File_Path, validatedAudioFileOutputPath);
                                //EmailHelper.Instance.Send(agency.EmailAddress, Index_Pour_Calsule_Audio_File_Path);
                                bgWorker.ReportProgress(90);
                                currentCompletedOperation = CompletedOperation.ValidationSuccess;
                                outputAudioFilePath       = validatedAudioFileOutputPath;
                            }
                            catch (Exception ex)
                            {
                                currentCompletedOperation = CompletedOperation.FaildToCopyAudioFile;
                            }
                        }
                        else
                        {
                            currentCompletedOperation = CompletedOperation.ValidationFailed;
                        }
                    }
                    else
                    {
                        currentCompletedOperation = CompletedOperation.ValidationFailed;
                    }

                    e.Result = e.Argument;
                    bgWorker.ReportProgress(100);
                }
                break;

            default:
                break;
            }
        }
 public WorkerThread(HttpContext context, SQLServerInfo sqlServerInfo)
 {
     this.SQLServerInfo = sqlServerInfo;
     logger             = context.RequestServices.GetRequiredService <ILogger <WorkerThread> >();
 }