Пример #1
0
        public static bool IncrementAttempts(this IObjectStorage storage, ObjectInfo info)
        {
            string[] parts = info.Path.Split('.');
            if (parts.Length < 3)
            {
                throw new ArgumentException(String.Format("Path \"{0}\" must contain the number of attempts.", info.Path));
            }

            int version;

            if (!Int32.TryParse(parts[1], out version))
            {
                throw new ArgumentException(String.Format("Path \"{0}\" must contain the number of attempts.", info.Path));
            }

            version++;
            string newpath = String.Join(".", parts[0], version, parts[2]);

            if (parts.Length == 4)
            {
                newpath += "." + parts[3];
            }

            string originalPath = info.Path;

            info.Path = newpath;

            return(storage.RenameObject(originalPath, newpath));
        }
Пример #2
0
        public void CanManageFiles()
        {
            Reset();

            IObjectStorage storage = GetStorage();

            storage.SaveObject("test.txt", "test");
            Assert.Equal(1, storage.GetObjectList("test.txt").Count());
            Assert.Equal(1, storage.GetObjectList().Count());
            var file = storage.GetObjectList().FirstOrDefault();

            Assert.NotNull(file);
            Assert.Equal("test.txt", file.Path);
            string content = storage.GetObject <string>("test.txt");

            Assert.Equal("test", content);
            storage.RenameObject("test.txt", "new.txt");
            Assert.True(storage.GetObjectList().Any(f => f.Path == "new.txt"));
            storage.DeleteObject("new.txt");
            Assert.Equal(0, storage.GetObjectList().Count());
            storage.SaveObject("test\\q\\" + Guid.NewGuid().ToString("N") + ".txt", "test");
            Assert.Equal(1, storage.GetObjectList("test\\q\\*.txt").Count());
            Assert.Equal(1, storage.GetObjectList("*", null, DateTime.Now).Count());
            List <ObjectInfo> files = storage.GetObjectList("*", null, DateTime.Now.Subtract(TimeSpan.FromMinutes(5))).ToList();

            Debug.WriteLine(String.Join(",", files.Select(f => f.Path + " " + f.Created)));
            Assert.Equal(0, files.Count);
        }
Пример #3
0
        public static bool LockFile(this IObjectStorage storage, ObjectInfo info)
        {
            if (info.Path.EndsWith(".x"))
            {
                return(false);
            }

            string lockedPath = String.Concat(info.Path, ".x");

            bool success = storage.RenameObject(info.Path, lockedPath);

            if (!success)
            {
                return(false);
            }

            info.Path = lockedPath;
            return(true);
        }
Пример #4
0
        public static bool ReleaseFile(this IObjectStorage storage, ObjectInfo info)
        {
            if (!info.Path.EndsWith(".x"))
            {
                return(false);
            }

            string path = info.Path.Substring(0, info.Path.Length - 2);

            bool success = storage.RenameObject(info.Path, path);

            if (!success)
            {
                return(false);
            }

            info.Path = path;
            return(true);
        }