private void _Check_GZ(string pathFileTAR, IDTSComponentEvents componentEvents) { bool b = false; if (_testarchive) { using (ICSharpCode.SharpZipLib.GZip.GZipInputStream gzip = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(System.IO.File.OpenRead(pathFileTAR))) { try { componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file GZ (" + _folderSource + _fileZip + ")", null, 0, ref b); gzip.CopyTo(System.IO.MemoryStream.Null); gzip.Flush(); componentEvents.FireInformation(1, "UnZip SSIS", "File ZIP verified GZ (" + _folderSource + _fileZip + ")", null, 0, ref b); } catch (Exception ex) { throw new Exception("Verify file: " + _fileZip + " failed. (" + ex.Message + ")"); } gzip.Close(); } } }
/// <summary> /// This method is called at runtime, and does all the "work". /// </summary> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { _localname = Localname(); if (ReportType == "Dataset Report") { Variables vars = null; var oleda = new System.Data.OleDb.OleDbDataAdapter(); var dt = new DataTable(Datasetname); variableDispenser.LockForRead(Recordset); variableDispenser.GetVariables(ref vars); componentEvents.FireInformation(0, "ReportGenerator", "Filename: " + _localname, string.Empty, 0, ref _refire); try { //var rv = new ReportViewer {ProcessingMode = ProcessingMode.Local}; var val = vars[Recordset].Value; oleda.Fill(dt, val); componentEvents.FireInformation(0, "ReportGenerator", "Starts report generation with " + dt.Rows.Count + " rows", string.Empty, 0, ref _refire); Run(Reportname, Datasetname, dt, _localname); componentEvents.FireInformation(0, "ReportGenerator", "The report was created.", string.Empty, 0, ref _refire); //Warning: debugmode is a user defined option. if (DebugMode) { componentEvents.FireInformation(0, "ReportGenerator", "Satrts local report generation", string.Empty, 0, ref _refire); var localReport = new ReportViewerUi { Datasetname = Datasetname, Data = dt, Reportname = Reportname }; localReport.ShowDialog(); } } catch (Exception ex) { componentEvents.FireError(0, "ReportGeneratorTask", ex.ToString(), "", 0); } finally { if (vars.Locked) { vars.Unlock(); } } } else { GenerateServerReport(variableDispenser, componentEvents); } // set prefixfilename to variable if (!string.IsNullOrEmpty(PrefixFilename) && PrefixFilename != "Choose a Variable") { SetPrefixFilename(variableDispenser, componentEvents); } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
public override DTSExecResult Validate(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log) { Boolean fireAgain = false; try { // Validate mandatory String properties. DTSExecResult propertyValidationResult = this.ValidateProperties(ref componentEvents); if (propertyValidationResult != DTSExecResult.Success) { return(propertyValidationResult); } // The package developer should know that files will be removed from the source. if (this.FtpRemove) { componentEvents.FireInformation(0, TASK_NAME, REMOVE_ENABLED_MESSAGE, String.Empty, 0, ref fireAgain); } // Verify the connection. using (Session winScpSession = this.EstablishSession()) { componentEvents.FireInformation(0, TASK_NAME, SESSION_OPEN_MESSAGE, String.Empty, 0, ref fireAgain); // Verify the remote resources. OperationMode operation = (OperationMode)Enum.Parse(typeof(OperationMode), this.FtpOperationName); switch (operation) { case OperationMode.PutFiles: Boolean remoteDirectoryExists = winScpSession.FileExists(this.FtpRemotePath); if (!remoteDirectoryExists) { componentEvents.FireInformation(0, TASK_NAME, String.Format(REMOTE_DIRECTORY_MISSING_MESSAGE_PATTERN, this.FtpRemotePath), String.Empty, 0, ref fireAgain); } break; case OperationMode.GetFiles: default: Boolean remoteFileExists = winScpSession.FileExists(this.FtpRemotePath); if (!remoteFileExists) { componentEvents.FireInformation(0, TASK_NAME, String.Format(REMOTE_FILES_MISSING_MESSAGE_PATTERN, this.FtpRemotePath), String.Empty, 0, ref fireAgain); } break; } } return(DTSExecResult.Success); } catch (Exception exc) { String exceptionMessage = exc != null ? exc.Message : UNKNOWN_EXCEPTION_MESSAGE; componentEvents.FireError(0, TASK_NAME, String.Format(EXCEPTION_MESSAGE_PATTERN, exceptionMessage), String.Empty, 0); return(DTSExecResult.Failure); } }
/// <summary> /// This method is a run-time method executed dtsexec.exe /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; GetNeededVariables(variableDispenser, HttpSourceFile); GetNeededVariables(variableDispenser, LocalDestinationFile); componentEvents.FireInformation(0, "SSISDownloadFileTask", string.Format("Source File: \"{0}\", Destination File \"{1}\"", EvaluateExpression(HttpSourceFile, variableDispenser), EvaluateExpression(LocalDestinationFile, variableDispenser)), string.Empty, 0, ref refire); try { componentEvents.FireInformation(0, "SSISDownloadFileTask", "Prepare variables", string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISDownloadFileTask", DownloadFile(connections, variableDispenser, componentEvents) ? "The file has been downloaded successfully." : "The file has NOT been downloaded.", string.Empty, 0, ref refire); } catch (Exception ex) { componentEvents.FireError(0, "SSISDownloadFileTask", string.Format("Problem: {0}", ex.Message), "", 0); } finally { if (_vars.Locked) { _vars.Unlock(); } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
private DTSExecResult ProxyExecute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; componentEvents.FireInformation(0, "SSISEncodeFileTask", "Prepare variables", string.Empty, 0, ref refire); if (!string.IsNullOrEmpty(FileSourcePathInVariable)) { GetNeededVariables(variableDispenser, FileSourcePathInVariable); } try { componentEvents.FireInformation(0, "SSISEncodeFileTask", EncodeFile(connections, variableDispenser, componentEvents) ? "The file has been encoded successfully." : "The file has NOT been encoded.", string.Empty, 0, ref refire); } catch (Exception ex) { componentEvents.FireError(0, "SSISEncodeFileTask", string.Format("Problem: {0}", ex.Message), string.Empty, 0); return(DTSExecResult.Failure); } finally { if (_vars != null) { if (_vars.Locked) { _vars.Unlock(); } } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
private void Executing(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { bool refire = false; try { PowerShellCoreScripting.GetNeededVariables(variableDispenser, ref _vars, componentEvents, this); componentEvents.FireInformation(0, "SSISPowerShell", String.Format("Launching PowerShell Script: {0} ", EvaluateExpression(PowerShellScript, variableDispenser)), string.Empty, 0, ref refire); var futureDevis = System.Threading.Tasks.Task.Factory.StartNew(() => PowerShellCoreScripting.RunScript(PowerShellScript, variableDispenser)); System.Threading.Tasks.Task.WaitAll(futureDevis); string retVal = futureDevis.Result.Trim(); componentEvents.FireInformation(0, "SSISPowerShell", String.Format("Execution of PowerShell Script succeeded"), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISPowerShell", string.Format("The result: {0}", retVal), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISPowerShell", string.Format("Attach result to the output variable: {0}", OutputVariableName), string.Empty, 0, ref refire); string output = PowerShellCoreScripting.GetVariableFromNamespaceContext(OutputVariableName).Trim(); try { _vars[output].Value = retVal; } catch (Exception exception) { componentEvents.FireError(0, "SSISPowerShell", string.Format("Error : {0}", exception.Message), "", 0); } } catch (Exception ex) { componentEvents.FireError(0, "SSISPowerShell", string.Format("Error : {0}", ex.Message), "", 0); } finally { if (_vars != null) { if (_vars.Locked != null) { if (_vars.Locked) { _vars.Unlock(); } } } } }
/// <summary> /// Overrides Execute logic /// Core Logic: It Fires a Custom Event, with the given ComponentType and Message /// <see cref="Microsoft.SqlServer.Dts.Runtime.Task.Execute"/> /// </summary> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refFire = false; componentEvents.FireInformation(ComponentType, "", GetMessageText(variableDispenser, componentEvents, MessageText), "", 0, ref refFire); return base.Execute(connections, variableDispenser, componentEvents, log, transaction); }
/// <summary> /// Overrides Execute logic /// Core Logic: It Fires a Custom Event, with the given ComponentType and Message /// <see cref="Microsoft.SqlServer.Dts.Runtime.Task.Execute"/> /// </summary> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refFire = false; componentEvents.FireInformation(ComponentType, "", GetMessageText(variableDispenser, componentEvents, MessageText), "", 0, ref refFire); return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { Boolean fireAgain = false; try { // Create a new FTP session. using (Session winScpSession = this.EstablishSession()) { componentEvents.FireInformation(0, TASK_NAME, SESSION_OPEN_MESSAGE, String.Empty, 0, ref fireAgain); // Determine the operation mode. OperationMode operation = (OperationMode)Enum.Parse(typeof(OperationMode), this.FtpOperationName); switch (operation) { case OperationMode.PutFiles: // When uploading files, make sure that the destination directory exists. Boolean remoteDirectoryExists = winScpSession.FileExists(this.FtpRemotePath); if (!remoteDirectoryExists) { winScpSession.CreateDirectory(this.FtpRemotePath); componentEvents.FireInformation(0, TASK_NAME, String.Format(REMOTE_DIRECTORY_CREATED_MESSAGE_PATTERN, this.FtpRemotePath), String.Empty, 0, ref fireAgain); } winScpSession.PutFiles(this.FtpLocalPath, this.FtpRemotePath, this.FtpRemove); break; case OperationMode.GetFiles: default: winScpSession.GetFiles(this.FtpRemotePath, this.FtpLocalPath, this.FtpRemove); break; } return(DTSExecResult.Success); } } catch (Exception exc) { String exceptionMessage = exc == null ? UNKNOWN_EXCEPTION_MESSAGE : exc.Message; componentEvents.FireError(0, TASK_NAME, String.Format(EXCEPTION_MESSAGE_PATTERN, exceptionMessage), String.Empty, 0); return(DTSExecResult.Failure); } }
private void _Check_ZIP(string pathFileZip, IDTSComponentEvents componentEvents) { bool b = false; if (_testarchive) { using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip))) { if (!string.IsNullOrEmpty(_password)) { fz.Password = _password; } try { ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry(); componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b); while (ze != null) { componentEvents.FireInformation(1, "UnZip SSIS", "Verifying Entry: " + ze.Name, null, 0, ref b); fz.CopyTo(System.IO.MemoryStream.Null); fz.Flush(); fz.CloseEntry(); ze = fz.GetNextEntry(); } componentEvents.FireInformation(1, "UnZip SSIS", "File ZIP verified ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b); } catch (Exception ex) { throw new Exception("Verify file: " + _fileZip + " failed. (" + ex.Message + ")"); } finally { fz.Close(); } } } }
private static void LockForWrite(VariableDispenser variableDispenser, ref Variables variables, List <string> lockForReadWrite, IEnumerable <string> mappedParams, IDTSComponentEvents componentEvents) { bool refire = false; foreach (string t in mappedParams) { try { string param = t.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("[", string.Empty).Replace("]", string.Empty).Replace("@", string.Empty); if (!IsVariableInLockForReadOrWrite(lockForReadWrite, param)) { componentEvents.FireInformation(0, "SSISPowerShell", String.Format("LockForWrite: {0} ", param), string.Empty, 0, ref refire); variableDispenser.LockOneForWrite(param, ref variables); } } catch (Exception) { componentEvents.FireInformation(0, "SSISPowerShell", String.Format("Unable to LockForWrite: {0} ", t), string.Empty, 0, ref refire); } } }
public static void GetNeededVariables(VariableDispenser variableDispenser, ref Variables variables, IDTSComponentEvents componentEvents, SSISPowerShellTask ssisPowerShellTask) { bool refire = false; var lockForReadWrite = new List <string>(); { var regex = new Regex(@"\@(.*?)\]"); componentEvents.FireInformation(0, "SSISPowerShell", String.Format("Search variable to LockForRead "), string.Empty, 0, ref refire); foreach (var match in regex.Matches(ssisPowerShellTask.PowerShellScript)) { componentEvents.FireInformation(0, "SSISPowerShell", String.Format("Match : {0} ", match), string.Empty, 0, ref refire); var mappedParams = match.ToString().Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries); componentEvents.FireInformation(0, "SSISPowerShell", String.Format("mappedParams : {0} ", mappedParams), string.Empty, 0, ref refire); LockForRead(variableDispenser, ref variables, lockForReadWrite, mappedParams, componentEvents); } } { var mappedParams = ssisPowerShellTask.OutputVariableName.Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries); LockForWrite(variableDispenser, ref variables, lockForReadWrite, mappedParams, componentEvents); } }
private static void LogCore(IDTSComponentEvents source, LogInfo info) { switch (info.Type) { case LogType.Error: source.FireError(info.Code, info.Component, info.MessageAndException(), null, 0); break; case LogType.Warning: source.FireWarning(info.Code, info.Component, info.MessageAndException(), null, 0); break; case LogType.Information: { bool fireAgain = false; source.FireInformation(info.Code, info.Component, info.MessageAndException(), null, 0, ref fireAgain); break; }; } ; }
/// <summary> /// Set filename with prefix to local variable /// </summary> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> private void SetPrefixFilename(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { try { if (PrefixFilename != null && PrefixFilename != "Choose a Variable") { Variables vars = null; variableDispenser.LockOneForWrite(PrefixFilename, ref vars); vars[PrefixFilename].Value = TypeConverter(_localname, vars[0].DataType); vars.Unlock(); variableDispenser.Reset(); componentEvents.FireInformation(0, "ReportGenerator", "Variable " + PrefixFilename + " set to " + _localname, string.Empty, 0, ref _refire); } } catch (Exception exc) { componentEvents.FireError(0, "ReportGenerator", "Task Errored: " + exc, "", -1); } }
/// <summary> /// /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool fireAgain = false; try { if (Action == "ZIP") { var compress = new Compress(Input, Output, FileFolder, ZipLevel, Password, AesKeySize, Zip64); componentEvents.FireInformation(0, "SSIS ZIP Task", Input + " has been compressed", null, 0, ref fireAgain); return(DTSExecResult.Success); } else { return(DTSExecResult.Failure); } } catch (Exception ex) { componentEvents.FireError(0, "SSIS ZIP Task", ex.ToString(), null, 0); return(DTSExecResult.Failure); } }
/// <summary> /// Executes the specified actions based on settings. /// </summary> /// <param name="connections">The connections.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> /// <param name="log">The log.</param> /// <param name="transaction">The transaction.</param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool fireAgain = true; try { string sourceFile = Common.GetVariableValue <string>(this.sourceFile, variableDispenser); string targetFile = Common.GetVariableValue <string>(this.targetFile, variableDispenser); string publicKey = Common.GetVariableValue <string>(this.publicKey, variableDispenser); string privateKey = Common.GetVariableValue <string>(this.privateKey, variableDispenser); string passPhrase = Common.GetVariableValue <string>(this.passPhrase, variableDispenser); if (this.fileAction == PGPFileAction.Decrypt) { componentEvents.FireInformation(1, "", String.Format("Decrypting file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.Decrypt(sourceFile, privateKey, passPhrase, targetFile, this.overwriteTarget, this.removeSource); componentEvents.FireInformation(1, "", String.Format("Successfully Decrypted file [{0}] -> [{1}]. ", sourceFile, targetFile), "", 0, ref fireAgain); } else if (this.fileAction == PGPFileAction.Encrypt) { componentEvents.FireInformation(1, "", String.Format("Encrypting file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.Encrypt(sourceFile, publicKey, targetFile, this.overwriteTarget, this.removeSource, this.isArmored); componentEvents.FireInformation(1, "", String.Format("Sucessfully Encrypted file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); } else if (this.fileAction == PGPFileAction.EncryptAndSign) { componentEvents.FireInformation(1, "", String.Format("Encrypting and Signing file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.EncryptAndSign(sourceFile, publicKey, privateKey, passPhrase, targetFile, this.overwriteTarget, this.removeSource, this.isArmored); componentEvents.FireInformation(1, "", String.Format("Sucessfully Encrypted and Signed file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); } } catch (Exception ex) { componentEvents.FireError(0, "Execute: ", ex.Message + Environment.NewLine + ex.StackTrace, "", 0); return(DTSExecResult.Failure); } return(DTSExecResult.Success); }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool b = false; componentEvents.FireInformation(1, "UnZip SSIS", "Start 1", null, 0, ref b); componentEvents.FireInformation(1, "UnZip SSIS", "Start process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); if (_typeOperation == Type_Operation.Please_Select) { componentEvents.FireError(1, "UnZip SSIS", "Please select type operation (De/Compress).", null, 0); throw new Exception("Please select type operation (De/Compress)."); } ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip(); if (!_folderSource.EndsWith("\\")) { _folderSource = _folderSource + "\\"; } if (!_folderDest.EndsWith("\\")) { _folderDest = _folderDest + "\\"; } if (!string.IsNullOrEmpty(_password)) { fz.Password = _password; } try { if (!System.IO.Directory.Exists(_folderDest)) { componentEvents.FireInformation(1, "UnZip SSIS", "Create Folder: '" + _folderDest + "'.", null, 0, ref b); System.IO.Directory.CreateDirectory(_folderDest); } if (_typeOperation == Type_Operation.Compress) { fz.CreateZip(_folderDest + _fileZip, _folderSource, _Recurse, _FileFilter); if ((_testarchive) || (!string.IsNullOrEmpty(_comment))) { ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderDest + _fileZip); if (_testarchive) { componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b); if (!zipFile.TestArchive(true)) { throw new Exception("Verify file zip: " + _fileZip + " failed."); } } if (!string.IsNullOrEmpty(_comment)) { componentEvents.FireInformation(1, "UnZip SSIS", "Set Comment.", null, 0, ref b); zipFile.BeginUpdate(); zipFile.SetComment(_comment); zipFile.CommitUpdate(); } } } else { if (_testarchive) { ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderSource + _fileZip); componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b); if (!zipFile.TestArchive(true)) { throw new Exception("Verify file zip: " + _fileZip + " failed."); } } fz.ExtractZip(_folderSource + _fileZip, _folderDest, _FileFilter); } } catch (Exception ex) { throw; } componentEvents.FireInformation(1, "UnZip SSIS", "End process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); return(DTSExecResult.Success); }
/// <summary> /// Gets the needed variables. /// </summary> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> private void GetNeededVariables(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { bool refire = false; List <string> lockForRead = new List <string>(); try { { var param = SQLServerInstance; componentEvents.FireInformation(0, "SSISBulkExportTask", "SQLServerInstance = " + SQLServerInstance, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach ( var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select( strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = Login; componentEvents.FireInformation(0, "SSISBulkExportTask", "Login = "******"@")) { var regexStr = param.Split('@'); foreach ( var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select( strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = Password; componentEvents.FireInformation(0, "SSISBulkExportTask", "Password = "******"@")) { var regexStr = param.Split('@'); foreach ( var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select( strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = Password; componentEvents.FireInformation(0, "SSISBulkExportTask", "Destination = " + DestinationPath, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach ( var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select( strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = Password; componentEvents.FireInformation(0, "SSISBulkExportTask", "Format File = " + FormatFile, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach ( var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select( strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { foreach (var mappingParams in (MappingParams)StoredProcedureParameters) { try { if (mappingParams.Value.Contains("@")) { var regexStr = mappingParams.Value.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISBulkExportTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch { } } } } catch { //oops, it's a fix value } } } } catch (Exception ex) { componentEvents.FireError(0, "SSISReportGeneratorTask", string.Format("Problem MappingParams: {0} {1}", ex.Message, ex.StackTrace), "", 0); } variableDispenser.GetVariables(ref _vars); }
/// <summary> /// Executes the specified actions based on settings. /// </summary> /// <param name="connections">The connections.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> /// <param name="log">The log.</param> /// <param name="transaction">The transaction.</param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool fireAgain = true; try { string sourceFile = Common.GetVariableValue<string>(this.sourceFile, variableDispenser); string targetFile = Common.GetVariableValue<string>(this.targetFile, variableDispenser); string publicKey = Common.GetVariableValue<string>(this.publicKey, variableDispenser); string privateKey = Common.GetVariableValue<string>(this.privateKey, variableDispenser); string passPhrase = Common.GetVariableValue<string>(this.passPhrase, variableDispenser); if (this.fileAction == PGPFileAction.Decrypt) { componentEvents.FireInformation(1, "", String.Format("Decrypting file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.Decrypt(sourceFile, privateKey, passPhrase, targetFile, this.overwriteTarget,this.removeSource); componentEvents.FireInformation(1, "", String.Format("Successfully Decrypted file [{0}] -> [{1}]. ", sourceFile, targetFile), "", 0, ref fireAgain); } else if (this.fileAction == PGPFileAction.Encrypt) { componentEvents.FireInformation(1, "", String.Format("Encrypting file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.Encrypt(sourceFile, publicKey, targetFile, this.overwriteTarget, this.removeSource, this.isArmored); componentEvents.FireInformation(1, "", String.Format("Sucessfully Encrypted file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); } else if (this.fileAction == PGPFileAction.EncryptAndSign) { componentEvents.FireInformation(1, "", String.Format("Encrypting and Signing file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); PGPManager.EncryptAndSign(sourceFile, publicKey, privateKey, passPhrase, targetFile, this.overwriteTarget, this.removeSource, this.isArmored); componentEvents.FireInformation(1, "", String.Format("Sucessfully Encrypted and Signed file [{0}] -> [{1}]", sourceFile, targetFile), "", 0, ref fireAgain); } } catch (Exception ex) { componentEvents.FireError(0, "Execute: ", ex.Message + Environment.NewLine + ex.StackTrace, "", 0); return DTSExecResult.Failure; } return DTSExecResult.Success; }
/// <summary> /// Executes the action based on seleted options. /// </summary> /// <param name="connections">The connections.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> /// <param name="log">The log.</param> /// <param name="transaction">The transaction.</param> /// <returns></returns> /// <exception cref="System.Exception">Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object.</exception> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { try { bool fireAgain = true; string _localFile = Common.GetVariableValue <string>(this.localFile, variableDispenser); string _remoteFile = Common.GetVariableValue <string>(this.remoteFile, variableDispenser); string _hostName = Common.GetVariableValue <string>(this.hostName, variableDispenser); int _portNumber = Common.GetVariableValue <int>(this.portNumber, variableDispenser); string _userName = Common.GetVariableValue <string>(this.userName, variableDispenser); string _passWord = Common.GetVariableValue <string>(this.passWord, variableDispenser); string _fileFilter = Common.GetVariableValue <string>(this.fileFilter, variableDispenser); List <ISFTPFileInfo> sftpFileInfo = new List <ISFTPFileInfo>(); SFTPConnection sftp = new SFTPConnection(_hostName, _userName, _passWord, _portNumber, this.stopOnFailure, componentEvents, this.logLevel); if (this.fileAction == SFTPFileAction.ReceiveMultiple || this.fileAction == SFTPFileAction.SendMultiple) { if (Common.GetVariableValue <object>(fileInfo, variableDispenser).GetType() != typeof(List <ISFTPFileInfo>)) { throw new Exception("Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object."); } } if (this.fileAction == SFTPFileAction.Send) { List <string> fileList = Common.GetFileList(_localFile, _fileFilter, this.isRecursive); foreach (string fileName in fileList) { sftpFileInfo.Add(new SFTPFileInfo(fileName, _remoteFile, this.overwriteDest, this.removeSource)); } if (sftpFileInfo.Count > 0) { sftp.UploadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.SendMultiple) { sftpFileInfo = (List <ISFTPFileInfo>)Common.GetVariableValue <object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) { sftp.UploadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.Receive) { List <IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); remoteFileList = Common.GetRemoteFileList(remoteFileList, _fileFilter); foreach (IRemoteFileInfo remoteFile in remoteFileList) { sftpFileInfo.Add(new SFTPFileInfo(_localFile, remoteFile.FullName, this.overwriteDest, this.removeSource)); } if (sftpFileInfo.Count > 0) { sftp.DownloadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.ReceiveMultiple) { sftpFileInfo = (List <ISFTPFileInfo>)Common.GetVariableValue <object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) { sftp.DownloadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.List) { List <IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); Common.SetVariableValue(this.remoteFileListVariable, remoteFileList, variableDispenser); } } catch (Exception ex) { componentEvents.FireError(0, "Execute: ", ex.Message + Environment.NewLine + ex.StackTrace, "", 0); return(DTSExecResult.Failure); } return(DTSExecResult.Success); }
/// <summary> /// Gets the needed variables. /// </summary> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> private void GetNeededVariables(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { bool refire = false; List <string> lockForRead = new List <string>(); try { var param = ServiceUrl; componentEvents.FireInformation(0, "SSISWebServiceTask", "ServiceUrl = " + ServiceUrl, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWebServiceTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } catch { //We will continue... } try { var param = Service; componentEvents.FireInformation(0, "SSISWebServiceTask", "Service = " + Service, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWebServiceTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } catch (Exception exception) { throw new Exception(exception.Message); } try { var param = WebMethod; componentEvents.FireInformation(0, "SSISWebServiceTask", "WebMethod = " + WebMethod, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWebServiceTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } catch (Exception exception) { throw new Exception(exception.Message); } try { if (!string.IsNullOrEmpty(ReturnedValue)) { var param = ReturnedValue; componentEvents.FireInformation(0, "SSISWebServiceTask", "ReturnedValue = " + ReturnedValue, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWebServiceTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForWrite(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } } catch (Exception exception) { throw new Exception(exception.Message); } try { componentEvents.FireInformation(0, "SSISWebServiceTask", "MappingParams ", string.Empty, 0, ref refire); //Get variables for MappingParams foreach (var mappingParams in (MappingParams)MappingParams) { try { if (mappingParams.Value.Contains("@")) { var regexStr = mappingParams.Value.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWebServiceTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } catch (Exception exception) { throw new Exception(exception.Message); } } } catch (Exception ex) { componentEvents.FireError(0, "SSISReportGeneratorTask", string.Format("Problem MappingParams: {0} {1}", ex.Message, ex.StackTrace), "", 0); } variableDispenser.GetVariables(ref _vars); }
private void _CompressZIP(string pathFileZip, IDTSComponentEvents componentEvents) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(_folderSource); System.IO.FileInfo[] fi_s = di.GetFiles("*.*", (_recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly)); bool b = false; try { using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create(pathFileZip))) { fz.SetLevel(9); if (!string.IsNullOrEmpty(_comment)) { componentEvents.FireInformation(1, "UnZip SSIS", "Set Comment.", null, 0, ref b); fz.SetComment(_comment); } if (!string.IsNullOrWhiteSpace(_password)) { componentEvents.FireInformation(1, "UnZip SSIS", "Set Password.", null, 0, ref b); fz.Password = _password; } foreach (System.IO.FileInfo fi in fi_s) { if (!System.Text.RegularExpressions.Regex.Match(fi.FullName, _fileFilter).Success) { componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fi.FullName + " doesn't match regex filter '" + _fileFilter + "'. File not processed.", null, 0, ref b); continue; } componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": Compress (with '" + _storePaths.ToString() + "') file: " + fi.FullName, null, 0, ref b); string file_name = ""; ICSharpCode.SharpZipLib.Zip.ZipEntry ze = null; if (_storePaths == Store_Paths.Absolute_Paths) { //Absolute Path file_name = ICSharpCode.SharpZipLib.Zip.ZipEntry.CleanName(fi.FullName); ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name); } else if (_storePaths == Store_Paths.Relative_Paths) { //Relative Path ICSharpCode.SharpZipLib.Zip.ZipNameTransform zn = new ICSharpCode.SharpZipLib.Zip.ZipNameTransform(_folderSource); file_name = zn.TransformFile(fi.FullName); if (_addRootFolder) { file_name = (di.Name + "/" + file_name).Replace("//", "/"); } ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name); } else if (_storePaths == Store_Paths.No_Paths) { //No Path file_name = fi.Name; ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name); } else { throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths)."); } using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { ze.Size = fs.Length; fz.PutNextEntry(ze); fs.CopyTo(fz); fs.Flush(); fz.Flush(); fz.CloseEntry(); } } fz.Flush(); } _Check_ZIP(pathFileZip, componentEvents); } catch (Exception ex) { componentEvents.FireError(1000, "UnZip SSIS", ex.Message, null, 0); throw; } finally { } }
/// <summary> /// Gets the needed variables. /// </summary> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> private void GetNeededVariables(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { bool refire = false; List <string> lockForRead = new List <string>(); { var param = ServiceUrl; componentEvents.FireInformation(0, "SSISWCFTask", "WcfServiceUrl = " + ServiceUrl, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWCFTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = ServiceContract; componentEvents.FireInformation(0, "SSISWCFTask", "ServiceContract = " + ServiceContract, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWCFTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { var param = OperationContract; componentEvents.FireInformation(0, "SSISWCFTask", "OperationContract = " + OperationContract, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWCFTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } { if (!string.IsNullOrEmpty(ReturnedValue)) { var param = ReturnedValue; componentEvents.FireInformation(0, "SSISWCFTask", "ReturnedValue = " + ReturnedValue, string.Empty, 0, ref refire); if (param.Contains("@")) { var regexStr = param.Split('@'); foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries))) { try { componentEvents.FireInformation(0, "SSISWCFTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForWrite(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch (Exception exception) { throw new Exception(exception.Message); } } } } } componentEvents.FireInformation(0, "SSISWCFTask", "MappingParams ", string.Empty, 0, ref refire); //Get variables for MappingParams foreach (var nexSplitedVal in ((MappingParams)MappingParams) .Where(mappingParam => mappingParam.Value.Contains("@")) .Select(mappingParam => mappingParam.Value.Split('@')) .SelectMany(regexStr => regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)))) { try { componentEvents.FireInformation(0, "SSISWCFTask", nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')), string.Empty, 0, ref refire); if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')))) { variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))); } } catch { } } variableDispenser.GetVariables(ref _vars); }
public static bool SendEmail(VariableDispenser variableDispenser, Connections connections, IDTSComponentEvents componentEvents, string filePath, string from, string to, string subject, string body, string smtp) { bool retVal = false; bool refire = false; try { componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Build the e-mail...", string.Empty, 0, ref refire); using (MailMessage mailMessage = new MailMessage { From = new MailAddress(EvaluateExpression(from, variableDispenser).ToString()), Subject = EvaluateExpression(subject, variableDispenser).ToString(), Body = EvaluateExpression(body, variableDispenser).ToString(), }) { var strTo = EvaluateExpression(to, variableDispenser).ToString().Split(';'); foreach (string item in strTo) { mailMessage.To.Add(new MailAddress(item)); } mailMessage.Attachments.Add(new Attachment(filePath)); componentEvents.FireInformation(0, "SSISReportGeneratorTask", "File attachment added", string.Empty, 0, ref refire); try { componentEvents.FireInformation(0, "SSISReportGeneratorTask", string.Format("Send e-mail using {0}", GetConnectionParameter(connections[smtp].ConnectionString, "SmtpServer")), string.Empty, 0, ref refire); SmtpClient smtpClient = new SmtpClient(GetConnectionParameter(connections[smtp].ConnectionString, "SmtpServer")) { EnableSsl = Convert.ToBoolean(GetConnectionParameter(connections[smtp].ConnectionString, "EnableSsl")), //Credentials = CredentialCache.DefaultNetworkCredentials, UseDefaultCredentials = Convert.ToBoolean(GetConnectionParameter(connections[smtp].ConnectionString, "UseWindowsAuthentication")) }; componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Send the e-mail", string.Empty, 0, ref refire); smtpClient.Send(mailMessage); componentEvents.FireInformation(0, "SSISReportGeneratorTask", "E-mail sended", string.Empty, 0, ref refire); } catch (Exception exception) { componentEvents.FireError(0, "SSISReportGeneratorTask", string.Format("Problem: {0} {1}", exception.Message, exception.StackTrace), "", 0); retVal = false; } } retVal = true; } catch (Exception exception) { componentEvents.FireError(0, "SSISReportGeneratorTask", string.Format("Problem: {0} {1}", exception.Message, exception.StackTrace), "", 0); retVal = false; } return(retVal); }
/// <summary> /// The main method used to encode a file /// </summary> /// <param name="componentEvents"></param> /// <returns></returns> public bool Encode(IDTSComponentEvents componentEvents) { bool retVal = false; bool refire = false; try { componentEvents.FireInformation(0, "SSISEncodeFileTask", string.Format("Tha value of ReadWriteBuffer: {0} ", _bufferSize), string.Empty, 0, ref refire); if (_bufferSize < 1) { throw new Exception("The ReadWriteBuffer cannot be less than 1"); } lock (LockObject) { using (var transactionScope = new TransactionScope()) { var fileInfo = new FileInfo(_filePath); string tempPath = string.Format(@"{0}\{1}", Path.GetTempPath(), fileInfo.Name); Encoding destinationEncoding = Encoding.GetEncoding(_destinationEncoding); componentEvents.FireInformation(0, "SSISEncodeFileTask", string.Format("Destination encoding: {0} - {1}", destinationEncoding.CodePage, destinationEncoding.EncodingName), string.Empty, 0, ref refire); using (var fileStream = new FileStream(_filePath, FileMode.Open, FileAccess.Read)) { Encoding sourceEncoding; if (_autoDetectEncoding) { sourceEncoding = new StreamReader(fileStream).CurrentEncoding; componentEvents.FireInformation(0, "SSISEncodeFileTask", string.Format("File to encode {0} from auto-detected encoding [{1} - {2}]", _filePath, sourceEncoding.CodePage, sourceEncoding.EncodingName), string.Empty, 0, ref refire); } else { sourceEncoding = Encoding.GetEncoding(_sourceEncoding); componentEvents.FireInformation(0, "SSISEncodeFileTask", string.Format("File to encode {0} from specified encoding [{1} - {2}]", _filePath, sourceEncoding.CodePage, sourceEncoding.EncodingName), string.Empty, 0, ref refire); } if (File.Exists(tempPath)) { File.Delete(tempPath); } using (var streamReader = new StreamReader(fileStream, sourceEncoding)) { var fileContent = new char[_bufferSize]; int charsRead = streamReader.Read(fileContent, 0, _bufferSize); using (var streamWriter = new StreamWriter(tempPath, false, destinationEncoding)) { while (charsRead > 0) { streamWriter.Write(fileContent, 0, RemovingChar(fileContent, '\0').Count()); fileContent = new char[_bufferSize]; charsRead = streamReader.Read(fileContent, 0, _bufferSize); } streamWriter.Close(); } streamReader.Close(); } fileStream.Close(); } File.Delete(_filePath); File.Copy(tempPath, _filePath); File.Delete(tempPath); transactionScope.Complete(); } } retVal = true; } catch (Exception exception) { componentEvents.FireError(0, "SSISEncodeFileTask", string.Format("Encoding Error :{0}", exception.Message), string.Empty, 0); } return(retVal); }
public byte[] RenderReport(string url, string reportPath, ReportParameter[] parameters, string formatType, bool humanReadablePdf, IDTSComponentEvents componentEvents) { bool refire = false; byte[] retVal; componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Create the instance of the WS - " + string.Format("{0}ReportExecution2005.asmx", (url.Substring(url.Length - 1, 1) == "/") ? url : url + "/"), string.Empty, 0, ref refire); using (var rs = new ReportExecutionService { Credentials = CredentialCache.DefaultCredentials, Url = string.Format("{0}ReportExecution2005.asmx", (url.Substring(url.Length - 1, 1) == "/") ? url : url + "/") }) { const string historyID = null; string encoding; string mimeType; string extension; Warning[] warnings; string[] streamIDs; var execHeader = new ExecutionHeader(); componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Load the report from " + reportPath, string.Empty, 0, ref refire); var execInfo = rs.LoadReport(reportPath, historyID); componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Set parameters", string.Empty, 0, ref refire); rs.SetExecutionParameters(parameters.Select(p => new ParameterValue { Label = p.Name, Name = p.Name, Value = p.Value }).ToArray(), "en-EN"); rs.ExecutionHeaderValue = execHeader; rs.ExecutionHeaderValue.ExecutionID = execInfo.ExecutionID; componentEvents.FireInformation(0, "SSISReportGeneratorTask", "Render the report", string.Empty, 0, ref refire); retVal = rs.Render(formatType, (humanReadablePdf) ? DeviceSettings : null, out extension, out encoding, out mimeType, out warnings, out streamIDs); } return(retVal); }
private void _CompressTAR(string pathFileTAR, IDTSComponentEvents componentEvents, System.IO.Stream stream) { bool b = false; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(_folderSource); System.IO.FileInfo[] fi_s = di.GetFiles("*.*", System.IO.SearchOption.AllDirectories); if (stream == null) { stream = System.IO.File.Create(pathFileTAR); } using (ICSharpCode.SharpZipLib.Tar.TarOutputStream tar = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(stream)) { foreach (System.IO.FileInfo fi in fi_s) { if (!System.Text.RegularExpressions.Regex.Match(fi.FullName, _fileFilter).Success) { componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fi.FullName + " doesn't match regex filter '" + _fileFilter + "'. File not processed.", null, 0, ref b); continue; } componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": Compress (with '" + _storePaths.ToString() + "') file: " + fi.FullName, null, 0, ref b); string fileName = fi.FullName; if (_storePaths == Store_Paths.Absolute_Paths) { //Absolute Path fileName = fi.FullName.Replace("\\", "/").Substring(3); } else if (_storePaths == Store_Paths.Relative_Paths) { //Relative Path fileName = fileName.Replace(_folderSource, "").Replace("\\", "/"); if (_addRootFolder) { fileName = (di.Name + "/" + fileName).Replace("//", "/"); } } else if (_storePaths == Store_Paths.No_Paths) { //No Path fileName = fi.Name; } else { throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths)."); } using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { ICSharpCode.SharpZipLib.Tar.TarEntry te = ICSharpCode.SharpZipLib.Tar.TarEntry.CreateTarEntry(fileName); te.Size = fs.Length; tar.PutNextEntry(te); fs.CopyTo(tar); fs.Flush(); tar.Flush(); tar.CloseEntry(); } } tar.Flush(); tar.Close(); } }
/// <summary> /// Generate SSRS Report /// </summary> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> private void GenerateServerReport(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents) { var fi = new FileInfo(Filename); Variables vars = null; // Create a new proxy to the web service var rs = new ReportService2010.ReportingService2010(); var rsExec = new ReportExecution2005.ReportExecutionService(); // Assign the URL of the Web service rs.Url = ReportServer + "/ReportService2010.asmx"; rsExec.Url = ReportServer + "/ReportExecution2005.asmx"; // Authenticate to the Web service using Windows credentials if (WindowsAuthorization) { rs.Credentials = CredentialCache.DefaultCredentials; rsExec.Credentials = CredentialCache.DefaultCredentials; } else { rs.CookieContainer = new CookieContainer(); rs.LogonUser(String.Format("{0}\\{1}", Domain, Username), Password, ReportServer); rsExec.CookieContainer = new CookieContainer(); rsExec.LogonUser(String.Format("{0}\\{1}", Domain, Username), Password, ReportServer); } rs.Timeout = TimeOut; rsExec.Timeout = TimeOut; componentEvents.FireInformation(0, "ReportGenerator", String.Format("WebService timeout is set to {0} milliseconds.", TimeOut), string.Empty, 0, ref _refire); componentEvents.FireInformation(0, "ReportGenerator", "Report Server:" + ReportServer, string.Empty, 0, ref _refire); if (Snapshot) { try { ReportService2010.Warning[] warn; rs.CreateItemHistorySnapshot(Reportname, out warn); componentEvents.FireInformation(0, "ReportGenerator", "A snapshot was created.", string.Empty, 0, ref _refire); } catch (Exception ex) { componentEvents.FireWarning(0, "ReportGeneratorTask", "A snapshot could not be created. Exception: " + ex.Message, "", 0); } } // Prepare Render arguments var renderExtensions = new RenderExtensions(); var renderExtension = renderExtensions.Get(fi.Extension); if (renderExtension == null) { throw new Exception("Not supported render type (GenerateServerReport): " + fi.Extension); } string format = renderExtension.Name; // fire render arguments componentEvents.FireInformation(0, "ReportGenerator", "Reportname: " + Reportname, string.Empty, 0, ref _refire); componentEvents.FireInformation(0, "ReportGenerator", "Filename: " + _localname, string.Empty, 0, ref _refire); componentEvents.FireInformation(0, "ReportGenerator", "Format: " + format, string.Empty, 0, ref _refire); try { // Prepare report parameter. //DataTable dt = (DataTable)ReportGenerator.DeserializeObject(_Reportparameter.ToString()); var dt = GetParameterDataTable(Reportparameter); var param = new List <ParameterValue>(); // set paramter for server report //foreach (var row in dt.Rows.Cast<DataRow>().Where(row => !string.IsNullOrEmpty(row[0].ToString()) && row[0].ToString() != "Choose a Variable")) foreach (DataRow row in dt.Rows) { if (!string.IsNullOrEmpty(row[0].ToString()) && row[0].ToString() != "Choose a Variable") { variableDispenser.LockForRead(row[0].ToString()); variableDispenser.GetVariables(ref vars); var variableValue = vars[row[0].ToString()].Value.ToString(); var multiValue = Convert.ToBoolean(row[2]) ? variableValue.Split(';') : new[] { variableValue }; foreach (var value in multiValue) { param.Add(new ReportExecution2005.ParameterValue { Name = row[1].ToString(), Value = value }); componentEvents.FireInformation(0, "ReportGenerator", row[1] + " --> " + row[0] + " --> " + value, string.Empty, 0, ref _refire); } } } //componentEvents.FireInformation(0, "ReportGenerator", iParams.ToString(), string.Empty, 0, ref _refire); // Load the selected report var ei = rsExec.LoadReport(Reportname, null); // Set the parameters if (param.Count > 0) { rsExec.SetExecutionParameters(param.ToArray(), "en-EN"); } // Render the report string[] streamIDs; ReportExecution2005.Warning[] warnings; string encoding; string mimeType; string extension; var results = rsExec.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs); var execInfo = rsExec.GetExecutionInfo(); componentEvents.FireInformation(0, "ReportGenerator", string.Format("ExecutionDateTime: {0}", execInfo.ExecutionDateTime.ToLongDateString()), string.Empty, 0, ref _refire); if (!string.IsNullOrEmpty(ExecutionDateTime) && ExecutionDateTime != "Choose a Variable") { variableDispenser.LockOneForWrite(ExecutionDateTime, ref vars); if (vars[ExecutionDateTime].DataType == TypeCode.DateTime) { vars[ExecutionDateTime].Value = execInfo.ExecutionDateTime; vars.Unlock(); componentEvents.FireInformation(0, "ReportGenerator", String.Format("ExecutionDateTime: {0}", execInfo.ExecutionDateTime.ToLongDateString()), string.Empty, 0, ref _refire); } else { componentEvents.FireWarning(0, "ReportGenerator", "Incorrect DataType for ExecutionDateTime", null, 0); } } if (!string.IsNullOrEmpty(ExecutionId) && ExecutionId != "Choose a Variable") { variableDispenser.LockOneForWrite(ExecutionId, ref vars); if (vars[ExecutionId].DataType == TypeCode.String) { vars[ExecutionId].Value = String.IsNullOrEmpty(execInfo.ExecutionID) ? "" : execInfo.ExecutionID; vars.Unlock(); componentEvents.FireInformation(0, "ReportGenerator", string.Format("ExecutionId: {0}", execInfo.ExecutionID), string.Empty, 0, ref _refire); } else { componentEvents.FireWarning(0, "ReportGenerator", "Incorrect DataType for ExecutionId", null, 0); } } if (!string.IsNullOrEmpty(ExpirationDateTime) && ExpirationDateTime != "Choose a Variable") { variableDispenser.LockOneForWrite(ExpirationDateTime, ref vars); if (vars[ExpirationDateTime].DataType == TypeCode.DateTime) { vars[ExpirationDateTime].Value = execInfo.ExpirationDateTime; vars.Unlock(); componentEvents.FireInformation(0, "ReportGenerator", String.Format("ExpirationDateTime: {0}", execInfo.ExpirationDateTime.ToLongDateString()), string.Empty, 0, ref _refire); } else { componentEvents.FireWarning(0, "ReportGenerator", "Incorrect DataType for ExpirationDateTime", null, 0); } } if (!string.IsNullOrEmpty(HistoryId) && HistoryId != "Choose a Variable") { variableDispenser.LockOneForWrite(HistoryId, ref vars); if (vars[HistoryId].DataType == TypeCode.String) { vars[HistoryId].Value = String.IsNullOrEmpty(execInfo.HistoryID) ? "" : execInfo.HistoryID; vars.Unlock(); componentEvents.FireInformation(0, "ReportGenerator", String.Format("HistoryId: {0}", execInfo.HistoryID), string.Empty, 0, ref _refire); } else { componentEvents.FireWarning(0, "ReportGenerator", "Incorrect DataType for HistoryId", null, 0); } } if (!string.IsNullOrEmpty(NumPages) && NumPages != "Choose a Variable") { variableDispenser.LockOneForWrite(NumPages, ref vars); if (vars[NumPages].DataType == TypeCode.Int16 || vars[NumPages].DataType == TypeCode.Int32 || vars[NumPages].DataType == TypeCode.Int64) { vars[NumPages].Value = execInfo.NumPages; vars.Unlock(); componentEvents.FireInformation(0, "ReportGenerator", String.Format("NumPages: {0}", execInfo.NumPages), string.Empty, 0, ref _refire); } else { componentEvents.FireWarning(0, "ReportGenerator", "Incorrect DataType for NumPages", null, 0); } } if (File.Exists(_localname)) { File.Delete(_localname); } //// Create a file stream and write the report to it using (var stream = File.OpenWrite(_localname)) { stream.Write(results, 0, results.Length); } componentEvents.FireInformation(0, "ReportGenerator", "Report was generated.", string.Empty, 0, ref _refire); // open ReportViewerUI in debugmode if (DebugMode) { componentEvents.FireInformation(0, "ReportGenerator", "Show Report in Debugmode.", string.Empty, 0, ref _refire); var localReport = new ReportViewerUi { Reportserver = ReportServer, Reportname = Reportname, WindowsAuthorization = WindowsAuthorization, Username = Username, Password = Password, Domain = Domain, ReportType = ReportType }; //set parameter for localreport if (param.Count > 0) { var parameter = new List <ReportParameter>(); //[iParams]; //foreach (var row in dt.Rows.Cast<DataRow>().Where(row => !String.IsNullOrEmpty(row[0].ToString()))) foreach (DataRow row in dt.Rows) { if (!string.IsNullOrEmpty(row[0].ToString())) { variableDispenser.LockForRead(row[0].ToString()); variableDispenser.GetVariables(ref vars); var varValue = vars[row[0].ToString()].Value.ToString(); var multiValue = Convert.ToBoolean(row[2]) ? varValue.Split(';') : new[] { varValue }; foreach (var value in multiValue) { var localparam = new ReportParameter { Name = row[1].ToString() }; localparam.Values.Add(value); parameter.Add(localparam); } } } localReport.Reportparameter = parameter.ToArray(); } localReport.ShowDialog(); } } catch (Exception ex) { componentEvents.FireError(0, "ReportGenerator", ex.ToString(), "", 0); componentEvents.FireError(0, "ReportGenerator", fi.Extension.ToString(), "", 0); } }
/// <summary> /// This method is a run-time method executed dtsexec.exe /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; componentEvents.FireInformation(0, "SSISWebServiceTask", "Prepare variables", string.Empty, 0, ref refire); GetNeededVariables(variableDispenser, componentEvents); try { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Initialize WebService: {0}", EvaluateExpression(ServiceUrl, variableDispenser)), string.Empty, 0, ref refire); object[] result; using (var wsdlHandler = new WSDLHandler(new Uri(EvaluateExpression(ServiceUrl, variableDispenser).ToString()))) { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("InvokeRemoteMethod: {0}=>{1}", EvaluateExpression(Service, variableDispenser), EvaluateExpression(WebMethod, variableDispenser)), string.Empty, 0, ref refire); result = wsdlHandler.InvokeRemoteMethod <object>(EvaluateExpression(Service, variableDispenser).ToString(), EvaluateExpression(WebMethod, variableDispenser).ToString(), (from parameters in ((MappingParams)MappingParams) select EvaluateExpression(parameters.Value, variableDispenser)).ToArray()); } if (result != null) { if (IsValueReturned == "1") { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Get the Returned Value to: {0}", ReturnedValue), string.Empty, 0, ref refire); string val = ReturnedValue.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Get the Returned Value to {0} and convert to {1}", val.Substring(0, val.Length - 1), _vars[val.Substring(0, val.Length - 1)].DataType), string.Empty, 0, ref refire); _vars[val.Substring(0, val.Length - 1)].Value = Convert.ChangeType(result[0], _vars[val.Substring(0, val.Length - 1)].DataType); componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("The String Result is {0} ", _vars[val.Substring(0, val.Length - 1)].Value), string.Empty, 0, ref refire); } else { componentEvents.FireInformation(0, "SSISWebServiceTask", "Execution without return or no associated return variable", string.Empty, 0, ref refire); } } } catch (Exception ex) { componentEvents.FireError(0, "SSISWebServiceTask", string.Format("Problem: {0}", ex.Message + "\n" + ex.StackTrace), "", 0); } finally { if (_vars.Locked) { _vars.Unlock(); } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
/// <summary> /// This method is a run-time method executed dtsexec.exe /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; componentEvents.FireInformation(0, "SSISWCFTask", "Prepare variables", string.Empty, 0, ref refire); GetNeededVariables(variableDispenser, componentEvents); try { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Initialize the WCF Service: {0}", EvaluateExpression(ServiceUrl, variableDispenser)), string.Empty, 0, ref refire); var dynamicProxyFactory = new DynamicProxyFactory(EvaluateExpression(ServiceUrl, variableDispenser).ToString()); int count = 0; foreach (ServiceEndpoint endpoint in dynamicProxyFactory.Endpoints.Where(endPoint => endPoint.Contract.Name == EvaluateExpression(ServiceContract, variableDispenser).ToString())) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Service Endpoint[{0}]", count++), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Address: {0}", endpoint.Address), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Contract: {0}", endpoint.Contract.Name), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Binding: {0}", endpoint.Binding.Name), string.Empty, 0, ref refire); } componentEvents.FireInformation(0, "SSISWCFTask", string.Format("InvokeRemoteMethod: {0} => {1}", EvaluateExpression(ServiceContract, variableDispenser), EvaluateExpression(OperationContract, variableDispenser)), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Creating DynamicProxy to {0} ServiceContract", EvaluateExpression(ServiceContract, variableDispenser)), string.Empty, 0, ref refire); DynamicProxy dynamicProxy = dynamicProxyFactory.CreateProxy(EvaluateExpression(ServiceContract, variableDispenser).ToString()); if (dynamicProxy == null) { throw new Exception("Cannot create the proxy"); } object result = null; componentEvents.FireInformation(0, "SSISWCFTask", "Creating the Client Channel", string.Empty, 0, ref refire); using (IClientChannel innerChannel = dynamicProxy.GetProperty("InnerChannel") as IClientChannel) { if (innerChannel != null) { using (new OperationContextScope(innerChannel)) { componentEvents.FireInformation(0, "SSISWCFTask", "Creating the Message Header", string.Empty, 0, ref refire); OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("SSISDynamicWCF", "", Guid.NewGuid().ToString())); componentEvents.FireInformation(0, "SSISWCFTask", "The used headers:", string.Empty, 0, ref refire); foreach (var header in ((MappingHeaders)MappingHeaders)) { var headerValue = Convert.ChangeType(EvaluateExpression(header.Value, variableDispenser).ToString(), Type.GetType(header.Type)); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Name: {0} | Type: {1} | Value: {2}", header.Name, header.Type, headerValue), string.Empty, 0, ref refire); OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader(header.Name, "", headerValue)); } componentEvents.FireInformation(0, "SSISWCFTask", "The used params:", string.Empty, 0, ref refire); foreach (var param in ((MappingParams)MappingParams)) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Name: {0} | Type: {1} | Value: {2}", param.Name, param.Type, Convert.ChangeType(EvaluateExpression(param.Value, variableDispenser).ToString(), Type.GetType(param.Type))), string.Empty, 0, ref refire); } componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Call [{0}] OperationContract with parameters:", EvaluateExpression(OperationContract, variableDispenser)), string.Empty, 0, ref refire); int countParam = ((MappingParams)MappingParams).Count; var objParams = new object[countParam]; for (int i = 0; i < countParam; i++) { objParams[i] = Convert.ChangeType(EvaluateExpression(((MappingParams)MappingParams)[i].Value, variableDispenser).ToString(), Type.GetType(((MappingParams)MappingParams)[i].Type)); } result = dynamicProxy.CallMethod(EvaluateExpression(OperationContract, variableDispenser).ToString(), objParams); //new object[] // { // (from parameters in ((MappingParams)MappingParams) // select Convert.ChangeType(EvaluateExpression(parameters.Value, variableDispenser).ToString(), Type.GetType(parameters.Type))).ToArray() // }); } } else { componentEvents.FireInformation(0, "SSISWCFTask", "Cannot create the Inner Channel", string.Empty, 0, ref refire); throw new Exception("Cannot Create the Inner Channel"); } } if (result != null) { if (IsValueReturned == Keys.TRUE) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Get the Returned Value to: {0}", ReturnedValue), string.Empty, 0, ref refire); string val = ReturnedValue.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Get the Returned Value to {0} and convert to {1}", val.Substring(0, val.Length - 1), _vars[val.Substring(0, val.Length - 1)].DataType), string.Empty, 0, ref refire); _vars[val.Substring(0, val.Length - 1)].Value = Convert.ChangeType(result, _vars[val.Substring(0, val.Length - 1)].DataType); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("The String Result is {0} ", _vars[val.Substring(0, val.Length - 1)].Value), string.Empty, 0, ref refire); } else { componentEvents.FireInformation(0, "SSISWCFTask", "Execution without return or no associated return variable", string.Empty, 0, ref refire); } } } catch (Exception ex) { componentEvents.FireError(0, "SSISWCFTask", string.Format("Problem: {0}", ex.Message + "\n" + ex.StackTrace), "", 0); } finally { if (_vars.Locked) { _vars.Unlock(); } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
private void _DeCompressZIP(string pathFileZip, IDTSComponentEvents componentEvents) { bool b = false; _Check_ZIP(pathFileZip, componentEvents); using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip))) { if (!string.IsNullOrEmpty(_password)) { fz.Password = _password; } ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry(); while (ze != null) { string fn = ze.Name.Replace("/", "\\"); System.IO.FileInfo fi = null; if ((!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success) || (ze.IsDirectory && ze.Size == 0)) { if (!System.Text.RegularExpressions.Regex.Match(fn, _fileFilter).Success) { componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fn + " doesn't match regex filter '" + _fileFilter + "'", null, 0, ref b); // Added information display when regex doesn't match (Updated on 2015-12-30 by Nico_FR75) } fz.CloseEntry(); ze = fz.GetNextEntry(); continue; } componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": De-Compress (with '" + _storePaths.ToString() + "') file: " + fn, null, 0, ref b); if (_storePaths == Store_Paths.Absolute_Paths || _storePaths == Store_Paths.Relative_Paths) { //Absolute / Relative Path fi = new System.IO.FileInfo(_folderDest + fn); if (!System.IO.Directory.Exists(fi.DirectoryName)) { System.IO.Directory.CreateDirectory(fi.DirectoryName); } } else if (_storePaths == Store_Paths.No_Paths) { //No Path fi = new System.IO.FileInfo(_folderDest + System.IO.Path.GetFileName(fn)); } else { throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths)."); } using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { fz.CopyTo(fs); fs.Flush(); } fz.CloseEntry(); ze = fz.GetNextEntry(); } fz.Close(); } }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool b = false; _fileZip = _CheckVarName(_fileZip, variableDispenser); _folderSource = _CheckVarName(_folderSource, variableDispenser); _folderDest = _CheckVarName(_folderDest, variableDispenser); _fileFilter = _CheckVarName(_fileFilter, variableDispenser); if (_typeOperation == Type_Operation.Please_Select) { componentEvents.FireError(1, "UnZip SSIS", "Please select type operation (De/Compress).", null, 0); throw new Exception("Please select type operation (De/Compress)."); } if (!_folderSource.EndsWith("\\")) { _folderSource = _folderSource + "\\"; } if (!_folderDest.EndsWith("\\")) { _folderDest = _folderDest + "\\"; } try { if (!System.IO.Directory.Exists(_folderDest)) { componentEvents.FireInformation(1, "UnZip SSIS", "Create Folder: '" + _folderDest + "'.", null, 0, ref b); System.IO.Directory.CreateDirectory(_folderDest); } if (_typeOperation == Type_Operation.Compress) { //COMPRESS ---------------> componentEvents.FireInformation(1, "UnZip SSIS", "Start -- " + _typeOperation.ToString() + " -- process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); // (Updated on 2015-12-30 by Nico_FR75) if (System.IO.File.Exists(_folderDest + _fileZip) && !this.OverwriteZipFile) { throw new Exception("File zip: '" + _folderDest + _fileZip + "' exists. Delete file or set 'OverwriteZipFile=true'"); } if (_typeCompression == Type_Compression.ZIP) { _CompressZIP(_folderDest + _fileZip, componentEvents); } else if (_typeCompression == Type_Compression.TAR) { _CompressTAR(_folderDest + _fileZip, componentEvents, null); } else if (_typeCompression == Type_Compression.TAR_GZ) { _CompressGZ(_folderDest + _fileZip, componentEvents); } else { throw new Exception("Type compression not supported."); } } else { //DE-COMPRESS ---------------> componentEvents.FireInformation(1, "UnZip SSIS", "Start -- " + _typeOperation.ToString() + " -- process file: '" + _folderSource + _fileZip + "'.", null, 0, ref b); // (Updated on 2015-12-30 by Nico_FR75) if (_typeCompression == Type_Compression.ZIP) { _DeCompressZIP(_folderSource + _fileZip, componentEvents); } else if (_typeCompression == Type_Compression.TAR) { _DeCompressTAR(_folderSource + _fileZip, componentEvents, null); } else if (_typeCompression == Type_Compression.TAR_GZ) { _DeCompressGZ(_folderSource + _fileZip, componentEvents); } else { throw new Exception("Type compression not supported."); } } } catch (Exception ex) { componentEvents.FireError(1000, "UnZip SSIS", ex.Message, null, 0); return(DTSExecResult.Failure); } componentEvents.FireInformation(1, "UnZip SSIS", "End -- " + _typeOperation.ToString() + " -- process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); return(DTSExecResult.Success); }
/// <summary> /// Executes the action based on seleted options. /// </summary> /// <param name="connections">The connections.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> /// <param name="log">The log.</param> /// <param name="transaction">The transaction.</param> /// <returns></returns> /// <exception cref="System.Exception">Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object.</exception> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { try { bool fireAgain = true; string _localFile = Common.GetVariableValue<string>(this.localFile, variableDispenser); string _remoteFile = Common.GetVariableValue<string>(this.remoteFile, variableDispenser); string _hostName = Common.GetVariableValue<string>(this.hostName, variableDispenser); int _portNumber = Common.GetVariableValue<int>(this.portNumber, variableDispenser); string _userName = Common.GetVariableValue<string>(this.userName, variableDispenser); string _passWord = Common.GetVariableValue<string>(this.passWord, variableDispenser); string _fileFilter = Common.GetVariableValue<string>(this.fileFilter, variableDispenser); List<ISFTPFileInfo> sftpFileInfo = new List<ISFTPFileInfo>(); SFTPConnection sftp = new SFTPConnection(_hostName, _userName, _passWord, _portNumber, this.stopOnFailure, componentEvents, this.logLevel); if (this.fileAction == SFTPFileAction.ReceiveMultiple || this.fileAction == SFTPFileAction.SendMultiple) { if (Common.GetVariableValue<object>(fileInfo, variableDispenser).GetType() != typeof(List<ISFTPFileInfo>)) throw new Exception("Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object."); } if (this.fileAction == SFTPFileAction.Send) { List<string> fileList = Common.GetFileList(_localFile, _fileFilter, this.isRecursive); foreach (string fileName in fileList) sftpFileInfo.Add(new SFTPFileInfo(fileName, _remoteFile, this.overwriteDest, this.removeSource)); if (sftpFileInfo.Count > 0) sftp.UploadFiles(sftpFileInfo); else componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } else if (this.fileAction == SFTPFileAction.SendMultiple) { sftpFileInfo = (List<ISFTPFileInfo>)Common.GetVariableValue<object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) sftp.UploadFiles(sftpFileInfo); else componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } else if (this.fileAction == SFTPFileAction.Receive) { List<IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); remoteFileList = Common.GetRemoteFileList(remoteFileList, _fileFilter); foreach (IRemoteFileInfo remoteFile in remoteFileList) sftpFileInfo.Add(new SFTPFileInfo(_localFile, remoteFile.FullName, this.overwriteDest, this.removeSource)); if (sftpFileInfo.Count > 0) sftp.DownloadFiles(sftpFileInfo); else componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } else if (this.fileAction == SFTPFileAction.ReceiveMultiple) { sftpFileInfo = (List<ISFTPFileInfo>)Common.GetVariableValue<object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) sftp.DownloadFiles(sftpFileInfo); else componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } else if (this.fileAction == SFTPFileAction.List) { List<IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); Common.SetVariableValue(this.remoteFileListVariable, remoteFileList, variableDispenser); } } catch (Exception ex) { componentEvents.FireError(0, "Execute: ", ex.Message +Environment.NewLine + ex.StackTrace, "", 0); return DTSExecResult.Failure; } return DTSExecResult.Success; }