コード例 #1
0
        public async Task <bool> SaveFile(string defaultFileName, List <KeyValuePair <string, List <string> > > fileTypeList, byte[] data)
        {
            try
            {
                StorageFile file = await SelectFile(defaultFileName, fileTypeList);

                if (file == null)
                {
                    return(false);  // Selezione annullata
                }
                await FileIO.WriteBytesAsync(file, data);

                OnSaveFileHandler?.Invoke(this, new FolderPickerResult
                {
                    Succeeded = true,
                    FilePath  = file.Path
                });

                Windows.ApplicationModel.Resources.ResourceLoader ResLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
                string msg = string.Format(ResLoader.GetString("msgPwdExportTo"), file.Path);

                Notifier notifier = new Notifier();
                notifier.SendNotification("PwdCrypter", msg);

                return(true);
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to save the password list. Error: " + Ex.Message);
            }
        }
コード例 #2
0
 /// <summary>
 /// Metodo da chiamare prima di utilizzare l'oggetto
 /// </summary>
 public void Init()
 {
     if (!IsInit)
     {
         MessagingCenter.Subscribe(this, SaveFileActivityMessage,
                                   (CrossPlatformSpecialFolder sender, FolderPickerResult info) =>
         {
             OnSaveFileHandler?.Invoke(sender, info);
         });
     }
     IsInit = true;
 }
コード例 #3
0
        public async Task <bool> SaveFile(string defaultFileName, List <KeyValuePair <string, List <string> > > fileTypeList, Stream streamData)
        {
            try
            {
                StorageFile file = await SelectFile(defaultFileName, fileTypeList);

                if (file == null)
                {
                    return(false);  // Selezione annullata
                }
                int    pos = -1, read = 0;
                byte[] data = new byte[streamData.Length];
                do
                {
                    long count = Math.Min(1024, streamData.Length - streamData.Position);
                    read = await streamData.ReadAsync(data, pos + 1, (int)count);

                    pos += read;
                }while (pos < streamData.Length - 1);
                await FileIO.WriteBytesAsync(file, data);

                OnSaveFileHandler?.Invoke(this, new FolderPickerResult
                {
                    Succeeded = true,
                    FilePath  = file.Path
                });

                Windows.ApplicationModel.Resources.ResourceLoader ResLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
                string msg = string.Format(ResLoader.GetString("msgPwdExportTo"), file.Path);

                Notifier notifier = new Notifier();
                notifier.SendNotification("PwdCrypter", msg);

                return(true);
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to save the password list. Error: " + Ex.Message);
            }
        }