示例#1
0
        public void GuidThingTest()
        {
            var guid = new Guid("f918382f-2bba-453f-a3e2-1f594016ed3b");

            Assert.AreEqual("f22br4n0fm5fli5c", GuidUtils.ToBase32String(guid, 16));
            Assert.AreEqual("f22br4n0f", GuidUtils.ToBase32String(guid, 9));
        }
        public static string CreateShadowId()
        {
            const int retries  = 50; // avoid infinite loop
            const int idLength = 8;  // 6 chars

            // shorten a Guid to idLength chars, and see whether it collides
            // with an existing directory or not - if it does, try again, and
            // we should end up with a unique identifier eventually - but just
            // detect infinite loops (just in case)

            for (var i = 0; i < retries; i++)
            {
                var id = GuidUtils.ToBase32String(Guid.NewGuid(), idLength);

                var virt      = ShadowFsPath + "/" + id;
                var shadowDir = IOHelper.MapPath(virt);
                if (Directory.Exists(shadowDir))
                {
                    continue;
                }

                Directory.CreateDirectory(shadowDir);
                return(id);
            }

            throw new Exception($"Could not get a shadow identifier (tried {retries} times)");
        }
示例#3
0
        /// <inheritdoc />
        public string GetFilePath(MediaFileManager fileManager, Guid itemGuid, Guid propertyGuid, string filename)
        {
            var combinedGuid = GuidUtils.Combine(itemGuid, propertyGuid);
            var directory    = GuidUtils.ToBase32String(combinedGuid, DirectoryLength);

            return(Path.Combine(directory, filename).Replace('\\', '/'));
        }
示例#4
0
        /// <inheritdoc />
        public string GetFilePath(IMediaFileSystem fileSystem, Guid itemGuid, Guid propertyGuid, string filename, string previous = null)
        {
            var combinedGuid = GuidUtils.Combine(itemGuid, propertyGuid);
            var directory    = GuidUtils.ToBase32String(combinedGuid, DirectoryLength);

            return(Path.Combine(directory, filename).Replace('\\', '/'));
        }