Exemplo n.º 1
0
 private static int AddConnection(genericConnection sqlConn)
 {
     lock (allConn)
     {
         nConn         += 1;
         totConn       += 1;
         allConn[nConn] = sqlConn;
         return(nConn);
     }
 }
Exemplo n.º 2
0
        async Task <object> openConnection(string connectionString, string driver)
        {
            genericConnection gen = dispatchConn(connectionString, driver);

            try
            {
                await gen.open();

                return(AddConnection(gen));
            }
            catch
            {
                throw new Exception("Error opening connection");
            }
        }
Exemplo n.º 3
0
        public Func <object, Task <object> > CompileFunc(IDictionary <string, object> parameters)
        {
            string connectionString = Environment.GetEnvironmentVariable("EDGE_SQL_CONNECTION_STRING");
            object tmp;

            if (parameters.TryGetValue("connectionString", out tmp))
            {
                connectionString = (string)tmp;
            }
            int handler = -1;

            if (parameters.TryGetValue("handler", out tmp))
            {
                handler = (int)tmp;
            }
            int timeOut = 30;

            if (parameters.TryGetValue("timeout", out tmp))
            {
                timeOut = (int)tmp;
            }

            Func <object, Task <object> > callback = null;

            tmp = null;
            if (parameters.TryGetValue("callback", out tmp))
            {
                callback = (Func <object, Task <object> >)tmp;
            }
            string driver = "sqlServer";

            tmp = null;
            if (parameters.TryGetValue("driver", out tmp))
            {
                driver = (string)tmp;
            }

            string command = "";

            if (parameters.TryGetValue("source", out tmp))
            {
                command = tmp.ToString().TrimStart();
            }

            tmp = null;
            if (parameters.TryGetValue("cmd", out tmp))
            {
                var cmd = ((string)tmp).ToLower().Trim();
                if (cmd == "open")
                {
                    return(async(o) => {
                        return await openConnection(connectionString, driver);
                    });
                }
                if (cmd == "close")
                {
                    closeConnection(handler);
                    return((o) => {
                        return Task.FromResult((object)null);
                    });
                }
                if (cmd == "nonquery")
                {
                    if (handler >= 0)
                    {
                        genericConnection conn = allConn[handler];
                        return(async(o) => {
                            return await conn.executeNonQueryConn(command, timeOut);
                        });
                    }
                    else
                    {
                        genericConnection conn = dispatchConn(connectionString, driver);
                        return(async(o) => {
                            return await conn.executeNonQuery(command, timeOut);
                        });
                    }
                }
            }

            int    packetSize = 0;
            object defPSize   = 0;

            if (parameters.TryGetValue("packetSize", out defPSize))
            {
                packetSize = Convert.ToInt32(defPSize);
            }
            if (handler != -1)
            {
                genericConnection conn = allConn[handler];
                return(async(o) => {
                    return await conn.executeQueryConn(command, packetSize, timeOut, callback);
                });
            }

            return(async(queryParameters) => {
                genericConnection conn = dispatchConn(connectionString, driver);
                return await conn.executeQuery(command, (IDictionary <string, object>) queryParameters,
                                               packetSize, timeOut, callback);
            });
        }