/// <summary> /// Retrives a list of items associated with the current node. /// </summary> /// <returns>A List of project items</returns> protected IList <EnvDTE.ProjectItem> GetListOfProjectItems() { return(UIThread.DoOnUIThread(delegate() { List <EnvDTE.ProjectItem> list = new List <EnvDTE.ProjectItem>(); for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling) { EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem; if (null != item) { list.Add(item); } } return list; })); }
public void ShowMessage(string message, bool isSuccess = false) { UIThread.Execute(() => { if (isSuccess) { NotiCenterWindowViewModel.Current.Manager.ShowSuccessMessage(message); } else { NotiCenterWindowViewModel.Current.Manager.CreateMessage() .Error(message) .Dismiss() .WithDelay(TimeSpan.FromSeconds(2)) .Queue(); } }); }
public static void ShowErrorMessage(this INotificationMessageManager manager, string message, int? delaySeconds = null) { UIThread.Execute(() => { var builder = NotificationMessageBuilder.CreateMessage(manager); builder.Error(message ?? string.Empty); if (delaySeconds.HasValue && delaySeconds.Value != 0) { builder .Dismiss() .WithDelay(TimeSpan.FromSeconds(4)) .Queue(); } else { builder .Dismiss().WithButton("忽略", null) .Queue(); } }); }
private bool GetGameDataFromUnity(FileSystemItem item) { string title = null; byte[] thumbnail = null; var result = false; try { var webClient = new WebClient(); var json = webClient.DownloadString(string.Format("http://xboxunity.net/Resources/Lib/TitleList.php?search={0}", item.Name)); if (!string.IsNullOrEmpty(json)) { var unityResponse = json.FromJson <UnityResponse>(); var firstResult = unityResponse.Items.FirstOrDefault(); title = firstResult != null?firstResult.Name.Trim() : null; result = !string.IsNullOrEmpty(title); if (result) { var bytes = webClient.DownloadData(string.Format("http://xboxunity.net/Resources/Lib/Icon.php?tid={0}", item.Name)); if (bytes != null && webClient.ResponseHeaders[HttpResponseHeader.ContentType] == "image/png") { thumbnail = bytes; } } } } catch {} if (result) { item.Title = title; if (thumbnail != null) { item.Thumbnail = thumbnail; item.RecognitionState = RecognitionState.Recognized; } else { UIThread.Run(() => _eventAggregator.GetEvent <NotifyUserMessageEvent>().Publish(new NotifyUserMessageEventArgs("PartialRecognitionMessage", MessageIcon.Warning))); item.RecognitionState = RecognitionState.PartiallyRecognized; } } return(result); }
public void Run(IDictionary args) { _staffingCalculatorPresenter.SaftyInvoke(p => p.Deactivate()); if (_staffingCalculatorPresenter == null) { args["service"] = this; _staffingCalculatorPresenter = _container.Resolve <IStaffingChartPresenter>(args); UIThread.BeginInvoke(() => View.SetModel(_contentView, _staffingCalculatorPresenter)); } else { _staffingCalculatorPresenter.Activate(); } }
protected override void OnInitialize() { BeginLoading(); new Thread(() => { Application.Current.Resources["AbsentEventTypes"] = _shiftDispatcherModel.GetAllAbsenetTypes(); _attendances = _shiftDispatcherModel.GetAgents(_schedule); _refreshLaborHourOnly = true; UIThread.Invoke(() => { Agents = _attendances.Cast <IEnumerable>().ToList(); EndLoading(); }); _refreshLaborHourOnly = false; }).Start(); base.OnInitialize(); }
/// <summary> /// Handle an exception, the connection to the server will be closed and a message will be displayed on the GUI. /// </summary> /// <param name="exception"></param> public void HandleException(Exception exception) { string formattedMessage = exception.Message; if (!Faulted) { _sender.StopApplication(); } UIThread.Execute(() => { if (CriticalError != null) { CriticalError(formattedMessage, EventArgs.Empty); } }); }
/// <summary> /// Handle a critical error, the connection to the server will be closed and a message will be displayed on the GUI. /// </summary> /// <param name="message"></param> /// <param name="args"></param> public void HandleCriticalError(string message, params object[] args) { string formattedMessage = string.Format(message, args); if (!Faulted) { _sender.StopApplication(); } UIThread.Execute(() => { if (CriticalError != null) { CriticalError(formattedMessage, EventArgs.Empty); } }); }
public static void ShowWindow( string downloadFileUrl, string fileTitle, // window, isSuccess, message, saveFileFullName, etagValue Action <ContainerWindow, bool, string, string> downloadComplete) { UIThread.Execute(() => { ContainerWindow.ShowWindow(new ContainerWindowViewModel { IconName = "Icon_Download", CloseVisible = System.Windows.Visibility.Visible, }, ucFactory: (window) => { FileDownloaderViewModel vm = new FileDownloaderViewModel(downloadFileUrl, (isSuccess, message, saveFileFullName) => { downloadComplete(window, isSuccess, message, saveFileFullName); }); return(new FileDownloader(vm)); }, fixedSize: true); }); }
private static void DeleteSolo <T>(DataGrid dg, Func <T, string> nameGetter, Action <T> actionBeforeDelete, string questionFmt, string caption, UIList <T> vm) { var item = (T)dg.SelectedItem; var msg = string.Format(questionFmt, nameGetter(item)); var resp = MessageBox.Show(msg, " " + caption, MessageBoxButton.YesNo, MessageBoxImage.Question); if (resp != MessageBoxResult.Yes) { return; } UIThread.Run(() => { actionBeforeDelete?.Invoke(item); vm.Remove(item); vm.RaiseItemDeleted(item); }); }
public MinerProfileIndex() { #if DEBUG NTStopwatch.Start(); #endif InitializeComponent(); this.OnLoaded((window) => { window.AddEventPath <ServerContextVmsReInitedEvent>("上下文视图模型集刷新后刷新界面上的popup", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { if (Vm.MinerProfile.MineWork != null) { return; } if (this.PopupKernel.Child != null && this.PopupKernel.IsOpen) { OpenKernelPopup(); } if (this.PopupMainCoinPool.Child != null && this.PopupMainCoinPool.IsOpen) { OpenMainCoinPoolPopup(); } if (this.PopupMainCoinPool1.Child != null && this.PopupMainCoinPool1.IsOpen) { OpenMainCoinPool1Popup(); } if (this.PopupMainCoin != null && this.PopupMainCoin.IsOpen) { OpenMainCoinPopup(); } if (this.PopupMainCoinWallet != null && this.PopupMainCoinWallet.IsOpen) { OpenMainCoinWalletPopup(); } }); }, location: this.GetType()); }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public void TestNpmUITabKeyBehavior() { using (var app = new VisualStudioApp()) { UIThread.InitializeAndAlwaysInvokeToCurrentThread(); UIThread.Invoke(() => { NpmPackageInstallWindow npmWindow = OpenNpmWindowAndWaitForReady(); npmWindow.FilterTextBox.Focus(); WaitForUIInputIdle(); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); var selectedItem = GetSelectedPackageListItemContainer(npmWindow); Assert.IsTrue(selectedItem.IsKeyboardFocused); // Install button disabled, must key down to select "installable" package TestUtilities.UI.Keyboard.PressAndRelease(Key.Down); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); Assert.IsTrue(npmWindow.DependencyComboBox.IsKeyboardFocused); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); Assert.IsTrue(npmWindow.SaveToPackageJsonCheckbox.IsKeyboardFocused); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); Assert.IsTrue(npmWindow.SelectedVersionComboBox.IsKeyboardFocused); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); Assert.IsTrue(npmWindow.ArgumentsTextBox.IsKeyboardFocused); TestUtilities.UI.Keyboard.PressAndRelease(Key.Tab); WaitForUIInputIdle(); Assert.IsTrue(npmWindow.InstallButton.IsKeyboardFocused); }); } }
/// <summary> /// 模拟鼠标操作 /// </summary> public static void SimulateMouseBehavior(IList <HookMouseEventArgs> MouseHisDataList) { if (MouseHisDataList.Count == 0) { return; } //----遍历历史记录,重新执行一遍----- var lastHis = MouseHisDataList.First(); var hisDataList = MouseHisDataList.ToList(); foreach (var hookMouseEventArgse in hisDataList) { var timeDiff = hookMouseEventArgse.EventTimeStamp - lastHis.EventTimeStamp; Thread.Sleep(timeDiff);//休眠 MouseSimulator.Position = hookMouseEventArgse.MousePosition; switch (hookMouseEventArgse.MouseEventType) { case MouseEventType.MouseDown: MouseSimulator.MouseDown(hookMouseEventArgse.ClickButton); UIThread.Invoke(() => { ShowMouseIndicator(MouseIndicatorWinView, hookMouseEventArgse.MousePosition, new SolidColorBrush(Color.FromRgb(255, 0, 0))); }); break; case MouseEventType.MouseUp: MouseSimulator.MouseUp(hookMouseEventArgse.ClickButton); UIThread.Invoke(() => { ShowMouseIndicator(MouseIndicatorWinView, hookMouseEventArgse.MousePosition, new SolidColorBrush(Color.FromRgb(26, 58, 246))); }); break; case MouseEventType.MouseWheel: MouseSimulator.MouseWheel(hookMouseEventArgse.MouseWheelDelta); break; case MouseEventType.MouseMove: MouseSimulator.MouseMove(hookMouseEventArgse.MousePosition.X, hookMouseEventArgse.MousePosition.Y, true); HideMouseIndicator(MouseIndicatorWinView); break; } lastHis = hookMouseEventArgse; } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (this.NavigationContext.QueryString.TryGetValue("blog_id", out blog_id) && this.NavigationContext.QueryString.TryGetValue("comment_id", out comment_id)) { List <Blog> blogs = DataService.Current.Blogs.ToList(); foreach (Blog currentBlog in blogs) { if (currentBlog.isWPcom() || currentBlog.hasJetpack()) { string currentBlogID = currentBlog.isWPcom() ? Convert.ToString(currentBlog.BlogId) : currentBlog.getJetpackClientID(); if (currentBlogID == blog_id) { BlogName.Text = currentBlog.BlogName; _currentBlog = currentBlog; } } } } if (_currentBlog == null) { if (NavigationService.CanGoBack) { NavigationService.GoBack(); } return; } GetAllCommentsRPC rpc = new GetAllCommentsRPC(_currentBlog); rpc.Number = 20; rpc.Offset = 0; rpc.Completed += OnFetchCurrentBlogCommentsCompleted; rpc.ExecuteAsync(); UIThread.Invoke(() => { ApplicationBar.IsVisible = false; App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.Loading); }); }
protected void UpdateFields(NotifyCollectionChangedEventArgs e) { UIThread.Dispatch(() => { if (e == null) { m_Groups.Clear(); m_Groups.AddAll(Data.GetGroups().Select(PodcastGroupViewModelConstructor)); } else if (e.Action == NotifyCollectionChangedAction.Add) { foreach (PodcastGroup group in e.NewItems) { m_Groups.Add(new PodcastGroupViewModel(group, ServiceContext)); } } }); }
public void FillTabs() { var mkt = Main.AppArgs.MarketState; var list = new List <SectionTabVM>(); var all = mkt.Sections.GetAll(); var activs = mkt.ActiveLeasesFor(Main.Date); foreach (var sec in all) { if (activs.Any(_ => _.Stall.Section.Id == sec.Id)) { list.Add(new SectionTabVM(list.Count, sec, Main)); } } UIThread.Run(() => this.SetItems(list)); Main.AppArgs.CurrentSection = this.FirstOrDefault()?.Section; }
private bool SetStatus(string responseString) { if (responseString == null) { return(false); } var r = new Regex("<b>Status :</b>(.*?)</td>"); var m = r.Match(responseString); _fsdStatus = null; if (m.Success) { var r2 = new Regex("( \\| )?FTP : Connected( \\| )?"); _fsdStatus = r2.Replace(m.Groups[1].Value.Trim(), string.Empty); } UIThread.Run(() => NotifyPropertyChanged(SIZEINFO)); return(!string.IsNullOrWhiteSpace(_fsdStatus)); }
/// <summary> /// Expands the view of Solution Explorer to show project items. /// </summary> public virtual void ExpandView() { CheckProjectIsValid(); UIThread.DoOnUIThread(delegate() { using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site)) { IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer); if (uiHierarchy == null) { throw new InvalidOperationException(); } ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder)); } }); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(); UIThread.CaptureSynchronizationContext(); await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); // Subscribe to the solution events this.solutionListeners.Add(new SolutionListenerForProjectReferenceUpdate(this)); this.solutionListeners.Add(new SolutionListenerForProjectOpen(this)); this.solutionListeners.Add(new SolutionListenerForBuildDependencyUpdate(this)); this.solutionListeners.Add(new SolutionListenerForProjectEvents(this)); foreach (SolutionListener solutionListener in this.solutionListeners) { solutionListener.Init(); } }
private void OnStfsContentParsed(object sender, ContentParsedEventArgs e) { //TODO: determine whether update is necessary or not _titleUpdated++; var game = (GameFile)e.Content; _titleRecognizer.UpdateTitle(new FileSystemItem { Name = game.TitleId, Title = game.Title, Type = ItemType.Directory, TitleType = TitleType.Game, Thumbnail = game.Thumbnail, RecognitionState = RecognitionState.Recognized }); _itemsChecked++; UIThread.Run(() => ProgressValue = _itemsCount == 0 ? 0 : _itemsChecked * 100 / _itemsCount); }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } this.Vm = new MainWindowViewModel(); this.DataContext = this.Vm; InitializeComponent(); NotiCenterWindow.Bind(this); this.AddEventPath <LocalIpSetInitedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole, action: message => { Vm.RefreshLocalIps(); }, location: this.GetType()); this.AddCmdPath <ShowLocalIpsCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => LocalIpConfig.ShowWindow()); }, location: this.GetType()); }
public static void StartAsync(Action <SpeedTestResult> actionWhenCompleted) { // ChildWindow msgBox = PopupHelper.PopupMessage(DialogTitles.Initializing, SR.CheckingConnectionSpeed); ConnectionTester test = new ConnectionTester(); test.SpeedTestCompleted += (s, ev) => { UIThread.Execute(() => { // msgBox.Close(); var result = ev.Result; actionWhenCompleted(result); }); }; test.RunSpeedTest(); }
public MinerProfileIndex() { InitializeComponent(); this.PopupKernel.Closed += Popup_Closed; this.PopupMainCoinPool.Closed += Popup_Closed; this.PopupMainCoin.Closed += Popup_Closed; this.PopupMainCoinWallet.Closed += Popup_Closed; this.RunOneceOnLoaded(() => { Window.GetWindow(this).On <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面上的popup", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (Vm.MinerProfile.MineWork != null) { return; } if (this.PopupKernel.Child != null) { this.PopupKernel.IsOpen = false; OpenKernelPopup(); } if (this.PopupMainCoinPool.Child != null) { this.PopupMainCoinPool.IsOpen = false; OpenMainCoinPoolPopup(); } if (this.PopupMainCoinPool1.Child != null) { this.PopupMainCoinPool1.IsOpen = false; OpenMainCoinPool1Popup(); } if (this.PopupMainCoin != null) { this.PopupMainCoin.IsOpen = false; OpenMainCoinPopup(); } if (this.PopupMainCoinWallet != null) { this.PopupMainCoinWallet.IsOpen = false; OpenMainCoinWalletPopup(); } }); }); }); }
public static void ShowWindow() { UIThread.Execute(() => { if (_instance == null) { lock (_locker) { if (_instance == null) { _instance = new KernelsWindow(); _instance.Show(); } } } else { _instance.ShowWindow(false); } }); }
private static void TriggerTypePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { FrameworkElement target = sender as FrameworkElement; UIThread.BeginInvoke(() => { var validators = ValidationService.GetValidators(target); if (validators.Count == 0) { return; } var triggerType = (TriggerType)args.NewValue; validators[0].CancelTriggerValidationEvent(); if (triggerType == TriggerType.Trigger) { validators[0].RegisterTriggerValidationEvent(); } }); }
public NTMinerFileViewModel() { _id = Guid.NewGuid(); _publishOn = DateTime.Now; this.Save = new DelegateCommand(() => { if (Login()) { OfficialServer.FileUrlService.AddOrUpdateNTMinerFileAsync(new NTMinerFileData().Update(this), (response, e) => { if (response.IsSuccess()) { MainWindowViewModel.Instance.Refresh(); UIThread.Execute(() => { TopWindow.GetTopWindow()?.Close(); }); } else { Logger.ErrorDebugLine($"AddOrUpdateNTMinerFileAsync失败"); } }); } }); this.Edit = new DelegateCommand(() => { NTMinerFileEdit window = new NTMinerFileEdit("Icon_Edit", new NTMinerFileViewModel(this)); window.ShowDialogEx(); }); this.Remove = new DelegateCommand(() => { if (Login()) { this.ShowDialog(message: $"确定删除{this.Version}({this.VersionTag})吗?", title: "确认", onYes: () => { OfficialServer.FileUrlService.RemoveNTMinerFileAsync(this.Id, (response, e) => { MainWindowViewModel.Instance.SelectedNTMinerFile = MainWindowViewModel.Instance.NTMinerFiles.FirstOrDefault(); if (this == MainWindowViewModel.Instance.ServerLatestVm) { MainWindowViewModel.Instance.ServerLatestVm = MainWindowViewModel.Instance.NTMinerFiles .FirstOrDefault(a => a != this && a.VersionData > MainWindowViewModel.Instance.LocalNTMinerVersion); } MainWindowViewModel.Instance.Refresh(); }); }, icon: IconConst.IconConfirm); } }); }
/// <summary> /// Retrives a list of items associated with the current node. /// </summary> /// <returns>A List of project items</returns> public IList <EnvDTE.ProjectItem> GetListOfProjectItems() { return(UIThread.DoOnUIThread(delegate() { List <EnvDTE.ProjectItem> list = new List <EnvDTE.ProjectItem>(); for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling) { if (!(child is ReferenceContainerNode)) // skip 'references' node when navigating over project items, to behave more like C#/VB { EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem; if (null != item) { list.Add(item); } } } return list; })); }
private void OnGetUsersBlogsCompleted(object sender, XMLRPCCompletedEventArgs <Blog> args) { GetUsersBlogsRPC rpc = sender as GetUsersBlogsRPC; rpc.Completed -= OnGetUsersBlogsCompleted; ApplicationBar.IsVisible = true; App.WaitIndicationService.KillSpinner(); if (args.Cancelled) { } else if (null == args.Error) { if (1 == args.Items.Count) { if (!(DataService.Current.Blogs.Any(b => b.Xmlrpc == args.Items[0].Xmlrpc))) { DataService.Current.AddBlogToStore(args.Items[0]); PushNotificationsHelper.Instance.sendBlogsList(); } NavigationService.Navigate(new Uri("/BlogsPage.xaml", UriKind.Relative)); } else { ShowBlogSelectionControl(args.Items); } } else { Exception currentException = args.Error; if (currentException is XmlRPCException && (currentException as XmlRPCException).FaultCode == 403) //username or password error { UIThread.Invoke(() => { MessageBox.Show(_localizedStrings.Prompts.UsernameOrPasswordError); }); } else { this.HandleException(args.Error); } } }
private ConsoleWindow() { this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; InitializeComponent(); this.Loaded += (sender, e) => { _thisWindowHandle = new WindowInteropHelper(this).Handle; IntPtr console = NTMinerConsole.GetOrAlloc(); SafeNativeMethods.SetWindowLong(console, SafeNativeMethods.GWL_STYLE, SafeNativeMethods.WS_VISIBLE); SafeNativeMethods.SetParent(console, _thisWindowHandle); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; 2.SecondsDelay().ContinueWith(t => { UIThread.Execute(() => { this.TbDescription.Visibility = Visibility.Visible; }); }); }
public void FillLeasesList() { var mkt = MainWindow.AppArgs.MarketState; var actives = mkt.ActiveLeases.GetAll() .OrderByDescending(_ => _.Id); var inactvs = mkt.InactiveLeases.GetAll() .OrderByDescending(_ => _.Id); var list = actives.Concat(inactvs) .Select(_ => new LeaseRowVM(_, MainWindow)); //var both = actives.Concat(inactvs).ToList(); //var list = new List<LeaseRowVM>(); // //for (int i = 0; i < both.Count; i++) // list.Add(new LeaseRowVM(i, both[i], MainWindow)); UIThread.Run(() => SetItems(list)); }