Exemplo n.º 1
0
        private static bool EnsureMinimalCompilerVersion()
        {
            // Check against compiler's informational version as well, so we don't allow a
            // prerelease package to be used against the corresponding stable release build
            // of Bridge CLI.
            if (Constants.MinBridgeVersion > BridgeVersion.GetCompilerInformationalVersion())
            {
                Error($"Minimum required version of Bridge compiler is {Constants.MinBridgeVersion}. Your version: {BridgeVersion.GetCompilerInformationalVersion()}.");

                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
 private static void EnsureProperty(dynamic obj, string name)
 {
     if (!IsPropertyExist(obj, name))
     {
         throw new InvalidOperationException($"'{name}' property doesn't exist in '{obj.GetType().FullName}'. Core version: {BridgeVersion.GetCompilerInformationalVersion()}");
     }
 }
Exemplo n.º 3
0
 private static void ShowVersion()
 {
     Console.WriteLine(BridgeVersion.GetCompilerInformationalVersion());
 }
Exemplo n.º 4
0
        private static PackageRequestResult RequestPackage(string repoPath, string packageName, string version, string localFile, string packagesFolder)
        {
            var  result     = new PackageRequestResult();
            bool hasVersion = !string.IsNullOrWhiteSpace(version);

            try
            {
                if (Directory.Exists(repoPath))
                {
                    string name = null;
                    if (hasVersion)
                    {
                        name = packageName + "." + version;
                    }
                    else
                    {
                        var packages    = Directory.GetFiles(repoPath, "*.nupkg", SearchOption.TopDirectoryOnly);
                        var escapedName = packageName.Replace(".", @"\.");

                        string pattern = "\\A" + escapedName + "\\.\\d+(\\.\\d+){2}\\z";

                        // Prerelease-aware pattern
                        if (Program.EnablePrerelease)
                        {
                            pattern = "\\A" + escapedName + "\\.\\d+(\\.\\d+){2}(|-.*)\\z";
                        }

                        version = null;
                        InformationalVersion latestVersion = null;

                        foreach (var p in packages)
                        {
                            var pName = Path.GetFileNameWithoutExtension(p);
                            if (Regex.IsMatch(pName, pattern, RegexOptions.IgnoreCase))
                            {
                                var pVersion = new InformationalVersion(pName.Substring(packageName.Length + 1));

                                if (latestVersion == null)
                                {
                                    latestVersion = pVersion;
                                }
                                else if (pVersion > latestVersion)
                                {
                                    latestVersion = pVersion;
                                }
                            }
                        }

                        if (latestVersion == null)
                        {
                            return(result);
                        }

                        BridgeVersion.ValidatePackageVersion(packageName, repoPath, latestVersion);

                        name = packageName + "." + latestVersion;
                    }

                    name = name[0].ToString().ToUpper() + name.Substring(1);
                    var packageFolder = Path.Combine(packagesFolder, name);

                    result.Folder = packageFolder;
                    if (Directory.Exists(packageFolder))
                    {
                        result.Exists  = true;
                        result.Success = true;
                    }
                    else
                    {
                        var packageFile = Path.Combine(repoPath, name + ".nupkg");

                        if (File.Exists(packageFile))
                        {
                            File.Copy(packageFile, localFile, true);
                            result.Success = true;
                        }
                        else
                        {
                            result.Success = false;
                        }
                    }
                }
                else
                {
                    var isFile = true;

                    try
                    {
                        var uri = new Uri(repoPath);
                        isFile = uri.IsFile;
                    }
                    catch (Exception)
                    {
                    }

                    if (!isFile)
                    {
                        if (!repoPath.EndsWith("/"))
                        {
                            repoPath += "/";
                        }

                        string uri  = repoPath + packageName + (hasVersion ? "/" + version : "");
                        string name = null;

                        if (hasVersion)
                        {
                            name = packageName + "." + version;
                        }
                        else
                        {
                            var webRequest = (HttpWebRequest)WebRequest.Create(uri + "?" + new Random().Next());
                            webRequest.AllowAutoRedirect = false;
                            var webResponse = (HttpWebResponse)webRequest.GetResponse();

                            if (!String.IsNullOrEmpty(webResponse.Headers["Location"]))
                            {
                                var fileName = System.IO.Path.GetFileName(webResponse.Headers["Location"]);
                                name = Path.GetFileNameWithoutExtension(fileName);
                            }

                            BridgeVersion.ValidatePackageVersion(packageName, repoPath, name.Substring(packageName.Length + 1));

                            webResponse.Dispose();
                        }

                        name = name[0].ToString().ToUpper() + name.Substring(1);
                        var packageFolder = Path.Combine(packagesFolder, name);

                        result.Folder = packageFolder;
                        if (Directory.Exists(packageFolder))
                        {
                            result.Exists  = true;
                            result.Success = true;
                        }
                        else
                        {
                            WebClient client = new WebClient();
                            client.DownloadFile(uri, localFile);
                            client.Dispose();
                            result.Success = true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result.Success   = false;
                result.Exception = new Exception("Package request failed.", e);
            }

            return(result);
        }