public void AddOverrideField(string sField, string sValue) { if (TranslatorBase.IsDisallowedOverrideField(sField)) { Logger.AddLogLine("[{1}] override not allowed on element: [{0}]".FormatString(m_zElement.name, sField)); } // empty override values are discarded (matches reference overrides) else if (!string.IsNullOrWhiteSpace(sValue)) { dictionaryOverrideFieldToValue[sField] = sValue; } }
protected void ProcessLines(List<List<string>> listLines, List<List<string>> listDefineLines, string sReferencePath) { #warning this method is horribly long const string ALLOWED_LAYOUT = "allowed_layout"; const string OVERRIDE = "override:"; var nDefaultCount = CardLayout.defaultCount; var listColumnNames = new List<string>(); var dictionaryColumnNames = new Dictionary<string, int>(); var dictionaryElementOverrides = new Dictionary<string, Dictionary<string, int>>(); var dictionaryDefines = new Dictionary<string, string>(); // Line Processing if (0 < listLines.Count) { // Read the column names var listAllColumnNames = listLines[0]; for (int nIdx = 0; nIdx < listAllColumnNames.Count; nIdx++) { string sKey = listAllColumnNames[nIdx].ToLower().Trim(); listColumnNames.Add(sKey); if (!dictionaryColumnNames.ContainsKey(sKey)) { dictionaryColumnNames.Add(sKey, nIdx); } else { IssueManager.Instance.FireAddIssueEvent("Duplicate column found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey); Logger.AddLogLine("Duplicate column found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey); } } // determine the allowed layout column index int nAllowedLayoutColumn; if (!dictionaryColumnNames.TryGetValue(ALLOWED_LAYOUT, out nAllowedLayoutColumn)) { nAllowedLayoutColumn = -1; } // construct the override dictionary foreach (string sKey in listColumnNames) { if (sKey.StartsWith(OVERRIDE)) { string[] arraySplit = sKey.Split(new char[] { ':' }); if (3 == arraySplit.Length) { string sElementName = arraySplit[1].Trim(); string sElementItemOverride = arraySplit[2].Trim(); if (!dictionaryElementOverrides.ContainsKey(sElementName)) { dictionaryElementOverrides.Add(sElementName, new Dictionary<string, int>()); } Dictionary<string, int> dictionaryOverrides = dictionaryElementOverrides[sElementName]; if (dictionaryOverrides.ContainsKey(sElementItemOverride)) { Logger.AddLogLine("Duplicate override found: {0}".FormatString(sElementItemOverride)); } dictionaryOverrides[sElementItemOverride] = dictionaryColumnNames[sKey]; } } } // remove the columns listLines.RemoveAt(0); // remove any lines that do not contain any values int nRow = 0; while(nRow < listLines.Count) { var listRow = listLines[nRow]; var bEmptyRow = true; foreach(string sCol in listRow) { if (0 < sCol.Trim().Length) { bEmptyRow = false; break; } } if (bEmptyRow) { listLines.RemoveAt(nRow); } else { nRow++; } } // remove any layout elements that do not match the card layout if (-1 != nAllowedLayoutColumn) { int nLine = 0; while (nLine < listLines.Count) { if (!CardLayout.Name.Equals(listLines[nLine][nAllowedLayoutColumn], StringComparison.CurrentCultureIgnoreCase)) { listLines.RemoveAt(nLine); } else { nLine++; } } } // indicate if no lines remain! if (0 == listLines.Count) { IssueManager.Instance.FireAddIssueEvent("No lines found?! allowed_layout may be cutting them!"); } } ValidLines.Clear(); // create the duplicated lines (with count > 0) foreach (List<string> listItems in listLines) { if (0 < listItems.Count) { int nNumber; if (!int.TryParse(listItems[0].Trim(), out nNumber)) { IssueManager.Instance.FireAddIssueEvent("Invalid card count found: [" + listItems[0] + "] The first column should always have a number value."); nNumber = 1; } for (var nCount = 0; nCount < nNumber; nCount++) { ValidLines.Add(new DeckLine(listItems, nCount)); } } } // always create a line if (0 == ValidLines.Count && 0 < nDefaultCount) { // create the default number of lines. for (int nIdx = 0; nIdx < nDefaultCount; nIdx++) { if (0 < listColumnNames.Count)// create each line and the correct number of columns { var arrayDefaultLine = new List<string>(); for (int nCol = 0; nCol < arrayDefaultLine.Count; nCol++) { arrayDefaultLine.Add(string.Empty); } ValidLines.Add(new DeckLine(arrayDefaultLine)); } else // no columns just create an empty row { ValidLines.Add(new DeckLine(new List<string>())); } } if (!string.IsNullOrEmpty(sReferencePath)) { IssueManager.Instance.FireAddIssueEvent("No lines found for this layout! Generated " + nDefaultCount); } } // Define Processing // remove the column names if (listDefineLines.Count > 0) { // the removal of the first row happens in the reader(s) for defines // listDefineLines.RemoveAt(0); foreach (var row in listDefineLines) { if (row.Count > 1) { string sKey = row[0]; int nIdx; string sVal; if (dictionaryDefines.TryGetValue(sKey.ToLower(), out sVal)) { string sMsg = "Duplicate define found: " + sKey; IssueManager.Instance.FireAddIssueEvent(sMsg); Logger.AddLogLine(sMsg); } else if (dictionaryColumnNames.TryGetValue(sKey.ToLower(), out nIdx)) { string sMsg = "Overlapping column name and define found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey; IssueManager.Instance.FireAddIssueEvent(sMsg); Logger.AddLogLine(sMsg); } else { dictionaryDefines.Add(sKey.ToLower(), row[1]); } } } } m_zTranslator = TranslatorFactory.GetTranslator(dictionaryColumnNames, dictionaryDefines, dictionaryElementOverrides, listColumnNames); #if MONO_BUILD Thread.Sleep(100); #endif WaitDialog.Instance.ThreadSuccess = true; WaitDialog.Instance.CloseWaitDialog(); }