aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Build_STUBS_GUI_INSTALLER.bat
blob: fc349006daca9c9cf7ba65e4196a2f39a65ddd78 (plain)
1
2
3
4
5
6
cd Visual_Studio
@echo Building Tango.Stubs.Installer project...
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe" Utilities\Tango.Stubs.Installer\Tango.Stubs.Installer.vdproj /build Debug
@echo.
@echo Done!
Pause
t .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using FluentFTP;
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.Fluent;

namespace Tango.AzureUtils.FTP
{
    public class FtpManager : AzureUtilsComponentBase
    {
        private IProgress<FtpProgress> _ftpDownloadProgress;
        private IProgress<FtpProgress> _ftpUploadProgress;
        private String _currentDownloadFile;

        public FtpManager(IAzure azure) : base(azure)
        {
            _ftpDownloadProgress = new Progress<FtpProgress>((p) =>
            {
                OnProgress(AzureUtilsStage.FtpDownload, $"Downloading {_currentDownloadFile}...", p.Progress, 100, false);
            });

            _ftpUploadProgress = new Progress<FtpProgress>((p) =>
            {
                OnProgress(AzureUtilsStage.FtpUpload, $"Uploading {_currentDownloadFile}...", p.Progress, 100, false);
            });
        }

        private FtpClient CreateFtpClient(String address, String userName, String password)
        {
            Uri uri = new Uri("ftp://" + address);
            string host = uri.Host;

            FtpClient client = new FtpClient(host, userName, password);
            //client.EncryptionMode = FtpEncryptionMode.Explicit;
            client.SslProtocols = SslProtocols.Tls;
            client.ValidateAnyCertificate = true;
            client.DataConnectionType = FtpDataConnectionType.PASV;
            client.DownloadDataType = FtpDataType.Binary;
            client.RetryAttempts = 5;
            client.SocketPollInterval = 1000;
            client.ConnectTimeout = 2000;
            client.ReadTimeout = 2000;
            client.DataConnectionConnectTimeout = 2000;
            client.DataConnectionReadTimeout = 2000;
            client.OnLogEvent = (ev, msg) => 
            {
                if (msg.Contains("DownloadFileAsync") || msg.Contains("UploadFileAsync"))
                {
                    var matches = Regex.Matches(msg, "(?<=\").+?(?=\")");
                    var match = matches.OfType<Match>().LastOrDefault();

                    if (match != null)
                    {
                        _currentDownloadFile = match.ToString();
                    }
                }
            };

            return client;
        }

        public async Task<List<FtpResult>> DownloadWebAppFiles(IWebAppBase app, String targetFolder)
        {
            OnProgress(AzureUtilsStage.FtpDownload, $"Downloading web app files for '{app.Name}'...");

            var profile = await app.GetPublishingProfileAsync();

            using (var ftp = CreateFtpClient(profile.FtpUrl, profile.FtpUsername, profile.FtpPassword))
            {
                await ftp.ConnectAsync();
                var downloadResults = await ftp.DownloadDirectoryAsync(targetFolder, "/site/wwwroot", progress: _ftpDownloadProgress);

                foreach (var downloadResult in downloadResults)
                {
                    if (downloadResult.IsFailed)
                    {
                        throw downloadResult.Exception;
                    }
                }

                return downloadResults;
            }
        }

        public async Task<List<FtpResult>> UploadWebAppFiles(IWebAppBase app, String sourceFolder)
        {
            OnProgress(AzureUtilsStage.FtpUpload, $"Uploading web app files for '{app.Name}'...");

            var profile = await app.GetPublishingProfileAsync();

            using (var ftp = CreateFtpClient(profile.FtpUrl, profile.FtpUsername, profile.FtpPassword))
            {
                var uploadResults = await ftp.UploadDirectoryAsync(sourceFolder, "/site/wwwroot", existsMode: FtpRemoteExists.Overwrite, progress: _ftpUploadProgress);

                foreach (var uploadResult in uploadResults)
                {
                    if (uploadResult.IsFailed)
                    {
                        throw uploadResult.Exception;
                    }
                }

                return uploadResults;
            }
        }

        public async Task CopyAppFiles(IWebAppBase sourceApp, IWebAppBase targetApp)
        {
            var webAppFilesTempFolder = TemporaryManager.CreateFolder();
            var downloadResults = await DownloadWebAppFiles(sourceApp, webAppFilesTempFolder);
            var uploadResults = await UploadWebAppFiles(targetApp, webAppFilesTempFolder);
        }

        public async Task<String> GetMachineServiceVersion(IWebAppBase app)
        {
            var exeTempFile = TemporaryManager.CreateImaginaryFile(".dll");

            var profile = await app.GetPublishingProfileAsync();

            using (var ftp = CreateFtpClient(profile.FtpUrl, profile.FtpUsername, profile.FtpPassword))
            {
                await ftp.ConnectAsync();
                await ftp.DownloadFileAsync(exeTempFile, "/site/wwwroot/bin/Tango.MachineService.dll");
                String version =  FileVersionInfo.GetVersionInfo(exeTempFile).ProductVersion;
                await exeTempFile.DeleteAsync();
                return version;
            }
        }
    }
}