コード例 #1
0
        private async Task ClearAllTasksAsync()
        {
            try
            {
                if (_taskSourceList.Count == 0)
                {
                    return;
                }

                using var dialog = new DisposableContentDialog
                      {
                          Title             = @"确定清空所有任务?",
                          Content           = @"将会停止所有任务并清空列表",
                          PrimaryButtonText = @"确定",
                          CloseButtonText   = @"取消",
                          DefaultButton     = ContentDialogButton.Close
                      };
                if (await dialog.ShowAsync() == ContentDialogResult.Primary)
                {
                    _taskSourceList.Items.ToList().ForEach(RemoveTask);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, @"停止任务出错");
            }
        }
コード例 #2
0
 public static async Task HandleExceptionWithContentDialogAsync(this Exception ex)
 {
     using var dialog = new DisposableContentDialog
           {
               Title             = nameof(NatTypeTester),
               Content           = ex.Message,
               PrimaryButtonText = @"OK"
           };
     await dialog.ShowAsync();
 }
コード例 #3
0
        private async Task AddRoomAsync(CancellationToken token)
        {
            try
            {
                var room = new RoomStatus();
                using (var dialog = new RoomDialog(RoomDialogType.Add, room))
                {
                    if (await dialog.ShowAsync() != ContentDialogResult.Primary)
                    {
                        return;
                    }
                }

                await room.GetRoomInfoDataAsync(true, token);

                if (_roomList.Items.Any(x => x.RoomId == room.RoomId))
                {
                    using var dialog = new DisposableContentDialog
                          {
                              Title             = @"房间已存在",
                              Content           = @"不能添加重复房间",
                              PrimaryButtonText = @"确定",
                              DefaultButton     = ContentDialogButton.Primary
                          };
                    await dialog.ShowAsync();

                    return;
                }

                AddRoom(room);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, @"添加房间出错");
                var message = ex is JsonException ? @"可能是房间号错误" : ex.Message;
                using var dialog = new DisposableContentDialog
                      {
                          Title             = @"添加房间出错",
                          Content           = message,
                          PrimaryButtonText = @"确定",
                          DefaultButton     = ContentDialogButton.Primary
                      };
                await dialog.ShowAsync();
            }
        }