VarConfig.AcronymLevelRow GetAddAferLevel(VarConfig.AcronymTypeRow internalType, VarConfig.AcronymLevelRow externalLevel) {//find the level after which to insert the new level //first collect all levels before the new level in the external type ... List <VarConfig.AcronymLevelRow> preRows = new List <VarConfig.AcronymLevelRow>(); foreach (VarConfig.AcronymLevelRow externalSiblingLevel in externalLevel.AcronymTypeRow.GetAcronymLevelRows()) { if (externalSiblingLevel.Index < externalLevel.Index) { preRows.Add(externalSiblingLevel); } } preRows = (from preRow in preRows select preRow).OrderBy(preRow => preRow.Index).ToList(); //... and order them by index //then try to find the (equivalent of the) new level's direct predecessor in the internal type, //if found - this is the level where to add the new one after, if not found - try with the next to the direct predecessor, and so on VarConfig.AcronymLevelRow addAfterLevel = null; for (int index = preRows.Count - 1; index >= 0; --index) { foreach (VarConfig.AcronymLevelRow internalSiblingLevel in internalType.GetAcronymLevelRows()) { if (internalSiblingLevel.Name.ToLower() == preRows.ElementAt(index).Name.ToLower()) { addAfterLevel = internalSiblingLevel; break; } } if (addAfterLevel != null) { break; } } return(addAfterLevel); }
TreeListNode AcronymTree_AddNode(TreeListNode parentNode, object nodeTag, string action = "") { TreeListNode node = treeAcronyms.AppendNode(null, parentNode); if (action == string.Empty) { node.SetValue(colPerformAcronyms, string.Empty); //do not show check box if just "header", e.g. type containing added/deleted/changed acronyms/levels, but not changed itself } else { node.SetValue(colPerformAcronyms, _actionDefaultPerform); } node.SetValue(colActionAcronyms, action); node.SetValue(colInfoAcronyms, string.Empty); node.Tag = nodeTag; //somewhat unelegant procedure, which serves only to determin the content of colAcronym string acronymText = string.Empty; VarConfig.AcronymTypeRow typeRow = null; VarConfig.AcronymLevelRow levelRow = null; VarConfig.AcronymRow acronymRow = null; bool tagIsDictionary = action == _actionChange || action == string.Empty; if (parentNode == null) { typeRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymTypeRow : (nodeTag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0); } else if (parentNode != null && parentNode.ParentNode == null) { levelRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymLevelRow : (nodeTag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0); } else { acronymRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymRow : (nodeTag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Keys.ElementAt(0); } if (typeRow != null) { acronymText = typeRow.ShortName.ToUpper() + " (" + typeRow.LongName + ")"; } if (levelRow != null) { acronymText = levelRow.Name; } if (acronymRow != null) { acronymText = acronymRow.Name + " (" + acronymRow.Description + ")"; } node.SetValue(colAcronym, acronymText); return(node); }
internal static bool IsTypeNode(TreeListNode node) { if (node == null || node.Tag == null) { return(false); } VarConfig.AcronymTypeRow typeRow = node.Tag as VarConfig.AcronymTypeRow; return(typeRow != null); }
VarConfig.AcronymLevelRow PerformAddLevel(VarConfig.AcronymTypeRow internalType, VarConfig.AcronymLevelRow externalLevel, VarConfig.AcronymLevelRow addAfterRow) { VarConfig.AcronymLevelRow internalLevel = _varConfigFacade.AddAcronymLevelRow(internalType, addAfterRow, externalLevel.Name); //todo: null is not correct foreach (VarConfig.AcronymRow externalAcronym in externalLevel.GetAcronymRows()) { PerformAddAcronym(internalLevel, externalAcronym); } _varConfigFacade.Commit(); return(internalLevel); }
void PerformAddType(VarConfig.AcronymTypeRow externalType) { VarConfig.AcronymTypeRow internalType = _varConfigFacade.AddAcronymTypeRow(externalType.LongName, externalType.ShortName); VarConfig.AcronymLevelRow addAfterRow = null; foreach (VarConfig.AcronymLevelRow externalLevel in _importVariablesForm._externalVarConfigFacade.GetAcronymLevelsSortedByIndex(externalType)) { addAfterRow = PerformAddLevel(internalType, externalLevel, addAfterRow); } _varConfigFacade.Commit(); }
void DisplayUnusedAcronyms(bool expand) //... as assessed in CheckForUnusedAcronyms { treeAcronyms.BeginUnboundLoad(); //store which nodes are expanded, the focused node and the first visible node List <string> expandedNodesIDs = new List <string>(); string focusedNodeID = string.Empty; string topVisibleNodeID = string.Empty; AcronymManager.StoreNodeStates(treeAcronyms, ref expandedNodesIDs, ref focusedNodeID, ref topVisibleNodeID); treeAcronyms.Nodes.Clear(); TreeListNode typeNode = null; TreeListNode levelNode = null; foreach (VarConfig.AcronymRow acroRow in _acronymsToDisplay) { VarConfig.AcronymTypeRow typeRow = acroRow.AcronymLevelRow.AcronymTypeRow; if (typeNode == null || !(typeNode.Tag as VarConfig.AcronymTypeRow).Equals(typeRow)) { typeNode = treeAcronyms.AppendNode(null, null); typeNode.SetValue(colAcronym, typeRow.LongName.ToUpper() + " (" + typeRow.ShortName.ToUpper() + ")"); typeNode.Tag = typeRow; } VarConfig.AcronymLevelRow levelRow = acroRow.AcronymLevelRow; if (levelNode == null || !(levelNode.Tag as VarConfig.AcronymLevelRow).Equals(levelRow)) { levelNode = treeAcronyms.AppendNode(null, typeNode); levelNode.SetValue(colAcronym, levelRow.Name); levelNode.Tag = levelRow; } TreeListNode acroNode = treeAcronyms.AppendNode(null, levelNode); acroNode.SetValue(colAcronym, acroRow.Description + " (" + acroRow.Name.ToUpper() + ")"); acroNode.SetValue(colDeleteAcronyms, true); acroNode.Tag = acroRow; } //restore collapse/expanded, focused and first visible node states AcronymManager.RestoreNodeStates(treeAcronyms, expandedNodesIDs, focusedNodeID, topVisibleNodeID); treeAcronyms.EndUnboundLoad(); colAcronym.BestFit(); colDeleteAcronyms.BestFit(); if (expand) { treeAcronyms.ExpandAll(); //initially, i.e. if called from btnLoad_Click, expand all nodes } }
void PerformClean() { try { //delete checked variables foreach (DataGridViewRow variableRow in dgvVariables.Rows) { if (EM_Helpers.SaveConvertToBoolean(variableRow.Cells[colDeleteVariables.Name].Value) == true) { (variableRow.Tag as VarConfig.VariableRow).Delete(); } } _varConfigFacade.Commit(); //delete checked acronyms foreach (TreeListNode typeNode in treeAcronyms.Nodes) { foreach (TreeListNode levelNode in typeNode.Nodes) { foreach (TreeListNode acroNode in levelNode.Nodes) { if (EM_Helpers.SaveConvertToBoolean(acroNode.GetValue(colDeleteAcronyms))) { (acroNode.Tag as VarConfig.AcronymRow).Delete(); } } _varConfigFacade.Commit(); VarConfig.AcronymLevelRow levelRow = levelNode.Tag as VarConfig.AcronymLevelRow; if (levelRow.GetAcronymRows().Count() == 0) { levelRow.Delete(); //delete level if all contained acronyms were deleted } } _varConfigFacade.Commit(); VarConfig.AcronymTypeRow typeRow = typeNode.Tag as VarConfig.AcronymTypeRow; if (typeRow.GetAcronymLevelRows().Count() == 0) { typeRow.Delete(); //delete type if all contained levels (and acronyms) were deleted (not very likely to happen) } _varConfigFacade.Commit(); } } catch (Exception exception) { Tools.UserInfoHandler.ShowException(exception); } }
internal override bool Perform() { if (!AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode)) { return(false); } VarConfig.AcronymTypeRow typeRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymTypeRow; string usage = string.Empty; List <VarConfig.AcronymRow> usedAcronymRows = new List <VarConfig.AcronymRow>(); foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(typeRow.ShortName)) { string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, typeRow.ShortName); if (usingVariables != string.Empty) { usedAcronymRows.Add(acronymRow); usage += acronymRow.Name + " used by " + usingVariables + Environment.NewLine; } } if (usage != string.Empty) { if (usage.Length > 2000) //probably this will happen only per accident, if a user tries to delete types like tax or benefit/pension (MessageBox is then too large for the screen) { usage = usage.Substring(0, 2000) + Environment.NewLine + Environment.NewLine + "etc., etc., etc."; } if (Tools.UserInfoHandler.GetInfo("The following acronyms of this type are used:" + Environment.NewLine + usage + Environment.NewLine + Environment.NewLine + "Cancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes) { return(false); } foreach (VarConfig.AcronymRow usedAcronymRow in usedAcronymRows) { usedAcronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels } typeRow.LongName = VariablesManager.DESCRIPTION_UNKNOWN; _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronymRows); } typeRow.Delete(); return(true); }
void AddAcros(bool local) { List <string> addIDs = GetRelevantIDs(_mcAcronyms, local, true); foreach (string ID in addIDs) { DataRow dataRow; switch (AssessAcroLevel(ID, false, out dataRow)) { case LEVEL_INVALID: continue; //should not happen case LEVEL_ACROTYPE: VarConfig.AcronymTypeRow acroType = dataRow as VarConfig.AcronymTypeRow; _vcFacLocal.CopyAcronymTypeRow(acroType); //note: this copies without content (i.e. without included levels, their acronyms and their categories (which may have been refused)) break; case LEVEL_ACROLEVEL: VarConfig.AcronymLevelRow acroLevel = dataRow as VarConfig.AcronymLevelRow; VarConfig.AcronymTypeRow parentType = _vcFacLocal.GetAcronymTypeByID(acroLevel.AcronymTypeRow.ID); if (parentType != null) //possible though non-sense (see comment below) { _vcFacLocal.CopyAcronymLevelRow(acroLevel, parentType); //see note above (i.e. included acronyms and their categories are not copied) } break; case LEVEL_ACRO: VarConfig.AcronymRow acro = dataRow as VarConfig.AcronymRow; VarConfig.AcronymLevelRow parentLevel = _vcFacLocal.GetAcronymLevelByID(acro.AcronymLevelRow.ID); if (parentLevel != null) //possible though non-sense (see comment below) { _vcFacLocal.CopyAcronymRow(acro, parentLevel); //see note above (i.e. included categories are not copied) } break; case LEVEL_ACROCAT: VarConfig.CategoryRow categ = dataRow as VarConfig.CategoryRow; VarConfig.AcronymRow parentAcro = _vcFacLocal.GetAcronymByID(categ.AcronymRow.ID); if (parentAcro != null) //may happen if (though non-sense) copying acro was refused while copying category was accepted { _vcFacLocal.CopyCategoryRow(categ, parentAcro); } break; } } _vcFacLocal.GetVarConfig().AcceptChanges(); }
internal VarConfig.AcronymLevelRow AddAcronymLevelRow(VarConfig.AcronymTypeRow parentRow, VarConfig.AcronymLevelRow addAfterRow = null, string name = "") { int indexAfter = 0; if (addAfterRow != null) { indexAfter = addAfterRow.Index; } foreach (VarConfig.AcronymLevelRow acronymLevelRow in parentRow.GetAcronymLevelRows()) { if (acronymLevelRow.Index > indexAfter) { ++acronymLevelRow.Index; } } string guid = Guid.NewGuid().ToString(); _guidsOfNewRows.Add(guid); return(_varConfig.AcronymLevel.AddAcronymLevelRow(guid, indexAfter + 1, parentRow, name)); }
void ChangeAcros(bool local) { foreach (MergeControl.NodeInfo nodeInfo in local ? _mcAcronyms.GetNodeInfoLocal() : _mcAcronyms.GetNodeInfoRemote()) { if (nodeInfo.changeType != MergeControl.ChangeType.changed || nodeInfo.changeHandling == (local ? MergeControl.ChangeHandling.accept : MergeControl.ChangeHandling.reject)) { continue; //not relevant, because neither changed nor locally accepted nor remotely rejected } const string NOT_CHANGED = "NOT_CHANGED"; MergeControl.CellInfo cellInfo = nodeInfo.cellInfo.First(); MergeControl.CellInfo cellInfoRemote = local ? _mcAcronyms.GetTwinCellInfo(cellInfo) : cellInfo; string changedName = (cellInfo.isChanged && (local ? !cellInfo.acceptChange : cellInfo.acceptChange)) //if name is changed and remotely accepted or locally rejected ? cellInfoRemote.text : NOT_CHANGED; //change to remote name (otherwise mark not changed) cellInfo = nodeInfo.cellInfo.Last(); cellInfoRemote = local ? _mcAcronyms.GetTwinCellInfo(cellInfo) : cellInfo; string changedDesc = (cellInfo.isChanged && (local ? !cellInfo.acceptChange : cellInfo.acceptChange)) //if description is changed and remotely accepted or locally rejected ? cellInfoRemote.text : NOT_CHANGED; //change to remote description (otherwise mark not changed) DataRow dataRow; switch (AssessAcroLevel(nodeInfo.ID, true, out dataRow)) { case LEVEL_INVALID: continue; //should not happen case LEVEL_ACROTYPE: VarConfig.AcronymTypeRow acroType = dataRow as VarConfig.AcronymTypeRow; if (changedName != NOT_CHANGED) { acroType.ShortName = changedName; } if (changedDesc != NOT_CHANGED) { acroType.LongName = changedDesc; } break; case LEVEL_ACROLEVEL: VarConfig.AcronymLevelRow acroLevel = dataRow as VarConfig.AcronymLevelRow; if (changedName != NOT_CHANGED) { acroLevel.Index = Convert.ToInt32(changedName); //probably not relevant } if (changedDesc != NOT_CHANGED) { acroLevel.Name = changedDesc; } break; case LEVEL_ACRO: VarConfig.AcronymRow acro = dataRow as VarConfig.AcronymRow; if (changedName != NOT_CHANGED) { acro.Name = changedName; } if (changedDesc != NOT_CHANGED) { acro.Description = changedDesc; } break; case LEVEL_ACROCAT: VarConfig.CategoryRow categ = dataRow as VarConfig.CategoryRow; if (changedName != NOT_CHANGED) { categ.Value = changedName; } if (changedDesc != NOT_CHANGED) { categ.Description = changedDesc; } break; } } }
internal void CopyAcronymLevelRow(VarConfig.AcronymLevelRow originalLevel, VarConfig.AcronymTypeRow parentType) { _varConfig.AcronymLevel.AddAcronymLevelRow(originalLevel.ID, originalLevel.Index, parentType, originalLevel.Name); }
internal void CopyAcronymTypeRow(VarConfig.AcronymTypeRow originalType) { _varConfig.AcronymType.AddAcronymTypeRow(originalType.ID, originalType.LongName, originalType.ShortName); }
void PerformChangeType(VarConfig.AcronymTypeRow internalType, VarConfig.AcronymTypeRow externalType) { internalType.LongName = externalType.LongName; _varConfigFacade.Commit(); }
internal List <VarConfig.AcronymLevelRow> GetAcronymLevelsSortedByName(VarConfig.AcronymTypeRow parentRow) { return((from acronymLevelRow in _varConfig.AcronymLevel where acronymLevelRow.TypeID == parentRow.ID select acronymLevelRow).OrderBy(acronymLevelRow => acronymLevelRow.Name).ToList()); }
void FillAcronymsList() { //(1) ACRONYM TYPES: search for elements existing only in one version as well as elements with different descriptions and/or content List <VarConfig.AcronymTypeRow> internalTypes = _internalVarConfigFacade.GetAcronymTypesSortedByShortName(); List <VarConfig.AcronymTypeRow> externalTypes = _externalVarConfigFacade.GetAcronymTypesSortedByShortName(); List <string> internalIDs = (from internalType in internalTypes select internalType.ShortName).ToList(); List <string> externalIDs = (from externalType in externalTypes select externalType.ShortName).ToList(); Dictionary <int, int> compareTypeIndexList = new Dictionary <int, int>(); List <int> addIndexList = new List <int>(); List <int> deleteIndexList = new List <int>(); AnalyseLists(internalIDs, externalIDs, ref compareTypeIndexList, ref addIndexList, ref deleteIndexList); //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(null, externalTypes.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(null, internalTypes.ElementAt(deleteIndex), _actionDelete); } foreach (int internalTypeIndex in compareTypeIndexList.Keys) //elements existent in both version: still have to check for different description and/or content { int externalTypeIndex = compareTypeIndexList[internalTypeIndex]; VarConfig.AcronymTypeRow internalType = internalTypes.ElementAt(internalTypeIndex); VarConfig.AcronymTypeRow externalType = externalTypes.ElementAt(externalTypeIndex); Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow> typeTag = new Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>(); typeTag.Add(internalType, externalType); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode typeNode = null; //check for different description (LongName) if (internalType.LongName != externalType.LongName) { typeNode = AcronymTree_AddNode(null, typeTag, _actionChange); typeNode.SetValue(colInfoAcronyms, _infoNewDescription + externalType.LongName); } //check for differnet content, i.e.: //(2) ACRONYM LEVELS: search for elements existing only in one version as well as elements with different content List <VarConfig.AcronymLevelRow> internalLevels = _internalVarConfigFacade.GetAcronymLevelsSortedByName(internalType); List <VarConfig.AcronymLevelRow> externalLevels = _externalVarConfigFacade.GetAcronymLevelsSortedByName(externalType); internalIDs = (from internalLevel in internalLevels select internalLevel.Name).ToList(); externalIDs = (from externalLevel in externalLevels select externalLevel.Name).ToList(); Dictionary <int, int> compareLevelIndexList = new Dictionary <int, int>(); addIndexList.Clear(); deleteIndexList.Clear(); AnalyseLists(internalIDs, externalIDs, ref compareLevelIndexList, ref addIndexList, ref deleteIndexList); if (typeNode == null && (addIndexList.Count != 0 || deleteIndexList.Count != 0)) { typeNode = AcronymTree_AddNode(null, typeTag); //generate parent node if necessary } //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(typeNode, externalLevels.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(typeNode, internalLevels.ElementAt(deleteIndex), _actionDelete); } foreach (int internalLevelIndex in compareLevelIndexList.Keys) //elements existent in both version: still have to check for different content { int externalLevelIndex = compareLevelIndexList[internalLevelIndex]; VarConfig.AcronymLevelRow internalLevel = internalLevels.ElementAt(internalLevelIndex); VarConfig.AcronymLevelRow externalLevel = externalLevels.ElementAt(externalLevelIndex); Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow> levelTag = new Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>(); levelTag.Add(internalLevel, externalLevel); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode levelNode = null; //check for differnet content, i.e.: //(3) ACRONYMS: search for elements existing only in one version as well as elements with different description List <VarConfig.AcronymRow> internalAcronyms = _internalVarConfigFacade.GetAcronymsOfLevelSortedByName(internalLevel); List <VarConfig.AcronymRow> externalAcronyms = _externalVarConfigFacade.GetAcronymsOfLevelSortedByName(externalLevel); internalIDs = (from internalAcronym in internalAcronyms select internalAcronym.Name).ToList(); externalIDs = (from externalAcronym in externalAcronyms select externalAcronym.Name).ToList(); Dictionary <int, int> compareAcronymIndexList = new Dictionary <int, int>(); addIndexList.Clear(); deleteIndexList.Clear(); AnalyseLists(internalIDs, externalIDs, ref compareAcronymIndexList, ref addIndexList, ref deleteIndexList); if (addIndexList.Count != 0 || deleteIndexList.Count != 0) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } } //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(levelNode, externalAcronyms.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(levelNode, internalAcronyms.ElementAt(deleteIndex), _actionDelete); } foreach (int internalAcronymIndex in compareAcronymIndexList.Keys) //elements existent in both version: still have to check for different description { int externalAcronymIndex = compareAcronymIndexList[internalAcronymIndex]; VarConfig.AcronymRow internalAcronym = internalAcronyms.ElementAt(internalAcronymIndex); VarConfig.AcronymRow externalAcronym = externalAcronyms.ElementAt(externalAcronymIndex); Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow> acronymTag = new Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>(); acronymTag.Add(internalAcronym, externalAcronym); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode acronymNode = null; //check for different description if (internalAcronym.Description != externalAcronym.Description) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } acronymNode = AcronymTree_AddNode(levelNode, acronymTag, _actionChange); acronymNode.SetValue(colInfoAcronyms, _infoNewDescription + externalAcronym.Description); } //check for different categories bool equal = internalAcronym.GetCategoryRows().Count() == externalAcronym.GetCategoryRows().Count(); if (equal) { foreach (VarConfig.CategoryRow internalCategory in internalAcronym.GetCategoryRows()) { bool found = false; foreach (VarConfig.CategoryRow externalCategory in externalAcronym.GetCategoryRows()) { if (internalCategory.Value == externalCategory.Value && internalCategory.Description == externalCategory.Description) { found = true; break; } } if (!found) { equal = false; break; //if one category different, acronym needs to be marked as changed - no need to check all categories here } } } if (!equal) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } string info = _infoChangeCategory; if (acronymNode == null) { acronymNode = AcronymTree_AddNode(levelNode, acronymTag, _actionChange); } else { info = acronymNode.GetDisplayText(colInfoAcronyms) + " + " + _infoChangeCategory; } acronymNode.SetValue(colInfoAcronyms, info); } } } } colPerformAcronyms.BestFit(); colAcronym.BestFit(); colActionAcronyms.BestFit(); colInfoAcronyms.BestFit(); treeAcronyms.ExpandAll(); }
internal static string VarNaming(List <string> print) { Parallel.ForEach(VariablesChecker.varData.Variable, v => { string vName = v.Name.ToLower().Trim(); if (vName == string.Empty) { lock (printLock) print.Add("variable without a name (ID " + v.ID + ")"); return; } // only for formal correctness if (vName.StartsWith("id")) { return; } string vType = vName.Substring(0, 1); var aT = from t in VariablesChecker.varData.AcronymType where t.ShortName.ToLower().Contains(vType) // Contains instead of = because we have b/p select t; if (aT == null || aT.Count() == 0) { lock (printLock) print.Add(string.Format("{0}\tunknown type {1}\t{2}", v.Name, v.Name[0], v.ItemArray[3])); return; } VarConfig.AcronymTypeRow acroType = aT.First(); List <string> mainAcros = new List <string>(); var aL = from l in VariablesChecker.varData.AcronymLevel where l.Name.ToLower() == "main" & l.AcronymTypeRow.ShortName.ToLower() == vType select l; if (aL != null && aL.Count() > 0) { mainAcros = (from a in aL.First().GetAcronymRows() select a.Name.ToLower()).ToList(); } if (vName.EndsWith(DefGeneral.POSTFIX_SIMULATED)) { vName = vName.Substring(0, vName.Length - 2); } int maxLevel = -1; bool good = true; List <string> vAcros = GetVarAcros(vName); foreach (string vAcro in vAcros) { var ac = from a in VariablesChecker.varData.Acronym where a.Name.ToLower() == vAcro & a.AcronymLevelRow.TypeID == acroType.ID select a; if (ac == null || ac.Count() == 0) { lock (printLock) print.Add(string.Format("{0}\tunknown acronym {1}\t{2}", v.Name, vAcro, v.ItemArray[3])); good = false; break; } int level = ac.First().AcronymLevelRow.Index; if (level < maxLevel) { lock (printLock) print.Add(string.Format("{0}\tinvalid order of acronyms\t{1}", v.Name, v.ItemArray[3])); good = false; break; } maxLevel = level; if (mainAcros.Contains(vAcro) && vAcros.IndexOf(vAcro) != 0) { lock (printLock) print.Add(string.Format("{0}\tacronyms of the Main-level must immediately follow after the type ({1}), this is violated by {2}\t{3}", v.Name, v.Name[0], vAcro, v.ItemArray[3])); good = false; break; } } if (!good) { return; } if (vName.Length != vAcros.Count * 2 + 1) { lock (printLock) print.Add(string.Format("{0}\tinvalid 1-character acronym {1}\t{2}", v.Name, v.Name.Last(), v.ItemArray[3])); } }); return((print.Count == 0) ? "No variable naming rule violations found" : print.Count.ToString() + " variable naming rule violations found"); }
void PerformImportNode(TreeListNode node, short nodeType) { string action = node.GetValue(_importVariablesForm.colActionAcronyms).ToString(); bool perform = false; if (action != string.Empty) { perform = EM_Helpers.SaveConvertToBoolean(node.GetValue(_importVariablesForm.colPerformAcronyms)); } if (!perform) { return; } switch (nodeType) { case _typeNode: switch (action) { case ImportVariablesForm._actionAdd: PerformAddType(node.Tag as VarConfig.AcronymTypeRow); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymTypeRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeType((node.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Values.ElementAt(0)); break; } break; case _levelNode: switch (action) { case ImportVariablesForm._actionAdd: VarConfig.AcronymTypeRow internalType = (node.ParentNode.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0); VarConfig.AcronymLevelRow externalLevel = node.Tag as VarConfig.AcronymLevelRow; PerformAddLevel(internalType, externalLevel, GetAddAferLevel(internalType, externalLevel)); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymLevelRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeLevel((node.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Values.ElementAt(0)); break; } break; case _acronymNode: switch (action) { case ImportVariablesForm._actionAdd: PerformAddAcronym((node.ParentNode.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0), node.Tag as VarConfig.AcronymRow); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeAcronym((node.Tag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Values.ElementAt(0), node.GetValue(_importVariablesForm.colInfoAcronyms).ToString()); break; } break; } }
internal static void StoreNodeStates(TreeList treeAcronyms, ref List <string> expandedNodesIDs, ref string focusedNodeID, ref string topVisibleNodeID) { foreach (TreeListNode typeNode in treeAcronyms.Nodes) { VarConfig.AcronymTypeRow typeRow = typeNode.Tag as VarConfig.AcronymTypeRow; if (typeRow.RowState != System.Data.DataRowState.Unchanged) { continue; //happens if tree is redrawn because of an undo action } string typeID = typeRow.ID; if (typeNode.Expanded == true) { expandedNodesIDs.Add(typeID); } if (typeNode.Focused == true) { focusedNodeID = typeID; } if (treeAcronyms.GetVisibleIndexByNode(typeNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = typeID; } foreach (TreeListNode levelNode in typeNode.Nodes) { VarConfig.AcronymLevelRow levelRow = levelNode.Tag as VarConfig.AcronymLevelRow; if (levelRow.RowState != System.Data.DataRowState.Unchanged) { continue; } string levelID = levelRow.ID; if (levelNode.Expanded == true) { expandedNodesIDs.Add(levelID); } if (levelNode.Focused == true) { focusedNodeID = levelID; } if (treeAcronyms.GetVisibleIndexByNode(levelNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = levelID; } foreach (TreeListNode acroNode in levelNode.Nodes) { VarConfig.AcronymRow acroRow = acroNode.Tag as VarConfig.AcronymRow; if (acroRow.RowState != System.Data.DataRowState.Unchanged) { continue; } string acroID = acroRow.ID; if (acroNode.Focused == true) { focusedNodeID = acroID; } if (treeAcronyms.GetVisibleIndexByNode(acroNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = acroID; } } } } }
internal override bool Perform() { string newValue = _eventArgs.Value.ToString(); VarConfig.AcronymTypeRow typeRow = _eventArgs.Node.Tag as VarConfig.AcronymTypeRow; string oldTypeName = string.Empty; //change of type-description (long name) if (_eventArgs.Column.Name == _variablesForm.colAcronymDescription.Name) { if (newValue == typeRow.LongName) { return(false); //only change if different } if (!DoChangeIfUsed(typeRow.ShortName, newValue)) { return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables or filter-checkboxes) } typeRow.LongName = newValue; } //change of type's short name else { if (newValue == typeRow.ShortName) { return(false); //only change if different } if (!DoChangeIfUsed(typeRow.ShortName, newValue)) { return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables or filter-checkboxes) } oldTypeName = typeRow.ShortName; //check for correctness if (_varConfigFacade.GetTypeShortNames().Contains(newValue.ToLower())) { Tools.UserInfoHandler.ShowError("Acronym type already exists. Please choose another short name."); _updateVariables = false; _updateFilterCheckboxes = false; return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables or filter-checkboxes) } //finally reflect change in datarow typeRow.ShortName = newValue; } //update automatic label of variables concerned List <KeyValuePair <string, string> > updateLabelAcronyms = new List <KeyValuePair <string, string> >(); foreach (VarConfig.AcronymLevelRow levelRow in typeRow.GetAcronymLevelRows()) { foreach (VarConfig.AcronymRow acroRow in levelRow.GetAcronymRows()) { if (acroRow.Name != string.Empty) { updateLabelAcronyms.Add(new KeyValuePair <string, string>(acroRow.Name, typeRow.ShortName)); //variables already using the new acro-type now get a valid auto-label if (oldTypeName != string.Empty) { updateLabelAcronyms.Add(new KeyValuePair <string, string>(acroRow.Name, oldTypeName)); //variables, which used the old acro-type get an invalid auto-label } } } } _variablesForm._acronymManager.UpdateAutomaticLabelForSpecificAcronyms(updateLabelAcronyms); return(true); }