Exemplo n.º 1
0
        private void ProcessResponse(string response)
        {
            if (!_greetSent)
            {
                return;
            }

            switch (CaptureData)
            {
            case 1:
                TransactionCommands.ProcessData(this, response);
                return;

            case 2:
            case 3:
            case 4:
                AuthenticationCommands.ProcessData(this, response.Trim());
                return;
            }

            response = response.Trim();

            string command;
            var    data = string.Empty;

            if (response.Contains(":"))
            {
                command = response.Substring(0, response.IndexOf(":", StringComparison.Ordinal)).ToUpper().TrimEnd();
            }
            else if (response.Contains(" "))
            {
                command = response.Substring(0, response.IndexOf(" ", StringComparison.Ordinal)).ToUpper().TrimEnd();
            }
            else
            {
                command = response.ToUpper();
            }

            if (command.Length != response.Length)
            {
                data = response.Substring(command.Length).TrimStart();
            }

            switch (command)
            {
            case "EHLO":
                Transaction      = null;
                _protocolVersion = 2;
                WriteText($"250-{Server.Options.ServerName} at your service");
                if (Server.AuthLogin != null)
                {
                    WriteText("250-AUTH LOGIN PLAIN");
                }
                if (!Secure && Server.Certificate != null)
                {
                    WriteText("250-STARTTLS");
                }
                WriteText("250 8BITMIME");
                break;

            case "HELO":
                Transaction      = null;
                _protocolVersion = 1;
                WriteText($"250 {Server.Options.ServerName} at your service");
                break;

            case "STARTTLS":
                if (Secure)
                {
                    WriteCode(503, "5.5.1");
                    return;
                }

                if (Server.Certificate == null)
                {
                    WriteCode(502, "5.5.1");
                    return;
                }

                WriteCode(220, "2.0.0", "Ready for TLS");

                _stream    = new SslStream(_innerStream, false);
                Secure     = true;
                Encryption = ConnectionEncryption.StartTls;
                ((SslStream)_stream).AuthenticateAsServer(Server.Certificate, false, Server.Options.Protocols, true);
                _reader = new StreamReader(_stream);
                break;

            case "HELP":
                WriteCode(214, "2.0.0");
                break;

            case "AUTH":
                if (_protocolVersion == 0)
                {
                    WriteCode(503, "5.5.1", "EHLO/HELO first.");
                    return;
                }
                AuthenticationCommands.ProcessCommand(this, data);
                break;

            case "NOOP":
                WriteCode(250, "2.0.0");
                break;

            case "QUIT":
                WriteCode(221, "2.0.0");
                Dispose();
                break;

            case "RSET":
            case "MAIL FROM":
            case "RCPT TO":
            case "DATA":
                if (_protocolVersion == 0)
                {
                    WriteCode(503, "5.5.1", "EHLO/HELO first.");
                    return;
                }
                TransactionCommands.ProcessCommand(this, command, data);
                break;

            case "VRFY":
                if (_protocolVersion == 0)
                {
                    WriteCode(503, "5.5.1", "EHLO/HELO first.");
                    return;
                }
                WriteCode(252, "5.5.1");
                break;

            default:
                if (_protocolVersion == 0)
                {
                    WriteCode(503, "5.5.1", "EHLO/HELO first.");
                    return;
                }
                WriteCode(502, "5.5.1");
                break;
            }
        }
Exemplo n.º 2
0
        private static void PackageCreation(string xml, SSISBuilder pkg, string processType)
        {
            XElement root    = XElement.Load(new StringReader(xml));
            XElement process = root.Element("Process");

            pkg.VerboseLogging = Convert.ToBoolean(process.Attribute("VerboseLogging").Value);
            foreach (XElement node in process.Elements())
            {
                //string stepName = steps.Attribute("Name").Value;
                if (node.Name != null && node.Name.ToString().ToUpper() == "CONNECTIONSET")
                {
                    CHEFMetaDataProcessConnectionSet con;
                    con = GetConnectionSet <CHEFMetaDataProcessConnectionSet>(node.ToString());
                    // for SQL Connection
                    if (con != null)
                    {
                        if (con.SQLConnection != null)
                        {
                            foreach (var oleCon in con.SQLConnection)
                            {
                                if (oleCon.key != string.Empty)
                                {
                                    if (oleCon.Encrypt != null && oleCon.Encrypt.ToUpper() == "FALSE")
                                    {
                                        oleCon.Encrypt = "False";
                                    }
                                    else
                                    {
                                        oleCon.Encrypt = "True";
                                    }

                                    if (oleCon.TrustedConnection != null && oleCon.TrustedConnection.ToUpper() == "FALSE")
                                    {
                                        ConnectionEncryption conEncryption = new ConnectionEncryption();
                                        string strPassword      = conEncryption.DecryptString(oleCon.EncryptedPassword);
                                        string connectionString = System.Configuration.ConfigurationManager.AppSettings["Database_Standard_Connection"].Replace("[DataBase_Name]", oleCon.DatabaseName).Replace("[Server_Name]", oleCon.ServerName).Replace("[Encrypt_Connection]", oleCon.Encrypt).Replace("[User_ID]", oleCon.UserID).Replace("[User_Password]", strPassword).Replace("[Encryption]", oleCon.Encrypt);
                                        pkg.AddConnection(new Connection()
                                        {
                                            Key = oleCon.key, ConnectionString = connectionString, ConnectionType = ConnectionTypes.OleDBConnection
                                        });
                                    }
                                    else
                                    {
                                        string connectionString = System.Configuration.ConfigurationManager.AppSettings["Database_Trusted_Connection"].Replace("[DataBase_Name]", oleCon.DatabaseName).Replace("[Server_Name]", oleCon.ServerName).Replace("[Encryption]", oleCon.Encrypt);
                                        pkg.AddConnection(new Connection()
                                        {
                                            Key = oleCon.key, ConnectionString = connectionString, ConnectionType = ConnectionTypes.OleDBConnection
                                        });
                                    }
                                }
                            }
                        }
                        if (con.SharePointListConnection != null)
                        {
                            foreach (var oleCon in con.SharePointListConnection)
                            {
                                if (oleCon.key != string.Empty)
                                {
                                    if (oleCon.UseWindowsAuthentication != null && oleCon.UseWindowsAuthentication.ToUpper() == "FALSE")
                                    {
                                        ConnectionEncryption conEncryption = new ConnectionEncryption();
                                        string strPassword      = conEncryption.DecryptString(oleCon.EncryptedPassword);
                                        string connectionString = "SiteURL=" + oleCon.SiteURL + ";UserID=" + oleCon.UserID + ";Password="******"TRUE")
                                    {
                                        connectionString = "UseDevelopmentStorage=true";
                                    }
                                    else
                                    {
                                        ConnectionEncryption conEncryption = new ConnectionEncryption();
                                        string strAccountKey = conEncryption.DecryptString(oleCon.EncryptedAccountKey);
                                        connectionString = "DefaultEndpointsProtocol=" + oleCon.DefaultEndpointsProtocol.Trim() + ";AccountName=" + oleCon.AccountName + ";AccountKey=" + strAccountKey;
                                    }
                                    pkg.AddConnection(new Connection()
                                    {
                                        Key = oleCon.key, ConnectionString = connectionString, ConnectionType = ConnectionTypes.TableStorageConnection
                                    });
                                }
                                else
                                {
                                    throw new Exception("Invalid TableStorage Connection");
                                }
                            }
                        }
                        // for File Connection
                        if (con.FileConnection != null)
                        {
                            foreach (var fileCon in con.FileConnection)
                            {
                                //not able to make two different file connection
                                if (fileCon.key != string.Empty)
                                {
                                    pkg.AddConnection(new Connection()
                                    {
                                        Key = fileCon.key, ConnectionString = fileCon.FileName, ConnectionType = ConnectionTypes.FileConnection
                                    });
                                }
                            }
                        }
                        // for FlatFile  Connection
                        if (con.FlatFileConnection != null)
                        {
                            foreach (var flatFileCon in con.FlatFileConnection)
                            {
                                if (flatFileCon.key != string.Empty)
                                {
                                    pkg.AddConnection(new Connection()
                                    {
                                        Key = flatFileCon.key, ConnectionString = flatFileCon.FileName, ConnectionType = ConnectionTypes.FlatFileConnection
                                    });
                                }
                            }
                        }
                        // for FlatFile  Connection
                        if (con.SMTPConnection != null)
                        {
                            foreach (var smtpCon in con.SMTPConnection)
                            {
                                string smpt = string.Empty;
                                if (smtpCon.key != string.Empty)
                                {
                                    if (smtpCon.UseWindowsAuthentication == string.Empty || smtpCon.UseWindowsAuthentication == null)
                                    {
                                        smtpCon.UseWindowsAuthentication = "False";
                                    }
                                    if (smtpCon.EnableSsl == string.Empty || smtpCon.EnableSsl == null)
                                    {
                                        smtpCon.EnableSsl = "False";
                                    }
                                    smpt = "SmtpServer=" + smtpCon.SmtpServer + ";UseWindowsAuthentication=" + smtpCon.UseWindowsAuthentication + ";EnableSsl=" + smtpCon.EnableSsl + ";";
                                    pkg.AddConnection(new Connection()
                                    {
                                        Key = smtpCon.key, ConnectionString = smpt, ConnectionType = ConnectionTypes.SMTPConnection
                                    });
                                }
                            }
                        }
                    }
                }
                else if (node.Name != null && node.Name.ToString().ToUpper() == "VARIABLES")
                {
                    foreach (var variableNode in node.Elements())
                    {
                        CHEFMetaDataProcessVariablesVariable variable;
                        variable = GetVariableSet <CHEFMetaDataProcessVariablesVariable>(variableNode.ToString());
                        if (variable != null)
                        {
                            pkg.SetVariableValue(variable.Name, variable.Value, variable.DataType);
                        }
                    }
                }
                else if (node.Name != null && node.Name.ToString().ToUpper() == "SETVARIABLES")
                {
                    SetVariables setvariable;

                    setvariable = GetSetVariableSet <SetVariables>(node.ToString());
                    if (setvariable != null)
                    {
                        pkg.SetVariableRuntime(setvariable.SetVariable, "Need To Complete", "");
                    }
                }
                else if (node.Name != null && node.Name.ToString().ToUpper() == "SENDMAILTASK")
                {
                    SendMailTask sendMailTask;
                    sendMailTask = GetSendEmailTaskSet <SendMailTask>(node.ToString());
                    if (sendMailTask != null)
                    {
                        pkg.AddSendMailTask(sendMailTask.Name, sendMailTask.SMTPServer, sendMailTask.From, sendMailTask.To, sendMailTask.CC, sendMailTask.BCC, sendMailTask.Subject, sendMailTask.MessageSource, sendMailTask.Attachments, sendMailTask.Priority, sendMailTask.MessageSourceType);
                    }
                }
                else if (node.Name != null && node.Name.ToString().ToUpper() == "STEP")
                {
                    //CHEFMetaDataProcessStep step;
                    //step = GetStepsSet<CHEFMetaDataProcessStep>(node.ToString());
                    string stepType = ProcessTypeNames.Staging.ToString();
                    Int32  stepID   = 0;
                    if (node.Attribute("TypeName") != null)
                    {
                        stepType = node.Attribute("TypeName").Value;
                    }

                    if (node.Attribute("ID") != null)
                    {
                        stepID = Convert.ToInt32(node.Attribute("ID").Value);
                    }
                    string stepName = node.Attribute("Name").Value;
                    foreach (var stepNode in node.Elements())
                    {
                        // This loop is for DataFlowTask
                        if (stepType == processType.ToString() && stepType != string.Empty && stepID >= startStepID)
                        {
                            if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "VARIABLES")
                            {
                                foreach (var variableNode in stepNode.Elements())
                                {
                                    CHEFMetaDataProcessVariablesVariable variable;
                                    variable = GetVariableSet <CHEFMetaDataProcessVariablesVariable>(variableNode.ToString());
                                    if (variable != null)
                                    {
                                        pkg.SetVariableValue(variable.Name, variable.Value, variable.DataType);
                                    }
                                }
                            }
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "SETVARIABLES")
                            {
                                SetVariables setvariable;

                                setvariable = GetSetVariableSet <SetVariables>(stepNode.ToString());
                                if (setvariable != null)
                                {
                                    pkg.SetVariableRuntime(setvariable.SetVariable, stepName, "");
                                }
                            }
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "SENDMAILTASK")
                            {
                                SendMailTask sendMailTask;
                                sendMailTask = GetSendEmailTaskSet <SendMailTask>(stepNode.ToString());
                                if (sendMailTask != null)
                                {
                                    pkg.AddSendMailTask(sendMailTask.Name, sendMailTask.SMTPServer, sendMailTask.From, sendMailTask.To, sendMailTask.CC, sendMailTask.BCC, sendMailTask.Subject, sendMailTask.MessageSource, sendMailTask.Attachments, sendMailTask.Priority, sendMailTask.MessageSourceType);
                                }
                            }
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "SQLTASKSET")
                            {
                                CHEFMetaDataProcessStepSQLTaskSet sQLTaskSet;
                                sQLTaskSet = GetSQLTaskSet <CHEFMetaDataProcessStepSQLTaskSet>(stepNode.ToString());
                                if (sQLTaskSet != null)
                                {
                                    pkg.AddSQLTaskSet(sQLTaskSet, stepName);
                                }
                            }
                            // This loop is for PackageExecution task
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "PACKAGEEXECUTION")
                            {
                                CHEFMetaDataProcessStepPackageExecution packageExecution;
                                packageExecution = GetPackageExecutionSet <CHEFMetaDataProcessStepPackageExecution>(stepNode.ToString());
                                if (packageExecution != null)
                                {
                                    pkg.AddExecutablePackage(packageExecution.PackageName, packageExecution.Connection);
                                }
                            }
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "DATAFLOWSET")
                            {
                                CHEFMetaDataProcessStepDataFlowSet dataFlowSet;
                                dataFlowSet = GetDataFlowSet <CHEFMetaDataProcessStepDataFlowSet>(stepNode.ToString());
                                if (dataFlowSet != null)
                                {
                                    pkg.AddDataFlowSet(dataFlowSet, stepName);
                                }
                            }
                            else if (stepNode.Name != null && stepNode.Name.ToString().ToUpper() == "TABLESTORAGESET")
                            {
                                CHEFMetaDataProcessStepTableStorageSet tableStorageSet;
                                tableStorageSet = GetTableStorageSet <CHEFMetaDataProcessStepTableStorageSet>(stepNode.ToString());
                                if (tableStorageSet != null)
                                {
                                    //pkg.AddDataFlowSet(tableStorageSet, stepName);
                                }
                            }
                        }
                    }
                }
            }
        }