public async Task TestExportRelationalHTMLSqlServer() { #region arrange string folderName = AppContext.BaseDirectory; //CreateExportFilesSqlServer(Path.Combine(folderName,"Views")); var connectionString = GetSqlServerConnectionString(); using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @" IF OBJECT_ID('dbo.TestAndrei', 'U') IS NOT NULL DROP TABLE dbo.TestAndrei;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = @"create table TestAndrei( ID int, FirstName varchar(64) not null )"; await cmd.ExecuteNonQueryAsync(); } } var rr = new ReceiverRelationalSqlServer(); rr.ConnectionString = connectionString; string OutputFileName = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderName, "relationalSqlServer.html")); var sender = new Sender_HTMLRazor("Views/sqlserver.cshtml", OutputFileName); var senderViz = new Sender_HTMLRelationViz("Name", OutputFileName); var filter = new FilterExcludeRelation("columns", "tables"); var job = new SimpleJobConditionalTransformers(); job.Receivers.Add(0, rr); job.AddSender(sender); job.Add(filter); job.Add(filter, senderViz); #endregion #region act await job.Execute(); #endregion #region assert Assert.IsTrue(File.Exists(OutputFileName), $"{OutputFileName} must exists"); //Process.Start("explorer.exe", OutputFileName); var text = File.ReadAllText(OutputFileName); Assert.IsTrue(text.Contains("TestAndrei"), "must contain table testandrei"); Assert.IsTrue(text.Contains("FirstName"), "must contain column FirstName "); #endregion }
static string DocumentSqlServer() { var rr = new ReceiverRelationalSqlServer(); rr.ConnectionString = "#file:SqlServerConnectionString#"; string OutputFileName = "relationalSqlServer.html"; var sender = new Sender_HTMLRazor("Views/sqlserver.cshtml", OutputFileName); sender.FileMode = FileMode.Create; var filter = new FilterExcludeRelation(new string[] { "columns", "tables", "views" }); var senderViz = new Sender_HTMLRelationViz("Name", OutputFileName); var si = new SimpleJobConditionalTransformers(); si.Receivers.Add(0, rr); si.AddSender(sender); si.Add(filter); si.Add(filter, senderViz); return(si.SerializeMe()); }
public static SimpleJobConditionalTransformers GetJobCSV() { #region ARRANGE StringBuilder sb = new StringBuilder(); sb.AppendLine("model,Track_number,buyYear"); sb.AppendLine("Ford,B325ROS,1990"); sb.AppendLine("Audi,PL654CSM,2004"); sb.AppendLine("BMW,B325DFH,2005"); sb.AppendLine("Ford,B325IYS,2007"); string filename = "mycsv.csv"; File.WriteAllText(filename, sb.ToString()); //define a receiver var receiverCSV = new ReceiverCSVFileInt(filename, Encoding.ASCII); //receiverCSV.Name = "From model:" + filename; //define a sender to csv for all records var senderAllToCSV = new Sender_CSV(DeleteFileIfExists("myAll.csv")); //senderAllToCSV.Name = "to csv allRecords"; //define a filter for audi var filterAudi = new FilterComparableEqual(typeof(string), "Audi", "model"); //define a sender just for audi var senderCSVAudi = new Sender_CSV(DeleteFileIfExists("myAudi.csv")); //senderCSVAudi.Name= "sender CSV"; //define a filter to transform the buyYear to string var buyYearTOString = new TransformerFieldStringInt("buyYear", "NewBuyYear"); //buyYearTOString.Name = "transform buyYear to int"; //define a filter for year>2000 var filterYear2000 = new FilterComparableGreat(typeof(int), 2000, "NewBuyYear"); //define a sender the year > 2000 to csv var sender2000CSV = new Sender_CSV(DeleteFileIfExists("my2000.csv")); //sender2000CSV.Name = "sender CSV"; //define a sender the year > 2000 to json var sender2000JSon = new Sender_JSON(DeleteFileIfExists("my2000.js")); //sender2000JSon.Name = "sender json"; //define a filter for Ford var filterFord = new FilterComparableEqual(typeof(string), "Ford", "model"); //define a sender just for ford var senderCSVFord = new Sender_CSV(DeleteFileIfExists("myFord.csv")); //senderCSVFord.Name = "sender CSV"; var cond = new SimpleJobConditionalTransformers(); //add a receiver cond.Receivers.Add(0, receiverCSV); //add a sender to csv for all records cond.AddSender(senderAllToCSV); //add a filter to transform the buyYear to string //and then fiter for year>2000 var buy = cond.Add(buyYearTOString, filterYear2000); //send the year> 2000 to csv cond.Add(filterYear2000, sender2000CSV); //send the year >2000 to json cond.Add(filterYear2000, sender2000JSon); //add a filter for audi and a sender just for audi cond.Add(filterAudi, senderCSVAudi); //add a filter for ford and a sender just for ford cond.Add(filterFord, senderCSVFord); return(cond); #endregion }
static async Task ExecuteSlnAnalysis() { string root = "@static:Path.GetPathRoot(#static:Directory.GetCurrentDirectory()#)@"; var si = new SimpleJob(); var recFolder = new ReceiverFolderHierarchical(root, "*tank*.sln;*StankinsSimpleJobNET*.exe"); si.Receivers.Add(0, recFolder); IFilter fi = new FilterForFilesHierarchical(); si.FiltersAndTransformers.Add(0, fi); si.UnSerialize(si.SerializeMe()); await si.Execute(); fi = si.FiltersAndTransformers[0] as IFilter; var exe = fi.valuesTransformed.FirstOrDefault(it => it.Values["FullName"].ToString().EndsWith(".exe")); if (exe == null) { Console.WriteLine("please build StankinsSimpleJobNET"); return; } string exePath = exe.Values["FullName"].ToString(); string exeDir = Path.GetDirectoryName(exePath); //cleanup foreach (var item in Directory.GetFiles(exeDir, "*.json")) { File.Delete(item); } //File.Copy("SolutionExport.txt", Path.Combine(exeDir, "SolutionExport.txt")); var slns = fi.valuesTransformed.Select(it => it.Values["FullName"]?.ToString()).Where(it => (it ?? "").Contains(".sln")).ToArray(); foreach (var sln in slns) { Console.WriteLine($"interpret:{sln}"); var psi = new ProcessStartInfo(exePath, "execute SolutionExport.txt"); psi.WorkingDirectory = exeDir; psi.Environment["solutionPath"] = sln; var p = Process.Start(psi); if (p.WaitForExit(60 * 1000)) { var newJob = new SimpleJobConditionalTransformers(); var json = Path.Combine(exeDir, Path.GetFileNameWithoutExtension(sln) + ".json"); var rec = new ReceiverJSONFileInt(json, Encoding.UTF8); newJob.Receivers.Add(0, rec); string fileName = Path.Combine(AppContext.BaseDirectory, Path.GetFileNameWithoutExtension(sln) + ".html"); if (File.Exists(fileName)) { File.Delete(fileName); } Console.WriteLine($"exporting to {fileName}"); string fileRazor = "solution.cshtml"; var sender = new SyncSenderMultiple( new Sender_Text(fileName, "<html><body>"), new Sender_HTMLRazor("Views/" + Path.GetFileName(fileRazor), fileName) ); newJob.AddSender(sender); var filter = new FilterExcludeRelation("referencedIn", "assemblyReferenced"); var senderViz = new SyncSenderMultiple( new Sender_HTMLRelationViz("Name", fileName), new Sender_Text(fileName, "</body></html>") ); newJob.Add(filter, senderViz); await newJob.Execute(); } } }
public async Task TestConditionalJobSQLServer2SQLServerAndFilter2SMTP() { #region arrange string connectionString = GetSqlServerConnectionString(); string commandText1 = "dbo.TestReiceverDBExecuteStoredProcedureNoParam2"; // Receiver SP (Source) string fileNameSerilizeLastRow = string.Empty; string parameters1 = string.Empty; string commandText2 = "dbo.TestSenderDBExecuteStoredProcedureWithParams2"; // Sender SP (Destination) string parameters2 = "@p1=PersonID;@p2=FirstName;@p3=LastName"; //Receiver: SQL Server Source using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "IF OBJECT_ID('dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam2') IS NOT NULL DROP TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam2; CREATE TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam2 (PersonID INT NOT NULL PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50)); INSERT dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam2 VALUES (0, 'John 0', 'Doe 0'), (1, 'John 1', 'Doe 1'), (2, 'John 2', 'Doe 2');"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "IF OBJECT_ID('dbo.TestReiceverDBExecuteStoredProcedureNoParam2') IS NOT NULL DROP PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam2;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "CREATE PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam2 AS SELECT * FROM dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam2;"; await cmd.ExecuteNonQueryAsync(); } } var rcvr = new ReceiverStmtSqlServer(connectionString, commandType, commandText1, fileNameSerilizeLastRow, parameters1); //Sender: SQL Server Destination using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "IF OBJECT_ID('dbo.TestingTestSenderDBExecuteStoredProcedureWithParams2') IS NOT NULL DROP TABLE dbo.TestingTestSenderDBExecuteStoredProcedureWithParams2; CREATE TABLE dbo.TestingTestSenderDBExecuteStoredProcedureWithParams2 (PersonID INT NOT NULL PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50));"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "IF OBJECT_ID('dbo.TestSenderDBExecuteStoredProcedureWithParams2') IS NOT NULL DROP PROCEDURE dbo.TestSenderDBExecuteStoredProcedureWithParams2;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "CREATE PROCEDURE dbo.TestSenderDBExecuteStoredProcedureWithParams2 (@p1 INT, @p2 VARCHAR(50), @p3 VARCHAR(50)) AS INSERT dbo.TestingTestSenderDBExecuteStoredProcedureWithParams2 (PersonID, FirstName, LastName) VALUES (@p1, @p2, @p3)"; await cmd.ExecuteNonQueryAsync(); } } var sndAll = new SenderToDBStmtSqlServer(connectionString, commandType, commandText2, parameters2); //Filter var fltPersCateg1 = new FilterComparableGreaterOrEqual(typeof(int), 1, "PersonID"); //Sender: SMTP Alert Configuration var sndPersCateg1 = new SenderToSMTP(from, to, string.Empty, string.Empty, subject, string.Empty, false, smtpServer, smtpPort, false, requiresAuthentication, user, password); //Sender: SMTP Clean using (var client = new Pop3Client()) { client.Connect(pop3Server, pop3Port, false); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(user, password); for (int i = 0; i < client.Count; i++) { var message = client.GetMessage(i); if (message.Subject == subject) { client.DeleteMessage(i); } } client.Disconnect(true); } //Job var job = new SimpleJobConditionalTransformers(); job.Receivers.Add(0, rcvr); job.AddSender(sndAll); job.Add(fltPersCateg1, sndPersCateg1); #endregion #region act await job.Execute(); #endregion #region assert //Check destination table using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT COUNT(*) AS Cnt FROM TestingTestSenderDBExecuteStoredProcedureWithParams2 tbl FULL JOIN (VALUES (0, 'John 0', 'Doe 0'), (1, 'John 1', 'Doe 1'), (2, 'John 2', 'Doe 2')) chk(PersonID, FirstName, LastName) ON tbl.PersonID = chk.PersonID AND tbl.FirstName = chk.FirstName AND tbl.LastName = chk.LastName WHERE EXISTS(SELECT tbl.PersonID EXCEPT SELECT chk.PersonID) OR EXISTS(SELECT tbl.FirstName EXCEPT SELECT chk.FirstName) OR EXISTS(SELECT tbl.LastName EXCEPT SELECT chk.LastName);"; var cnt = (int)await cmd.ExecuteScalarAsync(); Assert.AreEqual(0, cnt); } } //Check email //Read message and check Body (plain text) int numOfEmailFound = 0; using (var client = new Pop3Client()) { client.Connect(pop3Server, pop3Port, false); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(user, password); for (int i = 0; i < client.Count; i++) { var message = client.GetMessage(i); if (message.Subject == subject) { numOfEmailFound++; } } client.Disconnect(true); } Assert.AreEqual(1, numOfEmailFound); #endregion }