Ejemplo n.º 1
0
        void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            fileUpdateRequest         = args.Request;
            fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
            switch (cachedFileUpdaterUI.UIStatus)
            {
            case UIStatus.Hidden:
                if (fileUpdateRequest.File.Name.Contains("ConflictingFile"))
                {
                    fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                }
                else
                {
                    fileUpdateRequest.Status = FileUpdateStatus.Complete;
                }
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }
Ejemplo n.º 2
0
        private async void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            FileUpdateRequestDeferral fileUpdateRequestDeferral = _fileUpdateRequest.GetDeferral();

            // 由 CachedFileUpdater 更新 CachedFile,然后返回给 app 一个 FileUpdateStatus 状态
            await FileIO.AppendTextAsync(_fileUpdateRequest.File, Environment.NewLine + "由 CachedFileUpdater 更新:" + DateTime.Now.ToString());

            string fileContent = await FileIO.ReadTextAsync(_fileUpdateRequest.File);

            lblMsg.Text  = "文件名: " + _fileUpdateRequest.File.Name;
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "文件内容: " + fileContent;

            _fileUpdateRequest.Status = FileUpdateStatus.Complete;
            fileUpdateRequestDeferral.Complete();

            btnUpdate.IsEnabled = false;
        }
Ejemplo n.º 3
0
        async void _cachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            _fileUpdateRequest = args.Request;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = _fileUpdateRequest.GetDeferral();

            if (_cachedFileUpdaterUI.UpdateTarget == CachedFileTarget.Local) // 由 CachedFileUpdater 更新 CachedFile(CachedFileTarget.Local 方式)
            {
                // 开始激活 CachedFileUpdater 时,是 UIStatus.Hidden 状态的
                if (_cachedFileUpdaterUI.UIStatus == UIStatus.Hidden)
                {
                    // 下面针对两种方式分别写示例

                    // 方式一:直接更新文件,并设置为 FileUpdateStatus.Complete 状态,最后完成
                    if (DateTime.Now.Second % 2 == 0)
                    {
                        await FileIO.AppendTextAsync(_fileUpdateRequest.File, Environment.NewLine + "由 CachedFileUpdater 更新:" + DateTime.Now.ToString());

                        _fileUpdateRequest.Status = FileUpdateStatus.Complete;
                        fileUpdateRequestDeferral.Complete();
                    }
                    // 方式二:设置为 FileUpdateStatus.UserInputNeeded 状态,并完成,之后会再次触发这个事件,并且变为 UIStatus.Visible 状态,弹出本页界面,
                    // 这样的话可以在用户做一些操作之后再更新文件(参见下面的 btnUpdate_Click 部分)
                    else
                    {
                        _fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                        fileUpdateRequestDeferral.Complete();
                    }
                }
            }
            else if (_cachedFileUpdaterUI.UpdateTarget == CachedFileTarget.Remote) // 由 app 更新 CachedFile(CachedFileTarget.Remote 方式)
            {
                // 这里可以拿到 app 更新后的文件的结果
                string textContent = await FileIO.ReadTextAsync(_fileUpdateRequest.File);

                // 但是这里不能修改这个文件,否则会报错
                // await FileIO.AppendTextAsync(_fileUpdateRequest.File, Environment.NewLine + "由 CachedFileUpdater 更新:" + DateTime.Now.ToString());

                // CachedFileUpdater 返回给 app 一个 FileUpdateStatus 状态
                _fileUpdateRequest.Status = FileUpdateStatus.Complete;
                fileUpdateRequestDeferral.Complete();
            }
        }
Ejemplo n.º 4
0
        void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            fileUpdateRequest         = args.Request;
            fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
            switch (cachedFileUpdaterUI.UIStatus)
            {
            case UIStatus.Hidden:
                fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }
Ejemplo n.º 5
0
        private void OnFileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            switch (sender.UIStatus)
            {
            case UIStatus.Hidden:
                fileUpdateRequest         = args.Request;
                fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
                // process cached file
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                // use the class fields

                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }