Пример #1
0
        /// <summary>
        /// Resolves the provided package into a local file system directory path
        /// </summary>
        /// <param name="package">The package to which the target should be located</param>
        /// <param name="basePath">The resolved file system directory path</param>
        /// <returns>True if the package could be resolved to a specific path, false otherwise</returns>
        public static bool GetLocation(PackageTarget package, ref PathDescriptor basePath)
        {
            if (packageLocations.Count > 0)
            {
                Filter filter = new Filter();
                foreach (KeyValuePair <string, string> location in packageLocations)
                {
                    FilterToken last = null;
                    filter.Clear();

                    string[] tiles = location.Key.Split('.');
                    foreach (string tile in tiles)
                    {
                        FilterToken current = null;
                        if (last != null)
                        {
                            current = last.GetChild(tile);
                        }
                        if (current == null)
                        {
                            if (last != null)
                            {
                                current = filter.Add(last, tile);
                            }
                            else
                            {
                                current = filter.Add(tile);
                            }
                        }
                        last = current;
                    }
                    if (filter.IsMatch(package.Id.Owner, package.Id.Namespace, package.Id.Name))
                    {
                        basePath = basePath.Combine
                                   (
                            location.Value.Replace("[id]", package.FriendlyName(false))
                            .Replace("[owner]", package.Id.Owner.ToUpper())
                            .Replace("[namespace]", package.Id.Namespace.ToTitleCase())
                            .Replace("[name]", package.Id.Name.FromPackageName())
                                   );
                        return(true);
                    }
                }
            }
            basePath = basePath.Combine(DefaultPackageLocation, package.FriendlyName(false));
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Tries to convert a given string into a valid target
        /// </summary>
        /// <param name="value">A string in <owner>.<namespace>.<name>@<version> format</param>
        /// <returns>True if parsing the string was successful, false otherwise</returns>
        public static bool TryParse(string value, out PackageTarget result)
        {
            result = new PackageTarget();
            StringBuilder textBuffer = new StringBuilder(value);

            for (int i = 0; i <= textBuffer.Length; i++)
            {
                string buffer;
                if (i == textBuffer.Length)
                {
                    buffer = textBuffer.ToString().Trim();
                    textBuffer.Clear();
                }
                else if (textBuffer[i] == '@')
                {
                    buffer = textBuffer.ToString(0, i).Trim();
                    textBuffer.Remove(0, i + 1);
                }
                else
                {
                    continue;
                }
                PackageId tmp; if (PackageId.TryParse(buffer, out tmp))
                {
                    result.id = tmp;
                    break;
                }
                else
                {
                    return(false);
                }
            }
            if (textBuffer.Length > 0)
            {
                result.version = PackageVersion.Create(textBuffer.ToString().Trim());
                if (!result.version.IsValid)
                {
                    return(false);
                }
            }
            return(result.id.IsValid);
        }
Пример #3
0
 /// <summary>
 /// Creates a new dependency instance from the provided target
 /// </summary>
 public PackageTarget(PackageTarget target)
 {
     this.id           = target.id;
     this.version      = target.version;
     this.isDependency = true;
 }