Example #1
0
        private async void Buy(string productName, string price, string filename)
        {
            var woodgroveUri = new Uri("woodgrove-pay:");

            var options = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "111055f1-4e28-4634-b304-e76934e91e53_876gvmnfevegr";

            var inputData = new ValueSet();

            inputData["ProductName"] = productName;
            inputData["Amount"]      = price;


            StorageFolder assetsFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets\\ProductImages");

            StorageFile imgFile = await assetsFolder.GetFileAsync(filename);

            inputData["ImageFileToken"] = SharedStorageAccessManager.AddFile(imgFile);


            LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(woodgroveUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result["Status"] != null &&
                (result.Result["Status"] as string) == "Success")
            {
                this.Frame.Navigate(typeof(OrderPlacedPage), result.Result);
            }
        }
Example #2
0
        /// <summary>
        /// 获取经过截取后的图片流
        /// </summary>
        /// <returns>图片流</returns>
        public async Task <IRandomAccessStream> GetImageStream()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; //可通过使用图片缩略图创建丰富的视觉显示,以显示文件选取器中的文件
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");

            //选取单个文件
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            //文件处理
            if (file != null)
            {
                var inputFile   = SharedStorageAccessManager.AddFile(file);
                var destination = await ApplicationData.Current.LocalFolder.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);//在应用文件夹中建立文件用来存储裁剪后的图像

                var destinationFile = SharedStorageAccessManager.AddFile(destination);
                var options         = new LauncherOptions();

                options.TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe";

                //待会要传入的参数

                var parameters = new ValueSet();

                parameters.Add("InputToken", inputFile);                //输入文件
                parameters.Add("DestinationToken", destinationFile);    //输出文件
                parameters.Add("ShowCamera", false);                    //它允许我们显示一个按钮,以允许用户采取当场图象(但是好像并没有什么卵用)
                parameters.Add("EllipticalCrop", true);                 //截图区域显示为圆(最后截出来还是方形)
                parameters.Add("CropWidthPixals", 300);
                parameters.Add("CropHeightPixals", 300);

                //调用系统自带截图并返回结果
                var result = await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), options, parameters);

                //按理说下面这个判断应该没问题呀,但是如果裁剪界面点了取消的话后面会出现异常,所以后面我加了try catch
                if (result.Status == LaunchUriStatus.Success && result.Result != null)
                {
                    //对裁剪后图像的下一步处理
                    try
                    {
                        // 载入已保存的裁剪后图片
                        var stream = await destination.OpenReadAsync();

                        return(stream);
                    }

                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message + ex.StackTrace);
                    }
                }
            }
            return(null);
        }
        public async static Task <BitmapImage> LoadPicture()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            var inputFile = SharedStorageAccessManager.AddFile(file);

            CroppedImage = await ApplicationData.Current.LocalFolder.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);

            var destinationFile = SharedStorageAccessManager.AddFile(CroppedImage);
            var options         = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe";
            var parameters = new ValueSet();

            parameters.Add("InputToken", inputFile);
            parameters.Add("DestinationToken", destinationFile);
            parameters.Add("ShowCamera", false);
            parameters.Add("EllipticalCrop", true);
            parameters.Add("CropWidthPixals", 300);
            parameters.Add("CropHeightPixals", 300);

            var result = await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), options, parameters);

            return(await ImageHelper.LoadBitmapImage(CroppedImage));
        }
        /// <summary>
        /// Prepare for transcoding
        /// </summary>
        /// <param name="message">the transcode parameters</param>
        /// <param name="jsonValue">a JsonValue containing the token</param>
        /// <returns>an async task with a JsonValue</returns>
        private async Task PrepareTranscodeAsync(ValueSet message, JsonObject fileTokens)
        {
            var sourceToken      = fileTokens["SourceToken"].GetString();
            var destinationToken = fileTokens["DestinationToken"].GetString();

            var sourceFile = await SharedStorageAccessManager.RedeemTokenForFileAsync(sourceToken);

            if (_canceled)
            {
                throw new TaskCanceledException();
            }

            var destinationFile = await SharedStorageAccessManager.RedeemTokenForFileAsync(destinationToken);

            this._action = TranscodeAsync(sourceFile, destinationFile, message);

            await this._action;

            if (_canceled)
            {
                throw new TaskCanceledException();
            }

            this._action = null;
        }
Example #5
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();

                switch (incomingFileType)
                {
                case ".kdbx":
                    return(new Uri("/Sources/Download.xaml?folder=&fileToken=" + fileID, UriKind.Relative));

                default:
                    // Otherwise perform normal launch.
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            return(uri);
        }
Example #6
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName =
                    SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName);

                if (incomingFileType.Contains(".gpx"))
                {
                    return(new Uri("/ViewRoute.xaml?fileToken=" + fileID, UriKind.Relative));
                }
                else
                {
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            // Otherwise perform normal launch.
            return(uri);
        }
        async private void LoadToken(object sender, RoutedEventArgs e)
        {
            var token = txt_token.Text;
            var file  = await SharedStorageAccessManager.RedeemTokenForFileAsync(token);

            if (file != null)
            {
                //initialize customer
                _customer = new BMXCustomerInfo
                {
                    CustomerID = Guid.NewGuid(),
                };

                //load xml
                var xml_text = await file.ReadTextAsync();

                var xml = XElement.Parse(xml_text);

                //red xml into local values
                var customer_name  = xml.Element("name").Value;
                var customer_email = xml.Element("email").Value;
                var customer_dob   = xml.Element("dob").Value;
                var dob            = DateTime.Parse(customer_dob);

                //set values of controls
                txt_name.Text    = customer_name;
                txt_email.Text   = customer_email;
                control_dob.Date = dob;

                //hide overlay
                grid_overlay.Visibility = Visibility.Collapsed;
            }
        }
        private async void SaveImage_Click(object sender, RoutedEventArgs e)
        {
            if (protocolForResultsArgs == null)
            {
                SaveButton.IsEnabled = false;

                var savePicker = new FileSavePicker()
                {
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                    SuggestedFileName      = string.Format("QuickstartImage_{0}", DateTime.Now.ToString("yyyyMMddHHmmss"))
                };

                savePicker.FileTypeChoices.Add("JPG File", new List <string> {
                    ".jpg"
                });

                SaveImage(savePicker);
            }
            else
            {
                // save file to a local file, and send token back to caller
                var destFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("EditedOutput.jpg", CreationCollisionOption.GenerateUniqueName);
                await SaveImageAsync(destFile);

                var operation = protocolForResultsArgs.ProtocolForResultsOperation;

                var result = new ValueSet();
                result["Success"] = true;
                result["Reason"]  = "Completed";
                result["Token"]   = SharedStorageAccessManager.AddFile(destFile);

                operation.ReportCompleted(result);
            }
        }
Example #9
0
        public override Uri MapUri(Uri uri)
        {
            this.tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                int    fileIdIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIdIndex);

                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();

                if (incomingFileType.Contains("cloudsix")) //this is from cloudsix, need to get the true file name and file type
                {
                    CloudSixFileSelected fileinfo = CloudSixPicker.GetAnswer(fileID);
                    incomingFileName = fileinfo.Filename;
                    incomingFileType = Path.GetExtension(incomingFileName).ToLower();
                }


                if (incomingFileType == ".gb" || incomingFileType == ".gbc" || incomingFileType == ".gba" || incomingFileType == ".sav" ||
                    incomingFileType == ".sgm" || incomingFileType == ".zip" || incomingFileType == ".zib" || incomingFileType == ".rar" ||
                    incomingFileType == ".7z")
                {
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));
                }
                else
                {
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }

            return(uri);
        }
Example #10
0
        private async Task loadExternalFile(string fileID, string type)
        {
            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                isoStore.CreateDirectory("temp");
            }
            StorageFolder tempFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("temp");

            // Get the file name.
            string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
            var    file             = await SharedStorageAccessManager.CopySharedFileAsync(tempFolder, incomingFileName, NameCollisionOption.ReplaceExisting, fileID);

            var info             = new DatabaseInfo();
            var randAccessStream = await file.OpenReadAsync();

            if (type.ToLower() == ".kdbx")
            {
                info.SetDatabase(randAccessStream.AsStream(), new DatabaseDetails
                {
                    Source = "ExternalApp",
                    Name   = incomingFileName.RemoveKdbx(),
                    Type   = SourceTypes.OneTime,
                });
            }

            this.NavigateTo <MainPage>();
        }
        private async Task SendResultAsync(JsonObject result)
        {
            ValueSet val = new ValueSet();

            try
            {
                if (result.ContainsKey("imagePath"))
                {
                    var imagePath = result["imagePath"].GetString();
                    var imageFile = await StorageFile.GetFileFromPathAsync(imagePath);

                    result.Add("imagePathToken", JsonValue.CreateStringValue(SharedStorageAccessManager.AddFile(imageFile)));
                }

                if (result.ContainsKey("fullImagePath"))
                {
                    var imagePath = result["fullImagePath"].GetString();
                    var imageFile = await StorageFile.GetFileFromPathAsync(imagePath);

                    result.Add("fullImagePathToken", JsonValue.CreateStringValue(SharedStorageAccessManager.AddFile(imageFile)));
                }
                val["result"] = result.ToString();
            }
            catch (Exception e)
            {
                val["exception"] = e.Message;
            }
            finally
            {
                _operation.ReportCompleted(val);
            }
        }
Example #12
0
        private async Task<LaunchUriResult> CropImageAsync(IStorageFile input, IStorageFile destination, int width, int height) {
            // Get access tokens to pass input and output files between apps
            var inputToken = SharedStorageAccessManager.AddFile(input);
            var destinationToken = SharedStorageAccessManager.AddFile(destination);

            // Specify an app to launch by using LaunchUriForResultsAsync
            var options = new LauncherOptions();
            options.TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe";

            // Specify protocol launch options
            var parameters = new ValueSet();
            parameters.Add("InputToken", inputToken);
            parameters.Add("DestinationToken", destinationToken);
            parameters.Add("CropWidthPixels", width);
            parameters.Add("CropHeightPixels", height);
            parameters.Add("EllipticalCrop", false);
            parameters.Add("ShowCamera", false);

            // Perform LaunchUriForResultsAsync
            return await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), options, parameters);

            // See also: 
            // https://frayxrulez.wordpress.com/tag/microsoft-windows-photos-crop/ 
            // https://gist.github.com/c2f1bbfa996ad5751b87 
            // https://myignite.microsoft.com/videos/2571
        }
Example #13
0
        private async void LaunchApp()
        {
            var testAppUri = new Uri("weipo:"); // The protocol handled by the launched app
            var options    = new LauncherOptions {
                TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName
            };

            var inputData = new ValueSet();
            var data      = _shareArguments.ShareOperation.Data;

            if (data.Contains(StandardDataFormats.Text))
            {
                var text = await data.GetTextAsync();

                inputData["text"] = text;
            }

            if (data.Contains(StandardDataFormats.Bitmap))
            {
                var bitmap = await data.GetBitmapAsync();

                var file = await bitmap.SaveCacheFile();

                inputData["image"] = SharedStorageAccessManager.AddFile(file);
            }

            await Launcher.LaunchUriAsync(testAppUri, options, inputData);

            _shareArguments.ShareOperation.ReportCompleted();
        }
Example #14
0
        async void OnAppServiceRequestReceived(AppServiceConnection sender,
                                               AppServiceRequestReceivedEventArgs args)
        {
            var      localDeferral = args.GetDeferral();
            var      parameters    = args.Request.Message;
            ValueSet vs            = new ValueSet();

            if (parameters.ContainsKey("query"))
            {
                var result = await FlickrSearcher.SearchAsync((string)parameters["query"]);

                if ((result != null) && (result.Count > 0))
                {
                    var        first  = result[0];
                    HttpClient client = new HttpClient();
                    using (var response = await client.GetAsync(new Uri(first.ImageUrl)))
                    {
                        var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(first.Id.ToString(),
                                                                                                 CreationCollisionOption.ReplaceExisting);

                        using (var fileStream = await file.OpenStreamForWriteAsync())
                        {
                            await response.Content.CopyToAsync(fileStream);
                        }
                        var token = SharedStorageAccessManager.AddFile(file);
                        vs["pictureToken"] = token;
                    }
                }
            }
            await args.Request.SendResponseAsync(vs);

            localDeferral.Complete();
        }
Example #15
0
        public async static Task <StorageFile> CropImageFileAsync(StorageFile inputFile, int cropWidthPixels, int cropHeightPixels)
        {
            var outputFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Cropped_" + inputFile.Name, CreationCollisionOption.ReplaceExisting);

            var inputToken       = SharedStorageAccessManager.AddFile(inputFile);
            var destinationToken = SharedStorageAccessManager.AddFile(outputFile);

            var inputData = new ValueSet
            {
                { "InputToken", inputToken },
                { "DestinationToken", destinationToken },
                { "CropWidthPixels", cropWidthPixels },
                { "CropHeightPixels", cropHeightPixels },
                { "EllipticalCrop", false }
            };

            var launcherOptions = new LauncherOptions
            {
                TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe"
            };

            var launcherResult = await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), launcherOptions, inputData);

            if (launcherResult.Status != LaunchUriStatus.Success)
            {
                return(null);
            }

            return(outputFile);
        }
Example #16
0
        public override Uri MapUri(Uri uri)
        {
            this.tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                int    fileIdIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIdIndex);

                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string incomingFileType = Path.GetExtension(incomingFileName);

                switch (incomingFileType)
                {
                case ".smc":
                case ".sfc":
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));

                default:
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }

            return(uri);
        }
Example #17
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();
            // 根据文件类型打开程序
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // 获取fileID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);
                // 获取文件名.
                string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                // 获取文件后缀
                int    extensionIndex    = incommingFileName.LastIndexOf('.') + 1;
                string incommingFileType = incommingFileName.Substring(extensionIndex).ToLower();
                // 根据不同文件类型,跳转不同参数的地址
                switch (incommingFileType)
                {
                case "wx23c4db6d0d03d3f9":
                    return(new Uri("/Page/WeixinPage.xaml?fileToken=" + fileID, UriKind.Relative));

                default:
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                return(uri);
            }
        }
Example #18
0
    public override Uri MapUri(Uri uri)
    {
        strUri = uri.ToString();

        // File association launch
        if (strUri.Contains("/FileTypeAssociation"))
        {
            // Get the file ID (after "fileToken=").
            int    nFileIDIndex = strUri.IndexOf("fileToken=") + 10;
            string strFileID    = strUri.Substring(nFileIDIndex);

            string strFileName         = SharedStorageAccessManager.GetSharedFileName(strFileID);
            string strIncomingFileType = Path.GetExtension(strFileName);

            string strData = fnCopyToLocalFolderAndReadContents(strFileID).Result;

            switch (fileType)
            {
            case ".gmm":
                //determine if gmm is text
                if (objGMM.fnGetGMMType() == GMMFILETYPE.TXT)
                {
                    return(new Uri("/PageReadText.xaml?data=" + strData, UriKind.Relative));
                }
                break;
            }
        }
    }
Example #19
0
        protected async override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
            {
                return;
            }
            InitialLocalValues();
            if (NavigationContext.QueryString.ContainsKey("fileToken") && !e.IsNavigationInitiator)
            {
                string fileID           = NavigationContext.QueryString["fileToken"];
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string msg = Strings.Download_OpenConfirm + incomingFileName + "'";
                if (MessageBox.Show(msg, Strings.Download_OpenDB, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    await loadExternalFile(fileID, _type);
                }
            }

            var app = App.Current as App;

            if (app.QueueFileOpenPickerArgs.Count != 0)
            {
                this.ContinueFileOpenPicker(app.QueueFileOpenPickerArgs.Dequeue());
            }
        }
Example #20
0
    public override Uri MapUri(Uri uri)
    {
        string uriStr = uri.ToString();

        if (uriStr.Contains("/FileTypeAssociation"))
        {
            int    fileIDIndex       = uriStr.IndexOf("fileToken=") + 10;
            string fileID            = uriStr.Substring(fileIDIndex);
            string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

            // Path.GetExtension will return String.Empty if no file extension found.
            int    extensionIndex   = incommingFileName.LastIndexOf('.') + 1;
            string incomingFileType = incommingFileName.Substring(extensionIndex).ToLower();

            if (incomingFileType == WeChat.appId)
            {
                return(new Uri("/WeChatCallbackPage.xaml?fileToken=" + fileID, UriKind.Relative));
            }
        }

        if (upper != null)
        {
            var upperResult = upper.MapUri(uri);

            if (upperResult != uri)
            {
                return(upperResult);
            }
        }

        return(new Uri("/MainPage.xaml", UriKind.Relative));
    }
Example #21
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                var extension = Path.GetExtension(incomingFileName);
                if (extension != null)
                {
                    string incomingFileType = extension.ToLower();

                    if (".key" == incomingFileType || incomingFileType == ".kdbx")
                    {
                        return(new Uri($"/Sources/Download.xaml?type={incomingFileType}&folder=&fileToken={fileID}", UriKind.Relative));
                    }
                }
                return(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            return(uri);
        }
        public async void OnPhotoToFile(StorageFile file)
        {
            JsonObject result = new JsonObject();

            result.Add("imagePathToken", JsonValue.CreateStringValue(SharedStorageAccessManager.AddFile(file)));

            await SendResultAsync(result);
        }
 /// <summary>
 /// Gets the Transcoder extension description
 /// </summary>
 /// <param name="response"></param>
 private void GetDescription(ValueSet response)
 {
     response["DisplayName"]   = DisplayName;
     response["PublisherName"] = PublisherName;
     response["Version"]       = Version;
     response["Price"]         = Price;
     response["LogoFileToken"] = SharedStorageAccessManager.AddFile(this.LogoFile);
     response["SourceType"]    = this.SourceType;
 }
Example #24
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //get the fileID
            try
            {
                String fileID = NavigationContext.QueryString["fileToken"];
                NavigationContext.QueryString.Remove("fileToken");

                //currently only zip file need to use this page, copy the zip file to local storage
                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                string        fileName    = SharedStorageAccessManager.GetSharedFileName(fileID);
                tempZipFile = await SharedStorageAccessManager.CopySharedFileAsync(localFolder, fileName, NameCollisionOption.ReplaceExisting, fileID);

                //set the title
                CloudSixFileSelected fileinfo = CloudSixPicker.GetAnswer(fileID);
                currentFolderBox.Text = fileinfo.Filename;
                string ext = Path.GetExtension(fileinfo.Filename).ToLower();

                //open zip file or rar file
                try
                {
                    SkyDriveItemType type = SkyDriveItemType.File;
                    if (ext == ".zip" || ext == ".zib")
                    {
                        type = SkyDriveItemType.Zip;
                    }
                    else if (ext == ".rar")
                    {
                        type = SkyDriveItemType.Rar;
                    }
                    else if (ext == ".7z")
                    {
                        type = SkyDriveItemType.SevenZip;
                    }

                    skydriveStack = await GetFilesInArchive(type, tempZipFile);

                    this.skydriveList.ItemsSource = skydriveStack;

                    var indicator = SystemTray.GetProgressIndicator(this);
                    indicator.IsIndeterminate = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, AppResources.ErrorCaption, MessageBoxButton.OK);
                }
            }
            catch (Exception)
            {
                MessageBox.Show(AppResources.FileAssociationError, AppResources.ErrorCaption, MessageBoxButton.OK);
            }



            base.OnNavigatedTo(e);
        }
Example #25
0
 private async void parseData(string fileToken)
 {
     try
     {
         StorageFolder localFolder = ApplicationData.Current.LocalFolder;
         if (!FileUtil.dirExists("wechat_sdk"))
         {
             FileUtil.createDir("wechat_sdk");
         }
         await(await SharedStorageAccessManager.RedeemTokenForFileAsync(fileToken)).CopyAsync(localFolder, "wechat_sdk\\wp.wechat", NameCollisionOption.ReplaceExisting);
         //await SharedStorageAccessManager.CopySharedFileAsync(localFolder, "wechat_sdk\\wp.wechat", 1, fileToken);
         if (FileUtil.fileExists("wechat_sdk\\wp.wechat"))
         {
             TransactData transactData = TransactData.ReadFromFile("wechat_sdk\\wp.wechat");
             if (!transactData.ValidateData(true))
             {
                 await new Windows.UI.Popups.MessageDialog("数据验证失败").ShowAsync();
             }
             else if (!transactData.CheckSupported())
             {
                 await new Windows.UI.Popups.MessageDialog("当前版本不支持该请求").ShowAsync();
             }
             else if (transactData.Req != null)
             {
                 if (transactData.Req.Type() == 3)
                 {
                     this.On_GetMessageFromWX_Request(transactData.Req as GetMessageFromWX.Req);
                 }
                 else if (transactData.Req.Type() == 4)
                 {
                     this.On_ShowMessageFromWX_Request(transactData.Req as ShowMessageFromWX.Req);
                 }
             }
             else if (transactData.Resp != null)
             {
                 if (transactData.Resp.Type() == 2)
                 {
                     this.On_SendMessageToWX_Response(transactData.Resp as SendMessageToWX.Resp);
                 }
                 else if (transactData.Resp.Type() == 1)
                 {
                     this.On_SendAuth_Response(transactData.Resp as SendAuth.Resp);
                 }
                 else if (transactData.Resp.Type() == 5)
                 {
                     this.On_SendPay_Response(transactData.Resp as SendPay.Resp);
                 }
             }
         }
     }
     catch
     {
         await new Windows.UI.Popups.MessageDialog("未知错误").ShowAsync();
     }
 }
        private async void AppServiceConnection_RequestReceived(
            AppServiceConnection sender,
            AppServiceRequestReceivedEventArgs args)
        {
            var deferral = args.GetDeferral();

            try
            {
                var request = args.Request;

                var token = request.Message["FileToken"] as string;

                var data = request.Message["Data"] as string;

                var jsonData = JsonObject.Parse(data);

                var framesPerSecond = jsonData["FramesPerSecond"].GetNumber();

                var secondsPerFrame = 1.0 / framesPerSecond;

                var delayTime = System.Convert.ToUInt16(secondsPerFrame * 1000);

                var file = await SharedStorageAccessManager.RedeemTokenForFileAsync(token);

                var temporaryFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
                var gifFile         = await temporaryFolder.CreateFileAsync(file.DisplayName + ".gif", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                using (var stream = await file.OpenStreamForReadAsync())
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Read))
                    {
                        var journalXmlEntry = archive.GetEntry("journal.xml");

                        using (var journalStream = journalXmlEntry.Open())
                        {
                            await EncodeImagesAsync(delayTime, gifFile, archive, journalStream);
                        }
                    }
                }

                var gifToken = SharedStorageAccessManager.AddFile(gifFile);

                var responseMessage = new ValueSet
                {
                    ["FileToken"] = gifToken
                };

                await request.SendResponseAsync(responseMessage);
            }
            finally
            {
                deferral.Complete();
            }
        }
Example #27
0
    async Task <string> fnCopyToLocalFolderAndReadContents(string strIncomingFileId)
    {
        StorageFolder objLocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

        objFile = await SharedStorageAccessManager.CopySharedFileAsync(objLocalFolder, TEMP.gmm, NameCollisionOption.ReplaceExisting, strIncomingFileId);

        using (StreamReader streamReader = new StreamReader(objFile))
        {
            return(streamReader.ReadToEnd());
        }
    }
Example #28
0
        // 将沙盒内的指定文件设置为可共享,并生成 token
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(@"webabcdTest\sharedStorage.txt", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteTextAsync(file, "I am webabcd: " + DateTime.Now.ToString());

            _sharedToken = SharedStorageAccessManager.AddFile(file);

            lblMsg.Text += $"文件 {file.Path} 已经被设置为可共享,其 token 值为 {_sharedToken}";
            lblMsg.Text += Environment.NewLine;
        }
Example #29
0
        private async Task SaveFileToStorageAsync()
        {
            string fileToken = NavigationContext.QueryString["fileToken"];
            string fileName  = SharedStorageAccessManager.GetSharedFileName(fileToken);

            _storedFile = await SharedStorageAccessManager
                          .CopySharedFileAsync(_filesFolder,
                                               fileName,
                                               NameCollisionOption.ReplaceExisting,
                                               fileToken);
        }
        public async Task LaunchExtensionAsync(AppExtension appExtension)
        {
            // Il y a 2 types de packages, le bon et le mauvais
            // le bon, il est bon alors que le mauvais il est mauvais.
            if (false == appExtension.Package.Status.VerifyIsOK())
            {
                return;
            }

            // création d'une connexion
            var connection = new AppServiceConnection
            {
                AppServiceName = "com.infinitesquare.UWPWhatsNewExtension",

                // ciblage de l'extension
                PackageFamilyName = appExtension.Package.Id.FamilyName
            };

            var cameraCaptureUI = new CameraCaptureUI {
                PhotoSettings = { CroppedAspectRatio = new Size(1, 1), Format = CameraCaptureUIPhotoFormat.Jpeg }
            };
            var file = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file == null)
            {
                return;
            }

            var token = SharedStorageAccessManager.AddFile(file);

            // ouverture de la connexion
            var result = await connection.OpenAsync();

            if (result != AppServiceConnectionStatus.Success)
            {
                return;
            }

            var inputs = new ValueSet {
                { "targetFileToken", token }
            };

            // send input and receive output in a variable
            var response = await connection.SendMessageAsync(inputs);

            var outputFileToken = response.Message["outputFileToken"].ToString();

            var outputFile = await SharedStorageAccessManager.RedeemTokenForFileAsync(outputFileToken);

            var copied = await outputFile.CopyAsync(ApplicationData.Current.TemporaryFolder, outputFile.Name);

            OutputImage = new BitmapImage(new Uri(copied.Path));
        }