Beispiel #1
0
            /// <summary>
            /// Stores file in its own virtual drive rho\apps\app
            /// </summary>
            /// <param name="file">Stream of file that needs to be saved in the Location.</param>
            /// <param name="fileName">Name i n which the file needs to be saved</param>
            /// <param name="StorechoosePictureResult">Callback event</param>
            /// <param name="choosePicture_output">The path of the image needs to be stored</param>
            /// <returns>Successll or error</returns>
            public async Task SaveToLocalFolderAsync(Stream file, string fileName, IMethodResult StoreTakePictureResult, Dictionary <string, string> TakePicture_output)
            {
                string        FileNameSuffix = "__DTF__";
                StorageFolder localFolder    = ApplicationData.Current.LocalFolder;

                string strLocalFolder = CRhoRuntime.getInstance().getRootPath(ApplicationData.Current.LocalFolder.Path.ToString());

                string[] strFolders = strLocalFolder.Split(new string[] { ApplicationData.Current.LocalFolder.Path.ToString() }, StringSplitOptions.None);
                Dictionary <bool, bool> Rho_SubFolder_Pass = new Dictionary <bool, bool>();

                Rho_SubFolder_Pass.Add(true, true);
                try
                {
                    //bool FIleExists= Rho_SubFolder_Pass[strFolders[1].Contains(localFolder.Path.ToString())];
                    string[] StrSubFolders = strFolders[0].Split('/');

                    foreach (string Path in StrSubFolders)
                    {
                        try
                        {
                            bool BlankFolder = Rho_SubFolder_Pass[!string.IsNullOrEmpty(Path)];
                            var  subfolders  = await localFolder.GetFoldersAsync();

                            foreach (StorageFolder appFolder in subfolders)
                            {
                                try
                                {
                                    bool status = Rho_SubFolder_Pass[appFolder.Name.Contains(Path)];
                                    localFolder = appFolder;
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                string[] picList = Directory.GetFiles(localFolder.Path);
                try
                {
                    bool image = Rho_SubFolder_Pass[fileName.Contains(".jpg")];
                    fileName = fileName.Replace(".jpg", FileNameSuffix + ".jpg");
                }
                catch (Exception ex)
                {
                    fileName = fileName + FileNameSuffix;
                }

                foreach (string DeleteFile in picList)
                {
                    try
                    {
                        bool fileexist = Rho_SubFolder_Pass[DeleteFile.Contains(FileNameSuffix)];

                        File.Delete(DeleteFile);
                    }
                    catch (Exception ex)
                    {
                    }
                }


                StorageFile storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                Task <Stream> outputStreamTask = storageFile.OpenStreamForWriteAsync();
                Stream        outputStream     = outputStreamTask.Result;
                var           bitmap           = new BitmapImage();

                /*bitmap.SetSource(file);
                 * var wb = new WriteableBitmap(bitmap);
                 * wb.SaveJpeg(outputStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                 * outputStream.Close();*/

                TakePicture_output["imageUri"]  = "\\" + storageFile.Name;
                TakePicture_output["image_uri"] = "\\" + storageFile.Name;

                StoreTakePictureResult.set(TakePicture_output);
            }