コード例 #1
0
ファイル: TagsService.cs プロジェクト: shukriadams/tetrifact
        public void RemoveTag(string packageId, string tag)
        {
            string manifestPath = Path.Combine(_settings.PackagePath, packageId, "manifest.json");
            if (!File.Exists(manifestPath))
                throw new PackageNotFoundException(packageId);

            string targetPath = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag), packageId);
            if (File.Exists(targetPath))
                File.Delete(targetPath);

            // flush in-memory tags
            _packageListCache.Clear();
        }
コード例 #2
0
ファイル: TagsService.cs プロジェクト: shukriadams/tetrifact
        /// <summary>
        /// Gets packages with tags from the tag index.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public IEnumerable<string> GetPackageIdsWithTags(string[] tags)
        {
            IEnumerable<string> matches = new List<string>();

            foreach (string tag in tags) {
                string tagDirectory = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag));
                if (!Directory.Exists(tagDirectory))
                    throw new TagNotFoundException();

                string[] files = Directory.GetFiles(tagDirectory);
                matches = matches.Union(files.Select(r => Path.GetFileName(r)));
            }

            return matches;
        }
コード例 #3
0
ファイル: TagsService.cs プロジェクト: shukriadams/tetrifact
        public void AddTag(string packageId, string tag)
        {
            string manifestPath = Path.Combine(_settings.PackagePath, packageId, "manifest.json");
            if (!File.Exists(manifestPath))
                throw new PackageNotFoundException(packageId);

            // write tag to fs
            string targetFolder = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag));
            Directory.CreateDirectory(targetFolder);
            
            string targetPath = Path.Combine(targetFolder, packageId);
            if (!File.Exists(targetPath))
                File.WriteAllText(targetPath, string.Empty);

            // flush in-memory tags
            _packageListCache.Clear();
        }
コード例 #4
0
        /// <summary>
        /// "Decrypts" uniform string into FileIdentifier instance exposing its path and hash.
        /// </summary>
        /// <param name="cloakedId"></param>
        /// <returns></returns>
        public static FileIdentifier Decloak(string cloakedId)
        {
            cloakedId = Obfuscator.Decloak(cloakedId);
            Regex           regex   = new Regex("(.*)::(.*)");
            MatchCollection matches = regex.Matches(cloakedId);

            if (matches.Count() != 1)
            {
                throw new InvalidFileIdentifierException(cloakedId);
            }

            return(new FileIdentifier
            {
                Path = matches[0].Groups[1].Value,
                Hash = matches[0].Groups[2].Value
            });
        }
コード例 #5
0
ファイル: TagsService.cs プロジェクト: shukriadams/tetrifact
        /// <summary>
        /// Gets a list of all tags from tag index folder. Tags are not read from package manifests. 
        /// </summary>
        /// <returns></returns>
        public IEnumerable<string> GetAllTags()
        {
            string[] rawTags = Directory.GetDirectories(_settings.TagsPath);
            List<string> tags = new List<string>();

            foreach (string rawTag in rawTags)
            {
                try
                {
                    tags.Add(Obfuscator.Decloak(Path.GetFileName(rawTag)));
                }
                catch (FormatException)
                {
                    // log invalid tag folders, and continue.
                    _logger.LogError($"The tag \"{rawTag}\" is not a valid base64 string. This node in the tags folder should be pruned out.");
                }
            }

            return tags;
        }
コード例 #6
0
ファイル: TagsService.cs プロジェクト: shukriadams/tetrifact
        /// <summary>
        /// Gets a list of all tags, and all packages tagged by each tag.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, IEnumerable<string>> GetTagsThenPackages()
        {
            string[] rawTags = Directory.GetDirectories(_settings.TagsPath);
            Dictionary<string, IEnumerable<string>> tags = new Dictionary<string, IEnumerable<string>>();

            foreach (string rawTag in rawTags)
            {
                try
                {
                    IEnumerable<string> packages = Directory.GetFiles(rawTag).Select(r => Path.GetFileName(r));
                    tags.Add(Obfuscator.Decloak(Path.GetFileName(rawTag)), packages);
                }
                catch (FormatException)
                {
                    // log invalid tag folders, and continue.
                    _logger.LogError($"The tag \"{rawTag}\" is not a valid base64 string. This node in the tags folder should be pruned out.");
                }
            }

            return tags;
        }
コード例 #7
0
 /// <summary>
 /// Returns uniform string from Path+Hash
 /// </summary>
 /// <param name="path"></param>
 /// <param name="hash"></param>
 /// <returns></returns>
 public static string Cloak(string path, string hash)
 {
     return(Obfuscator.Cloak($"{path}::{hash}"));
 }