public void DisposedConnectionsAreRemovedFromActive_WhenMultipleConnectionsAreActive() { var serviceEndpoint = new ServiceEndPoint("https://localhost:42", Certificates.TentacleListeningPublicThumbprint); var connectionManager = new ConnectionManager(); //do it twice because this bug only triggers on multiple enumeration, having 1 in the collection doesn't trigger the bug connectionManager.AcquireConnection(connectionFactory, serviceEndpoint, new InMemoryConnectionLog(serviceEndpoint.ToString())); connectionManager.AcquireConnection(connectionFactory, serviceEndpoint, new InMemoryConnectionLog(serviceEndpoint.ToString())); connectionManager.Disconnect(serviceEndpoint, null); connectionManager.GetActiveConnections(serviceEndpoint).Should().BeNullOrEmpty(); }
private void LoadContainers(ConnectionManagerElement cme) { this.cmbContainerID.Items.Clear(); ConnectionManagerMappingEventArgs args = new ConnectionManagerMappingEventArgs(); args.ConnectionManagerElement = cme; ConnectionManager cm = this.GetSelectedConnectionManager(this, args); try { Microsoft.Samples.DataServices.Connectivity.Connection conn = cm.AcquireConnection(null) as Connection; if (conn != null) { Microsoft.Samples.DataServices.Connectivity.Container[] conts = conn.GetContainers(); if (conts != null) { foreach (Microsoft.Samples.DataServices.Connectivity.Container cont in conts) { this.cmbContainerID.Items.Add(cont.Id); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); this.cmbContainerID.Items.Clear(); this.btnNewContainer.Enabled = false; } }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { ConnectionManager cSSH = getConnectionManager(connections, _SSHconnMgrName); List <KeyValuePair <string, string> > connParams = (List <KeyValuePair <string, string> >)cSSH.AcquireConnection(transaction); string host = connParams.Find(t => t.Key == "Host").Value; string username = connParams.Find(t => t.Key == "Username").Value; string password = connParams.Find(t => t.Key == "Password").Value; int port = Convert.ToInt32(connParams.Find(t => t.Key == "Port").Value); if (_operation == SSHFTPOperation.SendFiles) { ConnectionManager cSend = getConnectionManager(connections, _sendFilesSourceConnectionManagerName); string sourceFile = cSend.AcquireConnection(transaction).ToString(); SshTransferProtocolBase sshCp; sshCp = new Sftp(host, username); sshCp.Password = password; string localFile = sourceFile; string remoteFile = getRemotePathAndFile(_sendFilesDestinationDirectory, Path.GetFileName(sourceFile)); try { sshCp.Connect(); sshCp.Put(localFile, remoteFile); } catch { throw; } finally { sshCp.Close(); } } if (_operation == SSHFTPOperation.ReceiveFiles) { ConnectionManager cReceive = getConnectionManager(connections, _receiveFilesDestinationConnectionManagerName); string destinationDirectory = cReceive.AcquireConnection(transaction).ToString(); SshTransferProtocolBase sshCp; sshCp = new Sftp(host, username); sshCp.Password = password; try { sshCp.Connect(); sshCp.Get(_receiveFilesSourceFile, destinationDirectory); } catch { throw; } finally { sshCp.Close(); } } return(DTSExecResult.Success); }
public void DisconnectDisposesActiveConnections() { var serviceEndpoint = new ServiceEndPoint("https://localhost:42", Certificates.TentacleListeningPublicThumbprint); var connectionManager = new ConnectionManager(); var activeConnection = connectionManager.AcquireConnection(connectionFactory, serviceEndpoint, new InMemoryConnectionLog(serviceEndpoint.ToString())); connectionManager.GetActiveConnections(serviceEndpoint).Should().OnlyContain(c => c == activeConnection); connectionManager.Disconnect(serviceEndpoint, new InMemoryConnectionLog(serviceEndpoint.ToString())); connectionManager.GetActiveConnections(serviceEndpoint).Should().BeNullOrEmpty(); }
private SqlCommand GetSqlCommand(ConnectionManager connMan) { SqlConnection conn = null; conn = connMan.AcquireConnection(Transaction) as SqlConnection; if (conn == null) { FireError("Failed to aquire ADO.NET connection"); } SqlCommand cmd = new SqlCommand(SQLCheckStatement, conn); return(cmd); }
public override void AcquireConnections(object transaction) { if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null) { //get runtime connection manager ConnectionManager cm = Microsoft.SqlServer.Dts.Runtime.DtsConvert.GetWrapper(ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager); this.OGRDataSource = cm.AcquireConnection(transaction) as DataSource; if (this.OGRDataSource == null) { throw new Exception("The connection manager did not provide a valid OGR datasource"); } this.isConnected = true; } }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { try { ConnectionManager cm = connections[_customSmtpConnectionID]; SmtpClient c = (SmtpClient)cm.AcquireConnection(transaction); using (MailMessage m = new MailMessage(_expediteur, _destinataire, _objet, _message)) { c.SendMailAsync(m); } return(DTSExecResult.Success); } catch (Exception e) { componentEvents.FireError(0, "Tâche Evoie Email", e.Message, "", 0); return(DTSExecResult.Failure); } }
/// <summary> /// Initializes connection used at design time /// </summary> private void InitDesignTimeConnection() { try { ConnectionManager conMgr = _connections[Constants.CONNECTION_MANAGER_OLEDB_NAME_CONFIG]; _configConnection = new OleDbConnection(conMgr.ConnectionString); ConnectionManagerId = conMgr.ID; } catch (Exception) { try { ConnectionManager conMgr = _connections[Constants.CONNECTION_MANAGER_ADO_NAME_CONFIG]; _configConnection = (DbConnection)conMgr.AcquireConnection(null); ConnectionManagerId = conMgr.ID; } catch (Exception) { } } }
/// <summary> /// Called at design time and runtime. Establishes a connection using a ConnectionManager in the package. /// </summary> /// <param name="transaction">Not used.</param> public override void AcquireConnections(object transaction) { if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null) { ConnectionManager cm = Microsoft.SqlServer.Dts.Runtime.DtsConvert.ToConnectionManager( ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager); _connection = (Connection)cm.AcquireConnection(null); if ((_connection == null) || (_connection.Test() != true)) { ComponentMetaData.FireError(0, ComponentMetaData.Name, "Connection object got from connection manager is not valid", string.Empty, 0, out this._cancel); } } else { _connection = null; } }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { Debugger.Launch(); var filesToTransfer = Directory.GetFiles(SourceDirectory, FileTypeFilter); WebHDFSClient client; if (filesToTransfer.Length == 0) { return(DTSExecResult.Success); } try { ConnectionManager cm = connections[this.ConnectionManagerName]; client = cm.AcquireConnection(transaction) as WebHDFSClient; } catch (Exception) { componentEvents.FireError(0, "HDFSTask", "Unable to create HDFS Connection Manager", "", 0); return(DTSExecResult.Failure); } foreach (var file in filesToTransfer) { string fileName = Path.GetFileName(file); string remoteFileName = RemoteDirectory + "/" + fileName; try { client.CreateFile(file, remoteFileName).Wait(); } catch (Exception) { componentEvents.FireError(0, "HDFSTask", "Unable to transfer file...", "", 0); return(DTSExecResult.Failure); } } return(DTSExecResult.Success); }
private void btnNewContainer_Click(object sender, EventArgs e) { ConnectionManagerMappingEventArgs args = new ConnectionManagerMappingEventArgs(); args.ConnectionManagerElement = this.cmbCM.SelectedItem as ConnectionManagerElement; ConnectionManager cm = this.GetSelectedConnectionManager(this, args); Connection conn = cm.AcquireConnection(null) as Connection; Microsoft.Samples.DataServices.Connectivity.Container cont = conn.CreateContainer(this.ContainerId); if (cont != null) { this.cmbContainerID.Items.Add(this.ContainerId); this.cmbContainerID.SelectedIndex = this.cmbContainerID.Items.Count - 1; MessageBox.Show("Created new container: " + this.ContainerId); } else { MessageBox.Show("Failed to create a new container.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public static PackageConfigurationSetting[] GetPackageConfigurationSettings(Microsoft.SqlServer.Dts.Runtime.Configuration c, Package p, string sVisualStudioRelativePath, bool bOfflineMode) { List <PackageConfigurationSetting> list = new List <PackageConfigurationSetting>(); if (c.ConfigurationType == DTSConfigurationType.ConfigFile || c.ConfigurationType == DTSConfigurationType.IConfigFile) { string sConfigurationString = c.ConfigurationString; if (c.ConfigurationType == DTSConfigurationType.IConfigFile) { sConfigurationString = System.Environment.GetEnvironmentVariable(c.ConfigurationString); } XmlDocument dom = new XmlDocument(); if (sConfigurationString != null) { if (sConfigurationString.Contains("\\")) { dom.Load(sConfigurationString); } else { //if it's a relative file path, then try this directory first, and if it's not there, then try the path relative to the dtsx package if (System.IO.File.Exists(sVisualStudioRelativePath + sConfigurationString)) { dom.Load(sVisualStudioRelativePath + sConfigurationString); } else { dom.Load(sConfigurationString); } } foreach (XmlNode node in dom.GetElementsByTagName("Configuration")) { list.Add(new PackageConfigurationSetting(node.Attributes["Path"].Value, node.SelectSingleNode("ConfiguredValue").InnerText)); } } } else if (c.ConfigurationType == DTSConfigurationType.SqlServer && !bOfflineMode) //not when in offline mode { string sConnectionManagerName; string sTableName; string sFilter; Microsoft.DataTransformationServices.Design.DesignUtils.ParseSqlServerConfigurationString(c.ConfigurationString, out sConnectionManagerName, out sTableName, out sFilter); ConnectionManager cm = p.Connections[sConnectionManagerName]; if (cm.OfflineMode) { return(list.ToArray()); } ISessionProperties o = cm.AcquireConnection(null) as ISessionProperties; try { IDBCreateCommand command = (IDBCreateCommand)o; ICommandText ppCommand; Guid IID_ICommandText = new Guid(0xc733a27, 0x2a1c, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); command.CreateCommand(IntPtr.Zero, ref IID_ICommandText, out ppCommand); Guid DBGUID_DEFAULT = new Guid(0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); ppCommand.SetCommandText(ref DBGUID_DEFAULT, "select ConfiguredValue, PackagePath from " + sTableName + " Where ConfigurationFilter = '" + sFilter.Replace("'", "''") + "'"); IntPtr PtrZero = new IntPtr(0); Guid IID_IRowset = new Guid(0xc733a7c, 0x2a1c, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); tagDBPARAMS dbParams = null; int recordsAffected = 0; object executeResult = null; int result = ppCommand.Execute(PtrZero, ref IID_IRowset, dbParams, out recordsAffected, out executeResult); System.Reflection.BindingFlags getmethodflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; System.Reflection.BindingFlags getstaticflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static; Type chapterHandleType = ExpressionHighlighterPlugin.GetPrivateType(typeof(System.Data.OleDb.OleDbCommand), "System.Data.OleDb.ChapterHandle"); object chapterHandle = chapterHandleType.InvokeMember("DB_NULL_HCHAPTER", getstaticflags, null, null, null); System.Data.OleDb.OleDbDataReader dataReader = null; dataReader = (System.Data.OleDb.OleDbDataReader) typeof(System.Data.OleDb.OleDbDataReader).GetConstructors(getmethodflags)[0].Invoke(new object[] { null, null, 0, System.Data.CommandBehavior.SingleResult }); IntPtr intPtrRecordsAffected = new IntPtr(-1); dataReader.GetType().InvokeMember("InitializeIRowset", getmethodflags, null, dataReader, new object[] { executeResult, chapterHandle, intPtrRecordsAffected }); dataReader.GetType().InvokeMember("BuildMetaInfo", getmethodflags, null, dataReader, new object[] { }); dataReader.GetType().InvokeMember("HasRowsRead", getmethodflags, null, dataReader, new object[] { }); executeResult = null; while (dataReader.Read()) { list.Add(new PackageConfigurationSetting(dataReader["PackagePath"].ToString(), dataReader["ConfiguredValue"].ToString())); } dataReader.Close(); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(o); } } else if (c.ConfigurationType == DTSConfigurationType.EnvVariable) { list.Add(new PackageConfigurationSetting(c.PackagePath, System.Environment.GetEnvironmentVariable(c.ConfigurationString))); } else if (c.ConfigurationType == DTSConfigurationType.ParentVariable || c.ConfigurationType == DTSConfigurationType.IParentVariable) { list.Add(new PackageConfigurationSetting(c.PackagePath, "")); //can't know value at design time } else if (c.ConfigurationType == DTSConfigurationType.RegEntry) { list.Add(new PackageConfigurationSetting(c.PackagePath, (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\" + c.ConfigurationString, "Value", ""))); } else if (c.ConfigurationType == DTSConfigurationType.IRegEntry) { list.Add(new PackageConfigurationSetting(c.PackagePath, (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\" + System.Environment.GetEnvironmentVariable(c.ConfigurationString), "Value", ""))); } return(list.ToArray()); }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { ConnectionManager conn = getCurrentConnectionManager(connections); List <KeyValuePair <string, string> > connParams = (List <KeyValuePair <string, string> >)conn.AcquireConnection(transaction); string host = connParams.Find(t => t.Key == "Host").Value; string username = connParams.Find(t => t.Key == "Username").Value; string password = connParams.Find(t => t.Key == "Password").Value; int port = Convert.ToInt32(connParams.Find(t => t.Key == "Port").Value); SshExec exec = new SshExec(host, username); exec.Password = password; try { string stdOut = string.Empty; string stdErr = string.Empty; exec.Connect(); StringReader sr = new StringReader(_commandText); while (true) { string s = sr.ReadLine(); if (s != null && stdErr.Trim().Length == 0) { int res = exec.RunCommand(s, ref stdOut, ref stdErr); } else { if (stdErr.Trim().Length > 0) { fireError(componentEvents, stdErr); return(DTSExecResult.Failure); } break; } } } catch (Exception ex) { fireError(componentEvents, ex.Message); return(DTSExecResult.Failure); } finally { exec.Close(); } return(DTSExecResult.Success); }
/// <summary> /// Called at design time and runtime. Establishes a connection using a ConnectionManager in the package. /// </summary> /// <param name="transaction">Not used.</param> public override void AcquireConnections(object transaction) { if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null) { ConnectionManager connectionManager = Microsoft.SqlServer.Dts.Runtime.DtsConvert.GetWrapper( ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager); Dictionary <string, string> connProperties = (Dictionary <string, string>)connectionManager.AcquireConnection(null); this.ClientID = connProperties["ClientID"]; this.PowerBIDataSets = connProperties["PowerBIDataSets"]; this.RedirectUri = connProperties["RedirectUri"]; this.ResourceUri = connProperties["ResourceUri"]; this.OAuth2AuthorityUri = connProperties["OAuth2AuthorityUri"]; this.PowerBIDataSets = connProperties["PowerBIDataSets"]; this.UserName = connProperties["UserName"]; this.Password = connProperties["Password"]; } else { throw new Exception("Couldn't get the Power BI connection manager, "); } }