/// <summary> /// Creates RetentionTimeRasterItem from XICTraceGenerator. /// </summary> private RetentionTimeRasterItem MakeRetentionTimeRasterItem(XICTraceGenerator <UnknownFeatureIonInstanceItem> tracer, int fileID) { // get raster points var raster = tracer.RetentionTimeRaster; // get raster info var info = tracer.RetentionTimeRasterInfo; // make RetentionTimeRasterItem return(new RetentionTimeRasterItem { ID = EntityDataService.NextId <RetentionTimeRasterItem>(), FileID = fileID, MSOrder = info.MSOrder, Polarity = info.Polarity, IonizationSource = info.IonizationSource, MassAnalyzer = info.MassAnalyzer, MassRange = info.MassRange, ResolutionAtMass200 = info.ResolutionAtMass200, ScanRate = info.ScanRate, ScanType = info.ScanType, ActivationTypes = info.ActivationTypes, ActivationEnergies = info.ActivationEnergies, IsolationWindow = info.IsolationWindow, IsolationMass = info.IsolationMass, IsolationWidth = info.IsolationWidth, IsolationOffset = info.IsolationOffset, IsMultiplexed = info.IsMultiplexed, Trace = new TraceData(raster), }); }
public void IsFriend_Success() { using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator()); EntityDataService <Connection, ConnectionValidator> cds = new EntityDataService <Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); Session.BeginTransaction(); IEnumerable <string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); Session.Transaction.Commit(); Assert.IsTrue(myself.IsFriend(friend, ds)); Assert.IsTrue(myself.IsFriend(friend2, ds)); Assert.IsTrue(friend.IsFriend(myself, ds)); Assert.IsTrue(friend2.IsFriend(myself, ds)); Assert.IsFalse(myself.IsFriend(friend3, ds)); Assert.IsFalse(friend3.IsFriend(myself, ds)); } } }
public override IEnumerable <ConsolidatedComponentPeak> RetrieveComponentPeaks() { // init container var componentPeaks = new List <ConsolidatedComponentPeak>(); // get entity reader var entityReader = EntityDataService.CreateEntityItemReader(); // read all the peaks foreach (var ion in entityReader.ReadAll <UnknownFeatureIonInstanceItem>()) { // 1 ion has at least 1 peak, monoisotopic was used for Ion information // (UnknownCompound..:process each ion individually) // make ConsolidatedComponentPeak var fid = Convert.ToUInt64(ion.FeatureID); componentPeaks.Add(new ConsolidatedComponentPeak { Mass = m_dict[fid].mass, RetentionTime = m_dict[fid].rt, Area = ion.Area, IonDescription = "unknown", FileID = ion.FileID, IdentifyingNodeNumber = ProcessingNodeNumber, RelatedItemIDs = ion.GetIDs() }); } return(componentPeaks); }
public void TestAddNewBusinessUser() { var a = EntityHelper.GetAccount("first", "lastName"); var a2 = EntityHelper.GetAccount("first1", "lastName1"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { Session.Transaction.Begin(); IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null); ba.CreateBusiness(b, a, Role.BusinessAdmin); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { Session.BeginTransaction(); IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null); var b1 = ba.GetBusiness(b.Id); ba.AddBusinessUser(b1, a2, Role.StoreStaff); Session.Transaction.Commit(); } } }
public void TestCreateBusiness() { var a = EntityHelper.GetAccount("first", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { Session.Transaction.Begin(); IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null); ba.CreateBusiness(b, a, Role.BusinessAdmin); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var b1 = bds.Find(b.Id); Assert.IsNotNull(b1); Assert.AreEqual(b, b1); } } }
public virtual void Initialize() { Data = new EntityDataService(this); FileSystem = new FileSystemService(this); Document = new DocumentService(this); User = new UserService(this); Image = new ImageService(this); }
public void TestCreatePromotion() { var a = EntityHelper.GetAccount("first", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var p1 = pds.Find(p.Id); Assert.IsNotNull(p1); Assert.AreEqual(p, p1); } } }
public void TestCreatePromotion() { var a = EntityHelper.GetAccount("first", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService <Promotion, PromotionValidator> pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService <Promotion, PromotionValidator> pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Scope.GetSessionFactory().OpenSession())); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Promotion, PromotionValidator> pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); var p1 = pds.Find(p.Id); Assert.IsNotNull(p1); Assert.AreEqual(p, p1); } } }
public static ContactsRESTController Mock() { var db = TestDB.Create(); var user = new User("user"); var service = new EntityDataService <TestDB, Contact>(db, user); var ctrl = new ContactsRESTController(service); ctrl.Configuration = new HttpConfiguration(); return(ctrl); }
public static ContactsODataController Mock() { var db = TestDB.Create(); var user = new User("user"); var service = new EntityDataService <TestDB, Contact>(db, user); var ctrl = new ContactsODataController(service); // We need the empty configuration for the Validate() method call // in the update tests ctrl.Configuration = new HttpConfiguration(); return(ctrl); }
public void IsFriendGenerateOkSQL_Success() { using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); Session.BeginTransaction(); Assert.IsTrue(ads.SaveOrUpdate(myself)); Assert.IsTrue(ads.SaveOrUpdate(friend)); Assert.IsTrue(ads.SaveOrUpdate(friend2)); Assert.IsTrue(ads.SaveOrUpdate(friend3)); Assert.IsTrue(ads.SaveOrUpdate(friend4)); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); EntityDataService<Connection, ConnectionValidator> cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); var m = ads.Find(myself.Id); var f = ads.Find(friend.Id); var f3 = ads.Find(friend3.Id); var f4 = ads.Find(friend4.Id); // there should be 1 friend for f Log.Debug("executing isfriend"); var spec = new AccountGetFriendQuery(f); Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 1); spec = new AccountGetFriendQuery(m); Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 2); // m should be friends of friend of f3 Log.Debug("executing isfriendoffriend"); var fof = new ConnectionIsFriendOfFriendQuery(m, f3); Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() > 0); // negative case fof = new ConnectionIsFriendOfFriendQuery(m, f4); Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() == 0); } } }
public void IsFriendGenerateOkSQL_Success() { using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator()); Session.BeginTransaction(); Assert.IsTrue(ads.SaveOrUpdate(myself)); Assert.IsTrue(ads.SaveOrUpdate(friend)); Assert.IsTrue(ads.SaveOrUpdate(friend2)); Assert.IsTrue(ads.SaveOrUpdate(friend3)); Assert.IsTrue(ads.SaveOrUpdate(friend4)); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator()); EntityDataService <Connection, ConnectionValidator> cds = new EntityDataService <Connection, ConnectionValidator>(r, new ConnectionValidator()); var m = ads.Find(myself.Id); var f = ads.Find(friend.Id); var f3 = ads.Find(friend3.Id); var f4 = ads.Find(friend4.Id); // there should be 1 friend for f Log.Debug("executing isfriend"); var spec = new AccountGetFriendQuery(f); Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 1); spec = new AccountGetFriendQuery(m); Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 2); // m should be friends of friend of f3 Log.Debug("executing isfriendoffriend"); var fof = new ConnectionIsFriendOfFriendQuery(m, f3); Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() > 0); // negative case fof = new ConnectionIsFriendOfFriendQuery(m, f4); Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() == 0); } } }
public DataService(EntityDataService<Account, AccountValidator> accountDataService, EntityDataService<Business, BusinessValidator> businessDataService, EntityDataService<Promotion, PromotionValidator> promotionDataService, EntityDataService<Event, EventValidator> eventDataService, EntityDataService<PromotionInstance, PromotionInstanceValidator> promoInstanceDataService, EntityDataService<Connection, ConnectionValidator> connectionDataService, EntityDataService<BusinessUser, BusinessUserValidator> businessUserDataService, EntityDataService<UserGroup, UserGroupValidator> userGroupDataService, EntityDataService<UserRating, UserRatingValidator> userRatingDataService, IUnitOfWork unitOfWork) { this.Account = accountDataService; this.Business = businessDataService; this.Promotion = promotionDataService; this.PromotionInstance = promoInstanceDataService; this.Event = eventDataService; this.Connection = connectionDataService; this.UnitOfWork = unitOfWork; this.BusinessUser = businessUserDataService; this.UserGroup = userGroupDataService; this.UserRating = userRatingDataService; }
public void IsFriendGenerateOkSQL_Success() { using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); IEnumerable<string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); ds.UnitOfWork.End(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); var c = ads.GetAll().ToList(); var m = ads.Find(myself.Id); var f = ads.Find(friend.Id); var f3 = ads.Find(friend3.Id); Log.Debug("executing isfriend"); Assert.IsTrue(m.IsFriend(f, ds)); Log.Debug("executing isfriendoffriend"); Assert.IsTrue(m.IsFriendOfFriend(f3, ds)); ds.UnitOfWork.End(); } } }
public void IsFriendGenerateOkSQL_Success() { using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService <Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); IEnumerable <string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); ds.UnitOfWork.End(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator()); var cds = new EntityDataService <Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); var c = ads.GetAll().ToList(); var m = ads.Find(myself.Id); var f = ads.Find(friend.Id); var f3 = ads.Find(friend3.Id); Log.Debug("executing isfriend"); Assert.IsTrue(m.IsFriend(f, ds)); Log.Debug("executing isfriendoffriend"); Assert.IsTrue(m.IsFriendOfFriend(f3, ds)); ds.UnitOfWork.End(); } } }
public void IsFriendOfFriend_Success() { using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator()); EntityDataService<Connection, ConnectionValidator> cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator()); DataService ds = new DataService(ads, null, null, null, null, cds, null, null, null, new UnitOfWork(Session)); ds.UnitOfWork.Begin(); IEnumerable<string> s; ds.Account.SaveOrUpdateAll(new Account[] { myself, friend, friend2, friend3, friend4 }, out s); ds.UnitOfWork.Commit(); Assert.IsTrue(myself.IsFriendOfFriend(friend3, ds)); Assert.IsTrue(friend3.IsFriendOfFriend(myself, ds)); Assert.IsFalse(myself.IsFriendOfFriend(friend4, ds)); Assert.IsFalse(friend4.IsFriendOfFriend(myself, ds)); } } }
public void TestAcceptDeclinePromotionInstance() { var a = EntityHelper.GetAccount("first", "lastName"); var i1 = EntityHelper.GetAccount("invite1", "lastName"); var i2 = EntityHelper.GetAccount("invite2", "lastName"); var i3 = EntityHelper.GetAccount("invite3", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService<Promotion, PromotionValidator> pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } IEnumerable<PromotionInstance> promoInstances; using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); PromotionInstanceActions pia = new PromotionInstanceActions(a, ds, Log, null); Session.Transaction.Begin(); promoInstances = pia.CreatePromoInstance(p, new Account[] { i1, i2, i3 }, "going here"); Assert.IsNotNull(promoInstances, "promotion should be saved succesfully"); Assert.AreEqual(3, promoInstances.Count(), "we should get 2 promotion instance"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i1, ds, Log, null); Session.Transaction.Begin(); var pia1 = pia.Accept(promoInstances.First(), "this sound like fun"); Assert.IsNotNull(pia1); Assert.AreEqual(StatusType.Accept, pia1.Status.StatusType); Assert.IsNotNull(pia1.Coupons, "Coupoin should not be null"); Assert.IsNotNull(pia1.Coupons.First().CouponCode, "Coupon code should be generated"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService<Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService<PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i2, ds, Log, null); Session.Transaction.Begin(); var pia2 = pia.Decline(promoInstances.ElementAt(1), "this sound like fun"); Assert.IsNotNull(pia2); Assert.AreEqual(StatusType.Decline, pia2.Status.StatusType); Assert.IsNull(pia2.Coupons, "Coupoin should not be null"); Session.Transaction.Commit(); } } }
/// <summary> /// Assigns to each detected chromatogram peak the nearest MS1 spectrum and all related data dependent spectra and persists the spectra afterwards. /// </summary> /// <param name="spectrumDescriptors">The spectrum descriptors group by file identifier.</param> /// <param name="compoundIon2IsotopePeaksDictionary">The detected peaks for each compound ion as dictionary.</param> private void AssignAndPersistMassSpectra(IEnumerable <SpectrumDescriptor> spectrumDescriptors, IEnumerable <KeyValuePair <UnknownFeatureIonInstanceItem, List <ChromatogramPeakItem> > > compoundIon2IsotopePeaksDictionary) { var time = Stopwatch.StartNew(); SendAndLogTemporaryMessage("Assigning MS1 spectra..."); var defaultCharge = 1; if (spectrumDescriptors.First().ScanEvent.Polarity == PolarityType.Negative) { defaultCharge = -1; } var orderedSpectrumDescriptors = spectrumDescriptors .OrderBy(o => o.Header.RetentionTimeCenter) .ToList(); if (orderedSpectrumDescriptors.Any(a => a.ScanEvent.MSOrder == MSOrderType.MS1) == false) { SendAndLogErrorMessage("Exception, MS1 spectra not available (check spectrum selector node)."); return; } // Create peak details for each detected peak using the charge of the related compound ion var detectedPeakDetails = compoundIon2IsotopePeaksDictionary.SelectMany( sm => sm.Value.Select( s => new DetectedPeakDetails(s) { Charge = sm.Key.Charge == 0 ? defaultCharge : sm.Key.Charge })) .ToList(); DetectedPeakDetailsHelper.AssignMassSpectraToPeakApexes(orderedSpectrumDescriptors, detectedPeakDetails); SendAndLogMessage("Assigning MS1 spectra to chromatogram peak apexes finished after {0}", StringHelper.GetDisplayString(time.Elapsed)); time.Restart(); BuildSpectralTrees(orderedSpectrumDescriptors, detectedPeakDetails); SendAndLogTemporaryMessage("Persisting assigned spectra..."); // get spectrum ids of distinct spectra var distinctSpectrumIds = detectedPeakDetails.SelectMany(s => s.AssignedSpectrumDescriptors) .Select(s => s.Header.SpectrumID) .Distinct() .ToList(); // Divide spectrum ids into parts to reduce the memory foot print. Therefore it is necessary to interrupt the spectra reading, // because otherwise a database locked exception will be thrown when storing the spectra foreach (var spectrumIdsPartition in distinctSpectrumIds .Partition(ServerConfiguration.ProcessingPacketSize)) { // Retrieve mass spectra and create MassSpectrumItem's var distinctSpectra = ProcessingServices.SpectrumProcessingService.ReadSpectraFromCache(spectrumIdsPartition.ToList()) .Select( s => new MassSpectrumItem { ID = s.Header.SpectrumID, FileID = s.Header.FileID, Spectrum = s }) .ToList(); // Persist mass spectra PersistMassSpectra(distinctSpectra); } // Persists peak <-> mass spectrum connections var peaksToMassSpectrumConnectionList = new List <EntityConnectionItemList <ChromatogramPeakItem, MassSpectrumItem> >(detectedPeakDetails.Count); // Get connections between spectrum and chromatographic peak foreach (var item in detectedPeakDetails .Where(w => w.AssignedSpectrumDescriptors.Any())) { var connection = new EntityConnectionItemList <ChromatogramPeakItem, MassSpectrumItem>(item.Peak); peaksToMassSpectrumConnectionList.Add(connection); foreach (var spectrumDescriptor in item.AssignedSpectrumDescriptors) { connection.AddConnection(new MassSpectrumItem { ID = spectrumDescriptor.Header.SpectrumID, FileID = spectrumDescriptor.Header.FileID, // Omit mass spectrum here to reduce the memory footprint (only the IDs are required to persist the connections) }); } } // Persists peak <-> mass spectrum connections EntityDataService.ConnectItems(peaksToMassSpectrumConnectionList); SendAndLogMessage("Persisting spectra finished after {0}", StringHelper.GetDisplayString(time.Elapsed)); m_currentStep += 1; ReportTotalProgress((double)m_currentStep / m_numSteps); time.Stop(); }
public void TestAcceptDeclinePromotionInstance() { var a = EntityHelper.GetAccount("first", "lastName"); var i1 = EntityHelper.GetAccount("invite1", "lastName"); var i2 = EntityHelper.GetAccount("invite2", "lastName"); var i3 = EntityHelper.GetAccount("invite3", "lastName"); var b = EntityHelper.GetBusiness("business1", Category.ActiveLife); var e = EntityHelper.GetEvent("ev name", "venue name"); var d = EntityHelper.GetDeal("dealname", 10); var p = new Promotion(b, e, d, 100, 5); using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>()) { using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService <Promotion, PromotionValidator> pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); b = ba.CreateBusiness(b, a, Role.BusinessAdmin); Assert.IsNotNull(b, "business should be saved succesfully"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); EntityDataService <Business, BusinessValidator> bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); EntityDataService <Promotion, PromotionValidator> pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); IDataService ds = new DataService(null, bds, pds, null, null, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); Session.Transaction.Begin(); p = pa.SavePromotion(p); Assert.IsNotNull(p, "promotion should be saved succesfully"); Session.Transaction.Commit(); } IEnumerable <PromotionInstance> promoInstances; using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService <PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); BusinessActions ba = new BusinessActions(a, ds, Log, null); PromotionActions pa = new PromotionActions(a, ds, Log, null); PromotionInstanceActions pia = new PromotionInstanceActions(a, ds, Log, null); Session.Transaction.Begin(); promoInstances = pia.CreatePromoInstance(p, new Account[] { i1, i2, i3 }, "going here"); Assert.IsNotNull(promoInstances, "promotion should be saved succesfully"); Assert.AreEqual(3, promoInstances.Count(), "we should get 2 promotion instance"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService <PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i1, ds, Log, null); Session.Transaction.Begin(); var pia1 = pia.Accept(promoInstances.First(), "this sound like fun"); Assert.IsNotNull(pia1); Assert.AreEqual(StatusType.Accept, pia1.Status.StatusType); Assert.IsNotNull(pia1.Coupons, "Coupoin should not be null"); Assert.IsNotNull(pia1.Coupons.First().CouponCode, "Coupon code should be generated"); Session.Transaction.Commit(); } using (ISession Session = Scope.OpenSession()) { IRepository r = new GenericRepository(Session); var bds = new EntityDataService <Business, BusinessValidator>(r, new BusinessValidator()); var pds = new EntityDataService <Promotion, PromotionValidator>(r, new PromotionValidator()); var pids = new EntityDataService <PromotionInstance, PromotionInstanceValidator>(r, new PromotionInstanceValidator()); IDataService ds = new DataService(null, bds, pds, null, pids, null, null, null, null, new UnitOfWork(Session)); PromotionInstanceActions pia = new PromotionInstanceActions(i2, ds, Log, null); Session.Transaction.Begin(); var pia2 = pia.Decline(promoInstances.ElementAt(1), "this sound like fun"); Assert.IsNotNull(pia2); Assert.AreEqual(StatusType.Decline, pia2.Status.StatusType); Assert.IsNull(pia2.Coupons, "Coupoin should not be null"); Session.Transaction.Commit(); } } }
/// <summary> /// Creates and persists XIC traces for all compound ion items. /// </summary> private void RebuildAndPersistCompoundIonTraces( int fileID, IEnumerable <SpectrumDescriptor> spectrumDescriptors, Dictionary <UnknownFeatureIonInstanceItem, List <ChromatogramPeakItem> > ionInstanceToPeaksMap) { SendAndLogTemporaryMessage("Re-creating XIC traces..."); var time = Stopwatch.StartNew(); // init XICPattern builder var xicPatternBuilder = new Func <List <ChromatogramPeakItem>, XICPattern>( peaks => { var masks = peaks.Select( peak => new XICMask( peak.IsotopeNumber, peak.Mass, MassTolerance.Value) ).ToList(); return(new XICPattern(masks)); }); // make XIC patterns var xicPatterns = ionInstanceToPeaksMap.ToDictionary(item => item.Key, item => xicPatternBuilder(item.Value)); // init XIC tracer var tracer = new XICTraceGenerator <UnknownFeatureIonInstanceItem>(xicPatterns); // get sprectrum IDs var spectrumIds = spectrumDescriptors .Where(s => s.ScanEvent.MSOrder == MSOrderType.MS1) .OrderBy(o => o.Header.RetentionTimeRange.LowerLimit) .Select(s => s.Header.SpectrumID) .ToList(); // add spectrum to tracer foreach (var spectrum in ProcessingServices.SpectrumProcessingService.ReadSpectraFromCache(spectrumIds)) { tracer.AddSpectrum(spectrum); } // make trace items var ionInstanceToTraceMap = new Dictionary <UnknownFeatureIonInstanceItem, XicTraceItem>(); foreach (var item in ionInstanceToPeaksMap) { // get trace var trace = tracer.GetXICTrace(item.Key, useFullRange: true, useFullRaster: false); // make XicTraceItem ionInstanceToTraceMap.Add( item.Key, new XicTraceItem { ID = EntityDataService.NextId <XicTraceItem>(), FileID = fileID, Trace = new TraceData(trace), }); } // make raster var rasterItem = MakeRetentionTimeRasterItem(tracer, fileID); // persist traces EntityDataService.InsertItems(ionInstanceToTraceMap.Values); EntityDataService.ConnectItems(ionInstanceToTraceMap.Select(s => Tuple.Create(s.Key, s.Value))); // persist raster EntityDataService.InsertItems(new[] { rasterItem }); EntityDataService.ConnectItems(ionInstanceToTraceMap.Select(s => Tuple.Create(s.Value, rasterItem))); time.Stop(); SendAndLogVerboseMessage("Re-creating and persisting {0} XIC traces took {1:F2} s.", ionInstanceToTraceMap.Values.Count, time.Elapsed.TotalSeconds); m_currentStep += 4; ReportTotalProgress((double)m_currentStep / m_numSteps); }