private async Task FetchCurrentRedirections()
        {
            if (ListItems.Count > 0)
            {
                ListItems.Clear();
            }
            FetchRedirectionsStatusTextBlock.Text = "Working...";
            List <FTPItem> listing = await FTPManager.GetDirectoryContents("/go", true);

            for (int i = 0; i < listing.Count; i++)
            {
                FTPItem currentItem = listing[i];
                if (!currentItem.IsDirectory)
                {
                    continue; // exclude .htaccess
                }
                else if (Utils.IsProtectedDirectory(currentItem.Name))
                {
                    continue; // exclude protected and error page directories
                }
                ListItems.Add(new TextBlock()
                {
                    Text = currentItem.Name
                });
            }
            CurrentRedirectionsListView.ItemsSource = ListItems;
        }
        private async void FetchDestination(string url)
        {
            DestinationTextBlock.Visibility   = Visibility.Collapsed;
            DestinationProgressBar.Visibility = Visibility.Visible;
            // get the actual html file
            StorageFile file = await FTPManager.Download("/go/" + url + "/", "index.html", true);

            string contents = await FileManager.GetFileContents(file), delimiter = "window.location=\"";

            string extractedDestination = "";

            if (contents.IndexOf(delimiter) != -1)
            {
                // extract destination
                extractedDestination = contents.Substring(contents.IndexOf(delimiter) + delimiter.Length);
            }
            else
            {
                // something went wrong
                extractedDestination = "There was an error while parsing\"";
            }
            // update UI
            DestinationTextBlock.Text = extractedDestination.Substring(0, extractedDestination.IndexOf("\""));
            Destination = DestinationTextBlock.Text;
            DestinationTextBlock.Visibility   = Visibility.Visible;
            DestinationProgressBar.Visibility = Visibility.Collapsed;
            IsPrimaryButtonEnabled            = true;
        }
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (FTPManager.Connected == true)
            {
                await FTPManager.Disconnect();
            }

            Hide();
        }
 private async void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     // OK
     if (FTPManager.Connected)
     {
         // disconnect if still connected
         await FTPManager.Disconnect();
     }
     Hide();
 }
示例#5
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (!FTPManager.ConfigurationLoaded)
            {
                FTPManager.LoadConfiguration();
            }
            UsernameTextBox.Text     = FTPManager.Username;
            PasswordTextBox.Password = FTPManager.Password;
            ServerTextBox.Text       = FTPManager.Server;

            BlankDeployCheckBox.IsChecked      = DeveloperOptions.GetBlankDeploy();
            UseTestDirectoryCheckBox.IsChecked = DeveloperOptions.GetUseTestDirectory();
            LocalDeployCheckBox.IsChecked      = DeveloperOptions.GetLocalDeploy();
        }
示例#6
0
        private async void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            Working(true);

            bool rename = RenameTextBox.Text.Length != 0;
            bool delete = (bool)ConfirmationCheckBox.IsChecked;

            // take action on applications
            if (delete)
            {
                await FTPManager.Connect();

                await FTPManager.DeleteFile("/go/" + URL + "/index.html");

                await FTPManager.DeleteDirectory("/go/" + URL);

                await FTPManager.Disconnect();

                // already deleted, can't delete again!
                DeleteRedirectionCheckBox.IsEnabled = false;
                // doesn't go anywhere!
                DestinationTextBlock.Text = "404 Not Found";
                Title = "(Removed)";
                // remove from existing redirections list view
                App.RedirectionRemoved            = true;
                App.RemovedRedirectionListItemURL = URL;
            }
            else if (rename)
            {
                // TODO: rename short URL
            }
            else
            {
                // should never reach here (hopefully!)
            }
            Working(false);
            Apply(false);
            Deleted();
        }
        private async Task DeployRedirection(string url, string destination)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            string path = "/go/" + url;

            MakeRedirectionStatusTextBlock.Text = "Writing file...";
            StorageFile file = await FileManager.CreateTemporaryFile(HTMLBuilder.GetRedirectionHTML(destination));

            MakeRedirectionStatusTextBlock.Text = "Connecting...";
            await FTPManager.Connect();

            MakeRedirectionStatusTextBlock.Text = "Checking for \"/" + url + "\"...";
            ExistsError = await FTPManager.GetDirectoryExists(path);

            if (!ExistsError)
            {
                MakeRedirectionStatusTextBlock.Text = "Creating \"/" + url + "\"...";
                await FTPManager.CreateDirectory(path);

                MakeRedirectionStatusTextBlock.Text = "Uploading file...";
                await FTPManager.UploadFile(file, path);
            }
            MakeRedirectionStatusTextBlock.Text = "Disconnecting...";
            await FTPManager.Disconnect();

            MakeRedirectionStatusTextBlock.Text = "Deleting file...";
            await file.DeleteAsync();
        }
        private async Task Deploy()
        {
            DateTime start    = DateTime.Now;
            double   interval = 100.0 / DeployPages.Count;
            int      i        = 1;

            DeployProgressBar.Value = 0;

            bool test  = DeveloperOptions.GetUseTestDirectory();
            bool blank = DeveloperOptions.GetBlankDeploy();

            if (DeveloperOptions.GetLocalDeploy())
            {
                StorageFolder deployFolder = null;
                if (await FileManager.GetExists(ApplicationData.Current.LocalFolder, "deploy"))
                {
                    deployFolder = (StorageFolder)(await ApplicationData.Current.LocalFolder.TryGetItemAsync("deploy"));
                    await deployFolder.DeleteAsync();
                }
                deployFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("deploy");

                foreach (ManagedWebPage page in DeployPages)
                {
                    StatusTextBlock.Text = $"{(DeployProgressBar.Value.ToString("0.00") + "%")} complete ({i} of {DeployPages.Count})";
                    Log($"\"{page.Title}\"... (Creating...)");

                    StorageFile indexHtml = await FileManager.CreateTemporaryFile(HTMLBuilder.GetFullPageHTML(page));

                    StorageFolder pageFolder = deployFolder, prev = deployFolder;
                    if (page.RelativeURL.Length > 1)
                    {
                        // recursively create folders
                        String[] dirs = page.RelativeURL.Split('/');
                        for (int ii = 0; ii < dirs.Length; ii++)
                        {
                            if (dirs[ii].Equals(""))
                            {
                                continue;
                            }
                            StorageFolder temp = prev;
                            if (await prev.TryGetItemAsync(dirs[ii]) == null)
                            {
                                prev = await temp.CreateFolderAsync(dirs[ii]);
                            }
                            else
                            {
                                prev = (StorageFolder)await temp.TryGetItemAsync(dirs[ii]);
                            }
                            pageFolder = prev;
                        }
                    }

                    // copy from temp to deploy
                    if (pageFolder != null)
                    {
                        await indexHtml.CopyAsync(pageFolder); // not home page, and needs its own directory
                    }
                    else
                    {
                        await indexHtml.CopyAsync(deployFolder); // must be home page
                    }
                    await indexHtml.DeleteAsync();

                    LogTextBlock.Text        = LogTextBlock.Text.Replace("(Creating...)", "(Done)");
                    DeployProgressBar.Value += interval;
                    i++;
                    page.Submitted();
                }
                // save because submitted times were updated
                await WebPageManager.Save();

                DeployProgressBar.Value = 100;
                StatusTextBlock.Text    = $"Finished ({(DateTime.Now.Subtract(start).TotalSeconds.ToString("0.0"))} seconds)";
                IsPrimaryButtonEnabled  = true;

                Log("Opening in File Explorer...");
                await Windows.System.Launcher.LaunchFolderAsync(deployFolder);

                return;
            }

            await FTPManager.Connect();

            // await Task.Delay(5000);
            // await FTPManager.Disconnect();
            Debug.Out("Connected!", "DEPLOY DIALOG");
            foreach (ManagedWebPage page in DeployPages)
            {
                string path = page.RelativeURL;
                if (test)
                {
                    path = $"/test{path}";
                }
                string percent = DeployProgressBar.Value.ToString("0.00") + "%";
                string msg     = "\"" + page.RelativeURL + "\"... (Uploading...)";

                StatusTextBlock.Text = percent + " complete (" + i + " of " + DeployPages.Count + ")";

                Log(msg);
                if (!blank)
                {
                    StorageFile file = await FileManager.CreateTemporaryFile(HTMLBuilder.GetFullPageHTML(page));

                    await FTPManager.UploadFile(file, path);

                    await file.DeleteAsync();

                    LogTextBlock.Text = LogTextBlock.Text.Replace("(Uploading...)", "(Finished)");
                }

                DeployProgressBar.Value += interval;
                i++;

                page.Submitted();
            }
            await FTPManager.Disconnect();

            // save because submitted times were updated
            await WebPageManager.Save();

            string timeTaken = DateTime.Now.Subtract(start).TotalSeconds.ToString("0.0");

            DeployProgressBar.Value = 100;
            StatusTextBlock.Text    = "Finished (" + timeTaken + " seconds)";
            IsPrimaryButtonEnabled  = true;
        }