Example #1
0
        /// <summary>
        /// Gets HTML SELECT for DataBases
        /// </summary>
        /// <param name="dbType">
        /// Connection Type 1 MSSQLSERVER 2 MYSQL
        /// </param>
        /// <param name="serverDb">
        /// Server Name
        /// </param>
        /// <param name="userDb">
        /// DataBase User
        /// </param>
        /// <param name="password">
        /// User Password
        /// </param>
        /// <returns>
        /// String
        /// </returns>
        public static String getDbListHtml(int dbType, string serverDb, string userDb, string password)
        {
            string retValue = "";

            DataSet dsDb = cSmo.cSmo.getDataBases(dbType, serverDb, userDb, password);

            if (dsDb != null)
            {
                for (int i = 0; i < dsDb.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        myConfig cfg = myConfig.getInstance();
                        cfg.dbName = (string)dsDb.Tables[0].Rows[i]["DBSCHEMAS"];
                        retValue  += "<option selected value='";
                    }
                    else
                    {
                        retValue += "<option value='";
                    }

                    retValue += dsDb.Tables[0].Rows[i]["DBSCHEMAS"];
                    retValue += "'>";
                    retValue += dsDb.Tables[0].Rows[i]["DBSCHEMAS"];
                    retValue += "</option>";
                }
            }

            return(retValue);
        }
Example #2
0
        /// <summary>
        /// Get Instance
        /// </summary>
        /// <returns>
        /// myConfig Instance
        /// </returns>
        public static myConfig getInstance()
        {
            if (INSTANCE == null)
            {
                INSTANCE = new myConfig();
            }

            return(INSTANCE);
        }
Example #3
0
        /// <summary>
        /// Constructor of Class
        /// </summary>
        public myModule()
        {
            Get["/"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                try
                {
                    return(View["static/tree.html", cfg]);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            };

            Post["/dblist"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                int    dbType   = Request.Form.dbType;
                string serverDb = Request.Form.serverDb;
                string userDb   = Request.Form.userDb;
                string password = Request.Form.password;

                cfg.dbType   = dbType;
                cfg.serverDb = serverDb;
                cfg.userDb   = userDb;
                cfg.password = password;

                return(myUtil.getDbListHtml(dbType, serverDb, userDb, password));
            };

            Post["/save"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                int    dbType = Request.Form.dbType;
                string dir    = Request.Form.dir;
                string dbName = Request.Form.dbName;

                cfg.dbName = dbName;

                cSmo.cSmo smo = cSmo.cSmo.getInstance(dbType, cfg.path, cfg.serverDb, cfg.userDb, cfg.password, cfg.dbName);

                if (smo.isConnected())
                {
                    smo.saveTables(dir);
                    smo.saveProcedures(dir);
                    smo.saveFunctions(dir);

                    return("Ok");
                }
                else
                {
                    return("Bad");
                }
            };

            Post["/encrypt"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                int    dbType = Request.Form.dbType;
                string dbName = Request.Form.dbName;

                cfg.dbName = dbName;

                if (dbType == cSmo.cSmo.MSSQLSERVER)
                {
                    cSmo.cSmo smo = cSmo.cSmo.getInstance(dbType, cfg.path, cfg.serverDb, cfg.userDb, cfg.password, cfg.dbName);

                    if (smo.isConnected())
                    {
                        smo.encryptProcedures();
                        smo.encryptFunctions();

                        return("Ok");
                    }
                    else
                    {
                        return("Bad");
                    }
                }
                else
                {
                    return("Bad");
                }
            };

            Post["/getfiles"] = parameters =>
            {
                string dir = Request.Form.dir;

                myConfig cfg = myConfig.getInstance();

                if (dir.Equals("./"))
                {
                    dir = cfg.path;
                }

                dir = HttpUtility.UrlDecode(dir);

                string strDir = "";

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dir);
                strDir = strDir + "<ul class=\"jqueryFileTree\" style=\"display: none;\">\n";

                foreach (System.IO.DirectoryInfo di_child in di.GetDirectories())
                {
                    strDir = strDir + "\t<li class=\"directory collapsed\"><a href=\"#\" rel=\"" + dir + di_child.Name + "/\">" + di_child.Name + "</a></li>\n";
                }

                foreach (System.IO.FileInfo fi in di.GetFiles())
                {
                    string ext = "";
                    if (fi.Extension.Length > 1)
                    {
                        ext = fi.Extension.Substring(1).ToLower();
                    }

                    strDir = strDir + "\t<li class=\"file ext_" + ext + "\"><a href=\"#\" rel=\"" + dir + fi.Name + "\">" + fi.Name + "</a></li>\n";
                }

                strDir = strDir + "</ul>";

                return(strDir);
            };
        }
Example #4
0
        /// <summary>
        /// Init Method
        /// </summary>
        /// <param name="args">
        /// web or any string for start Web Application
        /// </param>
        static void Main(string[] args)
        {
            int    dbType   = 0;
            string path     = "";
            string serverDb = "";
            string userDb   = "";
            string password = "";
            string dbName   = "";

            // No arguments Console App
            if (args.Length == 0)
            {
                Console.WriteLine("Welcome to cSqlTools on Console !!!");

                JConfig.JConfig cfg = new JConfig.JConfig("config.json");

                if (cfg.totalKeys() > 0)
                {
                    Console.WriteLine("Running saved configuration");

                    dbType   = Int32.Parse(cfg.getValue("dbType"));
                    path     = cfg.getValue("path");
                    serverDb = cfg.getValue("serverDb");
                    userDb   = cfg.getValue("userDb");
                    password = cfg.getValue("password");
                    dbName   = cfg.getValue("dbName");
                    int action = Int32.Parse(cfg.getValue("action"));

                    cSmo.cSmo smo;

                    if (dbType == 1)
                    {
                        smo = cSmo.cSmo.getInstance(cSmo.cSmo.MSSQLSERVER, path, serverDb, userDb, password, dbName);
                    }
                    else
                    {
                        smo = cSmo.cSmo.getInstance(cSmo.cSmo.MYSQL, path, serverDb, userDb, password, dbName);
                    }

                    if (smo.isConnected())
                    {
                        if (action == 1)
                        {
                            if ((Directory.Exists(path)))
                            {
                                Console.WriteLine("Saving DDL Scripts on: " + path);
                                smo.saveTables();
                                smo.saveProcedures();
                                smo.saveFunctions();
                            }
                            else
                            {
                                Console.WriteLine("The Path not Exists");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Encrypting Routines of SQL Server (MySQL not Support)");
                            smo.encryptProcedures();
                            smo.encryptFunctions();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Could not connect to DataBase Server");
                    }
                }
                else
                {
                    Console.WriteLine("Configure Application");

                    Console.Write("Enter DataBase Type (1 SQL Server 2 MySQL): ");
                    dbType = int.Parse(Console.ReadLine());

                    Console.Write("Enter Path to save Scripts: ");
                    path = Console.ReadLine();

                    Console.Write("Enter Server DataBase Name: ");
                    serverDb = Console.ReadLine();

                    if (dbType == 1)
                    {
                        Console.Write("Enter SQL Server User: "******"Enter MySQL User: "******"Enter Password: "******"Enter DataBase Name: ");
                    dbName = Console.ReadLine();

                    cSmo.cSmo smo;

                    if (dbType == 1)
                    {
                        smo = cSmo.cSmo.getInstance(cSmo.cSmo.MSSQLSERVER, path, serverDb, userDb, password, dbName);
                    }
                    else
                    {
                        smo = cSmo.cSmo.getInstance(cSmo.cSmo.MYSQL, path, serverDb, userDb, password, dbName);
                    }

                    if (smo.isConnected())
                    {
                        Console.Write("Enter Action (1 Save DDL Scripts 2 Encrypt Routines): ");
                        int action = int.Parse(Console.ReadLine());

                        // Save Configuration
                        cfg.setKey("dbType", dbType.ToString());
                        cfg.setKey("path", path);
                        cfg.setKey("serverDb", serverDb);
                        cfg.setKey("userDb", userDb);
                        cfg.setKey("password", password);
                        cfg.setKey("dbName", dbName);
                        cfg.setKey("action", action.ToString());
                        cfg.save();

                        Console.WriteLine("Configuration saved on config.json");

                        if (action == 1)
                        {
                            if ((Directory.Exists(path)))
                            {
                                Console.WriteLine("Saving DDL Scripts on: " + path);
                                smo.saveTables();
                                smo.saveProcedures();
                                smo.saveFunctions();
                            }
                            else
                            {
                                Console.WriteLine("The Path not Exists");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Encrypting Routines of SQL Server (MySQL not Support)");
                            smo.encryptProcedures();
                            smo.encryptFunctions();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Could not connect to DataBase Server");
                    }
                }
            }
            else
            {
                // Web Application
                Console.WriteLine("Welcome to cqlTools Web !!!");

                Console.Write("Enter Base Path to save Scripts: ");
                path = Console.ReadLine();

                Console.Write("Enter Application Port: ");
                string strPort = Console.ReadLine();

                if ((Directory.Exists(path)))
                {
                    myConfig cfg = myConfig.getInstance();
                    cfg.CurrentDir = Environment.CurrentDirectory.Replace("\\", "/");
                    cfg.path       = path;
                    cfg.dbType     = dbType;

                    new myHost(Int32.Parse(strPort));
                }
                else
                {
                    Console.WriteLine("Path doesn't Exists.");
                }
            }
        }
Example #5
0
        /// <summary>
        /// Manage Static Content
        /// </summary>
        public myStatic()
        {
            Get["/static/bootstrap/css/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                string content = myUtil.getTextForFile(cfg.CurrentDir + Request.Path);

                if (content == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.AsText(content, "text/plain"));
            };

            Get["/static/bootstrap/js/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                string content = myUtil.getTextForFile(cfg.CurrentDir + Request.Path);

                if (content == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.AsText(content, "text/plain"));
            };

            Get["/static/js/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                string content = myUtil.getTextForFile(cfg.CurrentDir + Request.Path);

                if (content == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.AsText(content, "text/plain"));
            };

            Get["/static/jqfiletree/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                string content = myUtil.getTextForFile(cfg.CurrentDir + Request.Path);

                if (content == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.AsText(content, "text/plain"));
            };

            Get["/static/img/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                FileStream stream = myUtil.getStreamForFile(cfg.CurrentDir + Request.Path);

                if (stream == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.FromStream(stream, "image/png"));
            };

            Get["/static/jqfiletree/images/{file}"] = parameters =>
            {
                myConfig cfg = myConfig.getInstance();

                FileStream stream = myUtil.getStreamForFile(cfg.CurrentDir + Request.Path);

                if (stream == null)
                {
                    return new Nancy.Response {
                               StatusCode = Nancy.HttpStatusCode.NotFound
                    }
                }
                ;

                return(Response.FromStream(stream, "image/png"));
            };
        }
    }
}