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
        }
示例#2
0
        static string ExecuteVisualizationDefinitionSimpleJob(string contents)
        {
            var si = new SimpleJob();

            si.UnSerialize(SimpleJobView(contents, "jobDefinition.html"));
            si.Execute().GetAwaiter().GetResult();
            return("jobDefinition.html");
        }
示例#3
0
 bool TryGetSimpleJob(string text)
 {
     try
     {
         var sj = new SimpleJob();
         sj.UnSerialize(text);
         Job = sj;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#4
0
        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
        }
示例#5
0
        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());
            }
        }
示例#6
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();
                }
            }
        }
示例#7
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
        }
示例#8
0
        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);
            }
        }