コード例 #1
0
ファイル: Program.cs プロジェクト: zzzz123321/Hawk
        private static void Run(Options options)
        {
            Console.WriteLine();
            Console.WriteLine("project file: {0} ...", options.ProjectFile);
            var container = new CommandLineContainer();

            var processManager = container.PluginDictionary["模块管理"] as DataProcessManager;
            var project        = ProjectItem.LoadProject(options.ProjectFile);

            XmlConfigurator.Configure(new FileInfo("log4net_cmd.config"));
            processManager.CurrentProject = project;
            var task = project.Tasks.FirstOrDefault(d => d.Name == options.TaskName);

            if (task == null)
            {
                Console.WriteLine("task not in project, project task lists:");
                foreach (var _task in project.Tasks)
                {
                    Console.WriteLine(_task.Name);
                }
                Console.ReadKey();
            }
            task.Load(false);
            Console.WriteLine("projec load successful");
            var realTask =
                processManager.CurrentProcessCollections.FirstOrDefault(d => d.Name == options.TaskName) as SmartETLTool;
            var queuelists = processManager.CurrentProcessTasks as ObservableCollection <TaskBase>;

            queuelists.CollectionChanged += (s, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (var item in e.NewItems.OfType <TaskBase>())
                    {
                        Console.WriteLine("task add: {0}", item.Name);
                        item.PropertyChanged += (s2, e2) =>
                        {
                            if (e2.PropertyName == "Percent")
                            {
                                Console.WriteLine($"task {item.Name}, percent {item.Percent}");
                            }
                        };
                    }
                }
                else
                {
                    foreach (var item in e.OldItems.OfType <TaskBase>())
                    {
                        Console.WriteLine("task finished: {0}", item.Name);
                    }
                }
                if (queuelists.Count == 0)
                {
                    Console.WriteLine("task all finished: quit");
                    Environment.Exit(0); //0代表正常退出,非0代表某种错误的退出
                }
            };
            realTask.ExecuteDatas();
            while (true)
            {
                var key = Console.ReadLine();
                if (key == "exit")
                {
                    Environment.Exit(0);
                }
            }
        }
コード例 #2
0
        private static void Run(Options options)
        {
            Console.WriteLine();
            XmlConfigurator.Configure(new FileInfo("log4net_cmd.config"));

            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += (s, e) => { Console.WriteLine("f**k"); };
            timer.Start();

            try
            {
                XLogSys.Print.Info($"Project file: {options.ProjectFile} ...");
                var container = new CommandLineContainer();

                var processManager = container.PluginDictionary["DataProcessManager"] as DataProcessManager;
                if (processManager == null)
                {
                    throw new Exception("Plugin System ERROR, DataProcessManager not Found, Reinstall Hawk");
                }

                var dataManager = container.PluginDictionary["DataManager"] as DataManager;

                if (dataManager == null)
                {
                    throw new Exception("Plugin System ERROR, dataManager not Found, Reinstall Hawk");
                }

                AppHelper.LoadLanguage();

                var project = Project.Load(options.ProjectFile);
                if (project == null)
                {
                    throw new Exception($"Project {options.ProjectFile} is not exists or format error");
                }

                project.DataCollections?.Execute(d => dataManager.AddDataCollection(d));
                processManager.CurrentProject = project;
                var task = project.Tasks.FirstOrDefault(d => d.Name == options.TaskName);

                if (task == null)
                {
                    foreach (var _task in project.Tasks)
                    {
                        Console.WriteLine(_task.Name);
                    }
                    throw  new Exception($"task {options.TaskName} not in project");
                }
                task.Load(false);
                XLogSys.Print.Info("project load successful");
                var realTask =
                    processManager.CurrentProcessCollections.FirstOrDefault(d => d.Name == options.TaskName) as
                    SmartETLTool;
                var queueList = processManager.CurrentProcessTasks as ObservableCollection <TaskBase>;
                queueList.CollectionChanged += (s, e) =>
                {
                    if (e.Action == NotifyCollectionChangedAction.Add)
                    {
                        foreach (var item in e.NewItems.OfType <TaskBase>())
                        {
                            XLogSys.Print.Info($"task add: {item.Name}");
                            item.PropertyChanged += (s2, e2) =>
                            {
                                if (e2.PropertyName == "Percent")
                                {
                                    XLogSys.Print.Info($"task {item.Name}, percent {item.Percent}");
                                }
                            };
                        }
                    }
                    else
                    {
                        foreach (var item in e.OldItems.OfType <TaskBase>())
                        {
                            XLogSys.Print.Info($"task finished: {item.Name}");
                        }
                    }
                    if (queueList.Count == 0)
                    {
                        Console.WriteLine("task all finished: quit");
                        // Environment.Exit(0); //0代表正常退出,非0代表某种错误的退出
                    }
                };


                realTask.ExecuteDatas();
            }
            catch (Exception e)
            {
                XLogSys.Print.Error(e.Message, e);
                Console.ReadKey();
                Environment.Exit(1);
            }
            while (true)
            {
                var key = Console.ReadLine();
                if (key == "exit")
                {
                    Environment.Exit(0);
                }
            }
        }