public DbCommand GetDbCommand(MetaConnection metaConnection) { DbCommand result = null; if (_commandMutex.WaitOne(1000)) { try { DbConnection connection = metaConnection.GetOpenConnection(); if (connection is OdbcConnection) { ((OdbcConnection)connection).InfoMessage += new OdbcInfoMessageEventHandler(OdbcDbInfoMessage); result = ((OdbcConnection)connection).CreateCommand(); } else { ((OleDbConnection)connection).InfoMessage += new OleDbInfoMessageEventHandler(OleDbInfoMessage); result = ((OleDbConnection)connection).CreateCommand(); } result.CommandTimeout = 0; } finally { _commandMutex.ReleaseMutex(); } } else { throw new Exception("Unable to get task command mutex..."); } return(result); }
/// <summary> /// Return the display value from the identifer /// </summary> public string GetDisplayValue(string id, MetaConnection connection, bool forRestriction = false) { var values = ValuesPerConnection ? GetValues(connection) : Values; MetaEV value = values.FirstOrDefault(i => i.Id == id); return(value == null ? id : (forRestriction ? value.DisplayRestriction : value.DisplayValue)); }
/// <summary> /// Remove a MetaConnection from the source /// </summary> public void RemoveConnection(MetaConnection item) { if (Connection == item) { throw new Exception("This connection is used as the current connection and cannot be removed."); } Connections.Remove(item); }
public List <MetaEV> GetValues(MetaConnection connection) { if (!ValuesPerConnection || connection == null) { return(Values); } return(Values.Where(i => i.ConnectionGUID == connection.GUID).ToList()); }
/// <summary> /// Create a MetaConnection in the source /// </summary> public MetaConnection AddConnection() { MetaConnection result = MetaConnection.Create(this); result.ConnectionString = DefaultConnectionString; result.Name = Helper.GetUniqueName(result.Name, (from i in Connections select i.Name).ToList()); Connections.Add(result); return(result); }
/// <summary> /// Add a default MetaConnection to the source /// </summary> public void AddDefaultConnection(Repository repository) { if (Connections.Count == 0) { //Add default connection MetaConnection connection = MetaConnection.Create(this); connection.ConnectionString = repository.Configuration.DefaultConnectionString; Connections.Add(connection); ConnectionGUID = connection.GUID; } }
/// <summary> /// Create a MetaConnection in the source /// </summary> public MetaConnection AddConnection() { MetaConnection result = MetaConnection.Create(this); result.ConnectionString = Repository.Configuration.DefaultConnectionString; result.DatabaseType = ConnectionStringEditor.GetDatabaseType(result.ConnectionString); result.Name = Helper.GetUniqueName(result.Name, (from i in Connections select i.Name).ToList()); Connections.Add(result); return(result); }
public bool CanSelectConnection(MetaConnection item) { var sourceName = item.Source.Name; if (item.Source is ReportSource) { sourceName = ((ReportSource)item.Source).MetaSourceName; } return(!ForbiddenConnections.Exists(i => (string.IsNullOrEmpty(i.Source) || i.Source == sourceName) && (string.IsNullOrEmpty(i.Name) || i.Name == item.Name) )); }
private string PromptForConnectionString(MetaConnection connection, string currentConnectionString, string initialConnectionString) { MSDASC.DataLinks dataLinks = new MSDASC.DataLinks(); string generatedConnectionString = currentConnectionString; string resultConnectionString = ""; ADODB.Connection dialogConnection = (ADODB.Connection)dataLinks.PromptNew(); if (dialogConnection != null) { connection.UserName = ""; connection.ClearPassword = ""; generatedConnectionString = dialogConnection.ConnectionString.ToString(); if (dialogConnection.Properties["Password"] != null && dialogConnection.Properties["Password"].Value != null && !generatedConnectionString.Contains("Password="******";Password={0}", dialogConnection.Properties["Password"].Value); } foreach (string config in generatedConnectionString.Split(';')) { if (config.StartsWith("User ID=")) { connection.UserName = config.Replace("User ID=", "").Replace("\"", ""); continue; } if (config.StartsWith("Password="******"Password="******""); continue; } if (resultConnectionString != "") resultConnectionString += ";"; resultConnectionString += config; } if (!string.IsNullOrEmpty(connection.UserName) && string.IsNullOrEmpty(connection.ClearPassword)) MessageBox.Show("Note that the Password is empty (Perhaps did you not check the option 'Allow Saving Password')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); DatabaseType newType = GetDatabaseType(resultConnectionString); if (newType != connection.DatabaseType) { connection.DatabaseType = newType; MessageBox.Show(string.Format("The database type has been set to {0}", newType), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { resultConnectionString = initialConnectionString; } return resultConnectionString; }
void setContext(ITypeDescriptorContext context) { _metaConnection = context.Instance as MetaConnection; _metaEnum = context.Instance as MetaEnum; _metaTable = context.Instance as MetaTable; _metaColumn = context.Instance as MetaColumn; _metaJoin = context.Instance as MetaJoin; _reportView = context.Instance as ReportView; _reportOutput = context.Instance as ReportOutput; _reportSchedule = context.Instance as ReportSchedule; _parameter = context.Instance as Parameter; _security = context.Instance as SealSecurity; _emailDevice = context.Instance as OutputEmailDevice; }
/// <summary> /// Executes the task with a given connection /// </summary> /// <param name="currentConnection"></param> public void Execute(MetaConnection currentConnection) { LogMessage("Starting task with connection '{0}'", currentConnection.Name); Progression = 0; if (!Report.Cancel && !string.IsNullOrEmpty(SQL)) { if (string.IsNullOrEmpty(currentConnection.ConnectionString) && string.IsNullOrEmpty(Connection.MSSqlServerConnectionString)) { throw new Exception("The connection string is not defined for this Task."); } _command = GetDbCommand(currentConnection); object sqlResult = null; try { string finalSql = RazorHelper.CompileExecute(SQL, this); LogMessage("Executing SQL: {0}", finalSql); _command.CommandText = finalSql; sqlResult = _command.ExecuteScalar(); } finally { _command.Connection.Close(); } if (sqlResult != null && !(sqlResult is DBNull)) { if (sqlResult.ToString().Trim() == "0") { LogMessage("SQL returns 0, the report is cancelled."); CancelReport = true; } } } if (!Report.Cancel && !string.IsNullOrEmpty(Script)) { LogMessage("Executing Script..."); string result = RazorHelper.CompileExecute(Script, this); if (result.Trim() == "0") { LogMessage("Script returns 0, the report is cancelled."); CancelReport = true; } } Progression = 100; //100% }
public void Execute(MetaConnection currentConnection) { Report.LogMessage("Starting task with connection '{0}'", currentConnection.Name); if (!Report.Cancel && !string.IsNullOrEmpty(SQL)) { if (string.IsNullOrEmpty(currentConnection.ConnectionString)) { throw new Exception("The connection string is not defined for this Task."); } _command = GetDbCommand(currentConnection); string finalSql = Helper.ParseRazor(SQL, this); Report.LogMessage("Executing SQL: {0}", finalSql); _command.CommandText = finalSql; object sqlResult = _command.ExecuteScalar(); if (sqlResult != null && !(sqlResult is DBNull)) { if (sqlResult.ToString() == "0") { Report.LogMessage("SQL returns 0, the report is cancelled."); CancelReport = true; } } } if (!Report.Cancel && !string.IsNullOrEmpty(Script)) { Report.LogMessage("Executing Script..."); string result = Helper.ParseRazor(Script, this); if (result == "0") { Report.LogMessage("Script returns 0, the report is cancelled."); CancelReport = true; } } }
/// <summary> /// Load the available MetaSources defined in the repository /// </summary> public void LoadRepositoryMetaSources(Repository repository) { if (Loaded) { return; } foreach (var connection in Connections) { connection.IsEditable = true; } foreach (var table in MetaData.Tables) { table.IsEditable = true; } foreach (var link in MetaData.TableLinks) { link.IsEditable = true; } foreach (var join in MetaData.Joins) { join.IsEditable = true; } foreach (var itemEnum in MetaData.Enums) { itemEnum.IsEditable = true; } if (!string.IsNullOrEmpty(MetaSourceGUID)) { MetaSource source = repository.Sources.FirstOrDefault(i => i.GUID == MetaSourceGUID); if (source != null) { IsDefault = source.IsDefault; IsNoSQL = source.IsNoSQL; InitScript = source.InitScript; _metaSourceName = source.Name; foreach (var item in source.Connections) { item.Source = source; item.IsEditable = false; Connections.Add(item); } foreach (var item in source.MetaData.Tables) { item.Source = source; item.IsEditable = false; MetaData.Tables.Add(item); } foreach (var item in source.MetaData.TableLinks) { item.IsEditable = false; MetaData.TableLinks.Add(item); } foreach (var item in source.MetaData.Joins) { item.Source = source; item.IsEditable = false; MetaData.Joins.Add(item); } foreach (var item in source.MetaData.Enums) { item.Source = source; item.IsEditable = false; MetaData.Enums.Add(item); } PreSQL = source.PreSQL; PostSQL = source.PostSQL; IgnorePrePostError = source.IgnorePrePostError; } else { Report.LoadErrors += string.Format("Unable to find repository source for '{0}' (GUID {1}). Check the data source files in the repository folder.\r\n", Name, MetaSourceGUID); } } if (Connections.Count == 0) { Connections.Add(MetaConnection.Create(this)); ConnectionGUID = Connections[0].GUID; } Loaded = true; }
public DbCommand GetDbCommand(MetaConnection metaConnection) { DbCommand result = null; if (_commandMutex.WaitOne(1000)) { try { DbConnection connection = metaConnection.GetOpenConnection(); if (connection is OdbcConnection) { ((OdbcConnection)connection).InfoMessage += new OdbcInfoMessageEventHandler(OdbcDbInfoMessage); result = ((OdbcConnection)connection).CreateCommand(); } else { ((OleDbConnection)connection).InfoMessage += new OleDbInfoMessageEventHandler(OleDbInfoMessage); result = ((OleDbConnection)connection).CreateCommand(); } result.CommandTimeout = 0; } finally { _commandMutex.ReleaseMutex(); } } else { throw new Exception("Unable to get task command mutex..."); } return result; }
public void Execute(MetaConnection currentConnection) { Report.LogMessage("Starting task with connection '{0}'", currentConnection.Name); if (!Report.Cancel && !string.IsNullOrEmpty(SQL)) { if (string.IsNullOrEmpty(currentConnection.ConnectionString)) throw new Exception("The connection string is not defined for this Task."); _command = GetDbCommand(currentConnection); string finalSql = Helper.ParseRazor(SQL, this); Report.LogMessage("Executing SQL: {0}", finalSql); _command.CommandText = finalSql; object sqlResult = _command.ExecuteScalar(); if (sqlResult != null && !(sqlResult is DBNull)) { if (sqlResult.ToString() == "0") { Report.LogMessage("SQL returns 0, the report is cancelled."); CancelReport = true; } } } if (!Report.Cancel && !string.IsNullOrEmpty(Script)) { Report.LogMessage("Executing Script..."); string result = Helper.ParseRazor(FullScript, this); if (result == "0") { Report.LogMessage("Script returns 0, the report is cancelled."); CancelReport = true; } } }
public void RemoveConnection(MetaConnection item) { if (Connection == item) throw new Exception("This connection is used as the current connection and cannot be removed."); Connections.Remove(item); }