public async Task TestUnzip() { #region arrange var dir = AppContext.BaseDirectory; string existingZip = Path.Combine(dir, "a.zip"); dir = Path.Combine(dir, "TestUnzip"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); File.Copy(existingZip, Path.Combine(dir, "a.zip")); var receive = new ReceiverFolderHierarchical(dir, "*.zip"); var sender = new SenderUnzipFile(dir); #endregion #region act var job = new SimpleJob(); job.Receivers.Add(0, receive); job.Senders.Add(0, sender); await job.Execute(); #endregion #region assert string file = Path.Combine(dir, "a.txt"); Assert.IsTrue(File.Exists(file), $"{file} should be unzipped"); #endregion }
public async Task TestTransformerFileToLines() { #region arrange var dir = AppContext.BaseDirectory; var folderSql = Path.Combine(dir, "SqlToExecute"); var receiverFolder = new ReceiverFolderHierarchical(folderSql, "*.sql"); DirectoryInfo di = new DirectoryInfo(folderSql); Console.WriteLine($"start files in {folderSql}"); foreach (var item in di.EnumerateFiles("*.sql")) { Console.WriteLine($"File {item.FullName}"); } Console.WriteLine($"end files in {folderSql}"); #endregion #region act var transformer = new TransformerFileToLines(); var j = new SimpleJob(); j.Receivers.Add(0, receiverFolder); j.FiltersAndTransformers.Add(0, transformer); await j.Execute(); #endregion #region assert receiverFolder.valuesRead?.Length.ShouldBeGreaterThan(1); transformer.valuesTransformed.ShouldNotBeNull(); var files = transformer.valuesTransformed.GroupBy(it => it.Values["FullName"]).ToArray(); files.Length.ShouldBeGreaterThan(1); var file1Len = files.First().Count(); var file2Len = files.Last().Count(); file1Len.ShouldBeGreaterThan(0); file2Len.ShouldBeGreaterThan(0); (file1Len + file2Len).ShouldBeGreaterThan(2); #endregion }
public async Task Test_ReceiverBookmarkFileChrome() { var dir = AppContext.BaseDirectory; #region ARRANGE string pathFile = Path.Combine(dir, "bookmarks_7_25_17.html"); if (!File.Exists(pathFile)) { throw new ArgumentException($"not found {pathFile}"); } var receiver = new ReceiverBookmarkFileChrome(pathFile); string transformExpression = "var secs = double.Parse((oldValue??null).ToString());" + "var val=new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(secs);" + "val"; var transform = new TransformOneValueGeneral(transformExpression, "ADD_DATE", "realDate"); #endregion #region ACT ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, receiver); job.FiltersAndTransformers.Add(0, transform); await job.Execute(); #endregion #region ASSERT Assert.AreEqual(5676, transform.valuesRead.Length); Assert.AreEqual(5676, transform.valuesTransformed.Length); Assert.AreEqual(new DateTime(2015, 5, 14, 19, 15, 50).ToString(), transform.valuesTransformed[0].Values["realDate"].ToString()); #endregion }
public async Task RunJobInterpreted() { #region arrange var dir = AppContext.BaseDirectory; foreach (var item in Directory.EnumerateFiles(dir, "*.csv")) { File.Delete(item); } StringBuilder sb = new StringBuilder(); sb.AppendLine("1,model,Track_number"); sb.AppendLine("2,Ford,B325ROS"); sb.AppendLine("3,Audi,PL654CSM"); sb.AppendLine("4,BMW,B325DFH"); sb.AppendLine("5,Ford,B325IYS"); File.WriteAllText(Path.Combine(dir, "cars.csv"), sb.ToString()); var textJob = File.ReadAllText(Path.Combine(dir, "InterpreterJobDateTime.txt")); //var j1 = new SimpleJob(); //j1.Senders.Add(0, new Sender_CSV(":ASDAS")); //File.WriteAllText("aaa.txt", j1.SerializeMe()); //Process.Start("notepad.exe", "aaa.txt"); #endregion #region act IJob j = new SimpleJob(); j.UnSerialize(textJob); await j.Execute(); #endregion #region assert Assert.IsTrue(File.Exists("SendTo" + DateTime.Now.ToString("yyyyMMdd") + ".csv")); #endregion }
static string ExecuteVisualizationDefinitionSimpleJob(string contents) { var si = new SimpleJob(); si.UnSerialize(SimpleJobView(contents, "jobDefinition.html")); si.Execute().GetAwaiter().GetResult(); return("jobDefinition.html"); }
public IHttpActionResult ScheduleJob() { var simpleJob = new SimpleJob(); RecurringJob.AddOrUpdate(() => simpleJob.Execute(), Cron.Minutely); return(Ok($"recurring job scheduled")); }
public IHttpActionResult ScheduleOneTimeJob() { var simpleJob = new SimpleJob(); var jobId = BackgroundJob.Enqueue(() => simpleJob.Execute()); return(Ok($"fire and forget job {jobId} fired")); }
public async Task TestReceiveSendDllHtml() { #region arrange var path = AppContext.BaseDirectory; var dir = AppContext.BaseDirectory; dir = Path.Combine(dir, "TestReceiveSendDllHtml"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); var fileRazor = Path.Combine(dir, "relationalGeneric.cshtml"); File.Copy(@"Views\relationalGeneric.cshtml", fileRazor, true); string fileNameDll = Path.Combine(path, "StanskinsImplementation.dll"); string filename = Path.Combine(dir, "senderhtml.html"); if (File.Exists(filename)) { File.Delete(filename); } var receiverDll = new ReceiverFromDllRelational(fileNameDll); ISend senderHTML = new SyncSenderMultiple( new Sender_Text(filename, "<html><body>"), new Sender_HTMLRazor("TestReceiveSendDllHtml/" + Path.GetFileName(fileRazor), filename), new Sender_HTMLRelationViz("Name", filename), new Sender_Text(filename, "</body></html>") ) ; #endregion #region act var job = new SimpleJob(); job.Receivers.Add(0, receiverDll); job.Senders.Add(0, senderHTML); await job.Execute(); #endregion #region assert File.Exists(filename).ShouldBeTrue($"file {filename} should exists"); //Process.Start("explorer.exe", filename); #endregion }
public async Task TestSerializeReceiveBKChromeTransformOneValueSendCSV() { var dir = AppContext.BaseDirectory; #region arange string filename = Path.Combine(dir, "a.csv"); if (File.Exists(filename)) { File.Delete(filename); } var receiver = new ReceiverBookmarkFileChrome(@"bookmarks_7_25_17.html"); string transformExpression = "var secs = double.Parse((oldValue??null).ToString());" + "var val=new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(secs);" + "val"; var transform = new TransformOneValueGeneral(transformExpression, "ADD_DATE", "realDate"); var sender = new Sender_CSV(filename); ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, receiver); job.FiltersAndTransformers.Add(0, transform); job.Senders.Add(0, sender); #endregion #region act var newJob = new SimpleJob(); newJob.UnSerialize(job.SerializeMe()); await newJob.Execute(); #endregion #region assert Assert.AreEqual(job.Senders.Count, newJob.Senders.Count); Assert.AreEqual(job.Receivers.Count, newJob.Receivers.Count); Assert.AreEqual(job.FiltersAndTransformers.Count, newJob.FiltersAndTransformers.Count); Assert.IsTrue(File.Exists(filename), $"file {filename} must exists in export csv"); Assert.AreEqual(5677, File.ReadAllLines(filename).Length); #endregion }
public async Task TestReceiveFromJobConditional() { #region arrange var dir = AppContext.BaseDirectory; dir = Path.Combine(dir, "TestReceiveFromJobConditional"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); var job = SimpleJobConditionalTransformersTest.GetJobCSV(); var receiver = new ReceiverFromJob(job); string file = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(dir, "job.html")); //var sender = new Sender_HierarchicalVizJob(file,"Name"); //var sender = new SenderMediaToFile(file, // new MediaTransformStringToText("<html><body>"), // new MediaTransformDotJob(), // new MediaTransformStringToText("</body></html>") // ); var export = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(dir, "export.cshtml")); File.WriteAllText(export, Sender_HTMLRazor.DefaultExport()); var sender = new SyncSenderMultiple( new Sender_Text(file, "<html><body>"), new Sender_HTMLRazor("TestReceiveFromJobConditional/" + Path.GetFileName(export), file), new Sender_HierarchicalVizJob(file, "Name"), new Sender_Text(file, "</body></html>") ); var newJob = new SimpleJob(); newJob.Receivers.Add(0, receiver); //newJob.Receivers.Add(1, new ReceiverFromJob(newJob)); newJob.Senders.Add(0, sender); #endregion #region act await newJob.Execute(); #endregion #region assert Assert.IsTrue(File.Exists(file)); //System.Diagnostics.Process.Start("explorer.exe", file); #endregion }
public async Task TestVariableMax() { return; #region arrange var dir = Path.Combine(AppContext.BaseDirectory, "TestVariableMax"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); var sb = new StringBuilder(); sb.AppendLine("nr,model,Track_number"); sb.AppendLine("1,Ford,B325ROS"); sb.AppendLine("2,Audi,PL654CSM"); sb.AppendLine("3,BMW,B325DFH"); sb.AppendLine("4,Ford,B325IYS"); var file = Path.Combine(dir, "cars.csv"); File.WriteAllText(file, sb.ToString()); SimpleJob sj = new SimpleJob(); sj .AddReceiver(new ReceiverCSVFileInt(file, Encoding.UTF8)) .AddTransformer(new TransformIntoVariable("MaxCars", GroupingFunctions.Max, "nr")) ; sj.RuntimeParameters = new RuntimeParameter[1]; sj.RuntimeParameters[0] = new RuntimeParameter(); sj.RuntimeParameters[0].VariableName = "MaxCars"; //sj.RuntimeParameters[0].NameObjectsToApplyTo = new string[] { "MyReceiver" }; #endregion #region act await sj.Execute(); #endregion #region assert #endregion }
private static void brrbrrrr() { ISerializeData sd = new SerializeDataInMemory(); var data = new DBTableData <int, SqlConnection>(sd) { ConnectionString = @"Server=(local)\SQL2016;Database=DatePtAndrei;Trusted_Connection=True;", FieldNameToMark = "id", TableName = "active_slowquery_test" }; IReceive r = new ReceiverTableSQLServerInt(data); ISend esExport = new SenderToElasticSearch(@"http://localhost:9200", "ix004", "type007", "id"); ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, r); job.Senders.Add(0, esExport); job.Execute().Wait(); }
public async Task TransmitDataJob2JobFileHardDisk() { StringBuilder sb = new StringBuilder(); sb.AppendLine("model,Track_number"); sb.AppendLine("Ford,B325ROS"); sb.AppendLine("Audi,PL654CSM"); sb.AppendLine("BMW,B325DFH"); sb.AppendLine("Ford,B325IYS"); string filename = SimpleJobConditionalTransformersTest.DeleteFileIfExists("mycsv.csv"); File.WriteAllText(filename, sb.ToString()); var CSVReceiver = new ReceiverCSVFileInt(filename, Encoding.ASCII); string bin = SimpleJobConditionalTransformersTest.DeleteFileIfExists("a.bin"); var senderBinary = new Sender_Binary(bin); var job = new SimpleJob(); job.Receivers.Add(0, CSVReceiver); job.Senders.Add(0, senderBinary); var continueJob = new SimpleJob(); var binReceiver = new ReceiverFileFromStorageBinary(bin); continueJob.Receivers.Add(0, binReceiver); #region ACT await job.Execute(); await continueJob.Execute(); #endregion #region assert Assert.AreEqual(4, binReceiver.valuesRead.Length); Assert.AreEqual("Ford", binReceiver.valuesRead[0].Values["model"]); Assert.AreEqual("B325IYS", binReceiver.valuesRead[3].Values["Track_number"]); #endregion }
static async Task MainAsync(string[] args) { var sj = new SimpleJob(); IReceive folder = new ReceiverFolderHierarchical(@"D:\test", "*.txt"); //await folder.LoadData(); var t = new TransformerFileToLines(); t.TrimEmptyLines = false; //t.valuesRead = folder.valuesRead; //await t.Run(); var addBak = new TransformerFieldAddString("FullName", "FullName", ".bak"); addBak.valuesRead = t.valuesTransformed; //await addBak.Run(); //var regex = new TransformRowRegex(@"^(?x<ip>123).*?$","text"); var regex = new TransformRowRegexReplaceGuid(@"^.*x(?<ip>\w+)123.*?$", "text"); regex.ReplaceAllNextOccurences = true; //regex.valuesRead = addBak.valuesTransformed; //await regex.Run(); var file = new SenderByRowToFile("FullName", "lineNr", "text", ".txt"); file.FileMode = System.IO.FileMode.Append; //file.valuesToBeSent = regex.valuesTransformed; //await file.Send(); sj .AddReceiver(folder) .AddTransformer(t) //.AddTransformer(addBak) .AddTransformer(regex) .AddSender(file); File.WriteAllText("def.txt", sj.SerializeMe()); await sj.Execute(); }
public async Task <IActionResult> OnPostAsync() { if (string.IsNullOrWhiteSpace(fileGenerated)) { return(Page()); } try { SimpleJob job = new SimpleJob(); job.UnSerialize(fileGenerated); var sd = new SenderDataTable(); job.AddSender(sd); await job.Execute(); Result = sd.result; return(Page()); } catch (Exception ex) { ExceptionMessage = ex.Message; return(Page()); } }
public async Task TestSqlFolder() { #region arrange var dir = AppContext.BaseDirectory; var conection = GetSqlServerConnectionString(); var folderSql = Path.Combine(dir, "SqlToExecute"); var receiverFolder = new ReceiverFolderHierarchical(folderSql, "*.sql"); var con = new DBDataConnection <SqlConnection>(); con.ConnectionString = conection; var senderSqlServer = new SenderSqlToDBSqlServer(con); #endregion #region act var j = new SimpleJob(); j.Receivers.Add(0, receiverFolder); j.Senders.Add(0, senderSqlServer); await j.Execute(); #endregion #region assert receiverFolder.valuesRead?.Length.ShouldBeGreaterThan(1); using (var conn = new SqlConnection(conection)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "select count(ID) from TestAndrei"; var res = await cmd.ExecuteScalarAsync(); res.ShouldNotBeNull(); var text = res.ToString(); text.ShouldBe("1"); } } #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 TestSimpleJobReceiverDBExecuteStoredProcedureToSenderElasticSearch() { string connectionString = GetSqlServerConnectionString(); string commandText = "dbo.TestReiceverDBExecuteStoredProcedure2"; string url = "http://localhost:9200"; string indexName = "ixtestsenderelasticsearch2"; string typeName = "Person"; string id = "PersonID"; string fileNameSerilizeLastRow = "TestExecStoredProcedure2.txt"; #region arange //Arange receiver using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "IF OBJECT_ID('dbo.TestReiceverDBExecuteStoredProcedure2') IS NOT NULL DROP PROCEDURE dbo.TestReiceverDBExecuteStoredProcedure2;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "CREATE PROCEDURE dbo.TestReiceverDBExecuteStoredProcedure2 AS SELECT 1 AS PersonID, 'John' AS FirstName , 'Doe' AS LastName UNION ALL SELECT 11, 'Joanna', 'Doe' ORDER BY PersonID"; await cmd.ExecuteNonQueryAsync(); } } ReceiverStmtSqlServer rcvr = new ReceiverStmtSqlServer(connectionString, commandType, commandText, fileNameSerilizeLastRow); //Arange sender var settings = new ConnectionSettings(new Uri(url)); var client = new ElasticClient(settings); if (client.IndexExists(indexName).Exists) { client.DeleteIndex(indexName); } //Arange simple job ISend snd = new SenderToElasticSearch(url, indexName, typeName, id); ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, rcvr); job.Senders.Add(0, snd); #endregion #region act job.Execute().Wait(-1); await Task.Delay(5000); //Missing of await keyword is intentional (Thread.Sleep(5000)). 5s shoudl be more than enough to insert 2 documents. #endregion #region assert //Same count ? var responseAll = client.Search <Dictionary <string, string> >(s => s.Size(10).Index(indexName).Type(typeName)); int countAll = responseAll.Documents.Count; Assert.AreEqual(countAll, 2, $"Inserted documents: 2, Read documents {countAll}"); //Same values ? (assuption: [1] both count are equals, [2] rows is already sorted by id) Dictionary <string, object>[] valuesReadFromESOrdered = (new List <Dictionary <string, string> >(responseAll.Documents)).OrderBy(ord => ord[id]).ToList <Dictionary <string, string> >().ToDictionaryStringObject().ToArray(); Assert.IsTrue(Utils.CompareDictionary(rcvr.valuesRead[0].Values, valuesReadFromESOrdered[0])); Assert.IsTrue(Utils.CompareDictionary(rcvr.valuesRead[1].Values, valuesReadFromESOrdered[1])); #endregion }
public async Task TestSimpleJobReceiverFromSQLServer2SenderToIoTHub() { #region arrange string connectionString = GetSqlServerConnectionString(); string commandText1 = "dbo.TestReiceverDBExecuteStoredProcedureNoParam3"; // Receiver SP (Source) string fileNameSerilizeLastRow = string.Empty; string parameters1 = string.Empty; //Receiver using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "IF OBJECT_ID('dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam3') IS NOT NULL DROP TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam3; CREATE TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam3 (PersonID INT NOT NULL PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50)); INSERT dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam3 VALUES (10, 'John 00', 'Doe 00'), (11, 'John 01', 'Doe 01');"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "IF OBJECT_ID('dbo.TestReiceverDBExecuteStoredProcedureNoParam3') IS NOT NULL DROP PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam3;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "CREATE PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam3 AS SELECT * FROM dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam3;"; await cmd.ExecuteNonQueryAsync(); } } var rcvr = new ReceiverStmtSqlServer(connectionString, commandType, commandText1, fileNameSerilizeLastRow, parameters1); //Sender string iotHubUri = "a"; string deviceId = "b"; string deviceKey = "c"; string messageType = "UnitTest"; var snd = new SenderToAzureIoTHub(iotHubUri, deviceId, deviceKey, messageType); //Job ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, rcvr); job.Senders.Add(0, snd); #endregion #region act await job.Execute(); //var j = job.SerializeMe(); //File.WriteAllText(@"e:\j.json", j); #endregion #region assert rcvr.valuesRead.Length.ShouldBe(2); //Assert Receiver IoT Hub settings string iotHubConnectionStringEventHubCompatible = "Endpoint=sb://iothub-ns-azbogdanst-208965-a24331514f.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=pPQtX7pSbtNM1cUngtgsdRJIopXGF/jfHZPRVtlcebg="; string iotHubMessageEntityEventHubCompatible = "azbogdanstankinsiothub"; string fileNameLastRow = "TestSimpleJobReceiverFromSQLServer2SenderToIoTHub_LastOffset.json"; var rcv = new ReceiverFromAzureIoTHub(iotHubConnectionStringEventHubCompatible, iotHubMessageEntityEventHubCompatible, fileNameLastRow, messageType, -1); await rcv.LoadData(); bool hasFirstRow = false; bool hasSecondRow = false; rcv.valuesRead.ShouldNotBeNull(); rcv.valuesRead.Length.ShouldBeGreaterThanOrEqualTo(2); foreach (var row in rcv.valuesRead) { if (row.Values.ContainsKey("PersonID") && row.Values.ContainsKey("FirstName") && row.Values.ContainsKey("LastName")) { hasFirstRow = ((long)row.Values["PersonID"] == 10 && (string)row.Values["FirstName"] == "John 00" && (string)row.Values["LastName"] == "Doe 00") ? true : hasFirstRow; hasSecondRow = ((long)row.Values["PersonID"] == 11 && (string)row.Values["FirstName"] == "John 01" && (string)row.Values["LastName"] == "Doe 01") ? true : hasSecondRow; } } Assert.IsTrue(hasFirstRow, "must have first row"); Assert.IsTrue(hasSecondRow, "must have second row"); #endregion }
public async Task TestSenderWithFilterSQL2SQL2SMTP() { #region arrange 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"; //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); } //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(); } } //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(); } } //Job var rcvr = new ReceiverStmtSqlServer(connectionString, commandType, commandText1, fileNameSerilizeLastRow, parameters1); var sndAll = new SenderToDBStmtSqlServer(connectionString, commandType, commandText2, parameters2); //It's not the real sender being used by sndSMTPFiltered var sndSMTP = new SenderToSMTP(from, to, string.Empty, string.Empty, subject, string.Empty, false, smtpServer, smtpPort, false, requiresAuthentication, user, password); //Real sender FilterComparable fltPerson = new FilterComparableGreaterOrEqual(typeof(Int32), 1, "PersonID"); ISend sndSMTPFiltered = new SenderWithFilterComparable(fltPerson, sndSMTP); var job = new SimpleJob(); job.Receivers.Add(0, rcvr); job.Senders.Add(0, sndAll); job.Senders.Add(1, sndSMTPFiltered); /* * var job = new SimpleJob(); * job.Receivers.Add(0, rcvr); * job.Senders.Add(0, sndSMTP); * * var j = job.SerializeMe(); * File.WriteAllText("j.json", j); * Process.Start("Notepad.exe", "j.json"); */ #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 async Task TestOneReceiverAndOneSender() { #region ARRANGE var dir = AppContext.BaseDirectory; string filename = Path.Combine(dir, "a.csv"); if (File.Exists(filename)) { File.Delete(filename); } ISend csvExport = new Sender_CSV(filename); //ADD A DATABASE AND PUT nrPostsToAdd data into table ISerializeData sd = new SerializeDataInMemory(); var connection = new SqliteConnection(); connection.ConnectionString = "DataSource=:memory:"; connection.Open(); var options = new DbContextOptionsBuilder <ApiContext>() .UseSqlite(connection) .Options; using (var context = new ApiContext(options)) { context.Database.EnsureCreated(); } int nrPostsToAdd = 10; using (var contextAdd = new ApiContext(options)) { for (int i = 0; i < nrPostsToAdd; i++) { contextAdd.Posts.Add(new Post() { Id = i + 1, UserId = i * 2, Content = "Post" + i }); } await contextAdd.SaveChangesAsync(); } using (var dt = new DBTableDataSqliteMemory <int>(connection, sd) { ConnectionString = "DataSource=:memory:", FieldNameToMark = "Id", TableName = "Posts" }) { #endregion #region act IReceive r = new ReceiverTableSQLiteInt(dt); ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, r); job.Senders.Add(0, csvExport); await job.Execute(); #endregion #region assert Assert.IsTrue(File.Exists(filename), $"file {filename} must exists in export csv"); var lines = File.ReadAllLines(filename); Assert.AreEqual(nrPostsToAdd + 1, lines.Length); var lineNames = lines[0].Split(','); Assert.AreEqual("Id", lineNames[0]); Assert.AreEqual("Content", lineNames[1]); Assert.AreEqual("LastModifiedOrCreatedTime", lineNames[2]); Assert.AreEqual("UserId", lineNames[3]); #endregion } }
public async Task TestPBXData() { #region arrange string 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.PBXData', 'U') IS NOT NULL DROP TABLE dbo.PBXData;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = @"CREATE TABLE [PBXData]( [NewDatePBX] [datetime] NOT NULL, [lineNr] [int] NOT NULL, [text] [nvarchar](500) NOT NULL, [FullName] [nvarchar](500) NOT NULL )"; await cmd.ExecuteNonQueryAsync(); } await Task.Delay(2000); var dir = AppContext.BaseDirectory; var dirPBX = Path.Combine(dir, "PBX"); File.AppendAllText(Path.Combine(dirPBX, "PBXRemove.log"), "aaaa"); #endregion #region act var serialize = new SerializeDataOnFile("a.txt"); IReceive r = new ReceiverFolderHierarchical(dirPBX, "*.log"); IFilter filterFiles = new FilterForFilesHierarchical(); #region filter for remove dates serialize var filterDateTime = new FilterComparableGreat(typeof(DateTime), DateTime.MinValue, "LastWriteTimeUtc"); IFilter filterDateTimeSerializable = new FilterComparableFromSerializable(filterDateTime, serialize); #endregion IFilter removeFilesMaxWritten = new FilterRemovePropertyMaxMinDateTime("LastWriteTimeUtc", GroupingFunctions.Max); ITransform transformLines = new TransformerFileToLines() { TrimEmptyLines = true }; var trDateRegex = new TransformRowRegex(@"^Date:\ (?<datePBX>.{23}).*?$", "text"); var trToDate = new TransformerFieldStringToDate("datePBX", "NewDatePBX", "yyyy/MM/dd HH:mm:ss.fff"); var trAddDate = new TransformAddFieldDown("NewDatePBX"); var trSimpleFields = new TransformRowRemainsProperties("NewDatePBX", "lineNr", "text", "FullName", "LastWriteTimeUtc"); var data = new DBTableDataConnection <SqlConnection>(new SerializeDataInMemory()); data.ConnectionString = GetSqlServerConnectionString(); data.Fields = new string[] { "NewDatePBX", "lineNr", "text", "FullName" }; data.TableName = "PBXData"; var bulk = new SenderSqlServerBulkCopy(data); var md = new MediaTransformMaxMin <DateTime>(); md.GroupFunction = GroupingFunctions.Max; md.FieldName = "LastWriteTimeUtc"; var serializeMaxDate = new SenderMediaSerialize <DateTime>(serialize, "LastWriteTimeUtc", md); var si = new SimpleJob(); si.Receivers.Add(0, r); int iFilterNr = 0; si.FiltersAndTransformers.Add(iFilterNr++, filterFiles); si.FiltersAndTransformers.Add(iFilterNr++, filterDateTimeSerializable); si.FiltersAndTransformers.Add(iFilterNr++, removeFilesMaxWritten); si.FiltersAndTransformers.Add(iFilterNr++, transformLines); si.FiltersAndTransformers.Add(iFilterNr++, trDateRegex); si.FiltersAndTransformers.Add(iFilterNr++, trToDate); si.FiltersAndTransformers.Add(iFilterNr++, trAddDate); si.FiltersAndTransformers.Add(iFilterNr++, trSimpleFields); //TODO: add transformer to add a field down for all fields //TODO: add transformer regex for splitting Key=Value //TODO: add field to separate Conn(1)Type(Any)User(InternalTask) CDL Request:RSVI(Get) si.Senders.Add(0, bulk); si.Senders.Add(1, serializeMaxDate); await si.Execute(); #endregion #region assert filterFiles.valuesTransformed.Length.ShouldBe(3, "three files after first filter"); removeFilesMaxWritten.valuesTransformed.Length.ShouldBe(2, "last one file written dismissed"); transformLines.valuesTransformed.Length.ShouldBe(77251); var d = transformLines.valuesTransformed.Select(it => it.Values["FullName"]).Distinct().ToArray(); d.Length.ShouldBe(2, "two files after reading contents"); //transformGroupingFiles.valuesTransformed.Length.ShouldBe(2); //trDateRegex.valuesTransformed.Count(it => it.Values.ContainsKey("datePBX")).ShouldBeGreaterThan(0,"datePBX"); //trToDate.valuesTransformed.Count(it => it.Values.ContainsKey("NewDatePBX")).ShouldBeGreaterThan(0,"NewDatePBX"); foreach (var item in trAddDate.valuesTransformed) { item.Values.ShouldContainKey("NewDatePBX"); } foreach (var item in trSimpleFields.valuesTransformed) { item.Values.Keys.Count.ShouldBe(5); } using (var con = new SqlConnection(connectionString)) { await con.OpenAsync(); using (var cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "select count(*) from PBXData"; var val = await cmd.ExecuteScalarAsync(); val.ShouldBe(77251); } } md.Result.Year.ShouldBe(DateTime.Now.Year); #endregion #region arange to read again r = new ReceiverFolderHierarchical(dirPBX, "*.log"); filterFiles = new FilterForFilesHierarchical(); #region filter for remove dates serialize filterDateTime = new FilterComparableGreat(typeof(DateTime), DateTime.MinValue, "LastWriteTimeUtc"); filterDateTimeSerializable = new FilterComparableFromSerializable(filterDateTime, serialize); #endregion #endregion #region act si = new SimpleJob(); si.Receivers.Add(0, r); iFilterNr = 0; si.FiltersAndTransformers.Add(iFilterNr++, filterFiles); si.FiltersAndTransformers.Add(iFilterNr++, filterDateTimeSerializable); await si.Execute(); #endregion #region assert filterDateTime.valuesTransformed?.Length.ShouldBe(1, "next time 1 file read - the added one"); #endregion } }
static void Main(string[] args) { var testClass = new TestClass { TheEncoding = Encoding.UTF8 }; var json = JsonConvert.SerializeObject(testClass, Formatting.Indented, new JsonEncodingConverter()); var obj = JsonConvert.DeserializeObject <TestClass>(json, new JsonEncodingConverter()); return; //var f = new TransformerIntString("asd", "bas"); //var settings1 = new JsonSerializerSettings() //{ // TypeNameHandling = TypeNameHandling.Objects, // Formatting = Formatting.Indented, // Error = HandleDeserializationError // //ConstructorHandling= ConstructorHandling.AllowNonPublicDefaultConstructor //}; //settings1.Converters.Add(new ExpressionJsonConverter(Assembly.GetEntryAssembly())); //var x = JsonConvert.SerializeObject(f,settings1); //Console.WriteLine(x); //return; brrbrrrr(); return; var receiver = new ReceiverBookmarkFileChrome(@"C:\Users\admin\Documents\bookmarks_7_25_17.html"); //var tr = new TransformAddField<string, DateTime>( // (addDate) => // { // var secs = double.Parse(addDate); // return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(secs); // } // , "ADD_DATE", "realDate"); //var tr = new TransformAddField<string, DateTime>( // (addDate) => // new DateTime(1970, 1, 1, 0, 0, 0, 0) // .AddSeconds(double.Parse(addDate)) // , "ADD_DATE", "realDate"); string transformExpression = "var secs = double.Parse((oldValue??null).ToString());" + "var val=new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(secs);" + "val"; var tr = new TransformOneValueGeneral(transformExpression, "ADD_DATE", "realDate"); var sender = new Sender_HTMLRazor("BKChrome.cshtml", "b.html"); SimpleJob sj = new SimpleJob(); sj.Receivers.Add(0, receiver); sj.FiltersAndTransformers.Add(0, tr); sj.Senders.Add(0, sender); sj.Execute().Wait(); return; //var x = MemoryMappedFile.CreateNew("testmap", 2); //using (var writer = x.CreateViewAccessor(0,200, MemoryMappedFileAccess.Write)) //{ // // Write to MMF // for(int s = 0; s < 20; s++) // { // Console.WriteLine(s); // writer.Write(s, ('a'+s)); // } //} //using (var reader = x.CreateViewAccessor(0, 2000, MemoryMappedFileAccess.Read)) //{ // // Write to MMF // for (int s = 0; s < 20; s++) // { // Console.WriteLine(s); // var d= reader.ReadByte(s); // Console.WriteLine((char)d); // } //} //return; ISerializeData sd = new SerializeDataInMemory(); ISend csvExport = new Sender_CSV("a.csv"); ISend xmlExport = new Sender_XML("a.xml", "values"); ISend jsonExport = new Sender_JSON("a.json"); //ISend influx = new SenderDB_Influx("http://localhost:8086", "mydb", "logical_reads", "cpu_time_ms", "total_elapsed_time_ms"); var data = new DBTableData <int, SqlConnection>(sd) { ConnectionString = "Server=.;Database=DatePtAndrei;Trusted_Connection=True;", FieldNameToMark = "id", TableName = "active_slowquery", //Fields=new string[] { "id", "[session_id]" } }; IReceive r = new ReceiverTableSQLServerInt(data); ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, r); job.Senders.Add(0, csvExport); job.Senders.Add(1, xmlExport); job.Senders.Add(2, jsonExport); //job.Senders.Add(3, influx); var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, Formatting = Formatting.Indented, Error = HandleDeserializationError //ConstructorHandling= ConstructorHandling.AllowNonPublicDefaultConstructor }; //var serialized = JsonConvert.SerializeObject(job, settings); //var deserialized = JsonConvert.DeserializeObject(File.ReadAllText("c.txt"), settings); ////File.WriteAllText("a.txt", serialized); //File.WriteAllText("b.txt",JsonConvert.SerializeObject(deserialized as IJob, settings)); //return; job.Execute().Wait(); return; Process.Start("notepad.exe", "a.json"); //var connection = new SqliteConnection(); //connection.ConnectionString = "DataSource=:memory:"; //connection.Open(); //Console.WriteLine("Hello World!"); //var options = new DbContextOptionsBuilder<ApiContext>() // //.UseInMemoryDatabase(databaseName: "Add_writes_to_database") // .UseSqlite(connection) // //.UseSqlite("DataSource=:memory:") // .Options; //using (var context = new ApiContext(options)) //{ // context.Database.EnsureCreated(); //} //var apiContext = new ApiContext(options); //apiContext.Posts.Add(new Post() //{ // Id = 1, // UserId = 1, // Content = "Post1" //}); //apiContext.SaveChanges(); //var db = apiContext.Database; //var cmd = connection.CreateCommand(); //cmd.CommandText = "select count(*) from Posts"; //var i=cmd.ExecuteScalar(); //var c = ClaimsPrincipal.Current; //if (c == null) //{ //} //var n = Thread.CurrentThread.Name; //Console.WriteLine("ASD"); }
public async Task TestSimpleJobReceiverToSenderDBExecuteSqlServerStoredProcedures() { #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"; //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');"; 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); //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 snd = new SenderToDBStmtSqlServer(connectionString, commandType, commandText2, parameters2); //Job ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, rcvr); job.Senders.Add(0, snd); #endregion #region act job.Execute().Wait(-1); #endregion #region assert 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')) 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); } } #endregion }
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 }
public async Task TestSimpleJobReceiverFromIoTHub2SenderToSQLServer() { #region arrange //Send test message string iotHubUri = "a"; string deviceId = "b"; string deviceKey = "c"; string messageType = "UnitTestSimpleJobReceiverFromIoTHub2SenderToSQLServer" + DateTime.Now.ToString(); var sndToIoTHub = new SenderToAzureIoTHub(iotHubUri, deviceId, deviceKey, messageType); var m = new Mock <IRow>(); var rows = new List <IRow>(); int nrRows = 2; for (int i = 0; i < nrRows; i++) { var row = new Mock <IRow>(); row.SetupProperty ( obj => obj.Values, new Dictionary <string, object>() { ["PersonID"] = i, ["FirstName"] = "John " + i, ["LastName"] = "Doe " + i } ); rows.Add(row.Object); } sndToIoTHub.valuesToBeSent = rows.ToArray(); await sndToIoTHub.Send(); //End of Send test message //Receiver settings string iotHubConnectionStringEventHubCompatible = "a"; string iotHubMessageEntityEventHubCompatible = "b"; string fileNameLastRow = "TestReceiveAzureIoTHubSimple_LastRow.json"; //Receiver string connectionString = GetSqlServerConnectionString(); string commandText2 = "dbo.TestReiceverDBExecuteStoredProcedureNoParam4"; // Sender SP (Destination) string parameters2 = "@p1=PersonID;@p2=FirstName;@p3=LastName"; //Source if (File.Exists(fileNameLastRow)) { File.Delete(fileNameLastRow); } var rcv = new ReceiverFromAzureIoTHub(iotHubConnectionStringEventHubCompatible, iotHubMessageEntityEventHubCompatible, fileNameLastRow, messageType, -4); //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.TestingTestReiceverDBExecuteStoredProcedureNoParam4') IS NOT NULL DROP TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam4; CREATE TABLE dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam4 (PersonID INT NOT NULL /*PRIMARY KEY*/, FirstName VARCHAR(50), LastName VARCHAR(50));"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "IF OBJECT_ID('dbo.TestReiceverDBExecuteStoredProcedureNoParam4') IS NOT NULL DROP PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam4;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = "CREATE PROCEDURE dbo.TestReiceverDBExecuteStoredProcedureNoParam4 (@p1 INT, @p2 VARCHAR(50), @p3 VARCHAR(50)) AS INSERT dbo.TestingTestReiceverDBExecuteStoredProcedureNoParam4 (PersonID, FirstName, LastName) VALUES (@p1, @p2, @p3)"; await cmd.ExecuteNonQueryAsync(); } } var snd = new SenderToDBStmtSqlServer(connectionString, commandType, commandText2, parameters2); //Job ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, rcv); job.Senders.Add(0, snd); //var j = job.SerializeMe(); //File.WriteAllText(@"E:\j2.json", j); #endregion #region act await job.Execute(); #endregion #region assert 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 TestingTestReiceverDBExecuteStoredProcedureNoParam4;"; var cnt = (int)await cmd.ExecuteScalarAsync(); Assert.IsTrue(cnt >= 2); // It requires a sender in arrange region } } #endregion }