Exemplo n.º 1
0
        private DomainModel.Project CreateProject(CreateProjectCommand project)
        {
            int     vkGroupId     = this.groupInfoProvider.GetVkGroupId(project.Url);
            VkGroup group         = this.vkGroupRepository.GetGroupById(vkGroupId);
            bool    isGroupExists = group != null;

            DomainModel.Project projectToCreate = new DomainModel.Project
            {
                Title        = project.Title,
                CreationDate = this.dateTimeHelper.GetDateTimeNow(),
                AccountId    = project.AccountId,
                VkGroup      = group ?? new VkGroup
                {
                    Id   = vkGroupId,
                    Name = this.groupInfoProvider.GetVkGroupName(project.Url),
                    Url  = project.Url,
                    Type = VkGroupType.Group
                }
            };

            using (ITransactionScope transaction = this.unitOfWorkProvider.CreateTransaction().Begin())
            {
                this.projectRepository.Save(projectToCreate);

                if (!isGroupExists)
                {
                    this.AddGroupRelatedData(projectToCreate);
                }

                transaction.Commit();
            }

            return(projectToCreate);
        }
Exemplo n.º 2
0
        public void EditUser(UserInfo userInfo)
        {
            using (this.unitOfWorkProvider.CreateUnitOfWork())
            {
                Hasher hasher = new Hasher();

                using (ITransactionScope transaction = Factory.GetInstance <ITransactionScope>().Begin())
                {
                    User user = this.userRepository.GetUserById(userInfo.Id);

                    user.FirstName = userInfo.FirstName.Trim();
                    user.LastName  = userInfo.LastName.Trim();
                    user.Email     = userInfo.Email.Trim();

                    if (!string.IsNullOrWhiteSpace(userInfo.Password))
                    {
                        user.Salt         = this.CreateRandomSalt();
                        user.PasswordHash = hasher.ComputeSaltedHash(userInfo.Password.Trim(), user.Salt);
                    }

                    this.userRepository.Update(user);
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 3
0
        static void Wiff2()
        {
            string wiffPath = @"C:\Users\david\Documents\BioInfo\47_praktikum\data\task7.wiff";
            string runID    = "sample=0";

            System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch();
            time.Start();
            Console.Out.WriteLine(time.Elapsed.TotalMinutes);
            using (var reader = new WiffFileReader(wiffPath))
                using (ITransactionScope txn = reader.BeginTransaction())
                {
                    System.Collections.Generic.IEnumerable <string> Items()
                    {
                        foreach (var ms in reader.ReadMassSpectra(runID))
                        {
                            //var peaks = reader.ReadSpectrumPeaks(ms.ID);
                            yield return(ms.ID);
                        }
                    }

                    txn.Commit();
                    Console.Out.WriteLine(Items().ToArray().Length);
                    Console.Out.WriteLine(time.Elapsed.TotalMinutes);
                }
        }
Exemplo n.º 4
0
        public void AddUser(UserInfo userInfo, int accountId)
        {
            IAccount account = this.accountRepository.GetAccount(accountId);

            using (this.unitOfWorkProvider.CreateUnitOfWork())
            {
                User user = new User
                {
                    FirstName = userInfo.FirstName.Trim(),
                    LastName  = userInfo.LastName.Trim(),
                    Email     = userInfo.Email.Trim(),
                    Account   = account
                };

                Hasher hasher = new Hasher();
                user.Salt         = this.CreateRandomSalt();
                user.PasswordHash = hasher.ComputeSaltedHash(userInfo.Password.Trim(), user.Salt);

                using (ITransactionScope transaction = Factory.GetInstance <ITransactionScope>().Begin())
                {
                    this.userRepository.Save(user);
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 5
0
        static void WiffToSQLite()
        {
            string wiffPath   = @"C:\Work\primaqdev\testdata\C2 Sol SWATH4.wiff";
            string mzLitePath = Path.Combine(Path.GetDirectoryName(wiffPath), Path.GetFileNameWithoutExtension(wiffPath) + ".mzlite");
            string runID      = "sample=0";

            if (File.Exists(mzLitePath))
            {
                File.Delete(mzLitePath);
            }

            using (IMzLiteDataReader reader = new WiffFileReader(wiffPath))
                using (ITransactionScope inTxn = reader.BeginTransaction())
                    using (MzLiteSQL writer = new MzLiteSQL(mzLitePath))
                        using (ITransactionScope outTxn = writer.BeginTransaction())
                        {
                            foreach (var ms in reader.ReadMassSpectra(runID))
                            {
                                var peaks    = reader.ReadSpectrumPeaks(ms.ID);
                                var clonedMS = MzLiteJson.JsonCloneModelItem("#1", ms);
                                writer.Insert(runID, clonedMS, peaks);
                                break;
                            }

                            foreach (var ms in writer.ReadMassSpectra(runID))
                            {
                                var peaks = writer.ReadSpectrumPeaks(ms.ID);
                                var ms1   = writer.ReadMassSpectrum(ms.ID);
                                break;
                            }

                            outTxn.Commit();
                        }
        }
Exemplo n.º 6
0
 public void Execute()
 {
     using (this.unitOfWorkProvider.CreateUnitOfWork())
         using (ITransactionScope transaction = this.unitOfWorkProvider.CreateTransaction().Begin())
         {
             Factory.GetInstance <SavePlacesFromVkProcess>().SaveCountriesAndCities();
             transaction.Commit();
         }
 }
Exemplo n.º 7
0
        public void Write(string tableName, IBulkDataReader dataReader)
        {
            // Perform Bulk Copy
            SqlConnection sqlConn = _sqlContext.GetConnection();

            if (sqlConn.State != ConnectionState.Open)
            {
                sqlConn.Open();
            }

            using (ITransactionScope <SqlTransaction> sqlTransaction = _sqlContext.BeginTransaction())
            {
                Write(tableName, dataReader, sqlConn, sqlTransaction.Current);
                sqlTransaction.Commit();
            }
        }
Exemplo n.º 8
0
        public void AddAccount(AccountInfo accountInfo)
        {
            using (this.unitOfWorkProvider.CreateUnitOfWork())
            {
                Account account = new Account
                {
                    Title             = accountInfo.Title,
                    MaxProjectsCount  = accountInfo.MaxProjectsCount,
                    CanDeleteProjects = accountInfo.CanDeleteProjects
                };

                using (ITransactionScope transaction = Factory.GetInstance <ITransactionScope>().Begin())
                {
                    this.accountRepository.Save(account);
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 9
0
        static void WiffToSQLite()
        {
            string wiffPath   = @"C:\Work\primaqdev\testdata\Für Alex\20160212_MS_DHpsan006.wiff";
            string mzLitePath = Path.Combine(Path.GetDirectoryName(wiffPath), Path.GetFileNameWithoutExtension(wiffPath) + ".mzlite");
            string runID      = "sample=0";
            int    msLevel;

            if (File.Exists(mzLitePath))
            {
                File.Delete(mzLitePath);
            }

            using (IMzLiteDataReader reader = new WiffFileReader(wiffPath))
                using (ITransactionScope inTxn = reader.BeginTransaction())
                    using (MzLiteSQL writer = new MzLiteSQL(mzLitePath))
                        using (ITransactionScope outTxn = writer.BeginTransaction())
                        {
                            foreach (var ms in reader.ReadMassSpectra(runID))
                            {
                                if (ms.TryGetMsLevel(out msLevel) && msLevel != 1)
                                {
                                    continue;
                                }

                                var peaks = reader.ReadSpectrumPeaks(ms.ID);
                                //var clonedMS = MzLiteJson.JsonCloneModelItem("#1", ms);
                                //var max = peaks.Peaks.GroupBy(x => x.Intensity);

                                writer.Insert(runID, ms, peaks);
                                //break;
                            }

                            //foreach (var ms in writer.ReadMassSpectra(runID))
                            //{
                            //    var peaks = writer.ReadSpectrumPeaks(ms.ID);
                            //    var ms1 = writer.ReadMassSpectrum(ms.ID);
                            //    break;
                            //}

                            outTxn.Commit();
                        }
        }
Exemplo n.º 10
0
        public void EditAccount(AccountInfo accountInfo)
        {
            using (this.unitOfWorkProvider.CreateUnitOfWork())
            {
                IAccount account = this.accountRepository.GetAccount(accountInfo.Id);

                if (account == null)
                {
                    throw new PalantirException("Account is not found");
                }

                using (ITransactionScope transaction = Factory.GetInstance <ITransactionScope>().Begin())
                {
                    account.Title             = accountInfo.Title;
                    account.MaxProjectsCount  = accountInfo.MaxProjectsCount;
                    account.CanDeleteProjects = accountInfo.CanDeleteProjects;

                    this.accountRepository.Save(account);
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 11
0
        public void DeleteUser(int userId)
        {
            // TODO: Implement multi user logic
            using (this.unitOfWorkProvider.CreateUnitOfWork())
            {
                IProjectRepository projectRepository = this.projectRepositoryFactory();
                IList <Project>    projects          = projectRepository.GetByAccountId(userId);
                User user = this.userRepository.GetUserById(userId);

                using (ITransactionScope transaction = Factory.GetInstance <ITransactionScope>().Begin())
                {
                    foreach (var project in projects)
                    {
                        projectRepository.Delete(project);
                    }

                    this.userRepository.Delete(user);

                    transaction.Commit();
                }
            }
        }
Exemplo n.º 12
0
 public void Finish()
 {
     CurrentTransactionScope.Commit();
     CurrentTransactionScope.Dispose();
 }