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
        }
Beispiel #2
0
        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
        }
Beispiel #3
0
        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
        }
Beispiel #4
0
        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
        }