首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何比较镜像(缓存镜像)?

如何比较镜像(缓存镜像)?
EN

Stack Overflow用户
提问于 2012-07-28 20:17:23
回答 1查看 782关注 0票数 0

我在我的metro风格的应用程序中进行简单的图像缓存。下面是我已经完成的工作:

代码语言:javascript
复制
    private async void GetImage()
    {
        bool isFolderExisting = true;
        bool isFileExisting = true;
        StorageFolder storageFolder = null;
        StorageFile storageFile = null;

        // get screenshots folder    
        try
        {
            storageFolder = await ApplicationData.Current.TemporaryFolder.GetFolderAsync("screenshots");
        }
        catch (System.IO.FileNotFoundException ex)
        {
            isFolderExisting = false;
        }
        // if folder doesn't exist, create new one
        if (isFolderExisting == false)
            storageFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("screenshots");

        // get screenshot
        try
        {
            storageFile = await storageFolder.GetFileAsync(this.LinkId);
            //IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync((source) => { updateImage(storageFile); });
        }
        catch (System.IO.FileNotFoundException ex)
        {
            isFileExisting = false;
        }

        // if file doesn't exists, download and save new one
        if (isFileExisting == false)
        {
            var uri = new Uri(WebServiceAddress + "/screenshot/" + this.LinkId, UriKind.Absolute);
            var thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(uri);
            storageFile = await StorageFile.CreateStreamedFileFromUriAsync(this.LinkId, uri, thumbnail);
            await storageFile.CopyAsync(storageFolder, storageFile.Name, NameCollisionOption.ReplaceExisting);
        }

        //this.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appdata:///temp/screenshots/" + this.LinkId)); 
        this.Image = "ms-appdata:///temp/screenshots/" + this.LinkId;
    }

现在我必须处理最后的部分,那就是比较图像。我正在检查临时文件夹中是否存在图像。如果它不存在,我只是下载新的,但如果存在,我需要检查它是否与服务器上的相同。我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

发布于 2012-07-28 21:25:40

在StorageFile类上使用GetBasicPropertiesAsync方法。BasicProperties对象包含一个DateModified属性,您可以使用该属性在客户端和服务器之间进行比较。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11700955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档