コード例 #1
0
        private void buttonGenAllDiff_Click(object sender, EventArgs e) // 批量生成差异结果
        {
            string outFolder = FileFolderHelper.BrowserFolder("请选择输出路径。");

            if (outFolder.Length == 0)
            {
                MessageBox.Show("你取消了此次命令。");
                return;
            }

            string        strIniFile = Application.StartupPath + "/config_public.ini";
            StringBuilder sb         = new StringBuilder(255);

            FileFolderHelper.ReadIniFile("DiffDirList", "Count", "", sb, 255, strIniFile);
            int pathCount = Convert.ToInt32(sb.ToString());

            string[] paths = new string[pathCount];

            for (int i = 1; i <= pathCount; i++)
            {
                FileFolderHelper.ReadIniFile("DiffDirList", "Dir" + i.ToString(), "", sb, 255, strIniFile);
                paths[i - 1] = sb.ToString();
            }

            m_diffColInfo = new Hashtable();
            FileFolderHelper.ReadIniFile("DiffColumns", "Count", "", sb, 255, strIniFile);
            int diffColDescCount = Convert.ToInt32(sb.ToString());

            for (int i = 1; i <= diffColDescCount; i++)
            {
                FileFolderHelper.ReadIniFile("DiffColumns", "Table" + i.ToString(), "", sb, 255, strIniFile);
                string      tblname = sb.ToString();
                DiffColInfo dci     = new DiffColInfo();
                FileFolderHelper.ReadIniFile("DiffColumns", "Keys" + i.ToString(), "", sb, 255, strIniFile);
                dci.keys = sb.ToString();
                FileFolderHelper.ReadIniFile("DiffColumns", "Display" + i.ToString(), "", sb, 255, strIniFile);
                dci.displays = sb.ToString();
                m_diffColInfo.Add(tblname.ToLower(), dci);
            }

            m_diffLog = string.Empty;
            foreach (string dir in paths)
            {
                GenerateTabDiffOutput(dir, outFolder);
            }
            FileFolderHelper.StringToFile(m_diffLog, Path.Combine(Application.StartupPath, "diff.log"));
        }
コード例 #2
0
        private void UpdateHistory(string filename)
        {
            string strfile    = Path.Combine(Application.StartupPath, "history.txt");
            string strHistory = FileFolderHelper.FileToString(strfile);

            string[] historys = strHistory.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (historys.Length < 4)
            {
                bool bHistoryContainsThisDoc = false;
                foreach (string history in historys)
                {
                    if (history == filename)
                    {
                        bHistoryContainsThisDoc = true;
                        break;
                    }
                }

                if (!bHistoryContainsThisDoc)
                {
                    string strContent = strHistory + (historys.Length == 0 ? string.Empty : "\r\n") + filename;
                    FileFolderHelper.StringToFile(strContent, strfile);
                }
            }
            else
            {
                bool bHistoryContainsThisDoc = false;
                foreach (string history in historys)
                {
                    if (history == filename)
                    {
                        bHistoryContainsThisDoc = true;
                        break;
                    }
                }

                if (!bHistoryContainsThisDoc)
                {
                    string[] newhistorys = new string[] { historys[1], historys[2], historys[3], filename };
                    string   content     = newhistorys[0] + "\r\n" + newhistorys[1] + "\r\n" + newhistorys[2] + "\r\n" + newhistorys[3];
                    FileFolderHelper.StringToFile(content, strfile);
                }
            }
        }
コード例 #3
0
        private void GenerateTabDiffOutput(string dir, string outFolder)
        {
            string dir1 = Path.Combine(leftFolder, dir);

            DirectoryInfo leftDirInfo = new DirectoryInfo(dir1);

            foreach (FileInfo fi in leftDirInfo.GetFiles())
            {
                if (fi.Extension.ToLower() == ".tab" || fi.Extension.ToLower() == ".txt")
                {
                    string rightFileName = fi.FullName.Replace(leftFolder, rightFolder);
                    if (!File.Exists(rightFileName))
                    {
                        continue;
                    }

                    if (FileFolderHelper.FileToString(fi.FullName) == FileFolderHelper.FileToString(rightFileName))
                    {
                        continue;
                    }

                    DiffColInfo info = FindDiffColInfo(fi.Name);

                    string        postfix      = "tab";
                    string        keys         = string.Empty;
                    string        namefield    = string.Empty;
                    string        rowcondition = string.Empty;
                    string        content      = string.Empty;
                    string        outputbasic  = string.Empty;
                    List <string> diffCols1    = new List <string>();
                    List <string> diffCols2    = new List <string>();

                    if (info != null)
                    {
                        keys      = info.keys;
                        namefield = info.displays;
                        if (keys == "$" || namefield == "$") // ignore this file
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!AnynalizeTabKeysAndNameField(fi.FullName, ref keys, ref namefield))
                        {
                            continue;
                        }
                    }

                    // try here
                    try
                    {
                        DiffGenerator.DiffGen(fi.FullName, rightFileName, postfix, keys, namefield, rowcondition, ref content, ref outputbasic, ref diffCols1, ref diffCols2);
                    }
                    catch (System.Exception e)
                    {
                        string strThisLog = string.Format("文件{0}的差异结果生成有误:{1}。\r\n", fi.FullName, e.Message);
                        m_diffLog += strThisLog;
                    }

                    string destFilename = fi.FullName.Replace(leftFolder, outFolder);
                    FileFolderHelper.CreatePath(destFilename);
                    FileFolderHelper.StringToFile(content, destFilename);
                }
            }

            foreach (DirectoryInfo di in leftDirInfo.GetDirectories())
            {
                if (di.Name.ToLower().Contains("svn"))
                {
                    continue;
                }

                GenerateTabDiffOutput(di.FullName, outFolder);
            }
        }