示例#1
0
        /// <summary>
        /// Método que importa un almacén a la aplicación. Solicita la clave del almacén y verifica que es un almacén,
        /// en cuyo caso, almacenará dicho almacén en la carpeta de la aplicación para poder ser utilizado más tarde.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Import_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder contents = new StringBuilder();

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".pfx");
            openPicker.FileTypeFilter.Add(".p12");
            StorageFile selectedFile2 = await openPicker.PickSingleFileAsync();

            if (selectedFile2 != null)
            {
                CredentialPanel cp = new CredentialPanel();
                cp.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                CustomDialog customDialog = new CustomDialog(cp, labels.GetString("Etiqueta_peticion_pass"));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_aceptar")));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_cancelar")));
                customDialog.DefaultCommandIndex = 0;
                customDialog.CancelCommandIndex  = 1;
                IUICommand com = await customDialog.ShowAsync();

                if (com.Label.Equals(labels.GetString("Boton_aceptar")))
                {
                    if (cp.getPassword() != null)
                    {
                        using (StreamReader reader = new StreamReader(await selectedFile2.OpenStreamForReadAsync()))
                        {
                            char[] password = cp.getPassword().ToCharArray();
                            try
                            {
                                store = new Pkcs12Store(reader.BaseStream, password);
                                if (store != null)
                                {
                                    await selectedFile2.CopyAsync(localFolder, selectedFile2.Name, NameCollisionOption.ReplaceExisting);

                                    AfirmaMetroUtils.showMessage(labels.GetString("Info_almacen_importado") + selectedFile2.Name + "\"", "Importación de almacén correcta");
                                    // Recargamos los almacenes
                                    loadStorage();
                                }
                            }
                            catch
                            {
                                AfirmaMetroUtils.showMessage(labels.GetString("Error_carga_almacen"), "TITULO");
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private async void Button_Import_Click(object sender, RoutedEventArgs e)
        {

            StringBuilder contents = new StringBuilder();
            StorageFile selectedFile2 = null;
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".pfx");
            openPicker.FileTypeFilter.Add(".p12");

            if (ApplicationView.Value == ApplicationViewState.Snapped)
            {
                if (ApplicationView.TryUnsnap())
                {
                    selectedFile2 = await openPicker.PickSingleFileAsync();
                }
            }
            else
            {                
                selectedFile2 = await openPicker.PickSingleFileAsync();
            }

            if (selectedFile2 != null)
            {
                CredentialPanel cp = new CredentialPanel();
                bool foco = cp.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                CustomDialog customDialog = new CustomDialog(cp, labels.GetString("Etiqueta_peticion_pass"));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_aceptar")));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_cancelar")));
                customDialog.DefaultCommandIndex = 0;
                customDialog.CancelCommandIndex = 1;
                IUICommand com = await customDialog.ShowAsync();

                if (com.Label.Equals(labels.GetString("Boton_aceptar")))
                    if (cp.getPassword() != null)
                        using (StreamReader reader = new StreamReader(await selectedFile2.OpenStreamForReadAsync()))
                        {
                            char[] password = cp.getPassword().ToCharArray();
                            try
                            {
                                store = new Pkcs12Store(reader.BaseStream, password);
                                if (store != null)
                                {
                                    await selectedFile2.CopyAsync(localFolder, selectedFile2.Name, NameCollisionOption.ReplaceExisting);
                                    storeData = new StoreData();
                                    storeData.LoadData();
                                    _source = storeData.GetGroupsByCategory();
                                    ItemGridView2.ItemsSource = storeData.Collection;
                                    EvaluateDeleteButton(storeData);
                                    // Le quitamos la extensión al nombre del almacén por coherencia con el borrado, que al pillarlo de la lista no tiene extensión.
                                    AfirmaMetroUtils.showMessage(labels.GetString("Info_almacen_importado") + selectedFile2.Name.Replace(selectedFile2.FileType, "") + "\".", "Importación de almacén correcta");

                                    // Lanzamos:
                                    var options = new Windows.System.LauncherOptions();
                                    options.DisplayApplicationPicker = true;
                                    var file2 = await localFolder.GetFileAsync(selectedFile2.Name);
                                    bool success = await Windows.System.Launcher.LaunchFileAsync(file2, options);

                                }
                            }
                            catch
                            {
                                AfirmaMetroUtils.showMessage(labels.GetString("Error_carga_almacen"), "Error en la importación de almacén");
                            }
                        }
            }
        }
示例#3
0
        /// <summary>
        /// Método que importa un almacén a la aplicación. Solicita la clave del almacén y verifica que es un almacén,
        /// en cuyo caso, almacenará dicho almacén en la carpeta de la aplicación para poder ser utilizado más tarde.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Import_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder contents = new StringBuilder();

            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".pfx");
            openPicker.FileTypeFilter.Add(".p12");
            StorageFile selectedFile2 = await openPicker.PickSingleFileAsync();
            
            if (selectedFile2 != null)
            {
                CredentialPanel cp = new CredentialPanel();
                cp.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                CustomDialog customDialog = new CustomDialog(cp, labels.GetString("Etiqueta_peticion_pass"));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_aceptar")));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_cancelar")));
                customDialog.DefaultCommandIndex = 0;
                customDialog.CancelCommandIndex = 1;
                IUICommand com = await customDialog.ShowAsync();

                if (com.Label.Equals(labels.GetString("Boton_aceptar")))
                    if (cp.getPassword() != null)
                        using (StreamReader reader = new StreamReader(await selectedFile2.OpenStreamForReadAsync()))
                        {
                            char[] password = cp.getPassword().ToCharArray();
                            try
                            {
                                store = new Pkcs12Store(reader.BaseStream, password);
                                if (store != null)
                                {
                                    await selectedFile2.CopyAsync(localFolder, selectedFile2.Name, NameCollisionOption.ReplaceExisting);
                                    AfirmaMetroUtils.showMessage(labels.GetString("Info_almacen_importado") + selectedFile2.Name + "\"", "Importación de almacén correcta");
                                    // Recargamos los almacenes
                                    loadStorage();
                                }
                            }
                            catch
                            {
                                AfirmaMetroUtils.showMessage(labels.GetString("Error_carga_almacen"), "TITULO");
                            }
                        }
                }
             
        }
示例#4
0
        private async void Button_Import_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder  contents      = new StringBuilder();
            StorageFile    selectedFile2 = null;
            FileOpenPicker openPicker    = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".pfx");
            openPicker.FileTypeFilter.Add(".p12");

            if (ApplicationView.Value == ApplicationViewState.Snapped)
            {
                if (ApplicationView.TryUnsnap())
                {
                    selectedFile2 = await openPicker.PickSingleFileAsync();
                }
            }
            else
            {
                selectedFile2 = await openPicker.PickSingleFileAsync();
            }

            if (selectedFile2 != null)
            {
                CredentialPanel cp           = new CredentialPanel();
                bool            foco         = cp.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                CustomDialog    customDialog = new CustomDialog(cp, labels.GetString("Etiqueta_peticion_pass"));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_aceptar")));
                customDialog.Commands.Add(new UICommand(labels.GetString("Boton_cancelar")));
                customDialog.DefaultCommandIndex = 0;
                customDialog.CancelCommandIndex  = 1;
                IUICommand com = await customDialog.ShowAsync();

                if (com.Label.Equals(labels.GetString("Boton_aceptar")))
                {
                    if (cp.getPassword() != null)
                    {
                        using (StreamReader reader = new StreamReader(await selectedFile2.OpenStreamForReadAsync()))
                        {
                            char[] password = cp.getPassword().ToCharArray();
                            try
                            {
                                store = new Pkcs12Store(reader.BaseStream, password);
                                if (store != null)
                                {
                                    await selectedFile2.CopyAsync(localFolder, selectedFile2.Name, NameCollisionOption.ReplaceExisting);

                                    storeData = new StoreData();
                                    storeData.LoadData();
                                    _source = storeData.GetGroupsByCategory();
                                    ItemGridView2.ItemsSource = storeData.Collection;
                                    EvaluateDeleteButton(storeData);
                                    // Le quitamos la extensión al nombre del almacén por coherencia con el borrado, que al pillarlo de la lista no tiene extensión.
                                    AfirmaMetroUtils.showMessage(labels.GetString("Info_almacen_importado") + selectedFile2.Name.Replace(selectedFile2.FileType, "") + "\".", "Importación de almacén correcta");

                                    // Lanzamos:
                                    var options = new Windows.System.LauncherOptions();
                                    options.DisplayApplicationPicker = true;
                                    var file2 = await localFolder.GetFileAsync(selectedFile2.Name);

                                    bool success = await Windows.System.Launcher.LaunchFileAsync(file2, options);
                                }
                            }
                            catch
                            {
                                AfirmaMetroUtils.showMessage(labels.GetString("Error_carga_almacen"), "Error en la importación de almacén");
                            }
                        }
                    }
                }
            }
        }