/// <summary>
        /// 打开文件选取器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OpenFileButtonAsync_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.ComputerFolder
            };

            openPicker.FileTypeFilter.Add(".txt");
            openPicker.FileTypeFilter.Add(".mast");

            _file = await openPicker.PickSingleFileAsync();

            if (_file != null)
            {
                ProgressBoard progressBoard = new ProgressBoard();
                ProgressBoard.SlideOn(CurrentRectanglesCanvas, progressBoard);
                ResetRectangle();  // 每次选择文件之后都要重置方块颜色

                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(_file);
                string text = await FileIO.ReadTextAsync(_file);

                try {
                    IEnumerable <string> lines = DatetimeParser.SplitByLine(text);
                    _model = new StatistTotalByDateTimeModel(lines);
                    ExtendStackCanvasByFilterOldRecorders(EarlierThanEarliestRectangle(_model.ToStatistTotalByDateTimeArray().ToList(), _earliestRectangle), _earliestRectangle);
                    ProgressBoard.CancelOn(CurrentRectanglesCanvas, progressBoard);
                    foreach (Canvas canvas in StackCanvas.Children)
                    {
                        ProgressBoard.SlideOn(canvas, new ProgressBoard());
                    }
                    TioSalamanca[] res = _model.GroupDateTimesByTotal();
#if DEBUG
                    for (int level = 0; level < res.Length; level++)
                    {
                        Debug.WriteLine($"level: {level + 1}");
                        Debug.WriteLine($"  List res[{level}]:");
                        foreach (var group in res[level])
                        {
                            Debug.WriteLine($"    Total: {group.Key}");
                            foreach (var item in group)
                            {
                                Debug.WriteLine($"      {item}");
                            }
                        }
                    }
#endif
                    DrawRectangleColor(res, false);
                }
                catch (ArgumentException err) {
                    PopErrorDialogAsync(err.Message);
                }
                _saveMode = SaveMode.OrginalFile; // 表示当前的操作基于磁盘上已有的文件
            }
        }
예제 #2
0
        /// <summary>
        /// 根据记录给每个方块面板中的方块绘制颜色。
        /// </summary>
        /// <param name="entries">分级后条目列表</param>
        /// <param name="haveProgressBoard">是否开启进度条面板,true 为开启,反之不开启</param>
        private void DrawRectangleColor(TioSalamanca[] entries, bool haveProgressBoard) {
            IDictionary<int, SolidColorBrush> colorDic = ClassifyColorByLevelScore(entries.Length);

            Windows.Foundation.IAsyncAction action = Windows.System.Threading.ThreadPool.RunAsync(
                async (asyncAction) => {
                    GusFring gusFring = new GusFring(entries, colorDic);
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                        priority: Windows.UI.Core.CoreDispatcherPriority.Normal,
                        agileCallback: () => {
                            foreach (Canvas canvas in this.StackCanvas.Children) {
                                if (haveProgressBoard) {
                                    ProgressBoard.SlideOn(canvas, new ProgressBoard());
                                }
                                foreach (var item in canvas.Children) { // 过滤掉非 Rectangle 的元素(比如 ProgressBoard 和 DateTag)
                                    if (item is Rectangle rect) {
#if DEBUG
                                        (int Level, BigInteger Total, SolidColorBrush Color) = gusFring[rect.Name];
                                        rect.Fill = Color;
                                        ToolTip toolTip = new ToolTip {
                                            Content = rect.Name + $"  Level:{Level}  Total:{Total}  Color:{Color}"
                                        };
                                        ToolTipService.SetToolTip(rect, toolTip);
#endif
#if DEBUG == false
                                        rect.Fill = gusFring[rect.Name];
                                        ToolTip toolTip = new ToolTip {
                                            Content = rect.Name"
                                        };
                                        ToolTipService.SetToolTip(rect, toolTip);
#endif
                                        _rectangleRegisteTable.Add(rect);
                                    }
                                }
                            }
                        });
                });
        }