private void button_Build_Click(object sender, EventArgs e) { if (!this.checkBox_blocks.Checked && !this.checkBox_functions.Checked) { this.label_Warning.ForeColor = Color.Red; this.label_Warning.Text = "Please check on at least one granularity type!"; return; } this.Close(); if (this.checkBox_blocks.Checked) { CloneGenealogy.mapFileCollection = AdjacentVersionMapping.GetMapFileCollection(true); CloneGenealogy.BuildAndSaveAll(CloneGenealogy.mapFileCollection); MessageBox.Show("Building Genealogy on Blocks level FINISHED!"); } if (this.checkBox_functions.Checked) { CloneGenealogy.mapFileCollection = AdjacentVersionMapping.GetMapFileCollection(false); CloneGenealogy.BuildAndSaveAll(CloneGenealogy.mapFileCollection); MessageBox.Show("Building Genealogy on Functions level FINISHED!"); } }
//静态方法,根据指定的映射文件集生成所有克隆家系 public static void BuildAndSaveAll(List <string> mapFileCollection) { //CloneGenealogy.genealogyList=new List<CloneGenealogy>(); if (!IsMapFileCollectionSuccessive(mapFileCollection)) //判断版本集是否连续 { MessageBox.Show("Map Files NOT Successive! Fix it and Try again!"); return; } List <XmlDocument> mapXmlCollection = new List <XmlDocument>(); //获得存放相邻版本映射信息的XmlDocument对象集合 foreach (string fileName in mapFileCollection) { mapXmlCollection.Add(AdjacentVersionMapping.GetXmlDocument(fileName)); } //寻找每个版本中新产生的CG,以其为根建立克隆家系 int index = -1; int id = 0; CloneGenealogy.SingleCgGenealogyList = new List <SingleCgGenealogy>(); //初始化单克隆群家系列表 foreach (XmlDocument mapXml in mapXmlCollection) { index++; string srcFileName, destFileName; //保存源和目标版本的CRD文件名(不含路径) srcFileName = mapXml.DocumentElement.ChildNodes[0].InnerText; destFileName = mapXml.DocumentElement.ChildNodes[1].InnerText; string prev = "0"; //记录前一个被构造的CG的id,避免重复构造(针对分裂的情况) #region 如果是第一个mapXml,为源版本中所有克隆群构建以其为根的克隆家系 if (index == 0) { #region 对每个CGMap中的源CG,以其为根构建克隆家系 foreach (XmlElement cgMapNode in mapXml.DocumentElement.SelectNodes("CGMap")) { CloneGroupMapping cgMapping = new CloneGroupMapping(); cgMapping.CreateCGMapppingFromCGMapNode(cgMapNode); //根据CGMap元素构造CloneGroupMapping对象 if (cgMapping.srcCGInfo.id != prev) { CloneGenealogy cloneGenealogy = new CloneGenealogy(); cloneGenealogy.BuildForCG(srcFileName, cgMapping.srcCGInfo, mapXmlCollection, ref id); cloneGenealogy.SaveGenealogyToXml(); //CloneGenealogy.genealogyList.Add(cloneGenealogy); prev = cgMapping.srcCGInfo.id; } } #endregion #region 为UnMappedSrcCG中每个CG构建克隆家系 if (mapXml.DocumentElement.SelectSingleNode("UnMappedSrcCG") != null) { foreach (XmlElement unMappedSrcCGNode in mapXml.DocumentElement.SelectSingleNode("UnMappedSrcCG").ChildNodes) { CGInfo cgInfo = new CGInfo(); cgInfo.id = unMappedSrcCGNode.GetAttribute("id"); cgInfo.size = int.Parse(unMappedSrcCGNode.GetAttribute("size")); CloneGenealogy cloneGenealogy = new CloneGenealogy(); //cloneGenealogy.BuildForCG(srcFileName, cgInfo, mapXmlCollection, ref id); //对于第一个版本中的UnMappedSrcCG,不需要此语句 SingleCgGenealogy sGenealogy = new CloneEvolutionAnalyzer.SingleCgGenealogy(); if (CloneGenealogy.granularity == GranularityType.BLOCKS) { sGenealogy.version = srcFileName.Substring(0, srcFileName.IndexOf("_blocks-")); } else { sGenealogy.version = srcFileName.Substring(0, srcFileName.IndexOf("_functions-")); } sGenealogy.cgInfo = cgInfo; CloneGenealogy.SingleCgGenealogyList.Add(sGenealogy); //cloneGenealogy.SaveGenealogyToXml(); //CloneGenealogy.genealogyList.Add(cloneGenealogy); } } #endregion } #endregion #region 对于所有mapXml,为UnMappedDestCG中每个CG构建克隆家系 if (mapXml.DocumentElement.SelectSingleNode("UnMappedDestCG") != null) { foreach (XmlElement unMappedDestCGNode in mapXml.DocumentElement.SelectSingleNode("UnMappedDestCG").ChildNodes) { CGInfo cgInfo = new CGInfo(); cgInfo.id = unMappedDestCGNode.GetAttribute("id"); cgInfo.size = int.Parse(unMappedDestCGNode.GetAttribute("size")); CloneGenealogy cloneGenealogy = new CloneGenealogy(); cloneGenealogy.BuildForCG(destFileName, cgInfo, mapXmlCollection, ref id); if (cloneGenealogy.evolutionList != null && cloneGenealogy.evolutionList.Count != 0) { cloneGenealogy.SaveGenealogyToXml(); } else { SingleCgGenealogy sGenealogy = new CloneEvolutionAnalyzer.SingleCgGenealogy(); if (CloneGenealogy.granularity == GranularityType.BLOCKS) { sGenealogy.version = destFileName.Substring(0, destFileName.IndexOf("_blocks-")); } else { sGenealogy.version = destFileName.Substring(0, destFileName.IndexOf("_functions-")); } sGenealogy.cgInfo = cgInfo; CloneGenealogy.SingleCgGenealogyList.Add(sGenealogy); } //CloneGenealogy.genealogyList.Add(cloneGenealogy); } } #endregion } SaveSingleCgGenealogiesToXml(); //保存SingleCgGenealogies.xml文件 }
private void button_MapAll_Click(object sender, EventArgs e) { if (!this.checkBox_functions.Checked && !this.checkBox_blocks.Checked) { this.label_Warning2.ForeColor = Color.Red; this.label_Warning2.Text = "Please check on at least one granularity type!"; return; } this.Close(); Global.mappingVersionRange = "ALLVERSIONS"; //置映射范围为全部版本 Global.mainForm.GetCRDDirFromTreeView1(); //获取CRD文件所在文件夹路径 DirectoryInfo dir = null; #region 在funtions粒度上映射所有版本 if (this.checkBox_functions.Checked) { try { dir = new DirectoryInfo(CloneRegionDescriptor.CrdDir + @"\functions"); } catch (Exception ee) { MessageBox.Show("Get CRD directory of functions failed! " + ee.Message); } FileInfo[] crdFiles = null; try { crdFiles = dir.GetFiles(); } catch (Exception ee) { MessageBox.Show("Get CRD files on functions failed! " + ee.Message); } List <string> fileNames = new List <string>(); foreach (FileInfo info in crdFiles) { if ((info.Attributes & FileAttributes.Hidden) != 0) //不处理隐藏文件 { continue; } else { //选出所有带有"_functions-"标签的-withCRD.xml文件,记录它们的文件名(不包含路径) if (info.Name.IndexOf("-withCRD.xml") != -1 && info.Name.IndexOf("_functions-") != -1) { fileNames.Add(info.Name); } } } if (fileNames.Count > 1) { for (int i = 0; i < fileNames.Count - 1; i++) { CGMapEventArgs ee = new CGMapEventArgs(); ee.srcStr = fileNames[i]; ee.destStr = fileNames[i + 1]; //OnMapSettingFinished(ee); //不采取触发事件的方式,原因:并发进程的处理问题?? AdjacentVersionMapping adjMap = new AdjacentVersionMapping(); adjMap.OnStartMapping(this, ee); //直接调用事件的响应函数OnStartMapping } MessageBox.Show("Mapping All Versions on Functions level Finished!"); } else { MessageBox.Show("No withCRD.xml file at Functions level for mapping!"); } if (Global.MapState != 2) //置映射状态为完成某粒度下所有相邻版本的映射 { Global.MapState = 2; } } #endregion #region 在blocks粒度上映射所有版本 if (this.checkBox_blocks.Checked) { try { dir = new DirectoryInfo(CloneRegionDescriptor.CrdDir + @"\blocks"); } catch (Exception ee) { MessageBox.Show("Get CRD directory of blocks failed! " + ee.Message); } FileInfo[] crdFiles = null; try { crdFiles = dir.GetFiles(); } catch (Exception ee) { MessageBox.Show("Get CRD files on blocks failed! " + ee.Message); } List <string> fileNames = new List <string>(); foreach (FileInfo info in crdFiles) { if ((info.Attributes & FileAttributes.Hidden) != 0) //不处理隐藏文件 { continue; } else { //选出所有带有"_blocks-"标签的-withCRD.xml文件,记录它们的文件名(不包含路径) if (info.Name.IndexOf("-withCRD.xml") != -1 && info.Name.IndexOf("_blocks-") != -1) { fileNames.Add(info.Name); } } } if (fileNames.Count > 1) { for (int i = 0; i < fileNames.Count - 1; i++) { CGMapEventArgs ee = new CGMapEventArgs(); ee.srcStr = fileNames[i]; ee.destStr = fileNames[i + 1]; //OnMapSettingFinished(ee); //不采取触发事件的方式,原因:并发进程的处理问题?? AdjacentVersionMapping adjMap = new AdjacentVersionMapping(); adjMap.OnStartMapping(this, ee); //直接调用事件的响应函数OnStartMapping } MessageBox.Show("Mapping All Versions on Blocks level Finished!"); } else { MessageBox.Show("No withCRD.xml files at Blocks level for mapping!"); } if (Global.MapState != 2) { Global.MapState = 2; } } #endregion }