Exemple #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            /*************************** custom calls ******************************************/

            // Initialize data access connection and other properties
            // DAL.connectionString = ConfigurationManager.ConnectionStrings["cnsAppAPI"].ConnectionString;

            //************************** Transfer to Controller Start **************************
            DALGlobals.APP_SETTINGS      = DataAccess.AppGlobals2.AppSetings;
            DALData.DAL.connectionString = ConfigurationManager.ConnectionStrings[DALGlobals.APP_SETTINGS["CONNECTION_NAME"]].ConnectionString;
            DALGlobals.GeneralRetObj     = new ReturnObjectExternal();
            AppDataset.configPath        = "";
            AppDataset.clientDevPath     = "";

            AppDataset.Initialize();  // Initialize dataset
            //************************** Transfer to Controller End **************************


            //DALData.DAL.LogMessage("Application Started ..");
            //DALData.DAL.LogMessage("Schema Path: " + DataAccess.AppGlobals2.PATH_SCHEMA_CONFIG);
            //DALData.DAL.LogMessage("Client Tables Path: " + DataAccess.AppGlobals2.PATH_TARGET_TYPESCRIPT_PATH);
            //DALData.DAL.LogMessage(HttpContext.Current.Server.MapPath("App_Data"));
        }
        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;
        //}
    }
}
        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());
        }