예제 #1
0
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = new WindowsHost( );
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml("Examples.AsyncUiUpdate.main.xml", null);

            windowsHost.Show(mainWindow);
            TextBlock textBlock = mainWindow.FindChildByName <TextBlock>("text");
            Thread    thread    = new Thread(() => {
                int i = 1;
                for ( ;;)
                {
                    ConsoleApplication.Instance.Post(new Action(() => {
                        textBlock.Text = i.ToString();
                    }));
                    Thread.Sleep(1000);
                    i++;
                }
            });

            thread.IsBackground = true;
            thread.Start();

            mainWindow.FindChildByName <Button>("btnMaximize").OnClick += (sender, eventArgs) => {
                ConsoleApplication.Instance.Maximize();
            };
            mainWindow.FindChildByName <Button>("btnRestore").OnClick += (sender, eventArgs) => {
                ConsoleApplication.Instance.Restore();
            };

            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = ( WindowsHost )ConsoleApplication.LoadFromXaml("Examples.MainMenu.windows-host.xml", null);
            DataContext dataContext = new DataContext(  );
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml(
                "Examples.MainMenu.main.xml", dataContext);

            windowsHost.Show(mainWindow);

            // Example of direct subscribing to Click event
            List <Control> menuItems = VisualTreeHelper.FindAllChilds(windowsHost.MainMenu, control => control is MenuItem);

            foreach (Control menuItem in menuItems)
            {
                MenuItem item = (( MenuItem )menuItem);
                if (item.Title == "Go")
                {
                    item.Click += (sender, eventArgs) => {
                        MessageBox.Show("", "", result => {
                            //
                        });
                    };
                }
            }
            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = new WindowsHost( );
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml("Examples.TabControl.main.xml", null);

            windowsHost.Show(mainWindow);
            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            DataContext dataContext = new DataContext();
            WindowsHost windowsHost = (WindowsHost)ConsoleApplication.LoadFromXaml(
                "Examples.Commands.windows-host.xml", dataContext);
            Window mainWindow = (Window)ConsoleApplication.LoadFromXaml(
                "Examples.Commands.main.xml", dataContext);

            windowsHost.Show(mainWindow);
            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #5
0
        static void Main(string[] args)
        {
            WindowsHost host        = new WindowsHost();
            Window      Loginwindow = (Window)ConsoleApplication.LoadFromXaml("HackIt.Console.Windows.LoginWindow.xml", null);

            var cb = Loginwindow.FindChildByName <ComboBox>("cb");

            host.ShowModal(Loginwindow);

            ConsoleApplication.Instance.Run(host);
        }
예제 #6
0
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = new WindowsHost( );
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml("Examples.CheckBoxes.main.xml", null);

            windowsHost.Show(mainWindow);
            CheckBox checkBox = mainWindow.FindChildByName <CheckBox>("checkbox");

            checkBox.OnClick += (sender, eventArgs) => {
                eventArgs.Handled = true;
            };
            ConsoleApplication.Instance.Run(windowsHost);
        }
        public static void Main(string[] args)
        {
            Context     context     = new Context();
            WindowsHost windowsHost = (WindowsHost)ConsoleApplication.LoadFromXaml(
                "Examples.TreeView.windows-host.xml", null);
            Window mainWindow = (Window)ConsoleApplication.LoadFromXaml(
                "Examples.TreeView.main.xml", context);

            windowsHost.Show(mainWindow);
            ConsoleFramework.Controls.TreeView tree = mainWindow.FindChildByName <ConsoleFramework.Controls.TreeView>("tree");
            // todo : придумать способ для того, чтобы обходиться без такого костыля
            context.Items = tree.Items;
            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #8
0
        public static void Main( string[ ] args ) {
            WindowsHost windowsHost = new WindowsHost( );
            Window mainWindow = ( Window ) ConsoleApplication.LoadFromXaml( "Examples.RadioButtons.main.xml", null );
            windowsHost.Show( mainWindow );

            var button = mainWindow.FindChildByName<Button>("btn");
            button.OnClick += (sender, eventArgs) =>
            {
                var radioGroup = mainWindow.FindChildByName<RadioGroup>("radio");
                if (radioGroup.SelectedItem == null)
                    MessageBox.Show("", "Not selected yet", result => { });
                else
                    MessageBox.Show("", radioGroup.SelectedItem.Caption, result => { });
            };

            ConsoleApplication.Instance.Run( windowsHost );
        }
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = ( WindowsHost )ConsoleApplication.LoadFromXaml("Examples.MainMenu.windows-host.xml", null);
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml("Examples.MainMenu.main.xml", null);

            windowsHost.Show(mainWindow);
            CheckBox checkBox = mainWindow.FindChildByName <CheckBox>("checkbox");

            checkBox.OnClick += (sender, eventArgs) => {
                eventArgs.Handled = true;
            };
            List <Control> menuItems = VisualTreeHelper.FindAllChilds(windowsHost.MainMenu, control => control is MenuItem);

            foreach (Control menuItem in menuItems)
            {
                (( MenuItem )menuItem).Click += (sender, eventArgs) => {
                    MessageBox.Show("", "", result => {
                        //
                    });
                };
            }
            ConsoleApplication.Instance.Run(windowsHost);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Logger.Disabled = false;

            ThreadPool.SetMaxThreads(3, 3);

            var cfg = ConverterConfigFactory.Get();

            ConverterConfigFactory.Save(cfg);

            dbconrtoller = new ArcController(cfg.ArcFileName)
            {
                AllowMessageLogging = cfg.AllowMessageLogging,
                SavePeriod          = cfg.SavePeriod,
                MaxDataLimit        = cfg.MaxLimit,
                Hyst = cfg.Hyst
            };
            //dbconrtoller.Start();

            var cts  = new CancellationTokenSource();
            var wCts = new CancellationTokenSource();

            var connnectionWfqydb = StreamSourceFactory.GetStreamSourceConfig(cfg.WFQYDBConnection).Get();

            var wFQYDBServer = new WFQYDBServer(
                connnectionWfqydb,
                new byte[] { 1, 0, 0, 0 },
                wCts.Token)
            {
                UpdatePeriod = new TimeSpan(0, 0, cfg.PeriodSec),
                CanA0        = cfg?.AllowedCommands.Contains <byte>(0xA0) ?? false,
                CanA1        = cfg?.AllowedCommands.Contains <byte>(0xA1) ?? false,
                CanA2        = cfg?.AllowedCommands.Contains <byte>(0xA2) ?? false,
                CanA3        = cfg?.AllowedCommands.Contains <byte>(0xA3) ?? false,
            };

            wFQYDBServer.PropertyChanged += WFQYDBServer_PropertyChanged;

            var modbusSvr = new ModbusSvr(
                cfg.ModbusSlaveTcpPort,
                cfg.ModbusSlaveRtuOverTcpPort,
                wFQYDBServer)
            {
                ArcController = dbconrtoller,
                //UpdatePeriod = new TimeSpan(cfg.PeriodSec * 10_000_000)
            };

            modbusSvr.Start();

            System.Threading.ThreadPool.GetMaxThreads(out int workerTh, out int completionTh);
            Logger.Info($"workerTh: {workerTh} completionTh: {completionTh}");

            if (args.Contains("TUI"))
            {
                Logger.Disabled = true;
                MainViewModel mvm = new MainViewModel();
                //mvm.ConnnectionWfqydb = connnectionWfqydb;
                mvm.WFQYDBServer = wFQYDBServer;
                mvm.ModbusSvr    = modbusSvr;
                Window window = (Window)ConsoleApplication
                                .LoadFromXaml("WfqydbModbusGateway.View.MainWin.xml", mvm);
                WindowsHost windowsHost = new WindowsHost {
                    Name = "temp"
                };
                windowsHost.Show(window);
                ConsoleApplication.Instance.Run(windowsHost);
            }
            else
            {
                int i = 0;

                while (!cts.Token.IsCancellationRequested)
                {
                    Thread.Sleep(200);
                    //if (wFQYDBServer.NeedToRestart)
                    //{
                    //    // restart services
                    //    Logger.Warn("Restarting services");
                    //    wCts.Cancel();
                    //    wCts = new CancellationTokenSource();
                    //    wFQYDBServer.PropertyChanged -= WFQYDBServer_PropertyChanged;
                    //    wFQYDBServer = new WFQYDBServer(connnectionWfqydb, new byte[] { 1, 0, 0, 0 }, cts.Token);
                    //    modbusSvr.WfqydbServer = wFQYDBServer;
                    //    GC.Collect();
                    //    wFQYDBServer.PropertyChanged += WFQYDBServer_PropertyChanged;
                    //}
                }
                wCts.Cancel();
                //Task.Delay(1000, cts.Token).Wait();
            }
            cts.Dispose();
            wCts.Dispose();
            dbconrtoller.Stop();
        }//Main
예제 #11
0
파일: Program.cs 프로젝트: windygu/WFQYDB
        public static void Main(string[] args)
        {
            Window window = (Window)ConsoleApplication.LoadFromXaml("TuiExperCF.Views.Win2.xml", context);

            window.KeyUp += WindowsHost_KeyUp;
            WindowsHost wh = new WindowsHost {
                Name = "temp"
            };

            wh.Show(window);
            ConsoleApplication.Instance.Run(wh);
            return;

            using (ConsoleApplication application = ConsoleApplication.Instance)
            {
                Panel panel = new Panel();
                panel.Name = "panel1";
                panel.HorizontalAlignment = HorizontalAlignment.Center;
                panel.VerticalAlignment   = VerticalAlignment.Stretch;
                panel.XChildren.Add(new TextBlock()
                {
                    Name   = "label1",
                    Text   = "Label1",
                    Margin = new Thickness(1, 2, 1, 0)
                             //,Visibility = Visibility.Collapsed
                });
                panel.XChildren.Add(new TextBlock()
                {
                    Name = "label2",
                    Text = "Label2_____",
                    HorizontalAlignment = HorizontalAlignment.Right
                });
                TextBox textBox = new TextBox()
                {
                    MaxWidth            = 10,
                    Margin              = new Thickness(1),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Size = 15,
                    Text = "{Binding Path=MyProperty}",
                };
                Button button = new Button()
                {
                    Name                = "button1",
                    Caption             = "Button!",
                    Margin              = new Thickness(1),
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                button.OnClick += (sender, eventArgs) => {
                    Debug.WriteLine("Click");
                    MessageBox.Show("Окно сообщения", "Внимание ! Тестовое сообщение", delegate(MessageBoxResult result) { });
                    Control label = panel.FindDirectChildByName("label1");
                    if (label.Visibility == Visibility.Visible)
                    {
                        label.Visibility = Visibility.Collapsed;
                    }
                    else if (label.Visibility == Visibility.Collapsed)
                    {
                        label.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        label.Visibility = Visibility.Visible;
                    }
                    label.Invalidate();
                };
                ComboBox comboBox = new ComboBox()
                {
                    //                        Width = 14
                    //HorizontalAlignment = HorizontalAlignment.Stretch
                };
                comboBox.Items.Add("Сделать одно");
                comboBox.Items.Add("Сделать второе");
                comboBox.Items.Add("Ничего не делать");
                ListBox listbox = new ListBox();
                listbox.Items.Add("First item");
                listbox.Items.Add("second item1!!!!!!1fff");
                listbox.HorizontalAlignment = HorizontalAlignment.Stretch;
                //listbox.Width = 10;
                panel.XChildren.Add(comboBox);
                panel.XChildren.Add(button);
                panel.XChildren.Add(textBox);
                panel.XChildren.Add(listbox);

                //application.Run(panel);
                WindowsHost windowsHost = new WindowsHost()
                {
                    Name = "WindowsHost"
                };
                Window window1 = new Window
                {
                    X = 5,
                    Y = 4,
                    //MinHeight = 100,
                    //MaxWidth = 30,
                    //Width = 10,
                    Height  = 20,
                    Name    = "Window1",
                    Title   = "Window1",
                    Content = panel
                };

                GroupBox groupBox = new GroupBox();
                groupBox.Title = "Группа";
                ScrollViewer scrollViewer = new ScrollViewer();
                ListBox      listBox      = new ListBox();
                for (int i = 0; i < 30; i++)
                {
                    listBox.Items.Add(string.Format("Длинный элемент {0}", i));
                }
                //                listBox.Items.Add( "Длинный элемент" );
                //                listBox.Items.Add("Длинный элемент 2");
                //                listBox.Items.Add("Длинный элемент 3");
                //                listBox.Items.Add("Длинный элемент 4");
                //                listBox.Items.Add("Длинный элемент 5");
                //                listBox.Items.Add("Длинный элемент 6");
                //                listBox.Items.Add("Длинный элемент 700");
                listBox.HorizontalAlignment = HorizontalAlignment.Stretch;
                listBox.VerticalAlignment   = VerticalAlignment.Stretch;
                scrollViewer.Content        = listBox;
                //                scrollViewer.HorizontalAlignment = HorizontalAlignment.Stretch;
                scrollViewer.VerticalAlignment       = VerticalAlignment.Stretch;
                scrollViewer.HorizontalScrollEnabled = true;

                groupBox.Content = scrollViewer;

                ComboBox combo = new ComboBox();
                combo.ShownItemsCount = 10;
                for (int i = 0; i < 30; i++)
                {
                    combo.Items.Add(string.Format("Длинный элемент {0}", i));
                }
                //                groupBox.Content = combo;

                groupBox.HorizontalAlignment = HorizontalAlignment.Stretch;


                windowsHost.Show(new Window()
                {
                    X = 30,
                    Y = 6,
                    //MinHeight = 10,
                    //MinWidth = 10,
                    Height      = 14,
                    Name        = "LongTitleWindow",
                    Title       = "Очень длинное название окна",
                    Content     = groupBox,
                    DataContext = context,
                });
                windowsHost.Show(window1);
                //windowsHost.Show(createdFromXaml);
                //textBox.SetFocus(); todo : научиться задавать фокусный элемент до добавления в визуальное дерево
                //application.TerminalSizeChanged += ( sender, eventArgs ) => {
                //    application.CanvasSize = new Size(eventArgs.Width, eventArgs.Height);
                //   application.RootElementRect = new Rect(new Size(eventArgs.Width, eventArgs.Height));
                // };
                //windowsHost.Width = 80;
                //windowsHost.Height = 20;
                application.Run(windowsHost);//, new Size(80, 30), Rect.Empty);

                windowsHost.KeyUp += WindowsHost_KeyUp;
            }
        }