Esempio n. 1
0
        private async void download_Click(object sender, RoutedEventArgs e)
        {
            if (helper.checkInternetConnection())
            {
                if (enableComponent)
                {
                    plotSecurity temp = await users.fetchPlotSecurity(teamName);

                    try
                    {
                        FolderPicker picker = new FolderPicker();
                        picker.FileTypeFilter.Add("*");
                        StorageFolder folder = await picker.PickSingleFolderAsync();

                        displayLoading("Verifying ...");
                        List <object> listSelected = list.SelectedItems.ToList <object>();

                        plotSecurity current = new plotSecurity();

                        if (await current.check(temp))
                        {
                            int total = listSelected.Count;
                            int cur   = 0;
                            //helper.popup(listSelected.Count.ToString(), "");
                            foreach (files data in listSelected)
                            {
                                displayLoading("Downloading \n Files:" + cur + "/" + total + "...");
                                await users.downloadFile(data.getHost(), data.getFilename(), folder);

                                list.SelectedItems.Remove(data);
                                cur++;
                            }
                            disableLoading();
                            helper.popup("The requested file has been downloaded and saved successfully", "Downloaded");
                        }
                        else
                        {
                            disableLoading();
                            helper.popup("Access denied", "Access denied");
                        }
                    }
                    catch { }
                }
            }
            else
            {
                helper.popup("Check your internet connection", "NO INTERNET");
            }
        }
Esempio n. 2
0
        public async Task <bool> getFileFromKey()
        {
            if (enableComponent)
            {
                if (helper.checkInternetConnection())
                {
                    if (DownloadFile.Content.ToString() != "Download")
                    {
                        if (helper.checkInternetConnection())
                        {
                            if (host.Text != "" && accessKey.Text != "")
                            {
                                try
                                {
                                    displayLoading("Fetching details...");

                                    if (await users.fetchAccessKeys(host.Text, accessKey.Text) == null)
                                    {
                                        helper.popup("You have entered a invalid access key!\nEnter a valid access key", "INCORRECT ACCESS KEY");
                                        disableLoading();
                                        return(false);
                                    }

                                    plotSecurity security = await users.fetchFileSecurity(host.Text + accessKey.Text);

                                    plotSecurity currentSecurity = new plotSecurity();
                                    if (security != null)
                                    {
                                        if (await currentSecurity.check(security))
                                        {
                                            disableLoading();
                                            DownloadFile.Content = "Download";
                                            host.IsEnabled       = false;
                                            accessKey.IsEnabled  = false;
                                            preview.Visibility   = Visibility.Visible;
                                        }
                                        else
                                        {
                                            disableLoading();
                                            helper.popup("Access denied", "ACCESS DENIED");
                                        }
                                    }
                                    else
                                    {
                                        disableLoading();
                                        DownloadFile.Content = "Download";
                                        host.IsEnabled       = false;
                                        accessKey.IsEnabled  = false;
                                        preview.Visibility   = Visibility.Visible;
                                    }
                                }

                                catch
                                {
                                    disableLoading();
                                    helper.popup("You have entered a invalid access code\nEnter a valid access code.", "INVALID ACCESS CODE");
                                }
                            }
                            else
                            {
                                disableLoading();
                                helper.popup("Complete the details required to get a file", "INCOMPLETE");
                            }
                        }
                        else
                        {
                            disableLoading();
                            helper.popup("Please check your internet connection", "Connection failed");
                        }

                        disableLoading();
                    }
                    else
                    {
                        FolderPicker picker = new FolderPicker();
                        picker.FileTypeFilter.Add("*");
                        StorageFolder folder = await picker.PickSingleFolderAsync();

                        List <accessKeys> tempList = await users.fetchAccessKeys(host.Text, accessKey.Text);

                        int current = 0, total = tempList.Count;
                        displayLoading("Downloading...");

                        StorageFolder finalFolder = await folder.CreateFolderAsync("PLoT Access key - (" + accessKey.Text + ")", CreationCollisionOption.GenerateUniqueName);

                        foreach (accessKeys temp in tempList)
                        {
                            displayLoading("Downloading files...\nFile: " + current.ToString() + "/" + total);
                            await users.downloadFile(temp.host, temp.RowKey, finalFolder);

                            current++;
                        }
                        disableLoading();
                        helper.popup("All the files are successfully downloaded and saved!", "DOWNLOAD COMPLETE");
                        navigationHelper.GoBack();
                    }
                }
                else
                {
                    helper.popup("Check your internet connection", "NO INTERNET");
                }
            }
            return(true);
        }