Ejemplo n.º 1
0
        }// End of PM configuration

        // Function that set and get Database config file and insert to database.
        public void databaseConfigGen(string projectCode, string quarter)
        {
            string timeStamp = GetTimestamp(DateTime.Now);
            string tempPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), "TEMP", "DB_" + timeStamp);
            Directory.CreateDirectory(tempPath);
            string fileName = DBConfigUpload.FileName.ToString();
            string filePath = Path.Combine(tempPath, fileName);
            DBConfigUpload.PostedFile.SaveAs(Path.Combine(tempPath, fileName));

            string backupDatabaseFile = BackupDatabaseFile.FileName.ToString();
            string backupDatabaseFilePath = Path.Combine(tempPath, backupDatabaseFile);
            BackupDatabaseFile.PostedFile.SaveAs(Path.Combine(tempPath, backupDatabaseFile));

            string backupControlFile = BackupControlFile.FileName.ToString();
            string backupControlFilePath = Path.Combine(tempPath, backupControlFile);
            BackupControlFile.PostedFile.SaveAs(Path.Combine(tempPath, backupControlFile));

            string backupArcheiveFile = BackupArchieveFile.FileName.ToString();
            string backupArcheiveFilePath = Path.Combine(tempPath, backupArcheiveFile);
            BackupArchieveFile.PostedFile.SaveAs(Path.Combine(tempPath, backupArcheiveFile));
            string backupDBF, backupCFF, backupALF;

            string alertFile = AlertLogFile.FileName.ToString();
            string alertFilePath = Path.Combine(tempPath, alertFile);
            AlertLogFile.PostedFile.SaveAs(Path.Combine(tempPath, alertFile));

            using (TextReader reader = File.OpenText(backupDatabaseFilePath)) {
                backupDBF = reader.ReadToEnd();                
            }

            using (TextReader reader = File.OpenText(backupControlFilePath))
            {
               backupCFF = reader.ReadToEnd();

            }

            using (TextReader reader = File.OpenText(backupArcheiveFilePath))
            {
               backupALF = reader.ReadToEnd();

            }
            dbHelper.InsertBackupDatabase(projectCode, quarter, backupDBF, backupCFF, backupALF);

            string alertLog;
            List<object> alertObj = new List<object>();
            using (TextReader reader = File.OpenText(alertFilePath))
            {
                while ((alertLog = reader.ReadLine()) != null)
                {
                    //if(alertLog.Contains("ora-"))
                       // alertObj.Add(alertLog);
                    dbHelper.InsertAlert(projectCode, quarter, alertLog);
                }
            }

             

            SetOfTableList tables = null;
            OracleInformation oracleInfo = new OracleInformation();

            using (TextReader logFile = File.OpenText(filePath))
            {
                tables = oracleInfo.readInputLog(logFile);
            }
                tableListWord tableWord;
                string binFolderPath = Server.MapPath("bin");
                string path = binFolderPath + "/Debug/config/4_1.txt";

            using (TextReader inFile = File.OpenText(path))
            {
                tableWord = oracleInfo.readOutputTable(inFile, tables);
                List<object[]> database4_1Obj = new List<object[]>();
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    if (tableWord.getRow(k)[0].Equals("Temp tablespace size"))
                    {
                        object[] obj1 = (object[])tableWord.getRows()[k];
                        tableListWord obj2 = (tableListWord)obj1[1];
                        List<object[]> database4_1_1Obj = new List<object[]>();
                        for (int z = 0; z < obj2.getRows().Count; z++)
                        {
                            object[] subDetail = (object[])obj2.getRows()[z];
                            database4_1_1Obj.Add(new object[] { subDetail[0].ToString(), subDetail[1].ToString()});
                        }
                        dbHelper.InsertTempTableSize(projectCode, quarter, database4_1_1Obj);
                    }
                    else if (tableWord.getRow(k)[0].Equals("Tablespace size"))
                    {
                        object[] obj1 = (object[])tableWord.getRows()[k];
                        tableListWord obj2 = (tableListWord)obj1[1];
                        List<object[]> database4_1_2Obj = new List<object[]>();
                        for (int z = 0; z < obj2.getRows().Count; z++)
                        {
                            object[] subDetail = (object[])obj2.getRows()[z];
                            database4_1_2Obj.Add(new object[] { subDetail[0].ToString(), subDetail[1].ToString() });
                        }
                        dbHelper.InsertTableSize(projectCode, quarter, database4_1_2Obj);
                    }
                    else
                    {
                        database4_1Obj.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1] });
                    }
                }
                dbHelper.InsertDatabaseConfiguration(projectCode, quarter, database4_1Obj);
            }
            path = binFolderPath + "/Debug/config/4_2.txt";
            using (TextReader inFile = File.OpenText(path))
            {
                tableWord = oracleInfo.readOutputTable(inFile, tables);
                List<object[]> database4_2Obj = new List<object[]>();
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    database4_2Obj.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1] });
                }
                dbHelper.InsertDatabaseParameter(projectCode, quarter, database4_2Obj);
            }   
            tableList tableTmp = null;
            tableTmp = tables.getTableList("4_4@Database file@1");
            if (tableTmp != null)
            {
                List<object[]> databaseFileList = new List<object[]>();
                tableWord = new tableListWord(tableTmp);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    databaseFileList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2], tableWord.getRow(k)[3], tableWord.getRow(k)[4], tableWord.getRow(k)[5] });
                }
                dbHelper.InsertDatabaseFile(projectCode, quarter, databaseFileList);
            }

            tableTmp = null;
            tableTmp = tables.getTableList("4_5@Temp file@1");
            if (tableTmp != null)
            {
                List<object[]> tempFileList = new List<object[]>();
                tableWord = new tableListWord(tableTmp);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    tempFileList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2], tableWord.getRow(k)[3], tableWord.getRow(k)[4], tableWord.getRow(k)[5] });
                }
                dbHelper.InsertTempFile(projectCode, quarter, tempFileList);
            }

            tableTmp = null;
            tableTmp = tables.getTableList("4_6@Redo log file@1");
            if (tableTmp != null)
            {
                List<object[]> redoLogList = new List<object[]>();
                tableWord = new tableListWord(tableTmp);
                /// Convert B to MB (***warning: available only MB is string that represent integer)
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    object[] rowTmp = tableWord.getRow(k);
                    if (rowTmp[2] is string)
                    {
                        rowTmp[2] = (float.Parse((string)(rowTmp[2])) / (1024 * 1024)).ToString();
                        redoLogList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], rowTmp[2]});
                    }
                    else
                    {
                        redoLogList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2] });
                    }
                }
                dbHelper.InsertRedoLogFile(projectCode, quarter, redoLogList);
            }
            tableTmp = null;
            tableTmp = tables.getTableList("4_7@Controlfile@1");
            if (tableTmp != null)
            {
                List<object> controlFileList = new List<object>();
                tableWord = new tableListWord(tableTmp);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    controlFileList.Add(tableWord.getRow(k)[0]);
                }
                dbHelper.InsertControlFile(projectCode, quarter, controlFileList);
            }

            tableTmp = null;
            tableTmp = tables.getTableList("4_8@Jobs@1");
            if (tableTmp != null)
            {
                List<object[]> dailyList = new List<object[]>();
                int[] indexA = { 1024, 3, 1024 };
                tableWord = new tableListWord(tableTmp, indexA);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    dailyList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2] });
                }
                dbHelper.InsertDiaryWorksheet(projectCode, quarter, dailyList);
            }
            path = binFolderPath + "/Debug/config/4_9.txt";
            using (TextReader inFile = File.OpenText(path))
            {
                tableWord = oracleInfo.readOutputTable(inFile, tables);
                List<object[]> monthLyList = new List<object[]>();
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    monthLyList.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2] });
                }
                dbHelper.InsertMonthlyWorksheet(projectCode, quarter, monthLyList);
            }

            //////////////////////////////////////////////////////////    O5    ////////////////////////////////////////////////////////// 
            
            path = binFolderPath + "/Debug/config/5_1.txt";
            using (TextReader inFile = File.OpenText(path))
            {
                tableWord = oracleInfo.readOutputTable(inFile, tables);
                List<object[]> performanceReview = new List<object[]>();

                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    if (k == 0)
                    {
                        object[] obj1 = (object[])tableWord.getRows()[k];
                        tableListWord obj2 = (tableListWord)obj1[1];
                        List<object[]> hitRatioList = new List<object[]>();
                        for (int z = 0; z < obj2.getRows().Count; z++)
                        {
                            object[] subDetail = (object[])obj2.getRows()[z];
                            hitRatioList.Add(new object[] {subDetail[0].ToString(), subDetail[1].ToString()});
                        }
                        dbHelper.InsertHitRatio(projectCode, quarter, hitRatioList);
                    }
                    else if (k == 1)
                    {
                        object[] obj1 = (object[])tableWord.getRows()[k];
                        tableListWord obj2 = (tableListWord)obj1[1];
                        List<object[]> pinRatioList = new List<object[]>();
                        for (int z = 0; z < obj2.getRows().Count; z++)
                        {
                            object[] subDetail = (object[])obj2.getRows()[z];
                            pinRatioList.Add(new object[] {subDetail[0].ToString(), subDetail[1].ToString(), subDetail[2].ToString() });
                        }
                        dbHelper.InsertHitRatio(projectCode, quarter, pinRatioList);
                    }
                    else if (k == 14)
                    {
                        object[] obj1 = (object[])tableWord.getRows()[k];
                        tableListWord obj2 = (tableListWord)obj1[1];
                        List<object[]> undoList = new List<object[]>();
                        for (int z = 0; z < obj2.getRows().Count; z++)
                        {
                            object[] subDetail = (object[])obj2.getRows()[z];
                            undoList.Add(new object[] { subDetail[0].ToString(), subDetail[1].ToString(), subDetail[2].ToString() });
                        }
                        dbHelper.InsertUndoSegmentsSize(projectCode, quarter, undoList);
                    }
                    else
                    {
                        performanceReview.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1] });
                    }
                }
                dbHelper.InsertPerformanceReview(projectCode, quarter, performanceReview);
            }

            // Table fress space.
            tableTmp = null;
            tableTmp = tables.getTableList("6_1@Table free space@1");
            if (tableTmp != null)
            {
                tableWord = new tableListWord(tableTmp);
                List<object[]> list = new List<object[]>();
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    list.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2], tableWord.getRow(k)[3], tableWord.getRow(k)[4] });
                }
                dbHelper.InsertTablespaceFreespace(projectCode, quarter, list);
            }

            // Temptable and tablespace
            tableTmp = null;
            tableTmp = tables.getTableList("7_1@default tbs/temp per user@1");
            if (tableTmp != null)
            {
                List<object[]> list = new List<object[]>();
                tableWord = new tableListWord(tableTmp);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    list.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2]});
                }
                dbHelper.InsertTablespaceAndTempTablespace(projectCode, quarter, list);
            }

            // Database registration Insert.
            tableTmp = null;
            tableTmp = tables.getTableList("8_1@dba registry@1");
            if (tableTmp != null)
            {
                List<object[]> list = new List<object[]>();
                tableWord = new tableListWord(tableTmp);
                for (int k = 0; k < tableWord.getRowNumber(); k++)
                {
                    list.Add(new object[] { tableWord.getRow(k)[0], tableWord.getRow(k)[1], tableWord.getRow(k)[2], tableWord.getRow(k)[3] });
                }
                dbHelper.InsertDatabaseRegistry(projectCode, quarter, list);
            }

            // Growth Rate Insert.
            string currentAllocate, currentUsed, allocateGrowth, useGrowth;
            currentAllocate = currAlloc.Text;
            currentUsed = usedAlloc.Text;
            allocateGrowth = allocGrowth.Text;
            useGrowth = usedGrowth.Text;

            object[] growthRateList = new object[] { currentAllocate, currentUsed, allocateGrowth, useGrowth };
            dbHelper.InsertDatabaseGrowthRate(projectCode, quarter, growthRateList);



            //Delete Folder temp.
            Directory.Delete(tempPath,true);
        }