Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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;
        }