Пример #1
0
        public MainWindow()
        {
            var myoption = new MyUserSettings();

            InitializeComponent();
            Mainwin.Title           = "TimeGather is collecting data...";
            Servermodelsdatacontext = new ServerModels();
            Servermodelsdatacontext.ServerModelList = new ObservableCollection <ServerModel>();
            Enableprefixfilter.Value = myoption.Isprefixfilterenabled;

            //StringCollection prefixes = myoption.Filters;
            //if (prefixes == null || prefixes.Count == 0)
            //{
            //    prefixes = new StringCollection() { "prefix1", "prefix2" };
            //    Properties.Settings.Default["prefixes"] = prefixes;
            //    Properties.Settings.Default.Save();
            //}

            //Loading = new ServerModel() { Name = "Loading..." };
            ServerModelsDG.DataContext = Servermodelsdatacontext.ServerModelList;
            //_servermodelsdatacontext.ServerModelList.Add(Loading);
            var computers = GetComputer.GetComputers();

            TimeQueryActionBlock = new ActionBlock <ServerModel>(sm =>
            {
                ServerModel temp = ServerModel.Updatethesecondsoffset(sm);
                var tq           = new TimeQuery();
                temp.Source      = tq.GetTimeSource(temp.Name);
                Application.Current.Dispatcher.BeginInvoke(new Action(() => this.Servermodelsdatacontext.ServerModelList.Add(temp)));
            }, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = 128
            }
                                                                 );

            if (Enableprefixfilter.Value)
            {
                var f = JsonConvert.DeserializeObject <string[]>(myoption.Filters);
                computers = (from pc in computers
                             where FilterByPrefix(pc, f) == true
                             select pc).ToList();
            }
            foreach (var s in computers)
            {
                TimeQueryActionBlock.Post(s);
            }
            TimeQueryActionBlock.Complete();

            //servermodelsdatacontext.ServerModelList = (from comp in computers.AsParallel()
            //                 select (ServerModel)Updatethesecondsoffset(comp)).ToList();
            //ServerModelsDG.DataContext = servermodelsdatacontext.ServerModelList;
        }