繁体   English   中英

在WP8中使用Skydrive API时,“请求已提交。”

[英]"The request has already been submitted.” while working with Skydrive API in WP8

我正在尝试使用SkyDrive API上传文件。 我尝试使用下面的代码。GEtAccountInformaiton和GetQuotaInformaiton方法已成功执行,但始终将错误设置为“请求已提交。”最后(在字段lblMessageBar.Text的UploadISOFileToSkyDriveAsync()方法中)。

   private async void GetAccountInformations()
    {
        try
        {
            LiveOperationResult operationResult = await App.liveConnectClient.GetAsync("me");
            var jsonResult = operationResult.Result as dynamic;
            string firstName = jsonResult.first_name ?? string.Empty;
            string lastName = jsonResult.last_name ?? string.Empty;
            lblMessageBar.Text = "Welcome " + firstName + " " + lastName;
            GetQuotaInformations();
        }
        catch (Exception e)
        {
            lblMessageBar.Text = e.ToString();
        }
    }
    private async void GetQuotaInformations()
    {
        try
        {
            LiveOperationResult operationResult = await App.liveConnectClient.GetAsync("me/skydrive/quota");
            var jsonResult = operationResult.Result as dynamic;
            quota = jsonResult.quota ?? string.Empty;
            available = jsonResult.available ?? string.Empty;
            lblMessageBar.Text = "Available space in bytes: " + ConvertBytesToGigabytes(available).ToString("#.####") + "GB " + "out of bytes " + ConvertBytesToGigabytes(quota).ToString("#.####") + "GB";
            UploadISOFileToSkyDriveAsync();

        }
        catch (Exception e)
        {
            lblMessageBar.Text = e.ToString();
        }
    }



    public async void UploadISOFileToSkyDriveAsync()
    {
        try
        {


            //http://developer.nokia.com/Community/Wiki/SkyDrive_-_How_to_upload_content_on_Windows_Phone
            IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
            StreamWriter Writer = new StreamWriter(new IsolatedStorageFileStream("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, FileMode.Append, fileStorage));
            //get the data from local database and write to the isolated file and then use the path of this file to saved it to skydrive..
            ObservableCollection<SavedLocationsTableEntity> SavedLocations = SavedLocationsTableEntity.GetSavedLocations();
            foreach (SavedLocationsTableEntity item in SavedLocations)
            {
                Writer.WriteLine(UtilityLib.GetGoogleURL(new System.Device.Location.GeoCoordinate(item.SavedLocationLatitude, item.SavedLocationLongitude, item.SavedLocationAltitude)));
            }

            Writer.Close();
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                fileStream = store.OpenFile("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, FileMode.OpenOrCreate, FileAccess.Read);

                //strEncryptedFileStream = Encoding.Unicode.GetBytes(fileStream.ToString()).ToString();
                if (fileStream.Length == 0)
                {
                    lblMessageBar.Text = "No data to upload to SkyDrive..";
                    return;
                }
                fileStream.Close();
            }
            //remove previous calls

            var reqList = BackgroundTransferService.Requests.ToList();
            foreach (var req in reqList)
            {
                if (req.UploadLocation.Equals(new Uri(MyFilePathInIsoStore, UriKind.Relative)))
                    BackgroundTransferService.Remove(BackgroundTransferService.Find(req.RequestId));
            }

            //Make a new call to upload
            LiveOperationResult res = await App.liveConnectClient.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, UriKind.Relative), OverwriteOption.Overwrite);
            lblMessageBar.Text = "File " + Constants.SkyDriveSavedLocationsFileName + " uploaded.";
            return;
        }
        catch (Exception ex)
        {
            lblMessageBar.Text = "Cannot upload to SkyDrive.. " + ex.Message;
            return;

        }
    }

看起来像MyFilePathInIsoStore

if (req.UploadLocation.Equals(new Uri(MyFilePathInIsoStore

不等于"/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName此处:

new Uri("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, UriKind.Relative)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM