Example #1
0
        private void findCorruptedFiles_Click(object sender, EventArgs e)
        {
            int           fileColumnIndex = Grid.Columns["File Name"].Index;
            List <string> targetFiles     = SystemMessage.getProblemFiles();
            List <string> problemFiles    = new List <string>();
            List <string> corruptedFiles  = new List <string>();
            Dictionary <string, List <string> > msgDict = new Dictionary <string, List <string> >();

            foreach (DataGridViewRow row in Grid.Rows)
            {
                bool   corrupted = false;
                string fileName  = row.Cells[fileColumnIndex].Value.ToString();
                string filePath  = txtPath.Text + "\\" + fileName;
                if (!fileName.Contains("\\"))
                {
                    fileName = Regex.Split(txtPath.Text, @"\\").Last() + "/" + fileName;
                }
                FileName = fileName.Replace("\\", "/");
                string dbFileName = FileName.Replace(".cs", "").ToLower();

                if (!targetFiles.Contains(dbFileName))
                {
                    continue;
                }

                List <string> allLines     = File.ReadAllLines(filePath).ToList();
                List <string> linesWithMsg = allLines.Where(line => line.Contains("m_msg")).ToList();
                if (linesWithMsg.Count == 0)
                {
                    continue;
                }

                List <string> inFileMsgs = new List <string>();
                foreach (string line in linesWithMsg)
                {
                    MatchCollection matches = Regex.Matches(line, @"T\d+");
                    foreach (Match match in matches)
                    {
                        if (!inFileMsgs.Contains(match.ToString()))
                        {
                            inFileMsgs.Add(match.ToString());
                        }
                        else
                        {
                            console.AppendText(match.ToString() + " duplicated in " + FileName + ". \r\n");
                            corrupted = true;
                        }
                    }
                }
                if (!msgDict.ContainsKey(dbFileName))
                {
                    msgDict.Add(dbFileName, inFileMsgs);
                }
                else
                {
                    List <string> msgsInCurrentFile = msgDict[dbFileName];
                    foreach (string msg in inFileMsgs)
                    {
                        if (!msgsInCurrentFile.Contains(msg))
                        {
                            msgsInCurrentFile.Add(msg);
                        }
                        else
                        {
                            console.AppendText(msg + " cross file duplicated in " + FileName + ". \r\n");
                            if (!problemFiles.Contains(FileName))
                            {
                                problemFiles.Add(FileName);
                            }
                        }
                    }
                }

                if (corrupted)
                {
                    corruptedFiles.Add(FileName);
                }
            }
            console.AppendText("\r\nDone\r\n");
            console.AppendText(corruptedFiles.Count + " files corrupted. \r\n");
            console.AppendText(String.Join("\r\n", corruptedFiles).ToString() + "\r\n\r\n");
            console.AppendText(problemFiles.Count + " files cross file duplicated. \r\n");
            console.AppendText(String.Join("\r\n", problemFiles).ToString() + "\r\n\r\n");
            console.ScrollToCaret();
        }
Example #2
0
        private void CheckMessageExist()
        {
            int           fileColumnIndex = Grid.Columns["File Name"].Index;
            SqlConnection conn            = SystemMessage.InitSqlConnection();
            SqlCommand    command         = new SqlCommand();
            string        sql             = "";

            foreach (DataGridViewRow row in Grid.Rows)
            {
                string fileName = row.Cells[fileColumnIndex].Value.ToString();
                string filePath = txtPath.Text + "\\" + fileName;
                if (!fileName.Contains("\\"))
                {
                    fileName = Regex.Split(txtPath.Text, @"\\").Last() + "/" + fileName;
                }
                FileName = fileName.Replace("\\", "/");

                List <string> allLines     = File.ReadAllLines(filePath).ToList();
                List <string> linesWithMsg = allLines.Where(line => line.Contains("m_msg") && !line.Contains("//")).ToList();
                if (linesWithMsg.Count == 0)
                {
                    continue;
                }
                List <string> inFileMsgs = new List <string>();
                List <string> existMsgs  = new List <string>();
                foreach (string line in linesWithMsg)
                {
                    Regex           rx      = new Regex(@"T\d+");
                    MatchCollection matches = rx.Matches(line);
                    foreach (Match match in matches)
                    {
                        inFileMsgs.Add(match.ToString());
                    }
                }
                sql = "SELECT MsgId FROM systemmessage WHERE FILENAME = '" + FileName.Replace(".cs", "") + "'";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataTable      dt = new DataTable();
                try
                {
                    da.Fill(dt);
                }
                catch
                {
                    dt = null;
                }
                da.Dispose();
                if (dt == null && inFileMsgs.Count != 0)
                {
                    console.AppendText(fileName + " has msg issues. \r\n");
                    console.AppendText(String.Join(", ", inFileMsgs).ToString() + " not found in database. \r\n");
                    console.ScrollToCaret();
                }

                foreach (DataRow dtrow in dt.Rows)
                {
                    existMsgs.Add(dtrow[0].ToString());
                }

                foreach (string msg in inFileMsgs)
                {
                    if (!existMsgs.Contains(msg))
                    {
                        console.AppendText(msg + " not found in database for file " + fileName + ". \r\n");
                        console.ScrollToCaret();
                    }
                }
            }
            console.AppendText("\r\nDone\r\n");
            console.ScrollToCaret();
            conn.Close();
        }