// todo: add in tests public DataStoreInstance AddOrUpdate(DataStoreInstance instance) { // todo: better error handling here // todo: add in test if (instance == null) { throw new Exception("You cannot create a blank instance"); } // todo: better error handling here // todo: add in test if (string.IsNullOrEmpty(instance.Name) || string.IsNullOrEmpty(instance.Description)) { throw new Exception("You need a Name and Description to add an instance"); } if (!instance.Exists(this)) { instance.Add(this); } else { instance.Update(this); } // Ensure that the cached instance reflects any changes made _instanceCache[instance.Name] = instance.Get(this); return GetCachedInstance(instance.Name); }
// CreateInstance() public DataStoreInstance CreateInstance(string name, string description) { var instance = new DataStoreInstance { DateCreated = DateTime.UtcNow, Description = description, Name = name }; AddOrUpdate(instance); return instance.Get(this); }