Example #1
0
 public CommandParam(string _cmdText = null,
                     Dictionary <string, dynamic> _cmdParams = null,
                     string _cmdGroup   = null, Int64 _tempKey    = 0, Int64 _newKey      = -1,
                     string _tempStrKey = null, string _newStrKey = null, DALTable _table = null, JObject _cmdOutput = null, Int64 _paramKeyValuePosition = -1, Int64 _paramKeyValue = -1)
 {
     CommandParamInit(_cmdText, _cmdParams, _cmdGroup, _tempKey, _newKey, _tempStrKey, _newStrKey, _table, _cmdOutput, _paramKeyValuePosition, _paramKeyValue);
 }
Example #2
0
        private static string SetTableRelations(DALTable tbl)
        {
            tbl.tableProcessLogs.Add(tbl.tableCode + "_SetTableRelations", tbl.relations == null ? " no table.relations " : tbl.relations.Count().ToString());
            if (tbl.relations == null)
            {
                return("");
            }

            string retVal = "";

            foreach (JObject j in tbl.relations)
            {
                string   type              = _g.TKVStr(j, "type");
                string   childTableCode    = _g.TKVStr(j, "foreign_code");
                string[] childTableCodeArr = childTableCode.Split('-');
                DALTable childTable        = AppTables[childTableCodeArr[0]];
                string   childType         = childTableCodeArr.Length == 1 ? "" : childTableCodeArr[1];

                if (tbl.tableRelations == null)
                {
                    tbl.tableRelations = new Dictionary <string, DALRelation>();
                }

                DALRelation rel = new DALRelation(type, tbl, childTable,
                                                  _g.TKVStr(j, "local_field"), _g.TKVStr(j, "foreign_field"), _g.TKVBln(j, "parent_detail"), childType: childType);

                tbl.tableRelations.Add(childTableCode, rel);
            }

            return(retVal);
        }
Example #3
0
        private void CommandParamInit(string _cmdText = null,
                                      Dictionary <string, dynamic> _cmdParams = null,
                                      string _cmdGroup   = null, Int64 _tempKey    = 0, Int64 _newKey      = -1,
                                      string _tempStrKey = null, string _newStrKey = null, DALTable _table = null, JObject _cmdOutput = null, Int64 _paramKeyValuePosition = -1, Int64 _paramKeyValue = -1)
        {
            //
            // TODO: Add constructor logic here
            //

            _SQLMode = (this.newKey != 0 || this.newStrKey != null ? SQLModes.INSERT : "");

            if (_cmdText != null)
            {
                cmdText = _cmdText;
            }
            if (_cmdParams != null)
            {
                cmdParams = _cmdParams;
            }
            if (_cmdGroup != null)
            {
                cmdGroup = _cmdGroup;
            }
            if (_table != null)
            {
                table = _table;
            }

            if (_cmdOutput != null)
            {
                cmdOutput = _cmdOutput;
            }

            tempKey = _tempKey;
            newKey  = _newKey;

            tempStrKey = _tempStrKey;
            newStrKey  = _newStrKey;

            paramKeyValuePosition = _paramKeyValuePosition;
            paramKeyValue         = _paramKeyValue;

            //if (_cmdInput != null) cmdInput = _cmdInput;
        }
Example #4
0
        public JObject NewInfo()
        {
            JObject ret = new JObject();

            try
            {
                var      ctx  = HttpContext.Current;
                var      code = ctx.Request.Params["code"];
                DALTable tbl  = AppDataset.AppTables[code];

                ret.Add("tableCode", tbl.tableCode);
                ret.Add("newId", tbl.NewAutoId);

                ret.Add("status", "success");
            }catch (Exception e)
            {
                ret.Add("status", "error");
                ret.Add("message", e.Message);
            }
            return(ret);
        }
Example #5
0
        public List <AppReturn> get(string table, string key = "",
                                    string keyField          = "", string includedFields = "",
                                    string filter            = "", string sortFields     = "",
                                    string pageNumber        = "0", string pageSize      = "0",
                                    string requestConfig     = "", string fieldMap       = "")
        //string keyField = "")
        {
            //_g.CONFIG_FILE = "ngarbi.settings.json";
            // process request where all parameters are embedded in the Base64 querystring parameter "_p"

            // Add all parameters to the AppArgs object

            List <AppReturn> retVal = new List <AppReturn> {
            };

            if (isAppDebug)
            {
                return new List <AppReturn> {
                           DebugPath
                }
            }
            ;

            AppReturn appReturn = new AppReturn();

            if (table == "@gents")
            {
                // Generate client-side typescript files
                AppDataset.Initialize();

                appReturn.props.Add("Tables", AppDataset.AppTables.Count());
                appReturn.subsKey = "Hello Test Me!";

                appReturn.props.Add("Views", AppDataset.AppViews.Count());
                appReturn.props.Add("StoredProcedures", AppDataset.AppProcedures.Count());

                foreach (string tblCode in AppDataset.AppTables.Keys)
                {
                    DALTable tbl = AppDataset.AppTables[tblCode];
                    appReturn.processLogs.Add(tblCode, tbl.tableName);
                    appReturn.processLogs.Add(tblCode + "_relation", tbl.tableRelations == null ? "0" : tbl.tableRelations.Count.ToString());
                    foreach (string pv in tbl.tableProcessLogs.Keys)
                    {
                        appReturn.processLogs.Add(tblCode + "_proc_" + pv, tbl.tableProcessLogs[pv]);
                    }
                }

                //retVal.Add(appReturn); return retVal;
                return(new List <AppReturn> {
                    appReturn
                });
            }

            if (table == "@locs")
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                string[] keyArr = key.Split('`');
                string   pCode  = "";

                if (keyArr.Length >= 2)
                {
                    pCode = keyArr[1];
                }

                DALData.DAL.BuildNodeLocation(Convert.ToInt32(keyArr[0]), pCode);
                appReturn.returnCode = table;
                st.Stop();
                appReturn.requestDuration = st.ElapsedMilliseconds;

                return(new List <AppReturn> {
                    appReturn
                });
            }
            if (table == "@mtbl")
            {
                // multi table query, accepts json formatted parameters supplied as
                // Base64 encoded querystring parameters named ?p=
                // api call <protocol>://<domain>[/application]/api/app/@mtbl?p=<base64 encoded parameters>
                return(new List <AppReturn> {
                    appReturn
                });
            }

            if (isAppDebugPaths)
            {
                return new List <AppReturn> {
                           DebugPath
                }
            }
            ;


            JObject jArgs = new JObject()
            {
            };

            // split "table" parameter to get the parent table code (first element) and from clause join codes (second element)
            string[] tableArr = table.Split('|');

            jArgs.Add("code", tableArr[0]);
            if (tableArr.Length > 1)
            {
                jArgs.Add("fromClauseExpr", tableArr[1]);
            }

            jArgs.Add("key", (key == "-" ? "" : key));
            jArgs.Add("keyField", (keyField == "-" ? "" : keyField));
            jArgs.Add("includedFields", (includedFields == "-" ? "" : includedFields));
            jArgs.Add("filter", (filter == "-" ? "" : filter));
            jArgs.Add("fieldMap", (filter == "-" ? "" : fieldMap));
            jArgs.Add("sortFields", (sortFields == "-" ? "" : sortFields));
            jArgs.Add("pageNumber", (!pageNumber.All(char.IsDigit) ? 0 : Convert.ToInt64(pageNumber)));
            jArgs.Add("pageSize", (!pageSize.All(char.IsDigit) ? 0 : Convert.ToInt64(pageSize)));
            jArgs.Add("requestConfig", (requestConfig == "-" ? "" : requestConfig));
            jArgs.Add("snapshot", _g.TKVBln(AppArgs, "snapshot"));
            jArgs.Add("distinct", _g.TKVBln(AppArgs, "distinct"));

            AppArgs.Add(_g.KEY_REQ_ARGS_ARR, new JArray()
            {
                jArgs
            });

            return(ExecuteGetRequest());
        }

        //public ReturnObjectExternal xxxxpostX(string table, [FromBody]JObject values)
        //{
        //    ReturnObject retVal = AppDataset.Post(table, values, AppArgs);
        //    return retVal.result;
        //}


        /**********************************************************************************************************
         *  Private Methods
         *********************************************************************************************************/

        //private JObject AppArgs()
        //{
        //    // Collect query string arguments and some headers ...

        //    JObject ret = new JObject();

        //    List<KeyValuePair<string, string>> retList = ControllerContext.Request.GetQueryNameValuePairs().ToList();

        //    // add request data/time stamp
        //    retList.Add(new KeyValuePair<string, string>(AppGlobals.KEY_REQUEST_STAMP, DateTime.Now.ToString()));

        //    //add content type
        //    if (this.Request.Content.Headers.Contains("Content-Type"))
        //    {
        //        ret.Add(new KeyValuePair<string, string>(AppGlobals.KEY_CONTENT_TYPE, this.Request.Content.Headers.ContentType.ToString().ToLower()));
        //    }

        //    foreach (KeyValuePair<string, string> arg in retList)
        //    {
        //        ret.Add(arg.Key, arg.Value);
        //    }
        //    return ret;
        //}
    }
}
Example #6
0
        public List <AppReturn> post([FromBody] JObject values)
        {
            //_g.CONFIG_FILE = "ngarbi.settings.json";

            DateTime startProcess = DateTime.Now;

            if (values[_g.KEY_QPARAM_JSON] != null)
            {
                // get request with complex parameters initiated
                return(RequestData(values));
            }


            //dGhpcyBpcyBhIHRlc3Q=
            byte[] bytes = Convert.FromBase64String("dGhpcyBpcyBhIHRlc3Q=");
            string text  = System.Text.Encoding.Default.GetString(bytes);

            byte[] bytes2  = System.Text.Encoding.Default.GetBytes(text);
            string textB64 = Convert.ToBase64String(bytes2);

            JObject args = AppArgs;

            // initialize return object
            AppReturn ret = new AppReturn();



            if (values.ContainsKey(_g.KEY_REQUEST_HEADER_CODE))
            {
                try
                {
                    string  header    = (String)values[_g.KEY_REQUEST_HEADER_CODE];        // extract header Base64
                    byte[]  jsonBytes = Convert.FromBase64String(header);                  // convert to byte array
                    string  jsonText  = System.Text.Encoding.Default.GetString(jsonBytes); // convert to JSON string
                    JObject json      = JObject.Parse(jsonText);                           // convert to JSON object

                    // loop through header information and add token to AppArgs if not yet existing
                    foreach (JProperty jph in (JToken)json)
                    {
                        if (!args.ContainsKey(jph.Name))
                        {
                            args.Add(jph.Name, jph.Value);
                        }
                    }

                    ret.headerProcessResult.Add("result", "Success");
                }
                catch (Exception e)
                {
                    ret.headerProcessResult.Add("ErrorDetails", e.ToString());
                    ret.headerProcessResult.Add("result", "Error");
                }
            }

            List <AppReturn> retVal        = new List <AppReturn> {
            };
            List <CommandParam> cmds       = new List <CommandParam>();
            JObject             postConfig = null;
            bool         useCommonNewKey   = false;
            bool         firstTable        = true;
            List <Int64> tblCommonId       = new List <Int64>();

            // generate collection of commands to execute
            foreach (JProperty jp in (JToken)values)
            {
                // iterate through all tables to generate CommandParams collection
                if (jp.Name == _g.KEY_PROCESS_HEADER_CODE)
                {
                    DALData.DAL.LogGlobalMessage("proces header code is supplied!", "invoke_process");
                    // this section is where application-specific process will be invoked
                    ret.invokeResult = RunModels.Invoke(jp);
                }
                else if (jp.Name == _g.KEY_REQUEST_HEADER_CODE)
                {
                    ;
                }
                else if (jp.Name == _g.KEY_PROCESS_CONFIG_CODE)
                // config code value contains instruction/parameters which
                // will determine specific process when posting
                // eg. on creation of new record with sub table, use common id
                // for both
                {
                    postConfig = (JObject)jp.Value;
                    if (postConfig["useCommonNewKey"] != null)
                    {
                        useCommonNewKey = (bool)postConfig["useCommonNewKey"];
                    }
                }

                else
                {
                    // PROCESS TABLE CREATE, UPDATE, DELETE

                    // get table object from the collection
                    DALTable tbl = AppDataset.AppTables[jp.Name];
                    // if(!firstTable && tblCommonId)
                    //
                    Int64 newRecordKeyId = -1;


                    // get collection of CommandParams per table
                    List <CommandParam> cmdsTemp = tbl.GetCommandParamsForPosting((JArray)jp.Value, args);
                    CommandParam        cmd1     = cmdsTemp[0];
                    if (firstTable)
                    {
                        // record first table record ids.
                        // iterate through the records' parameters

                        if (cmd1.newKey != -1)
                        {
                            // new record. populate tblCommonId with key id's of all commands
                            cmdsTemp.ForEach(cmd => tblCommonId.Add(cmd.paramKeyValue));
                        }

                        firstTable = false; // set first table flag to false after processing it
                    }
                    else
                    {
                        // if use common id,
                        if (useCommonNewKey && cmd1.newKey != -1 && tblCommonId.Count != 0)
                        {
                            int ctr = 0;
                            cmdsTemp.ForEach(cmd =>
                            {
                                cmd.cmdParams[DALData.PARAM_PREFIX + "p" + (int)cmd.paramKeyValuePosition] = tblCommonId[ctr];
                                ctr++;
                            });
                        }
                    }
                    if (DALData.DAL.globalError.Length != 0)
                    {
                        // error has occured, therefore empty list is returned. handle error here
                        break;
                    }



                    // append commands to the general collection for execution in bulk
                    foreach (CommandParam cmd in cmdsTemp)
                    {
                        cmds.Add(cmd);
                    }
                }

                // execute commands
            }

            List <ReturnObject> cmdResults = new List <ReturnObject>();

            // execute all commands in the collection (if any) - debug bypass by alv 2020/12/04 5:40am
            cmdResults = DALData.DAL.Excute(cmds, true);

            DateTime endProcess = DateTime.Now;

            long dur = ((endProcess.Millisecond +
                         endProcess.Second * 1000 +
                         endProcess.Minute * 60 * 1000 +
                         endProcess.Hour * 60 * 60 * 1000) -
                        (startProcess.Millisecond +
                         startProcess.Second * 1000 +
                         startProcess.Minute * 60 * 1000 +
                         startProcess.Hour * 60 * 60 * 1000));

            //ret.returnStrings.Add("Process Duration in milliseconds: " + dur.ToString() + "(ms)");
            //if (errMessage.Length!=0) ret.returnStrings.Add("Error:" + errMessage);

            //ret.stamps = new DALStamps(cmds[0].table.columns, "@alv");
            ret.stamps = null;

            ret.errorMessage = DALData.DAL.globalError;

            if (DALData.DAL.globalMessages.Count() != 0)
            {
                ret.globalMesages = DALData.DAL.globalMessages;
            }

            retVal.Add(ret);

            // ***** Generate result summary for client-side processing ******
            foreach (ReturnObject rObj in cmdResults)
            {
                string retCode = rObj.returnCode;
                if (retCode == "chgTrack" || retCode == "")
                {
                    continue;
                }

                ret = new AppReturn();

                ret.returnCode       = rObj.returnCode;
                ret.errorMessage     = rObj.result.exceptionMessage;
                ret.returnDataParams = rObj.result.returnDataParams;
                ret.result           = rObj.result.result;

                retVal.Add(ret);
            }

            return(retVal);
            //return new List<AppReturn>();
            //return new List<AppReturn> { new AppReturn() };
        }   /** End of POST method **/
Example #7
0
        public List <AppReturn> post([FromBody] JObject values)
        {
            /************************************************************************************
            * 20 Dec 2019 - alv
            * values:
            * {
            *  "<tableCode>":[{data row object 1},...,{data row object n}]
            * }
            ************************************************************************************/

            /************************************************************************************
            * 15 April 2020 - alv
            *
            * public static string KEY_REQUEST_HEADER_CODE = "__header__";
            *
            * public static string KEY_REQUEST_STAMP = "_req_stamp_";
            * public static string KEY_USER_ID = "__uid__";
            * public static string KEY_USER_RIGHTS = "__rights__";
            * public static string KEY_ACTION = "__action__";
            *
            * JSON
            *
            *  "__header__" :
            *  {
            *       "_req_stamp_":"",
            *       "__uid__":"alv",
            *       "__rights__":"",
            *       "__action__":""
            *  }
            *  "__header__" :{"_req_stamp_":"","__uid__":"alv","__rights__":"","__action__":""}
            *
            *  https://www.base64encode.org/
            *  Equivalent base64: eyJfcmVxX3N0YW1wXyI6IiIsIl9fdWlkX18iOiJhbHYiLCJfX3JpZ2h0c19fIjoiIiwiX19hY3Rpb25fXyI6IiJ9
            *
            * Converted to Base64 text
            ************************************************************************************/

            DateTime startProcess = DateTime.Now;


            //dGhpcyBpcyBhIHRlc3Q=
            byte[] bytes = Convert.FromBase64String("dGhpcyBpcyBhIHRlc3Q=");
            string text  = System.Text.Encoding.Default.GetString(bytes);

            byte[] bytes2  = System.Text.Encoding.Default.GetBytes(text);
            string textB64 = Convert.ToBase64String(bytes2);

            JObject args = AppArgs;

            if (values.ContainsKey(_g.KEY_REQUEST_HEADER_CODE))
            {
                string  header    = (String)values[_g.KEY_REQUEST_HEADER_CODE];        // extract header Base64
                byte[]  jsonBytes = Convert.FromBase64String(header);                  // convert to byte array
                string  jsonText  = System.Text.Encoding.Default.GetString(jsonBytes); // convert to JSON string
                JObject json      = JObject.Parse(jsonText);                           // convert to JSON object

                // loop through header information and add token to AppArgs if not yet existing
                foreach (JProperty jph in (JToken)json)
                {
                    if (!args.ContainsKey(jph.Name))
                    {
                        args.Add(jph.Name, jph.Value);
                    }
                }
            }

            List <AppReturn> retVal  = new List <AppReturn> {
            };
            List <CommandParam> cmds = new List <CommandParam>();

            // generate collection of commands to execute
            foreach (JProperty jp in (JToken)values)
            {
                // iterate through all tables to generate CommandParams collection
                if (jp.Name != _g.KEY_REQUEST_HEADER_CODE)
                {
                    // get table object from the collection
                    DALTable tbl = AppDataset.AppTables[jp.Name];

                    // get collection of CommandParams per table
                    List <CommandParam> cmdsTemp = tbl.GetCommandParamsForPosting((JArray)jp.Value, args);
                    if (DALData.DAL.globalError.Length != 0)
                    {
                        // error has occured, therefore empty list is returned. handle error here
                        break;
                    }

                    // append commands to the general collection for execution in bulk
                    foreach (CommandParam cmd in cmdsTemp)
                    {
                        cmds.Add(cmd);
                    }
                }

                // execute commands
            }

            // execute all commands in the collection
            List <ReturnObject> cmdResults = DALData.DAL.Excute(cmds, true);

            DateTime endProcess = DateTime.Now;

            AppReturn ret = new AppReturn();
            long      dur = ((endProcess.Millisecond +
                              endProcess.Second * 1000 +
                              endProcess.Minute * 60 * 1000 +
                              endProcess.Hour * 60 * 60 * 1000) -
                             (startProcess.Millisecond +
                              startProcess.Second * 1000 +
                              startProcess.Minute * 60 * 1000 +
                              startProcess.Hour * 60 * 60 * 1000));

            //ret.returnStrings.Add("Process Duration in milliseconds: " + dur.ToString() + "(ms)");
            //if (errMessage.Length!=0) ret.returnStrings.Add("Error:" + errMessage);

            //ret.stamps = new DALStamps(cmds[0].table.columns, "@alv");
            ret.stamps = null;

            //AppReturn ar = new AppReturn();
            //ar.stamps = new DALStamps(cmds[0].table.columns, "@alv");
            //retVal.Add(ar);

            ret.errorMessage = DALData.DAL.globalError;

            retVal.Add(ret);

            foreach (ReturnObject rObj in cmdResults)
            {
                ret = new AppReturn();
                ret.errorMessage = rObj.result.exceptionMessage;
                retVal.Add(ret);
            }

            return(retVal);
            //return new List<AppReturn> { new AppReturn() };
        }
Example #8
0
        public List <AppReturn> get(string table, string key = "",
                                    string keyField          = "", string includedFields = "",
                                    string filter            = "", string sortFields     = "",
                                    string pageNumber        = "0", string pageSize      = "0",
                                    string requestConfig     = "", string fieldMap       = "")
        //string keyField = "")
        {
            //_g.CONFIG_FILE = "ngarbi.settings.json";
            // process request where all parameters are embedded in the Base64 querystring parameter "_p"

            // Add all parameters to the AppArgs object

            List <AppReturn> retVal = new List <AppReturn> {
            };

            if (isAppDebug)
            {
                return new List <AppReturn> {
                           DebugPath
                }
            }
            ;

            AppReturn appReturn = new AppReturn();

            if (table == "@gents")
            {
                // Generate client-side typescript files
                AppDataset.Initialize();

                appReturn.props.Add("Tables", AppDataset.AppTables.Count());
                appReturn.subsKey = "Hello Test Me!";

                appReturn.props.Add("Views", AppDataset.AppViews.Count());
                appReturn.props.Add("StoredProcedures", AppDataset.AppProcedures.Count());

                foreach (string tblCode in AppDataset.AppTables.Keys)
                {
                    DALTable tbl = AppDataset.AppTables[tblCode];
                    appReturn.processLogs.Add(tblCode, tbl.tableName);
                    appReturn.processLogs.Add(tblCode + "_relation", tbl.tableRelations == null ? "0" : tbl.tableRelations.Count.ToString());
                    foreach (string pv in tbl.tableProcessLogs.Keys)
                    {
                        appReturn.processLogs.Add(tblCode + "_proc_" + pv, tbl.tableProcessLogs[pv]);
                    }
                }

                //retVal.Add(appReturn); return retVal;
                return(new List <AppReturn> {
                    appReturn
                });
            }

            if (table == "@locs")
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                string[] keyArr = key.Split('`');
                string   pCode  = "";

                if (keyArr.Length >= 2)
                {
                    pCode = keyArr[1];
                }

                DALData.DAL.BuildNodeLocation(Convert.ToInt32(keyArr[0]), pCode);
                appReturn.returnCode = table;
                st.Stop();
                appReturn.requestDuration = st.ElapsedMilliseconds;

                return(new List <AppReturn> {
                    appReturn
                });
            }
            if (table == "@mtbl")
            {
                // multi table query, accepts json formatted parameters supplied as
                // Base64 encoded querystring parameters named ?p=
                // api call <protocol>://<domain>[/application]/api/app/@mtbl?p=<base64 encoded parameters>
                return(new List <AppReturn> {
                    appReturn
                });
            }

            if (isAppDebugPaths)
            {
                return new List <AppReturn> {
                           DebugPath
                }
            }
            ;


            JObject jArgs = new JObject()
            {
            };

            // split "table" parameter to get the parent table code (first element) and from clause join codes (second element)
            string[] tableArr = table.Split('|');

            jArgs.Add("code", tableArr[0]);
            if (tableArr.Length > 1)
            {
                jArgs.Add("fromClauseExpr", tableArr[1]);
            }

            jArgs.Add("key", (key == "-" ? "" : key));
            jArgs.Add("keyField", (keyField == "-" ? "" : keyField));
            jArgs.Add("includedFields", (includedFields == "-" ? "" : includedFields));
            jArgs.Add("filter", (filter == "-" ? "" : filter));
            jArgs.Add("fieldMap", (filter == "-" ? "" : fieldMap));
            jArgs.Add("sortFields", (sortFields == "-" ? "" : sortFields));
            jArgs.Add("pageNumber", (!pageNumber.All(char.IsDigit) ? 0 : Convert.ToInt64(pageNumber)));
            jArgs.Add("pageSize", (!pageSize.All(char.IsDigit) ? 0 : Convert.ToInt64(pageSize)));
            jArgs.Add("requestConfig", (requestConfig == "-" ? "" : requestConfig));
            jArgs.Add("snapshot", _g.TKVBln(AppArgs, "snapshot"));
            jArgs.Add("distinct", _g.TKVBln(AppArgs, "distinct"));

            AppArgs.Add(_g.KEY_REQ_ARGS_ARR, new JArray()
            {
                jArgs
            });

            return(ExecuteGetRequest());
        }
Example #9
0
        private static void SetTableConfiguration()
        {
            // clear DALTable objects in the Dataset
            AppTables.Clear();
            // Get all table configuration files
            string[] configFiles = Directory.GetFiles(_g.PATH_SCHEMA_CONFIG, _g.PTN_TABLE_CONFIG);

            foreach (string fn in configFiles)
            {
                // Get Object Code that will be used as key to the element in the object dicationary
                string objCode = _g.GetCodeFromPattern(fn, _g.PTN_TABLE_CONFIG);

                // convert JSON string to JObject
                JObject jObject = JObject.Parse(File.ReadAllText(fn));

                // Convert JSON String of the columns property to JArray object
                JArray jCols = JArray.Parse(_g.TKVStr(jObject, "columns", "[]"));

                // Initialize new colsInfo list
                List <ColumnInfo> colsInfo = new List <ColumnInfo>()
                {
                };
                string fieldPrefix = _g.TKVStr(jObject, "tableFieldPrefix");

                // loop through columns if found in the configuration file
                if (jCols.Count != 0)
                {
                    foreach (JObject jCol in jCols)
                    {
                        colsInfo.Add(new ColumnInfo(
                                         _g.TKVStr(jCol, "name")
                                         , _g.TKVStr(jCol, "type", "String")
                                         , _g.TKVStr(jCol, "caption")
                                         , _g.TKVStr(jCol, "alias")
                                         , _g.TKVStr(jCol, "roles")
                                         , _g.TKVInt(jCol, "keyPosition")
                                         , _g.TKVInt(jCol, "uniquePosition")
                                         , _g.TKVInt(jCol, "groupPosition")
                                         , _g.TKVInt(jCol, "sortPosition")
                                         , _g.TKVInt(jCol, "displayPosition")
                                         , _g.TKVBln(jCol, "isRequired")
                                         , _g.TKVBln(jCol, "isLong")
                                         , fieldPrefix
                                         ));
                    }
                }

                // Add new item in the Table dictionary
                AppTables.Add(
                    objCode, new DALTable(
                        _g.TKVStr(jObject, "tableName")
                        , colsInfo
                        , description: _g.TKVStr(jObject, "description")
                        , tableCode: objCode
                        , tableClassFilename: _g.TKVStr(jObject, "tableClassFilename")
                        , tableClass: _g.TKVStr(jObject, "tableClass")
                        , tableRowClass: _g.TKVStr(jObject, "tableRowClass")
                        , tableFieldPrefix: _g.TKVStr(jObject, "tableFieldPrefix")
                        , links: _g.TKVJArr(jObject, "links")
                        , relations: _g.TKVJArr(jObject, "relations")
                        , captions: _g.TKVJObj(jObject, "captions")
                        , tableLinks: _g.TKVJArr(jObject, "tableLinks")
                        , tableLinksFields: _g.TKVJObj(jObject, "tableLinksFields")
                        , tableCollection: AppTables
                        , clientConfig: _g.TKVJObj(jObject, "clientConfig")
                        )
                    );
            }   // end of foreach configFiles

            bool clientSideDevExist = File.Exists(_g.PATH_TARGET_TYPESCRIPT_DATASET);

            // iterate through tables to generate single client-side typescript file
            string typeScript     = "";
            string importScript   = "";
            string instanceScript = "";
            string tblClassName;

            string relScript = "";

            // Iterate through all generated DALTable objects to perform
            // Table post creation property assignments

            for (int idx = 0; idx < AppTables.Count(); idx++)
            {
                DALTable tblObj = AppTables.ElementAt(idx).Value;

                SetTableRelations(tblObj);
                if (tblObj.tableRelations != null)
                {
                    string relFmt = "\n    this.t{0}.tableRelations.push(new Relation(\"{1}\", \"{2}\", this.t{3}, this.t{4}, \"{5}\", \"{6}\", {7}));";
                    foreach (string relKey in tblObj.tableRelations.Keys)
                    {
                        DALRelation rel = tblObj.tableRelations[relKey];
                        relScript += String.Format(relFmt, tblObj.tableClass.Substring(1), rel.foreignTableCode,
                                                   rel.type, rel.table.tableClass.Substring(1), rel.tableChild.tableClass.Substring(1),
                                                   rel.localField, rel.foreignField, rel.parentDetail.ToString().ToLower());
                    }
                    //this.tblAnomalies.tableRelations["an"]=new Relation("lnk",this.ds.tblAnomalies,this.ds.tblFailureThreats);
                }

                if (idx == 0)
                {
                    typeScript = tblObj.templateImports;
                }
                typeScript += "\n\n\n" + tblObj.templateClass;

                tblClassName = tblObj.tableClass;

                importScript += "\n" + _g.TPL_TARGET_TYPESCRIPT_IMPORT
                                .Replace("<TABLE>", tblClassName)
                                .Replace("<TABLEROW>", tblObj.tableRowClass);

                instanceScript += "\n  " + _g.TPL_TARGET_TYPESCRIPT_INSTANCE
                                  .Replace("<TABLEVAR>", tblClassName.Substring(0, 1).ToLower() + tblClassName.Substring(1))
                                  .Replace("<TABLE>", tblClassName);
            }

            // write typecript to client side script file
            if (clientSideDevExist)
            {
                DALData.DAL.writeAllText(_g.PATH_TARGET_TYPESCRIPT_PATH, typeScript);

                string dsts = File.ReadAllText(_g.PATH_TARGET_TYPESCRIPT_DATASET);
                // write in between INCLUDES
                //<INCLUDES>
                //</INCLUDES>

                string[] tsArr  = _g.Split(dsts, "//<INCLUDES>");
                string[] tsArr2 = _g.Split(tsArr[1], "//</INCLUDES>");
                string   fmt    = "//<INCLUDES>{0}\n//</INCLUDES>";

                dsts = tsArr[0] + String.Format(fmt, importScript) + tsArr2[1];

                tsArr  = _g.Split(dsts, "//<INSTANTIATE>");
                tsArr2 = _g.Split(tsArr[1], "//</INSTANTIATE>");

                fmt  = "//<INSTANTIATE>{0}\n//</INSTANTIATE>";
                dsts = tsArr[0] + String.Format(fmt, instanceScript) + tsArr2[1];

                if (relScript.Length != 0)
                {
                    tsArr  = _g.Split(dsts, "//<RELATIONS>");
                    tsArr2 = _g.Split(tsArr[1], "//</RELATIONS>");

                    fmt  = "//<RELATIONS>{0}\n//</RELATIONS>";
                    dsts = tsArr[0] + String.Format(fmt, relScript) + tsArr2[1];
                }

                tsArr  = _g.Split(dsts, "//<DECLARE>");
                tsArr2 = _g.Split(tsArr[1], "//</DECLARE>");

                string declareString = String.Format("\n  this.apiCommon.PARAMS_DELIM_CHAR = '{0}';", _g2.PARAMS_DELIM_CHAR) +
                                       String.Format("\n  this.apiCommon.PARAMS_VAL_DELIM_CHAR = '{0}';", _g2.PARAMS_VAL_DELIM_CHAR) +
                                       String.Format("\n  this.apiCommon.FIELD_PARENT_LINK_ALIAS = '{0}';", _g2.FIELD_PARENT_LINK_ALIAS) +
                                       String.Format("\n  this.apiCommon.FIELD_CHILD_FIRST_ALIAS = '{0}';", _g2.FIELD_CHILD_FIRST_ALIAS) +
                                       String.Format("\n  this.apiCommon.FIELD_CHILD_COUNT_ALIAS = '{0}';", _g2.FIELD_CHILD_COUNT_ALIAS);

                fmt  = "//<DECLARE>{0}\n  //</DECLARE>";
                dsts = tsArr[0] + String.Format(fmt, declareString) + tsArr2[1];

                DALData.DAL.writeAllText(_g.PATH_TARGET_TYPESCRIPT_DATASET, dsts);
            }

            GeneralRetObj.debugStrings.Add("Total Tables: " + AppTables.Count());

            // set change track table property for non-change track tables...

            if (AppTables.ContainsKey(_g.KEY_TABLE_UPDATE_TRACK_CODE))
            {
                DALTable chgTrack = AppTables[_g.KEY_TABLE_UPDATE_TRACK_CODE];
                foreach (KeyValuePair <string, DALTable> tbl in AppTables)
                {
                    tbl.Value.tableChangeTrack = chgTrack;
                }
            }
        }   // end of SetTableConfiguration method