/// <summary>
        /// 增加请求的回调方法。
        /// </summary>
        /// <param name="result"></param>
        private void OnChangesSaved(IAsyncResult result)
        {
            Dispatcher.BeginInvoke(() =>
            {
                SampleProjects svcContext = result.AsyncState as SampleProjects;

                try
                {
                    // 完成保存改变操作显示结果。
                    WriteOperationResponse(svcContext.EndSaveChanges(result));
                }
                catch (DataServiceRequestException ex)
                {
                    // 显示错误信息。
                    WriteOperationResponse(ex.Response);
                }
                catch (InvalidOperationException ex)
                {
                    messageTextBlock.Text = ex.Message;
                }
                finally
                {
                    // 重新加载绑定的集合来刷新Grid,显示操作的结果。
                    // 你也可以删除下边的代码行,并通过刷新本也或者直接查看数据库来看操作结果。
                    LoadData();
                }
            });
        }
        /// <summary>
        /// Callback method of the insert operation.
        /// </summary>
        /// <param name="result"></param>
        private void OnChangesSaved(IAsyncResult result)
        {
            Dispatcher.BeginInvoke(() =>
            {
                SampleProjects svcContext = result.AsyncState as SampleProjects;

                try
                {
                    // Complete the save changes operation and display the response.
                    WriteOperationResponse(svcContext.EndSaveChanges(result));
                }
                catch (DataServiceRequestException ex)
                {
                    // Display the error from the response.
                    WriteOperationResponse(ex.Response);
                }
                catch (InvalidOperationException ex)
                {
                    messageTextBlock.Text = ex.Message;
                }
                finally
                {
                    // Reload the binding collection to refresh Grid to see if it's successfully updated.
                    // You can also remove the following line. To see the update effect, just refresh the page or check out database directly.
                    LoadData();
                }
            });
        }
        /// <summary>
        /// 本方法中,我们向ADO.NET Data Service发送了一个异步的REST请求,来获得Category
        /// 记录。
        /// </summary>
        private void LoadData()
        {
            _context = new SampleProjects(new Uri(_sampleUri));
            DataServiceQuery <Category> query = (DataServiceQuery <Category>)(
                from c in _context.Categories
                select c);

            query.BeginExecute(OnCategoryQueryComplete, query);
        }
        private void selectDownloadedPackage(IPackage pack)
        {
            string packagePath         = GetPackagePath(pack);
            IEnumerable <string> files = Directory.EnumerateFiles(packagePath, "*.dspx", SearchOption.AllDirectories);

            if (NuGet.EnumerableExtensions.Any <string>(files))
            {
                foreach (var item in SampleProjects)
                {
                    if (item is ISampleProject && Path.GetFileNameWithoutExtension(files.First()) == (item as ISampleProject).Name)
                    {
                        lstProjectTemplates.SelectedIndex = SampleProjects.IndexOf(item);
                        CreateProjectFromTemplate();
                        break;
                    }
                }
            }
        }