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 }
bool TryGetSimpleJobConditionalTransformers(string text) { try { var sj = new SimpleJobConditionalTransformers(); sj.UnSerialize(text); Job = sj; return(true); } catch (Exception) { return(false); } }
public async Task SerializeSimpleJobConditionalTransformersTestSimpleReadCSV() { #region ACT var cond = GetJobCSV(); var str = cond.SerializeMe(); //cond = null; var newJob = new SimpleJobConditionalTransformers(); newJob.UnSerialize(str); await newJob.Execute(); #endregion #region ASSERT AssertJobCSV(); #endregion }
private IRowReceive[] FromSimpleJobConditionalTransformers(SimpleJobConditionalTransformers sj) { var li = new List <IRowReceiveHierarchicalParent>(); for (int i = 0; i < sj.Receivers.Count; i++) { var item = sj.Receivers[i]; var newRow = new RowReadHierarchical(); newRow.Values.Add("Name", item.Name ?? item.GetType().Name); newRow.Values.Add("Type", item.GetType().Name); newRow.Values.Add("RowType", "Receiver"); li.Add(newRow); if (li.Count > 1) { newRow.Parent = li[li.Count - 2]; } } li.AddRange(FromSimpleTree(sj.association, li[li.Count - 1])); return(li.ToArray()); }
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(); } } }
static async Task MainAsync(string[] args) { //using (StartLogging st = new StartLogging("asd", "Asda", 1)) //{ // st.LogInformation("test'"); // Thread.Sleep(10); //} //return; Console.WriteLine(Directory.GetCurrentDirectory()); string dir = Directory.GetCurrentDirectory(); //if you want you can execute with StankinsSimpleJob //string file = Path.Combine(dir,"jobFolders.txt"); //File.WriteAllText(file, SimpleJobFolders()); //Console.WriteLine($"executing file {file}"); IJob si; DirectoryInfo di = null; string file; Action <string, string> moveFile = (fileNameSource, fileDestination) => { string destDir = Path.GetDirectoryName(fileDestination); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } if (File.Exists(fileDestination)) { File.Delete(fileDestination); } File.Move(fileNameSource, fileDestination); }; Action <string, string> copyFile = (fileNameSource, fileDestination) => { string destDir = Path.GetDirectoryName(fileDestination); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } if (File.Exists(fileDestination)) { File.Delete(fileDestination); } File.Copy(fileNameSource, fileDestination); }; Action <string, string, string> moveFiles = (path, search, pathDestination) => { var files = Directory.EnumerateFiles(path, search, SearchOption.TopDirectoryOnly); foreach (var fileLoop in files) { var name = Path.GetFileName(fileLoop); moveFile(fileLoop, Path.Combine(pathDestination, name)); } }; // //goto andrei; var strDemo1 = SimpleJobFolders(); File.WriteAllText("jobDefinition.txt", strDemo1); si = new SimpleJob(); si.UnSerialize(strDemo1); await si.Execute(); #region move into demos di = Directory.CreateDirectory("Demo1JobFolders"); file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "Demo1SimpleJobFolders.html"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/RazorHierarchical.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo1); moveFile(file, Path.Combine(di.FullName, file)); #endregion var strDemo2 = SimpleJobView(SimpleJobFolders(), "Demo2SimpleJobView.html"); File.WriteAllText("jobDefinition.txt", strDemo2); si = new SimpleJob(); si.UnSerialize(strDemo2); await si.Execute(); #region move into demos di = Directory.CreateDirectory("Demo2SimpleJobView"); file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "Demo2SimpleJobView.html"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/RazorHierarchical.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo2); moveFile(file, Path.Combine(di.FullName, file)); #endregion var strDemo3 = ExecuteSqlCIOrder(); File.WriteAllText("jobDefinition.txt", strDemo3); si = new SimpleJob(); si.UnSerialize(strDemo3); await si.Execute(); #region move into demos file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); di = Directory.CreateDirectory("Demo3ExecuteSql"); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "SqlToExecute/001Sql.sql"; copyFile(file, Path.Combine(di.FullName, file)); file = "SqlToExecute/002Sql.sql"; copyFile(file, Path.Combine(di.FullName, file)); file = "appsettings.json"; copyFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo3); moveFile(file, Path.Combine(di.FullName, file)); #endregion #region DocumentSqlServer //TODO:add demo DocumentSqlServer var strDemo4 = DocumentSqlServer(); File.WriteAllText("jobDefinition.txt", strDemo3); si = new SimpleJobConditionalTransformers(); si.UnSerialize(strDemo4); await si.Execute(); #region move into demos file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); di = Directory.CreateDirectory("Demo4DocumentSqlServer"); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/sqlserver.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/databases.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/tables.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/views.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); file = "Views/columns.cshtml"; copyFile(file, Path.Combine(di.FullName, file)); file = "relationalSqlServer.html"; copyFile(file, Path.Combine(di.FullName, file)); file = "appsettings.json"; copyFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo4); moveFile(file, Path.Combine(di.FullName, file)); #endregion #endregion #region PBX var strDemo5 = PBXJob(); File.WriteAllText("jobDefinition.txt", strDemo5); si = new SimpleJob(); si.UnSerialize(strDemo5); try { await si.Execute(); } catch (InvalidOperationException) { //do nothing - sql server does not have table } #region move into demos file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); di = Directory.CreateDirectory("Demo5PBX"); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "appsettings.json"; copyFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo5); moveFile(file, Path.Combine(di.FullName, file)); #endregion #endregion #region analysis project if (false) { await ExecuteSlnAnalysis(); di = Directory.CreateDirectory("Demo6AnalysisProject"); file = "Stankins.html"; moveFile(file, Path.Combine(di.FullName, file)); file = "StankinsNETFramework.html"; moveFile(file, Path.Combine(di.FullName, file)); } #endregion #region showDllTypes var strDemo7 = SimpleJobDllLoadTypes(); di = Directory.CreateDirectory("Demo7LoadDllTypes"); File.WriteAllText("jobDefinition.txt", strDemo7); si = new SimpleJob(); si.UnSerialize(strDemo7); await si.Execute(); #region move into demos file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "appsettings.json"; copyFile(file, Path.Combine(di.FullName, file)); file = "relationalDLL.html"; moveFile(file, Path.Combine(di.FullName, file)); //execute visualization file = ExecuteVisualizationDefinitionSimpleJob(strDemo7); moveFile(file, Path.Combine(di.FullName, file)); #endregion #endregion andrei: #region blockly table var strDemo8 = JobDllBlockly(); di = Directory.CreateDirectory("Demo8Blockly"); if (File.Exists("jobDefinition.txt")) { File.Delete("jobDefinition.txt"); } File.WriteAllText("jobDefinition.txt", strDemo8); si = new SimpleJobConditionalTransformers(); si.UnSerialize(strDemo8); await si.Execute(); #region move into demos file = "readme.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "jobDefinition.txt"; copyFile(file, Path.Combine(di.FullName, file)); file = "appsettings.json"; copyFile(file, Path.Combine(di.FullName, file)); file = "blockly.html"; moveFile(file, Path.Combine(di.FullName, file)); //execute visualization var dirBlocks = Path.Combine(di.FullName, "blocks"); moveFiles(Directory.GetCurrentDirectory(), "*block*.*", dirBlocks); moveFiles(Directory.GetCurrentDirectory(), "*def*.*", dirBlocks); moveFiles(Directory.GetCurrentDirectory(), "*code*.*", dirBlocks); file = ExecuteVisualizationDefinitionSimpleJob(strDemo8); moveFile(file, Path.Combine(di.FullName, file)); #endregion #endregion }
static string JobDllBlockly() { string dir = Environment.CurrentDirectory; IReceive folderWithDll = new ReceiverFolderHierarchical("#static:Directory.GetCurrentDirectory()#", "*.dll"); var filterFiles = new FilterForFilesHierarchical(); var recContentFile = new ReceiverFromDllRelational(); var loadDllFromFiles = new TransformerApplyReceiver(recContentFile, "DllFileName", "FullName"); //retain just types var filterTypes = new FilterRetainRelationalName(FilterType.Equal, "Types"); //load types that are not generic or abstract //var justTypes = new FilterComparableEqual(typeof(string), "Types", "NameRelation"); var notAbstract = new FilterComparableEqual(typeof(bool), false, "IsAbstract"); var notGeneric = new FilterComparableEqual(typeof(bool), false, "IsGeneric"); var notInterface = new FilterComparableEqual(typeof(bool), false, "IsInterface"); //var noInterface = new FilterExcludeRelation("Interfaces"); //var rel2plain = new TransformerRelationalToPlain(); var haveProps = new FilterComparableGreat(typeof(int), 0, "PropertiesNr"); //var justRelations = new FilterRetainItemsWithKey("NameRelation", FilterType.Equal); var fileRazor = Path.Combine(dir, "blockly.cshtml"); string filename = "#static:Directory.GetCurrentDirectory()#\\blockly.html"; ISend senderHTML = new SyncSenderMultiple( new Sender_Text(filename, "<html><body>") { FileMode = FileMode.Create }, new Sender_HTMLRazor("Views/" + Path.GetFileName(fileRazor), filename), //new Sender_HTMLRelationViz("Name", filename), new Sender_Text(filename, "</body></html>") ) ; var senderRow = new SenderByRowToFile("Name", "txt", "Block Definition", "txt"); var clear = new TransformClearValues(); var trReceiveHtml = new ReceiverHTMLTable(@"blockly.html", Encoding.UTF8); var decodeHtml = new TransformerHtmlDecode(); //var addJS = new TransformModifyField("Name", "{0}.js"); var senderBlockTag = new SenderByRowToFile("Name", "_def.txt", "Block definition", "txt"); var senderBlockDefinitionJs = new SenderByRowToFile("Name", "_block.js", "Block JS", "js"); var senderBlockCodeJs = new SenderByRowToFile("Name", "_code.js", "Block CodeGenerator", "js"); var job = new SimpleJobConditionalTransformers(); job .AddReceiver(folderWithDll) .AddFilter(filterFiles) .AddTransformer(loadDllFromFiles) .AddFilter(filterTypes) .AddFilter(notAbstract) .AddFilter(notGeneric) .AddFilter(notInterface) .AddFilter(haveProps) //.AddTransformer(noInterface) //.AddTransformer(rel2plain) .AddSender(senderHTML) .AddTransformer(clear) .Add(clear, trReceiveHtml) .Add(trReceiveHtml, decodeHtml) .Add(decodeHtml, senderBlockTag) .Add(decodeHtml, senderBlockDefinitionJs) .Add(decodeHtml, senderBlockCodeJs) ; return(job.SerializeMe()); }
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 }
public static int ExecuteJob(string fileName) { //var settings = new JsonSerializerSettings() //{ // TypeNameHandling = TypeNameHandling.Objects, // Formatting = Formatting.Indented, // Error = HandleDeserializationError // //ConstructorHandling= ConstructorHandling.AllowNonPublicDefaultConstructor //}; var valSerialized = File.ReadAllText(fileName); #region running the file from where it is var dir = Path.GetDirectoryName(fileName); if (!string.IsNullOrWhiteSpace(dir)) { Directory.SetCurrentDirectory(dir); } #endregion IJob job = null; try { var newJob = new SimpleJob(); newJob.UnSerialize(valSerialized); for (int nr = 0; nr < newJob.Receivers?.Count; nr++) { newJob.Receivers[nr] = new ReceiverDecorator(newJob.Receivers[nr]); } for (int nr = 0; nr < newJob.Senders?.Count; nr++) { newJob.Senders[nr] = new SendDecorator(newJob.Senders[nr]); } job = newJob; } catch (Exception ex) { Console.WriteLine(ex.Message); job = null; //TODO:log } if (job == null) { try { //TODO: add decorators job = new SimpleJobConditionalTransformers(); job.UnSerialize(valSerialized); } catch (Exception ex) { Console.WriteLine(ex.Message); job = null; //TODO:log } } if (job == null) { throw new ArgumentException($"cannot deserialize {fileName}"); } ; //var deserialized = JsonConvert.DeserializeObject(valSerialized, settings) as ISimpleJob; Console.WriteLine($"execute {job.GetType().FullName}"); try { job.Execute().Wait(); Console.WriteLine("OK"); return(0); } catch (Exception ex) { Console.WriteLine(ex.Message); return(-1); } }