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; }
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; }
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); }