Exemplo n.º 1
0
        public void Load(string file)
        {
            lock (_connections) {
                foreach (var key in _connections.Keys)
                {
                    if (_connections[key] is SQLConnection)
                    {
                        var sqlConnection = (SQLConnection)_connections[key];

                        if (sqlConnection != null)
                        {
                            try {
                                sqlConnection.Connection.Close();
                                sqlConnection.Connection.Dispose();
                            } catch (Exception e) {
                                API.Log.write("Error while closing SQL connection - " + e);
                            }
                        }
                    }
                }
                _connections.Clear();

                if (System.IO.File.Exists(file))
                {
                    var content = System.IO.File.ReadAllText(file);

                    try {
                        var json = new Json(content);
                        foreach (var key in json.Keys)
                        {
                            var connectionJson = json.Object(key);
                            var type           = connectionJson.String("type").ToLower();

                            if (type == "sql")
                            {
                                _connections[key] = new SQLConnection(connectionJson.String("connectionString"));
                            }
                            else if (type == "http")
                            {
                                _connections[key] = new HTTPConnection(connectionJson.String("url"));
                            }
                            else if (type == "mongodb")
                            {
                                _connections[key] = new MongoDBConnection(connectionJson.String("connectionString"), connectionJson.String("database"));
                            }
                        }
                    }catch (Exception e) {
                        API.Log.write("Error while parsing connection JSON - " + e);
                    }
                }
                else
                {
                }
            }
        }
Exemplo n.º 2
0
        public void Load(string file)
        {
            lock (_connections) {
                foreach (var key in _connections.Keys)
                {
                    if (_connections[key] is SQLConnection)
                    {
                        var sqlConnection = (SQLConnection)_connections[key];

                        if (sqlConnection != null)
                        {
                            try {
                                sqlConnection.Connection.Close();
                                sqlConnection.Connection.Dispose();
                            } catch (Exception) {
                                // TODO: log error
                            }
                        }
                    }
                }
                _connections.Clear();

                if (System.IO.File.Exists(file))
                {
                    var content = System.IO.File.ReadAllText(file);

                    var json = new Json(content);
                    foreach (var key in json.Keys)
                    {
                        var connectionJson = json.Object(key);
                        var type           = connectionJson.String("type").ToLower();

                        if (type == "sql")
                        {
                            _connections[key] = new SQLConnection(connectionJson.String("connectionString"));
                        }
                        else if (type == "http")
                        {
                            _connections[key] = new HTTPConnection(connectionJson.String("url"));
                        }
                    }
                }
                else
                {
                }
            }
        }