Exemplo n.º 1
0
        /// <nodoc />
        public DownloadData(
            FrontEndContext context,
            IDownloadFileSettings settings,
            Uri downloadUri,
            AbsolutePath resolverRoot,
            ContentHash?contentHash)
        {
            Contract.Requires(context != null);
            Contract.Requires(settings != null);
            Contract.Requires(downloadUri != null);
            Contract.Requires(resolverRoot.IsValid);

            Settings    = settings;
            DownloadUri = downloadUri;

            ModuleRoot = resolverRoot.Combine(context.PathTable, settings.ModuleName);

            var fileName = settings.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Path.GetFileName(downloadUri.AbsolutePath.TrimEnd(new[] { '/', '\\' }));
            }

            DownloadedFilePath = ModuleRoot.Combine(context.PathTable, "f").Combine(context.PathTable, fileName);

            ContentsFolder = settings.ArchiveType == DownloadArchiveType.File ? DirectoryArtifact.Invalid : DirectoryArtifact.CreateWithZeroPartialSealId(ModuleRoot.Combine(context.PathTable, "c"));

            ModuleConfigFile     = ModuleRoot.Combine(context.PathTable, "module.config.dsc");
            ModuleSpecFile       = ModuleRoot.Combine(context.PathTable, "project.dsc");
            DownloadManifestFile = ModuleRoot.Combine(context.PathTable, "manifest.download.txt");
            ExtractManifestFile  = ModuleRoot.Combine(context.PathTable, "manifest.extract.txt");

            ContentHash = contentHash;
        }
Exemplo n.º 2
0
 /// <nodoc />
 public DownloadFileSettings(IDownloadFileSettings template)
 {
     ModuleName  = template.ModuleName;
     Url         = template.Url;
     FileName    = template.FileName;
     ArchiveType = template.ArchiveType;
     Hash        = template.Hash;
 }
Exemplo n.º 3
0
 /// <nodoc />
 public DownloadFileSettings(IDownloadFileSettings template)
 {
     ModuleName          = template.ModuleName;
     Url                 = template.Url;
     FileName            = template.FileName;
     ArchiveType         = template.ArchiveType;
     Hash                = template.Hash;
     DownloadedValueName = template.DownloadedValueName;
     ExtractedValueName  = template.ExtractedValueName;
 }
Exemplo n.º 4
0
        private string DownloadSettingsToDScript(IDownloadFileSettings settings)
        {
            return($@"
{{
    moduleName: '{settings.ModuleName}',
    url: '{settings.Url}',
    archiveType: '{settings.ArchiveType.ToString().ToLower(CultureInfo.InvariantCulture)}',
    {(!string.IsNullOrEmpty(settings.Hash) ? $"hash: '{settings.Hash}'," : string.Empty)}
    {(!string.IsNullOrEmpty(settings.ExtractedValueName) ? $"extractedValueName: '{settings.ExtractedValueName}'," : string.Empty)}
    {(!string.IsNullOrEmpty(settings.DownloadedValueName) ? $"downloadedValueName: '{settings.DownloadedValueName}'," : string.Empty)}
}}");
        }
Exemplo n.º 5
0
        private bool ValidateAndExtractDownloadData(
            FrontEndContext context,
            IDownloadFileSettings downloadSettings,
            Dictionary <string, DownloadData> downloads,
            AbsolutePath resolverFolder,
            out DownloadData downloadData)
        {
            downloadData = null;
            if (string.IsNullOrEmpty(downloadSettings.ModuleName))
            {
                Logger.Log.DownloadFrontendMissingModuleId(m_context.LoggingContext, downloadSettings.Url);
                return(false);
            }

            if (downloads.ContainsKey(downloadSettings.ModuleName))
            {
                Logger.Log.DownloadFrontendDuplicateModuleId(m_context.LoggingContext, downloadSettings.ModuleName, Kind, Name);
                return(false);
            }

            if (string.IsNullOrEmpty(downloadSettings.Url))
            {
                Logger.Log.DownloadFrontendMissingUrl(m_context.LoggingContext, downloadSettings.ModuleName);
                return(false);
            }

            if (!Uri.TryCreate(downloadSettings.Url, UriKind.Absolute, out var downloadLocation))
            {
                Logger.Log.DownloadFrontendInvalidUrl(m_context.LoggingContext, downloadSettings.ModuleName, downloadSettings.Url);
                return(false);
            }

            ContentHash?contentHash;

            if (string.IsNullOrEmpty(downloadSettings.Hash))
            {
                contentHash = null;
            }
            else
            {
                if (!ContentHash.TryParse(downloadSettings.Hash, out var hash))
                {
                    Logger.Log.DownloadFrontendHashValueNotValidContentHash(m_context.LoggingContext, downloadSettings.ModuleName, downloadSettings.Url, downloadSettings.Hash);
                    return(false);
                }

                contentHash = hash;
            }

            downloadData = new DownloadData(context, downloadSettings, downloadLocation, resolverFolder, contentHash);
            return(true);
        }
        private bool ValidateAndExtractDownloadData(
            FrontEndContext context,
            IDownloadFileSettings downloadSettings,
            Dictionary <string, DownloadData> downloads,
            AbsolutePath resolverFolder,
            out DownloadData downloadData)
        {
            downloadData = null;
            if (string.IsNullOrEmpty(downloadSettings.ModuleName))
            {
                Logger.Log.DownloadFrontendMissingModuleId(m_context.LoggingContext, downloadSettings.Url);
                return(false);
            }

            if (downloads.ContainsKey(downloadSettings.ModuleName))
            {
                Logger.Log.DownloadFrontendDuplicateModuleId(m_context.LoggingContext, downloadSettings.ModuleName, Kind, Name);
                return(false);
            }

            if (string.IsNullOrEmpty(downloadSettings.Url))
            {
                Logger.Log.DownloadFrontendMissingUrl(m_context.LoggingContext, downloadSettings.ModuleName);
                return(false);
            }

            if (!Uri.TryCreate(downloadSettings.Url, UriKind.Absolute, out var downloadLocation))
            {
                Logger.Log.DownloadFrontendInvalidUrl(m_context.LoggingContext, downloadSettings.ModuleName, downloadSettings.Url);
                return(false);
            }

            ContentHash?contentHash;

            if (string.IsNullOrEmpty(downloadSettings.Hash))
            {
                contentHash = null;
            }
            else
            {
                if (!ContentHash.TryParse(downloadSettings.Hash, out var hash))
                {
                    Logger.Log.DownloadFrontendHashValueNotValidContentHash(m_context.LoggingContext, downloadSettings.ModuleName, downloadSettings.Url, downloadSettings.Hash);
                    return(false);
                }

                contentHash = hash;
            }

            // For these last two validations, the TS parser would also complain, but we just give a more targeted error before that happens.
            if (!string.IsNullOrEmpty(downloadSettings.DownloadedValueName) && !SymbolAtom.TryCreate(context.StringTable, downloadSettings.DownloadedValueName, out _))
            {
                Logger.Log.NameContainsInvalidCharacters(m_context.LoggingContext, "downloadedValueName", downloadSettings.DownloadedValueName);
                return(false);
            }

            if (!string.IsNullOrEmpty(downloadSettings.ExtractedValueName) && !SymbolAtom.TryCreate(context.StringTable, downloadSettings.ExtractedValueName, out _))
            {
                Logger.Log.NameContainsInvalidCharacters(m_context.LoggingContext, "extractedValueName", downloadSettings.ExtractedValueName);
                return(false);
            }

            downloadData = new DownloadData(context, downloadSettings, downloadLocation, resolverFolder, contentHash, downloadSettings.DownloadedValueName, downloadSettings.ExtractedValueName);
            return(true);
        }