UcSectionControllerState.xaml.cs 3.34 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
using FLY.Thick.Base.IService;
using FLY.Thick.Base.UI.OnInit;
using Misc;
using MultiLayout;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Unity;

namespace FLY.Thick.Base.UI.CustomSection
{
    /// <summary>
    /// UcControllerState.xaml 的交互逻辑
    /// </summary>
    public partial class UcSectionControllerState : UserControl
    {
        ParamDictionary paramDictionary;
        IUnityContainer container;
        FlyLayoutManager manager;

        public UcSectionControllerState()
        {
            InitializeComponent();
        }

        [Unity.InjectionMethod]
        public void Init(
            IUnityContainer container,
            ParamDictionary paramDictionary,
            FlyLayoutManager manager)
        {
            this.container = container;
            this.paramDictionary = paramDictionary;
            this.manager = manager;

            InitializeTabControl();
        }

        void InitializeTabControl() 
        {
潘栩锋's avatar
潘栩锋 committed
53
            //找出全部 xxx.service 服务容器 且包含 ITDGageService服务
潘栩锋's avatar
潘栩锋 committed
54 55 56 57 58 59
            var rontainerNames =
                from regist in container.Registrations
                where
                (regist.RegisteredType == typeof(IUnityContainer))
                && (!string.IsNullOrEmpty(regist.Name))
                && Regex.IsMatch(regist.Name, @"\w+\.service")
潘栩锋's avatar
潘栩锋 committed
60
                && container.Resolve<IUnityContainer>(regist.Name).IsRegistered<ITDGageService>()
潘栩锋's avatar
潘栩锋 committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
                select regist.Name;

            if (rontainerNames.Count() == 0) 
            {
                return;//一个服务容器都没有
            }

            tabControl.Visibility = Visibility.Visible;

            foreach (var rontainerName in rontainerNames)
            {
                var serviceContainer = container.Resolve<IUnityContainer>(rontainerName);

                //找出设备页面
                var gageTabItems = from _gageTabItem in manager.layout.GageTabItems where _gageTabItem.ServiceContainerName == rontainerName select _gageTabItem;
                if (gageTabItems.Count() == 0)
                    continue;
                
                var gageTabItem = gageTabItems.First();

                //找到状态切换条件
                var controllerStateTabItems = paramDictionary.GetValue<List<ControllerStateTabItem>>($"{rontainerName}.stateChanged");
                if (controllerStateTabItems == null)
                {
                    controllerStateTabItems = new List<ControllerStateTabItem>();
                    paramDictionary.SetValue($"{rontainerName}.stateChanged", controllerStateTabItems);
                }
                var tabItem = new TabItem();
                tabItem.Header = gageTabItem.Title;

                var singleTab = new UcSingleStateTab();
                singleTab.Init(controllerStateTabItems, gageTabItem);

                singleTab.Margin = new Thickness(5);
                tabItem.Content = singleTab;

                tabControl.Items.Add(tabItem);
            }
        }
    }
}