Beispiel #1
0
 bool TryGetSimpleJobConditionalTransformers(string text)
 {
     try
     {
         var sj = new SimpleJobConditionalTransformers();
         sj.UnSerialize(text);
         Job = sj;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
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
        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);
            }
        }