Exemplo n.º 1
0
        public bool Insert(UnitInfoModel unitInfoModel)
        {
            // if the work unit is not valid simply return
            if (!ValidateUnitInfo(unitInfoModel.UnitInfoData))
            {
                return(false);
            }

            // The Insert operation does not setup a WuHistory table if
            // it does not exist.  This was already handled when the
            // the DatabaseFilePath was set.
            Debug.Assert(TableExists(SqlTable.WuHistory));

            // ensure this unit is not written twice
            if (UnitInfoExists(unitInfoModel.UnitInfoData))
            {
                return(false);
            }

            var entry = AutoMapper.Mapper.Map <HistoryEntry>(unitInfoModel.UnitInfoData);

            // cannot map these two properties from a UnitInfo instance
            // they only live at the UnitInfoLogic level
            entry.FramesCompleted = unitInfoModel.FramesComplete;
            entry.FrameTimeValue  = unitInfoModel.GetRawTime(PpdCalculationType.AllFrames);
            // copy protein values for insert
            entry.WorkUnitName  = unitInfoModel.CurrentProtein.WorkUnitName;
            entry.KFactor       = unitInfoModel.CurrentProtein.KFactor;
            entry.Core          = unitInfoModel.CurrentProtein.Core;
            entry.Frames        = unitInfoModel.CurrentProtein.Frames;
            entry.Atoms         = unitInfoModel.CurrentProtein.NumberOfAtoms;
            entry.BaseCredit    = unitInfoModel.CurrentProtein.Credit;
            entry.PreferredDays = unitInfoModel.CurrentProtein.PreferredDays;
            entry.MaximumDays   = unitInfoModel.CurrentProtein.MaximumDays;
            using (var connection = new SQLiteConnection(ConnectionString))
            {
                connection.Open();
                using (var database = new PetaPoco.Database(connection))
                {
                    database.Insert(entry);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
      public bool Insert(UnitInfoModel unitInfoModel)
      {
         // if the work unit is not valid simply return
         if (!ValidateUnitInfo(unitInfoModel.UnitInfoData))
         {
            return false;
         }

         // The Insert operation does not setup a WuHistory table if
         // it does not exist.  This was already handled when the
         // the DatabaseFilePath was set.
         Debug.Assert(TableExists(SqlTable.WuHistory));

         // ensure this unit is not written twice
         if (UnitInfoExists(unitInfoModel))
         {
            return false;
         }

         var entry = AutoMapper.Mapper.Map<HistoryEntry>(unitInfoModel.UnitInfoData);
         // cannot map these two properties from a UnitInfo instance
         // they only live at the UnitInfoLogic level
         entry.FramesCompleted = unitInfoModel.FramesComplete;
         entry.FrameTimeValue = unitInfoModel.GetRawTime(PpdCalculationType.AllFrames);
         // copy protein values for insert
         entry.WorkUnitName = unitInfoModel.CurrentProtein.WorkUnitName;
         entry.KFactor = unitInfoModel.CurrentProtein.KFactor;
         entry.Core = unitInfoModel.CurrentProtein.Core;
         entry.Frames = unitInfoModel.CurrentProtein.Frames;
         entry.Atoms = unitInfoModel.CurrentProtein.NumberOfAtoms;
         entry.BaseCredit = unitInfoModel.CurrentProtein.Credit;
         entry.PreferredDays = unitInfoModel.CurrentProtein.PreferredDays;
         entry.MaximumDays = unitInfoModel.CurrentProtein.MaximumDays;
         using (var connection = new SQLiteConnection(ConnectionString))
         {
            connection.Open();
            using (var database = new PetaPoco.Database(connection))
            {
               database.Insert(entry);
            }
         }

         return true;
      }