/// <summary> /// Instantiates a new instance of the <see cref="CachedProfile"/> class /// </summary> /// <param name="profile"></param> /// <param name="updatedOn"></param> public CachedProfile(NeoProfile profile, DateTime updatedOn) { if (profile == null) { throw new ArgumentNullException("profile"); } this.Profile = profile; this.Body = profile.GetOrderBody(); this.UpdatedOn = updatedOn; }
/// <summary> /// Returns a freshly loaded profile from disk /// </summary> /// <param name="path"></param> /// <returns></returns> public CachedProfile GetProfile(string path) { var normalizedPath = PathUtility.NormalizeFilePath(path); return new CachedProfile(NeoProfile.Load(normalizedPath), DateTime.Now); }
/// <summary> /// Returns the body of an order profile /// </summary> /// <param name="profile"></param> /// <returns></returns> public static List <ProfileBehavior> GetOrderBody(this NeoProfile profile) { return(profile.GetPrivateField <List <ProfileBehavior> >("Order")); }
/// <summary> /// Gets the profile behavior tree /// </summary> /// <param name="profile"></param> /// <returns></returns> public IEnumerable <Composite> GetProfileBehavior(NeoProfile profile) { var body = profile.GetPrivateField <List <ProfileBehavior> >("Order"); return(this.GetProfileBehaviorCollectionBehavior(body)); }
/// <summary> /// Gets the profile behavior tree /// </summary> /// <param name="profile"></param> /// <returns></returns> public IEnumerable<Composite> GetProfileBehavior(NeoProfile profile) { var body = profile.GetPrivateField<List<ProfileBehavior>>("Order"); return this.GetProfileBehaviorCollectionBehavior(body); }
/// <summary> /// Gets a <see cref="NeoProfile"/> from the cache. If the cache /// object has not been instantiated, the specified file will /// be loaded. /// </summary> /// <param name="path"></param> /// <returns></returns> public CachedProfile GetProfile(string path) { var normalizedPath = PathUtility.NormalizeFilePath(path); // Get an existing profile var existingProfile = ObjectCache <CachedProfile> .Instance[normalizedPath]; // Get the last write time on the file var lastWrite = FileUtility.GetLastWriteTime(path); // Compare the update datetimes and load a fresh copy if it has been updated if (existingProfile != null && lastWrite <= existingProfile.UpdatedOn) { return(existingProfile); } return(ObjectCache <CachedProfile> .Instance[normalizedPath] = new CachedProfile(NeoProfile.Load(normalizedPath), lastWrite)); }