/// <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; // 表示当前的操作基于磁盘上已有的文件
            }
        }
Example #2
0
        /// <summary>
        /// 播放进度条模块动画
        /// </summary>
        /// <param name="parentCanvas">承载进度条模块的容器</param>
        /// <param name="progressBoard">进度条模块</param>
        public static void SlideOn(Canvas parentCanvas, ProgressBoard progressBoard)
        {
            progressBoard._progressBoard = progressBoard.CreateProgressBoard("ProgressBoard");
            if (parentCanvas.Children.Contains(progressBoard._progressBoard) == false)
            {
                parentCanvas.Children.Add(progressBoard._progressBoard);
            }
            HorizontalCenterOnCanvas(progressBoard._progressBoard, parentCanvas);

            progressBoard._startStoryboard = new Storyboard();
            KeyTime startTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 0));
            KeyTime endTime   = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 300));
            DoubleAnimationUsingKeyFrames slideAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();

            slideAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame()
            {
                Value   = Canvas.GetTop(progressBoard._progressBoard),
                KeyTime = startTime
            });
            slideAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame()
            {
                Value   = (parentCanvas.Height - progressBoard._progressBoard.Height) / 2,
                KeyTime = endTime
            });

            /*
             * 把 startStoryboard.Completed 事件的 Handler 作为局部函数能让它的作用域捕获 ProgressBoard._progressBoard,
             * 从而使得 Completed 事件能够在动画播放结束时为 parentCanvas 移除  ProgressBoard._progressBoard
             */
            void StartStoryboard_Completed(object sender, object e)
            {
                parentCanvas.Children.Remove(progressBoard._progressBoard);
            }

            progressBoard._startStoryboard.Completed += StartStoryboard_Completed;
            progressBoard._startStoryboard.Children.Add(slideAnimationUsingKeyFrames);
            Storyboard.SetTarget(slideAnimationUsingKeyFrames, progressBoard._progressBoard);
            Storyboard.SetTargetName(slideAnimationUsingKeyFrames, progressBoard._progressBoard.Name);
            Storyboard.SetTargetProperty(slideAnimationUsingKeyFrames, "(Canvas.Top)");
            progressBoard._startStoryboard.Begin();
        }
        /// <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);
                                    }
                                }
                            }
                        });
                });
        }
Example #4
0
 /// <summary>
 /// 取消进度条模块
 /// </summary>
 /// <param name="parentCanvas">承载进度条模块的容器</param>
 /// <param name="progressBoard">进度条模块</param>
 public static void CancelOn(Canvas parentCanvas, ProgressBoard progressBoard)
 {
     parentCanvas.Children.Remove(progressBoard._progressBoard);
 }