从服务器的影像传输到本地文件夹中的Windows Store应用 [英] Transfer images from server to local folder Windows Store App

查看:175
本文介绍了从服务器的影像传输到本地文件夹中的Windows Store应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的情况:

  • 我有一个的 Windows服务的能够访问服务器上的文件

  • 一个的 Windows应用商店的应用的可访问上述服务

  • Windows应用商店的应用的没有进入位图对象(仅的BitmapImage

  • 该服务访问位图而不是的BitmapImage

  • 该服务只能访问 file.io

  • Windows应用商店的应用的只能访问 Windows.Storage

我有困难找到一种方法,我所有的图像从服务传递到的的Windows Store应用的,因为我无法找到2 之间的共同点。

我试图转移位图键,将其转换为的BitmapImage 但我不能找到一种方法到BitmapImage的保存到特定的文件夹。

什么可以把我在正确的轨道,只要找到一个共同的目标转移任何想法?

解决方案

非常感谢ChicagoMike的把我在正确的轨道。这里是我做到了。

对象从服务传送到客户端:

 进口System.IO

    公共类PictureSender
        公共属性PictureBytes为字节()
        公共属性PictureName作为字符串
    末级
 

客户端调用它的控制器code(因为我已经在各自的文件夹中多种类型图像的LINQ和For循环是在我的情况下非常有用)

 专用异步子btnGetPictures_Click(发送者为对象,E为RoutedEventArgs)
        获取的所有类别的图片列表中,以便通过所有文件夹从本地保存。
        昏暗lstFolders方式列表(字符串)=(从p在等待ImageController.GetImageDetails选择p.Categorie).Distinct.ToList()
        对于i = 0到lstFolders.Count  -  1
            PicturesController.GetPicturesServer(lstFolders(I))
        下一个
    结束小组
 

code。在客户机控制器:

 公共异步子GetPicturesServer(_​​folderName作为字符串)
        昏暗的服务作为新ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1)

        昏暗的RCV =等待service.SelectAllPicturesAsync(_folderName)

        '获取文件夹
        昏暗的文件夹= ApplicationData.Current.LocalFolder
        文件夹=等待folder.CreateFolderAsync(图像,CreationCollisionOption.OpenIfExists)
        等待folder.CreateFolderAsync(_folderName,CreationCollisionOption.ReplaceExisting)
        文件夹=等待folder.GetFolderAsync(_folderName)

        通过所有照片运行,并将其保存
        对于i = 0到rcv.Count  -  1
            昏暗MYFILE作为StorageFile = CTYPE(等待folder.CreateFileAsync(RCV(我).PictureName,CreationCollisionOption.ReplaceExisting),StorageFile)
            等待Windows.Storage.FileIO.WriteBufferAsync(MYFILE,RCV(我).PictureBytes.AsBuffer())
        下一个
 

在服务code:

 函数执行(TypeOfPictures作为字符串)作为目录(中PictureSender)
        昏暗PicturesinDirectory方式列表(串)= Directory.GetFiles(\\ SERVER \ DATA \图片\+ TypeOfPictures +\,* .JPG *)。了ToList()

        昏暗lstPicturesToSend方式列表(中PictureSender)=新名单(中PictureSender)
        对于i = 0到PicturesinDirectory.Count  -  1
            昏暗的ByteArray为字节()= File.ReadAllBytes(PicturesinDirectory(I))

            影响PictureSender对象
            昏暗PictureSenderObject作为PictureSender =新PictureSender
            PictureSenderObject.PictureBytes =的ByteArray
            PictureSenderObject.PictureName = PicturesinDirectory(ⅰ).Substring(PicturesinDirectory(ⅰ).LastIndexOf(\)+1)
            lstPicturesToSend.Add(PictureSenderObject)
        下一个
        返回lstPicturesToSend

    端功能
 

这code pretty的多发回字节()和,然后客户端使用该服务的图片名称。客户端使用缓存写的文件,并重新创建的图片

Here is my situation :

  • I have a windows service with access to the files on the server

  • A Windows Store Apps with access to said service

  • Windows Store Apps don't have access to the bitmap object (only bitmapimage)

  • The service has access to bitmap but not bitmapimage

  • The service only has access to file.io

  • Windows Store Apps only have access to Windows.Storage

I am having difficulties finding a way to pass all my images from the service to the Windows Store App as I can't find a common ground between the 2.

I have tried to transfer a bitmap and convert it to a bitmapimage but then I could not find a way to save the BitmapImage to a specific folder.

Any idea of what could put me on the right track as far as finding a common object to transfer ?

解决方案

Big Thanks to ChicagoMike for putting me on the right track. Here is how I did it

Object to transfer from the service to the client :

Imports System.IO

    Public Class PictureSender
        Public Property PictureBytes As Byte()
        Public Property PictureName As String
    End Class

Code on the client calling its controller (The linq and For loop is useful in my case since I have multiple types of images in their respective folders):

    Private Async Sub btnGetPictures_Click(sender As Object, e As RoutedEventArgs)
        ' Get the list of all categories of picture to go through all folders from local saves.
        Dim lstFolders As List(Of String) = (From p In Await ImageController.GetImageDetails Select p.Categorie).Distinct.ToList()
        For i = 0 To lstFolders.Count - 1
            PicturesController.GetPicturesServer(lstFolders(i))
        Next
    End Sub

Code in the client controller :

    Public Async Sub GetPicturesServer(_folderName As String)
        Dim service As New ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1)

        Dim rcv = Await service.SelectAllPicturesAsync(_folderName)

        ' Get the folder
        Dim folder = ApplicationData.Current.LocalFolder
        folder = Await folder.CreateFolderAsync("Images", CreationCollisionOption.OpenIfExists)
        Await folder.CreateFolderAsync(_folderName, CreationCollisionOption.ReplaceExisting)
        folder = Await folder.GetFolderAsync(_folderName)

        ' Run through all pictures and save them
        For i = 0 To rcv.Count - 1
            Dim myfile As StorageFile = CType(Await folder.CreateFileAsync(rcv(i).PictureName, CreationCollisionOption.ReplaceExisting), StorageFile)
            Await Windows.Storage.FileIO.WriteBufferAsync(myfile, rcv(i).PictureBytes.AsBuffer())
        Next

Code on the service :

    Function Execute(TypeOfPictures As String) As List(Of PictureSender)
        Dim PicturesinDirectory As List(Of String) = Directory.GetFiles("\\SERVER\Data\Image\" + TypeOfPictures + "\", "*.jpg*").ToList()

        Dim lstPicturesToSend As List(Of PictureSender) = New List(Of PictureSender)
        For i = 0 To PicturesinDirectory.Count - 1
            Dim ByteArray As Byte() = File.ReadAllBytes(PicturesinDirectory(i))

            ' Affect the PictureSender object
            Dim PictureSenderObject As PictureSender = New PictureSender
            PictureSenderObject.PictureBytes = ByteArray
            PictureSenderObject.PictureName = PicturesinDirectory(i).Substring(PicturesinDirectory(i).LastIndexOf("\") + 1)
            lstPicturesToSend.Add(PictureSenderObject)
        Next
        Return lstPicturesToSend

    End Function

This code pretty much sends back a Byte() and a picture name from the service which is then used by the client. The client uses the buffer to write on the files and recreating the picture

这篇关于从服务器的影像传输到本地文件夹中的Windows Store应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆