public void Save() { ICollection<DependentObject> depedentObjects = new Collection<DependentObject> { new DependentObject { SifObjectName = "AttendanceSummary", ObjectKeyValue = "key3" }, new DependentObject { SifObjectName = "StudentDailyAttendance", ObjectKeyValue = "key4" } }; CachedObject savedObject = new CachedObject { SifObjectName = "StudentAttendance", DependentObjects = depedentObjects }; (new CachedObjectDao()).Save(savedObject); if (log.IsDebugEnabled) log.Debug("Saved object: " + savedObject); Console.WriteLine("Saved object: " + savedObject); using (ISession session = sessionFactory.OpenSession()) { CachedObject comparisonObject = session.Get<CachedObject>(savedObject.Id); if (log.IsDebugEnabled) log.Debug("Comparison object: " + comparisonObject); Console.WriteLine("Comparison object: " + comparisonObject); Assert.IsNotNull(comparisonObject); Assert.AreNotSame(savedObject, comparisonObject); Assert.AreEqual(savedObject.SifObjectName, comparisonObject.SifObjectName); Assert.AreEqual(savedObject.ZoneId, comparisonObject.ZoneId); Assert.AreEqual(savedObject.AgentId, comparisonObject.AgentId); } }
public void RetrieveFail() { using (ISession session = sessionFactory.OpenSession()) { CachedObject addedObject = new CachedObject { SifObjectName = "TeachingGroup", ObjectKeyValue = "tg1", ApplicationId = "app1", ZoneId = "zone1" }; session.Save(addedObject); } CachedObject retrievedObject = (new CachedObjectDao()).Retrieve("TeachingGroup", "tg1", "app1", "zone1"); }
/// <see cref="Systemic.Sif.Sbp.Framework.Service.IDependentObjectCacheService.DeleteCachedObject(CachedObject)">DeleteCachedObject</see> public void DeleteCachedObject(CachedObject cachedObject) { cachedObjectDao.Delete(cachedObject); }
/// <see cref="Systemic.Sif.Sbp.Framework.Service.IDependentObjectCacheService.StoreObjectInCache((SifDataObject, EventAction, string, string, string)">StoreObjectInCache</see> public void StoreObjectInCache(string sifObjectName, string objectKeyValue, string sifDataObjectXml, string eventAction, string agentId, string applicationId, string zoneId, string expiryStrategy, int expiryPeriod, ICollection<DependentObject> dependentObjects) { if (String.IsNullOrEmpty(sifObjectName) || String.IsNullOrEmpty(objectKeyValue) || String.IsNullOrEmpty(sifDataObjectXml) || String.IsNullOrEmpty(agentId) || String.IsNullOrEmpty(applicationId) || String.IsNullOrEmpty(zoneId) || String.IsNullOrEmpty(expiryStrategy)) { throw new ArgumentException("A parameter is null or empty."); } if (dependentObjects == null || dependentObjects.Count == 0) { if (log.IsInfoEnabled) log.Info("The following SIF Data Object has no dependent objects and will therefore not be cached:\n" + sifDataObjectXml); } else { CachedObject cachedObject = new CachedObject(); cachedObject.SifObjectName = sifObjectName; cachedObject.ObjectKeyValue = objectKeyValue; cachedObject.ObjectXml = sifDataObjectXml; cachedObject.ReceivedDate = DateTime.Now; cachedObject.AgentId = agentId; cachedObject.ApplicationId = applicationId; cachedObject.ZoneId = zoneId; cachedObject.RemainingDependencies = dependentObjects.Count; cachedObject.ExpiryDate = cachedObject.ReceivedDate.AddMilliseconds(expiryPeriod); cachedObject.ExpiryStrategy = expiryStrategy; cachedObject.DependentObjects = dependentObjects; if (eventAction == null) { cachedObject.IsEvent = false; } else { cachedObject.IsEvent = true; cachedObject.EventType = eventAction; } // Iterate through all dependent objects and set the application and zone IDs. foreach (DependentObject dependentObject in cachedObject.DependentObjects) { // Ensure that the dependent object has not yet been requested. if (!dependentObject.Requested) { // Don't assign the agent because we don't know which agent is responsible for requesting it. Instead // assign the application ID because whichever agent is responsible for the retrieval of this dependent // object must pick it up for that application. dependentObject.ZoneId = zoneId; dependentObject.Requested = false; dependentObject.ApplicationId = applicationId; } } cachedObjectDao.Save(cachedObject); } }
private void CreateInitialData() { CachedObject parentObject = new CachedObject(); dependentObjects = new[] { new DependentObject { SifObjectName = "StudentPersonal", ObjectKeyValue = "st1", ApplicationId = "app1", ZoneId = "zone1", ParentObjects = new Collection<CachedObject>() { parentObject } }, new DependentObject { SifObjectName = "StudentPersonal", ObjectKeyValue = "st2", ApplicationId = "app2", ZoneId = "zone2", ParentObjects = new Collection<CachedObject>() { parentObject } }, new DependentObject { SifObjectName = "StudentPersonal", ObjectKeyValue = "st3", ApplicationId = "app3", ZoneId = "zone3", Requested = true }, new DependentObject { SifObjectName = "StudentPersonal", ObjectKeyValue = "st4", ApplicationId = "app3", ZoneId = "zone3", Requested = true }, new DependentObject { SifObjectName = "StudentPersonal", ObjectKeyValue = "st5", ApplicationId = "app3", ZoneId = "zone3", } }; using (ISession session = sessionFactory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(parentObject); foreach (DependentObject cachedObject in dependentObjects) { session.Save(cachedObject); } transaction.Commit(); } } }