예제 #1
0
        public static void AddPackageDescriptionMetadata(TentaclesListJson packageDescription, string localisation, bool isUrl)
        {
            string toSaveLoc = localisation;

            if (localisation.EndsWith(TentaclesManagerVars.TENTACLES_PUBLIC_LIST) == true)
            {
                toSaveLoc = localisation.Substring(0, localisation.Length - TentaclesManagerVars.TENTACLES_PUBLIC_LIST.Length);

                while (toSaveLoc.EndsWith("/") || toSaveLoc.EndsWith("\\"))
                {
                    toSaveLoc = toSaveLoc.Substring(0, toSaveLoc.Length - 1);
                }
            }

            if (packageDescription.PackageDescription == null)
            {
                packageDescription.PackageDescription = new PackageDescription()
                {
                    Localisation = new Uri(toSaveLoc),
                    Name         = GetPackageName(localisation, isUrl),
                    IsUrl        = isUrl
                }
            }
            ;
            else
            {
                packageDescription.PackageDescription.Localisation = new Uri(toSaveLoc);
                packageDescription.PackageDescription.Name         = GetPackageName(localisation, isUrl);
                packageDescription.PackageDescription.IsUrl        = isUrl;
            }
        }
예제 #2
0
        public static bool HasRequiredPackage(TentaclesListJson package, string componentName, string componentVersion = null)
        {
            if (package.ListPuneHedgehog.ContainsKey(componentName) == true)
            {
                var component = package.ListPuneHedgehog[componentName];

                if (componentVersion != "")
                {
                    return(component.Version == componentVersion);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        public static TentaclesListJson GetPackageDescription(string urlOrPath, bool tryToAdapt = false, string gitBranch = "")
        {
            if (gitBranch == "")
            {
                gitBranch = TentaclesManagerVars.TENTACLES_DEFAULT_BRANCH;
            }

            string packageUrlOrPath = urlOrPath;

            // if its an url: download with requests.get and return text
            if (GetIsUrl(packageUrlOrPath) == true)
            {
                if (tryToAdapt == true)
                {
                    if (packageUrlOrPath.EndsWith("/") == false)
                    {
                        packageUrlOrPath += "/";
                    }

                    // if checking on github, try adding branch and file
                    if (packageUrlOrPath.Contains(TentaclesManagerVars.GITHUB) == true)
                    {
                        packageUrlOrPath += $"{gitBranch}/{TentaclesManagerVars.TENTACLES_PUBLIC_LIST}";
                    }
                    // else try adding file
                    else
                    {
                        packageUrlOrPath += TentaclesManagerVars.TENTACLES_PUBLIC_LIST;
                    }
                }

                TentaclesListJson downloadedResult = TentaclesListJson.FromJson(FileUtilities.GetFileContents($"Config/{TentaclesManagerVars.TENTACLES_PUBLIC_LIST}"));

                PropertyInfo[] lst = downloadedResult.GetType().GetProperties();
                foreach (PropertyInfo pi in lst)
                {
                    var type = pi.PropertyType;
                    if (type == typeof(TentacleModule))
                    {
                        downloadedResult.ListPuneHedgehog.Add(pi.Name, (TentacleModule)pi.GetValue(downloadedResult));
                    }
                }

                if (downloadedResult == null && packageUrlOrPath.Contains(TentaclesManagerVars.GITHUB_BASE_URL) == true)
                {
                    Debug.WriteLine(1);
                }

                // add package metadata
                AddPackageDescriptionMetadata(downloadedResult, packageUrlOrPath, true);

                return(downloadedResult);
            }
            // if its a local path: return file content
            else
            {
                Debug.WriteLine(1);

                return(null);
            }
        }