/// <summary> /// Call this only AFTER the build methods for both sdict's CP and TM have been called! /// </summary> public void BuildSortDictForModuleTables() { CValueTableModule valueTableModule_TM; CValueTableModule valueTableModule_MT; SysCollGen.List <CValueTableModule> listTableModules_UnkMod; SysCollGen.List <CValueTableModule> listTableModules_MT = null; SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableTable> > .KeyCollection keyColl_CP; SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableTable> > .KeyCollection keyColl_PC; bool boolUnknownModuleKey_HasBeenAddedToMT; // // Skip whole method if sdict MT already exists. if (null != this.m_runProperties.m_sdictModuleTables) { goto LABEL_RETURN_kdx67_LABEL; } else { this.m_runProperties.m_sdictModuleTables = new SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableModule> >(); } // First, a simple copy of data from sdict TM to sdict MT. foreach (SysCollGen.KeyValuePair <string, CValueTableModule> eachKvpTM in this.m_runProperties.m_sdictTableModules ) { valueTableModule_TM = eachKvpTM.Value; valueTableModule_MT = new CValueTableModule ( valueTableModule_TM.GetTableName(), valueTableModule_TM.GetTableName(), valueTableModule_TM.GetModuleName() ); if (!this.m_runProperties.m_sdictModuleTables.ContainsKey (valueTableModule_MT.GetModuleNameLowercaseNoSpaces()) ) { // New key. listTableModules_MT = new SysCollGen.List <CValueTableModule>(); listTableModules_MT.Add(valueTableModule_MT); this.m_runProperties.m_sdictModuleTables.Add (valueTableModule_MT.GetModuleNameLowercaseNoSpaces(), listTableModules_MT ); } else // Key ALREADY exists. { listTableModules_MT = this.m_runProperties.m_sdictModuleTables [valueTableModule_MT.GetModuleNameLowercaseNoSpaces()]; listTableModules_MT.Add(valueTableModule_MT); } } //________________________________________________ //________________________________________________ // Create the special "UnknownModule" key in sdict MT. // First, loop through CP for all C. // Second, loop through PC for all P. //__________ Loop CP boolUnknownModuleKey_HasBeenAddedToMT = false; keyColl_CP = this.m_runProperties.GetSDictOfChildParents().Keys; foreach (string eachKey_C in keyColl_CP) { if (!this.m_runProperties.GetSDictOfTableModules().ContainsKey(eachKey_C)) { // This child table name was NOT in the T-M data gathered from Dynamics AX6 (AX 2012) by X++. // Thus put this child table into the pretend Unknown Module. valueTableModule_MT = new CValueTableModule ( eachKey_C, // IComparable eachKey_C, // TableName CRunProperties.M_readonly_sUnknownModule // ModuleName ); try { if ((!boolUnknownModuleKey_HasBeenAddedToMT) && !this.m_runProperties.GetSDictOfModuleTables().ContainsKey (CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces) ) { // This is the first missing table name yet encountered, so // create the key etc in the sdict MT. listTableModules_UnkMod = new SysCollGen.List <CValueTableModule>(); listTableModules_UnkMod.Add(valueTableModule_MT); this.m_runProperties.GetSDictOfModuleTables().Add ( CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces, listTableModules_UnkMod ); boolUnknownModuleKey_HasBeenAddedToMT = true; } else { // sdict MT already has the Unknown Module key, so // simply add the current table name to the corresponding value list. listTableModules_UnkMod = this.m_runProperties.GetSDictOfModuleTables() [CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces]; listTableModules_UnkMod.Add(valueTableModule_MT); } } catch (Exception ee) { Console.WriteLine("Error_1742sc5: {0}", ee); throw ee; } } } // EOForeach eachKey_C //__________ Loop PC //boolUnknownModuleKey_HasBeenAddedToMT = false; keyColl_PC = this.m_runProperties.GetSDictOfParentChilds().Keys; foreach (string eachKey_P in keyColl_PC) { if (!this.m_runProperties.GetSDictOfTableModules().ContainsKey(eachKey_P)) { // This child table name was NOT in the T-M data gathered from Dynamics AX6 (AX 2012) by X++. // Thus put this child table into the pretend Unknown Module. valueTableModule_MT = new CValueTableModule ( eachKey_P, // IComparable eachKey_P, // TableName CRunProperties.M_readonly_sUnknownModule // ModuleName ); try { if ((!boolUnknownModuleKey_HasBeenAddedToMT) && !this.m_runProperties.GetSDictOfModuleTables().ContainsKey (CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces) ) { // This is the first missing table name yet encountered, so // create the key etc in the sdict MT. listTableModules_UnkMod = new SysCollGen.List <CValueTableModule>(); listTableModules_UnkMod.Add(valueTableModule_MT); this.m_runProperties.GetSDictOfModuleTables().Add ( CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces, listTableModules_UnkMod ); boolUnknownModuleKey_HasBeenAddedToMT = true; } else { // sdict MT already has the Unknown Module key, so // simply add the current table name to the corresponding value list. listTableModules_UnkMod = this.m_runProperties.GetSDictOfModuleTables() [CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces]; listTableModules_UnkMod.Add(valueTableModule_MT); } } catch (Exception ee) { Console.WriteLine("Error_1742sc5: {0}", ee); throw ee; } } } // EOForeach eachKey_P //________________________________________________ //________________________________________________ // Add the "UnknownModule" tables to T-M sdict. if (boolUnknownModuleKey_HasBeenAddedToMT) { listTableModules_UnkMod = this.m_runProperties.GetSDictOfModuleTables() [CRunProperties.M_readonly_sUnknownModule_LowercaseNoSpaces]; foreach (CValueTableModule eachValue_MT_UnkMod_T in listTableModules_UnkMod) { valueTableModule_TM = new CValueTableModule ( eachValue_MT_UnkMod_T.GetModuleName(), // IComparable eachValue_MT_UnkMod_T.GetTableName(), eachValue_MT_UnkMod_T.GetModuleName() ); if (this.m_runProperties.GetSDictOfTableModules() .ContainsKey(eachValue_MT_UnkMod_T.GetTableNameLowercase()) ) { //Console.WriteLine("??? Caution_1733qf7: Semi-Unexpected duplicate key from PC loop into TM for UnkMod , {0}", // eachValue_MT_UnkMod_T.GetTableNameLowercase()); } else { this.m_runProperties.GetSDictOfTableModules() .Add(eachValue_MT_UnkMod_T.GetTableNameLowercase(), valueTableModule_TM); } } // EOForeach eachValue_MT_UnkMod_T } LABEL_RETURN_kdx67_LABEL :; if (null == this.m_runProperties.m_sdictModuleTables) { this.m_runProperties.m_sdictModuleTables = new SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableModule> >(); } return; }
/// <summary> /// Such as CustTable might be a child of three other tables, according to Dynamics AX 2012 AOT /// (thus three key-value pairs for CustTable). /// </summary> /// <returns>SortedDictionary, key=ChildTableName (+" "+ParentTableName), value=CValueTableTable. /// Never null.</returns> /// <remarks>Caution: In this method pair, GetSortDictFor* ChildParents & ParentChilds, /// each method initializes both itself and the other sdict, when appropriate. /// </remarks> public void BuildSortDictForChildParents_and_ParentChilds() { SysIo.FileStream fileStream; SysIo.StreamReader streamReader; SysCollGen.List <CValueTableTable> listTableTable; CValueTableTable valueTableTable_CP, valueTableTable_PC; char[] cDelims = { '\t' }; string[] sSplits; string sLine = "Initialize."; string sChildTableName, sParentTableName; int nKeyTT; int nLineReadCount = 0; // if (null != this.m_runProperties.m_sdictChildParents) { goto LABEL_RETURN_msj58_LABEL; } else { this.m_runProperties.m_sdictChildParents = new SysCollGen.SortedDictionary // C-P <string, SysCollGen.List <CValueTableTable> >(); this.m_runProperties.m_sdictParentChilds = new SysCollGen.SortedDictionary // P-C <string, SysCollGen.List <CValueTableTable> >(); } using ( fileStream = new SysIo.FileStream ( this.m_runProperties.GetPathToInputDelimFiles() + this.m_runProperties.GetInputDelimFilesCommonPrefix() + this.m_runProperties.GetDelimFileChildParents(), SysIo.FileMode.Open, SysIo.FileAccess.Read, SysIo.FileShare.Read ) ) { streamReader = new SysIo.StreamReader(fileStream); while (streamReader.Peek() >= 0) { try { nLineReadCount++; sLine = streamReader.ReadLine(); sSplits = sLine.Split(cDelims, StringSplitOptions.RemoveEmptyEntries); if (3 > sSplits.Length) { continue; } if (sSplits[0].StartsWith("//")) { continue; } if (sSplits[0].Trim().Length == 0) { continue; } nKeyTT = Convert.ToInt32(sSplits[0]); sChildTableName = sSplits[1]; sParentTableName = sSplits[2]; valueTableTable_CP = new CValueTableTable ( sParentTableName, // IComparable. nKeyTT, sChildTableName, sParentTableName ); // Child-Parents if (this.m_runProperties.m_sdictChildParents.ContainsKey(valueTableTable_CP.GetKeyChildDelimParent())) { listTableTable = this.m_runProperties.m_sdictChildParents[valueTableTable_CP.GetKeyChildDelimParent()]; listTableTable.Add(valueTableTable_CP); // Also SORTED, by Parent, earlier during X++ time. } else // ! ContainsKey { listTableTable = new SysCollGen.List <CValueTableTable>(); listTableTable.Add(valueTableTable_CP); this.m_runProperties.m_sdictChildParents.Add ( valueTableTable_CP.GetKeyChildDelimParent(), listTableTable ); } // Parent-Childs // Clone vtt, need different IComparable string to sort by. valueTableTable_PC = valueTableTable_CP.CloneThis(valueTableTable_CP.GetTableNameChild()); if (this.m_runProperties.m_sdictParentChilds.ContainsKey(valueTableTable_PC.GetKeyParentDelimChild())) { listTableTable = this.m_runProperties.m_sdictParentChilds[valueTableTable_PC.GetKeyParentDelimChild()]; listTableTable.Add(valueTableTable_PC); // SORTED, by Child, by IComparable. } else // ! ContainsKey { listTableTable = new SysCollGen.List <CValueTableTable>(); listTableTable.Add(valueTableTable_PC); this.m_runProperties.m_sdictParentChilds.Add ( valueTableTable_PC.GetKeyParentDelimChild(), listTableTable ); } } catch (Exception e) { Console.WriteLine("Error_cys78: nLineReadCount={0}, sLine={1}", nLineReadCount, sLine); throw e; } } // EOWhile peek. } // EOUsing FileStream. LABEL_RETURN_msj58_LABEL :; if (null == this.m_runProperties.m_sdictChildParents) { this.m_runProperties.m_sdictChildParents = new SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableTable> >(); this.m_runProperties.m_sdictParentChilds = new SysCollGen.SortedDictionary <string, SysCollGen.List <CValueTableTable> >(); } return; }
public void BuildSortDictForColumnsFkyPky() { SysIo.FileStream fileStream; SysIo.StreamReader streamReader; SysCollGen.List <CValueColumnColumn> listColumnColumn; CValueColumnColumn valueColumnColumn; char[] cDelims = { '\t' }; string[] sSplits; string sLine = "Initialize."; int nLineReadCount = 0; // if (null != this.m_runProperties.m_sdictColumnsFkyPky) { goto LABEL_RETURN_csh89_LABEL; } else { this.m_runProperties.m_sdictColumnsFkyPky = new SysCollGen.SortedDictionary <int, SysCollGen.List <CValueColumnColumn> >(); } using ( fileStream = new SysIo.FileStream ( this.m_runProperties.GetPathToInputDelimFiles() + this.m_runProperties.GetInputDelimFilesCommonPrefix() + this.m_runProperties.GetDelimFileColumnColumn(), SysIo.FileMode.Open, SysIo.FileAccess.Read, SysIo.FileShare.Read ) ) { streamReader = new SysIo.StreamReader(fileStream); while (streamReader.Peek() >= 0) { try { nLineReadCount++; sLine = streamReader.ReadLine(); sSplits = sLine.Split(cDelims, StringSplitOptions.RemoveEmptyEntries); if (4 > sSplits.Length) { continue; } if (sSplits[0].StartsWith("//")) { continue; } if (sSplits[0].Trim().Length == 0) { continue; } valueColumnColumn = new CValueColumnColumn (Convert.ToInt32(sSplits[0]), Convert.ToInt32(sSplits[1]), sSplits[2], sSplits[3]); if (this.m_runProperties.m_sdictColumnsFkyPky.ContainsKey(valueColumnColumn.GetIdentityTT())) { listColumnColumn = this.m_runProperties.m_sdictColumnsFkyPky[valueColumnColumn.GetIdentityTT()]; listColumnColumn.Add(valueColumnColumn); } else // ! ContainsKey { listColumnColumn = new SysCollGen.List <CValueColumnColumn>(); listColumnColumn.Add(valueColumnColumn); this.m_runProperties.m_sdictColumnsFkyPky.Add ( valueColumnColumn.GetIdentityTT(), listColumnColumn ); } } catch (Exception e) { Console.WriteLine("Error_qmc41: nLineReadCount={0}, sLine={1}", nLineReadCount, sLine); throw e; } } // EOWhile peek. } // EOUsing FileStream. LABEL_RETURN_csh89_LABEL :; if (null == this.m_runProperties.m_sdictColumnsFkyPky) { this.m_runProperties.m_sdictColumnsFkyPky = new SysCollGen.SortedDictionary <int, SysCollGen.List <CValueColumnColumn> >(); } return; }
static void RunIntro(string name, int num, bool isExpt2, string rsrcPath = "resources") { DateTime time1 = DateTime.Now; Stopwatch stopwatch1 = new Stopwatch(); stopwatch1.Start(); // basic datatypes bool isDone = false; int numI = 0, arrLen = (int)ConstItems.ZERO, delayMsecs = 2500, seedp = time1.Millisecond; float timeDiff = 0.0f; char ch = '\0'; // strings & arrays string greetStr, dateStr, greetPath = "greet.txt"; char[] str1 = new char[64]; int[] numArr = { 9, 9, 0x9, 9 }; // {bin, oct, hex, dec} //composites UVar uVar1 = new UVar(); //User user1 = new User() {Name = "World", Num = 0, TimeIn = time1}; User user1 = new User("World", 0, time1); var tup1 = new Tuple <byte, short>((byte)Kind.INTSHORT, 100); Person pers; Random rnd = new Random(seedp); IO.TextWriter fOut = Console.Out; TimeZone tz1 = TimeZone.CurrentTimeZone; string tzStr = tz1.IsDaylightSavingTime(time1) ? tz1.DaylightName : tz1.StandardName; arrLen = numArr.Length; for (int i = 0; arrLen > i; ++i) // foreach (int elem in numArr) { numI += numArr[i]; // numI += elem; } Trace.Assert((numArr.Length * numArr[0]) == numI, "arrLen * numArr[0] != numI"); ch = Misc.DelayChar(delayMsecs); do { uVar1.kind = tup1.Item1; uVar1.val = new UnionVal() { sh = tup1.Item2 }; uVar1.kind = (byte)Kind.INTSHORT; uVar1.val = new UnionVal() { sh = -1 }; uVar1.kind = (byte)Kind.UINTLONG; uVar1.val = new UnionVal() { ul = 1UL }; uVar1.kind = (byte)Kind.FLOAT; uVar1.val = new UnionVal() { f = 100.0f }; uVar1.kind = (byte)Kind.DOUBLE; uVar1.val = new UnionVal() { d = 100.0d }; uVar1.kind = (byte)Kind.DECIMAL; uVar1.val = new UnionVal() { m = 1000.0m }; str1[0] = '\0'; Trace.Assert(((byte)Kind.DECIMAL == uVar1.kind) && (1000.0m == uVar1.val.m), "kind == Kind.DECIMAL && val == 1000.0m is false"); } while (isDone); user1.Name = name; user1.Num = 0 == num?rnd.Next(0, 17) + 2 : num; SysTextRegex.Regex re = new SysTextRegex.Regex(@"(?i)^quit$"); SysTextRegex.Match m = re.Match(name); Console.WriteLine("{0} match: {1} to {2}\n", m.Success ? "Good" : "Does not", name, re); dateStr = user1.TimeIn.ToString("ddd MMM dd HH:mm:ss yyyy zzz"); //greetStr = Misc.Greeting(greetPath, user1.Name); try { //greetStr = (new IO.StreamReader(rsrcPath + "/" + greetPath)).ReadToEnd().TrimEnd('\n', '\r') + user1.Name; greetStr = IO.File.ReadAllText(rsrcPath + "/" + greetPath).TrimEnd('\n', '\r') + user1.Name; } catch (Exception exc0) { Console.Error.WriteLine("(exc: {0}) Bad env var RSRC_PATH: {1}\n", exc0, rsrcPath); try { greetStr = Util.GetFromResources(greetPath, assembly).TrimEnd('\n', '\r') + user1.Name; } catch (Exception exc1) { throw; Environment.Exit(1); } } Console.WriteLine("{0} {1}\n{2}!", dateStr, tzStr, greetStr); stopwatch1.Stop(); timeDiff = stopwatch1.ElapsedMilliseconds; Console.WriteLine("(program {0}) Took {1:F1} seconds.", progName, timeDiff * 1.0e-3); int[] ints = { 2, 1, 0, 4, 3 }; var lst = new SysCollGen.List <int>(ints); if (isExpt2) { fOut.WriteLine("Expt(2.0, {0}) = {1}", user1.Num, Classic.ExptLp(2.0f, user1.Num)); var res = Util.MkString(lst); Console.Write("Reverse({0}): ", res); var lstTmp = Seqops.CopyOfLp <int>(lst); Seqops.ReverseLp <int>(lstTmp); res = Util.MkString(lstTmp); Console.WriteLine("{0}", res); res = Util.MkString(lst); Console.Write("{0}.Sort(): ", res); lst.Sort(); res = Util.MkString(lst); Console.WriteLine("{0}", res); } else { fOut.WriteLine("Fact({0}) = {1}", user1.Num, Classic.FactLp(user1.Num)); int el = 3; var res = Util.MkString(lst); int idx = Seqops.IndexOfLp <int>(el, lst); Console.WriteLine("IndexOf({0}, {1}): {2}", el, res, idx); int newVal = 50; Console.Write("{0}.Add({1}): ", res, newVal); lst.Add(newVal); res = Util.MkString(lst); Console.WriteLine("{0}", res); } Console.WriteLine(new string('-', 40)); int nPascal = 5; int[][] arrPascal = Classic.PascalTriAdd(nPascal); Console.WriteLine("PascalTri(n: {0}): ", nPascal); Classic.PrintPascalTri(nPascal, arrPascal); Console.WriteLine(new string('-', 40)); int ndisks = 4, lenHanoi = (int)Math.Pow(2.0f, ndisks) - 1; int[][] arrHanoi = ClassicPuzzles.Hanoi(1, 2, 3, ndisks); Console.WriteLine("Hanoi(src: 1, dest: 2, spare: 3, ndisks: {0}): ", ndisks); for (int i = 0; lenHanoi > i; ++i) { Console.WriteLine("move #{0,-2}: move from {1} to {2}", i + 1, arrHanoi[i][0], arrHanoi[i][1]); } Console.WriteLine(new string('-', 40)); int numqueens = 8, queensNdx = rnd.Next(0, 50); int[] arrNqueens = ClassicPuzzles.Nqueens(queensNdx, numqueens); Console.WriteLine("Nqueens(ndx: {0}, numqueens: {1}):", queensNdx, numqueens); Console.Write("{"); for (int r = 0; numqueens > r; ++r) { Console.Write("({0}, {1}), ", (char)('a' + r), arrNqueens[r]); } Console.WriteLine("}"); for (int r = 0; numqueens > r; ++r, Console.WriteLine()) { Console.Write("'{0}'", numqueens - 1 - r); for (int c = 0; numqueens > c; ++c) { Console.Write("'{0}'", (numqueens - 1 - r) == arrNqueens[c] ? 'Q' : '.'); } } Console.Write("' '"); for (int c = 0; numqueens > c; ++c) { Console.Write("'{0}'", (char)('a' + c)); } Console.WriteLine("\n"); Console.WriteLine(new string('-', 40)); //pers = new Person("John", 32); pers = new Person { Name = "I.M. Computer", Age = 32 }; Trace.Assert(pers.GetType() == typeof(Person), "Debug Error: Type mismatch"); Trace.Assert(pers is Object, "Trace Error: Type inheritance mismatch"); Console.WriteLine("{0}", pers.ToString()); Console.Write("pers.Age = {0}: ", 33); pers.Age = 33; Console.WriteLine("{0}", pers.ToString()); Console.WriteLine(new string('-', 40)); }