Esempio n. 1
0
        public void Exec(string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.Exec"))
            {
                Debugger.Launch();
            }

            try
            {
                CommandObject.CommandType    = CommandType.Text;
                CommandObject.CommandTimeout = timeout;
                CommandObject.CommandText    = sql;
                while (CommandObject.Connection.State == ConnectionState.Connecting)
                {
                    Thread.Sleep(1);
                }
                CommandObject.CommandText = sql;

                CommandObject.ExecuteNonQuery();
                LastError = null;
            }
            catch (Exception E)
            {
                LastError = E;
                return;
            }
        }
Esempio n. 2
0
        public DataTable DTEval(string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.DTEval"))
            {
                Debugger.Launch();
            }

            DataTable table = new DataTable();

            try
            {
                CommandObject.CommandType    = CommandType.Text;
                CommandObject.CommandTimeout = timeout;
                CommandObject.CommandText    = sql;
                while (CommandObject.Connection.State == ConnectionState.Connecting)
                {
                    Thread.Sleep(1);
                }
                using (SqlDataReader reader = CommandObject.ExecuteReader())
                {
                    table.Load(reader);
                }
                LastError = null;
            }
            catch (Exception E)
            {
                LastError = E;
                return(null);
            }
            return(table);
        }
Esempio n. 3
0
        public DataTable DTEval(SqlConnection connection, string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.DTEval"))
            {
                Debugger.Launch();
            }

            SqlCommand command = connection.CreateCommand();

            DataTable table = new DataTable();

            command.CommandType    = CommandType.Text;
            command.CommandTimeout = timeout;
            command.CommandText    = sql;
            while (command.Connection.State == ConnectionState.Connecting)
            {
                Thread.Sleep(1);
            }
            using (SqlDataReader reader = command.ExecuteReader())
            {
                table.Load(reader);
            }

            return(table);
        }
Esempio n. 4
0
        public static string OAuth2Connect(string client_id, string scope, string login_hint)
        {
            if (DebugPoints.DebugPointRequested("GoogleOAuth2.OAuth2Connect"))
            {
                Debugger.Launch();
            }
            string title = "";
            var    url   = string.Format(
                "https://accounts.google.com/o/oauth2/auth?{0}&{1}&{2}&{3}&{4}&{5}",
                "response_type=code",
                "client_id=" + client_id,
                "redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob",
                "scope=" + WebUtility.HtmlEncode(scope),
                "state=acit",
                "login_hint=" + login_hint);

            var driver = new FirefoxDriver();

            driver.Navigate().GoToUrl(url);
            // could automate the whole thing
            TimeSpan    ts      = new TimeSpan(0, 1, 0); // one minute
            IWebElement element = (new WebDriverWait(driver, ts))
                                  .Until(ExpectedConditions.ElementToBeClickable(By.Id("code")));

            title = driver.FindElement(By.Id("code")).GetAttribute("value");
            driver.Quit();
            driver.Dispose();
            return(title);
        }
Esempio n. 5
0
        public static string GetAccessToken(string client_id, string client_secret, string refresh_token)
        {
            if (DebugPoints.DebugPointRequested("GoogleOAuth2.GetAccessToken"))
            {
                Debugger.Launch();
            }

            Dictionary <string, object> dso = GoogleOAuth2.RefreshToken(client_id, client_secret, refresh_token);

            return(dso["access_token"].ToString());
        }
Esempio n. 6
0
        public string Eval(string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.Eval"))
            {
                Debugger.Launch();
            }

            StringBuilder evalResult = new StringBuilder();
            DataTable     table      = new DataTable();

            CommandObject.CommandText    = sql;
            CommandObject.CommandTimeout = timeout;
            CommandObject.CommandType    = CommandType.Text;
            try
            {
                using (SqlDataReader reader = CommandObject.ExecuteReader())
                {
                    table.Load(reader);
                }


                foreach (var col in table.Columns)
                {
                    evalResult.Append(col.ToString() + ",");
                }

                evalResult.Replace(",", System.Environment.NewLine, evalResult.Length - 1, 1);

                foreach (DataRow dr in table.Rows)
                {
                    foreach (var column in dr.ItemArray)
                    {
                        var typ = column.GetType();
                        evalResult.Append("\"" + column.ToString() + "\",");
                    }

                    evalResult.Replace(",", System.Environment.NewLine, evalResult.Length - 1, 1);
                }

                table.Dispose();
                LastError = null;
            }
            catch (Exception E)
            {
                LastError = E;
                return(null);
            }

            return(evalResult.ToString());
        }
Esempio n. 7
0
        public SQL(string connectionString)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL"))
            {
                Debugger.Launch();
            }

            try
            {
                this.Connect(connectionString);
            }
            catch (Exception E)
            {
                LastError = E;
            }
        }
Esempio n. 8
0
        public string Eval(SqlConnection connection, string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.Eval"))
            {
                Debugger.Launch();
            }

            SqlCommand    command    = connection.CreateCommand();
            StringBuilder evalResult = new StringBuilder();
            DataTable     table      = new DataTable();

            command.CommandText    = sql;
            command.CommandTimeout = timeout;
            command.CommandType    = CommandType.Text;
            while (command.Connection.State == ConnectionState.Connecting)
            {
                Thread.Sleep(1);
            }
            using (SqlDataReader reader = command.ExecuteReader())
            {
                table.Load(reader);
            }

            foreach (var col in table.Columns)
            {
                evalResult.Append(col.ToString() + ",");
            }

            evalResult.Replace(",", System.Environment.NewLine, evalResult.Length - 1, 1);

            foreach (DataRow dr in table.Rows)
            {
                foreach (var column in dr.ItemArray)
                {
                    var typ = column.GetType();
                    evalResult.Append("\"" + column.ToString() + "\",");
                }

                evalResult.Replace(",", System.Environment.NewLine, evalResult.Length - 1, 1);
            }

            table.Dispose();
            return(evalResult.ToString());
        }
Esempio n. 9
0
        public void Exec(SqlConnection connection, string sql, int timeout = 60)
        {
            LastError = null;
            if (DebugPoints.DebugPointRequested("SQL.Exec"))
            {
                Debugger.Launch();
            }
            SqlCommand command = connection.CreateCommand();

            command.CommandType    = CommandType.Text;
            command.CommandTimeout = timeout;
            command.CommandText    = sql;
            while (command.Connection.State == ConnectionState.Connecting)
            {
                Thread.Sleep(1);
            }
            command.ExecuteNonQuery();
        }
Esempio n. 10
0
 public void Connect(string connectionString)
 {
     LastError = null;
     if (DebugPoints.DebugPointRequested("SQL.Connect"))
     {
         Debugger.Launch();
     }
     try
     {
         ConnectionObject = new SqlConnection(connectionString);
         ConnectionObject.Open();
         while (ConnectionObject.State == ConnectionState.Connecting)
         {
             Thread.Sleep(1);
         }
         CommandObject = ConnectionObject.CreateCommand();
     }
     catch (Exception E)
     {
         LastError = E;
     }
 }
Esempio n. 11
0
        public static string OAuth2ConnectExplorer(string client_id, string scope, string login_hint)
        {
            if (DebugPoints.DebugPointRequested("GoogleOAuth2.OAuth2ConnectExplorer"))
            {
                Debugger.Launch();
            }
            var url = string.Format(
                "https://accounts.google.com/o/oauth2/auth?{0}&{1}&{2}&{3}&{4}&{5}",
                "response_type=code",
                "client_id=" + client_id,
                "redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob",
                "scope=" + WebUtility.HtmlEncode(scope),
                "state=acit",
                "login_hint=" + login_hint);

            var internetExplorer = new IE();

            internetExplorer.Launch(true);
            internetExplorer.Navigate(url);
            string title = internetExplorer.GetTitle().Replace("Success state=acit&code=", string.Empty);

            internetExplorer.Quit();
            return(title);
        }
Esempio n. 12
0
        public static string GetAccessTokenViaCfg(string cfgFile, string scopes = "", bool forceReAuth = false, bool forceRefresh = false)
        {
            if (DebugPoints.DebugPointRequested("GoogleOAuth2.GetAccessTokenViaCfg"))
            {
                Debugger.Launch();
            }

            Config cfg     = new Config(cfgFile);
            string secrets = cfg.Retrieve(".secrets", "");

            if (string.Empty == secrets || !System.IO.File.Exists(secrets))
            {
                return(string.Empty);
            }
            string jsonText = System.IO.File.ReadAllText(secrets);

            if (string.Empty == jsonText)
            {
                return(string.Empty);
            }
            Dictionary <string, object> dso = new Dictionary <string, object>();

            dso = (Dictionary <string, object>)GoogleOAuth2.DecodeJson(jsonText);
            dso = (Dictionary <string, object>)dso["installed"]; // might be "web" too
            string client_id     = dso["client_id"].ToString();
            string client_secret = dso["client_secret"].ToString();

            var accessToken    = cfg.Retrieve(".access_token", "");
            var refreshToken   = cfg.Retrieve(".refresh_token", "");
            var developerToken = cfg.Retrieve(".developer");

            long   timeout;
            string tokens;

            if (string.Empty == refreshToken || forceReAuth == true)
            {
                if (string.Empty == accessToken || forceReAuth == true)
                {
                    string code = GoogleOAuth2.OAuth2Connect(client_id, scopes, cfg.Retrieve(".login_hint"));
                    tokens = GoogleOAuth2.GetTokens(client_id, client_secret, code);
                    dso    = (Dictionary <string, object>)GoogleOAuth2.DecodeJson(tokens);
                    cfg.Define(".access_token", dso["access_token"].ToString());
                    cfg.Define(".refresh_token", dso["refresh_token"].ToString());
                    cfg.Define(".expires_in", dso["expires_in"].ToString());
                    cfg.Define(".token_type", dso["token_type"].ToString());
                    timeout = long.Parse(dso["expires_in"].ToString());
                    DateTime dt = DateTime.Now.AddSeconds((timeout.FromUnixTime()).ToUnixTime());
                    cfg.Define(".timeout", (int)dt.ToUnixTime());
                    cfg.Define(".token_type", dso["token_type"].ToString());
                    cfg.Save();
                    accessToken = dso["access_token"].ToString();
                }
            }
            else
            {
                //var arg = "force";
                timeout = (long)cfg.Retrieve(".timeout", 0);
                long nowMilli = DateTime.Now.ToUnixTime();
                if (timeout < nowMilli || forceRefresh == true)
                {
                    dso         = GoogleOAuth2.RefreshToken(client_id, client_secret, refreshToken);
                    accessToken = dso["access_token"].ToString();
                    cfg.Define(".access_token", accessToken);
                    cfg.Define(".expires_in", dso["expires_in"].ToString());
                    cfg.Define(".token_type", dso["token_type"].ToString());
                    timeout = long.Parse(dso["expires_in"].ToString());
                    DateTime dt = DateTime.Now.AddSeconds((timeout.FromUnixTime()).ToUnixTime());
                    cfg.Define(".timeout", (int)dt.ToUnixTime());
                    cfg.Save();
                }
                else
                {
                    accessToken = cfg.Retrieve(".access_token");
                }
            }

            return(accessToken);
        }