Exemplo n.º 1
0
        private void LoadEvaluations()
        {
            //            For testing
            //var x = SqLiteConnection.DropTable<Evaluation>();
            //x = SqLiteConnection.DropTable<Option>();
            //x = SqLiteConnection.DropTable<CriteriaOption>();
            //x = SqLiteConnection.DropTable<Criteria>();

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try {
                Evaluations = new ObservableRangeCollection <Evaluation>(SqLiteConnection.GetAllWithChildren <Evaluation>());
            } catch (Exception ex) {
                if (ex.Message == "no such table: Evaluation" || ex.Message == "no such table: Criteria" || ex.Message == "no such table: Option" || ex.Message == "no such table: CriteriaOption")
                {
                    SqLiteConnection.CreateTable <Criteria>();
                    SqLiteConnection.CreateTable <Option>();
                    SqLiteConnection.CreateTable <Evaluation>();
                    SqLiteConnection.CreateTable <CriteriaOption>();
                    Evaluations = new ObservableRangeCollection <Evaluation>(SqLiteConnection.Table <Evaluation>().ToList());
                }
            } finally {
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
        private void SubscribeAddCriteriaM()
        {
            MessagingCenter.Subscribe <NewCriteriaViewModel, Criteria>(this, "AddCriteriaM", (sender, args) => {
                Criterias.Add(args);

                //neues Criteria für jede Option in CurrentEvaluation hinzufügen
                foreach (var _option in CurrentEvaluation.Options)
                {
                    if (_option.Criterias != null)
                    {
                        _option.Criterias.Add(args);
                    }
                    else
                    {
                        _option.Criterias = new ObservableRangeCollection <Criteria>().ToList();
                        _option.Criterias.Add(args);
                    }
                }

                // Current Evaluation update
                try {
                    SqLiteConnection.UpdateWithChildren(CurrentEvaluation);
                } catch (Exception e) {
                    throw new NotImplementedException();
                }
            });
        }
        /// <summary>
        /// Performs hard delete for given id.
        /// </summary>
        /// <param name="id">id to hard delete</param>
        /// <returns>Process task.</returns>
        protected async Task HardDeleteEntity(TId id)
        {
            var tableName = await FetchTableName();

            var idColName = await FetchColumnNameFromAttribute <PrimaryKeyAttribute>();

            await SqLiteConnection.ExecuteAsync($"DELETE FROM {tableName} WHERE {idColName} = ?", id);
        }
Exemplo n.º 4
0
        private DatabaseManager()
        {
            string fileName = Path.Combine(PathController.Instance.Path, "settigs.db");
            _database = new SqLiteConnection(fileName);
            //_database.DropTable<Game>();
            _database.CreateTable<Game>();

            var count = _database.Table<Game>().ToList();
        }
 /// <inheritdoc />
 protected override void PrepareForWrite()
 {
     if (_sqLiteTransaction == null)
     {
         if (_createTransaction)
         {
             _sqLiteTransaction = SqLiteConnection.BeginTransaction();
         }
     }
 }
        /// <summary>
        /// Dispose the transaction if it is not null
        /// Set the transaction to null.
        /// </summary>
        private void Close()
        {
            // call the derived classes a chance to perform some work.
            PrepareForClose();

            // the database is closed, all we can do now is dispose of the transaction.
            _sqLiteTransaction?.Dispose();
            _sqLiteTransaction = null;

            SqLiteConnection.Close();
            SqLiteConnection.Dispose();
        }
Exemplo n.º 7
0
        public void GetRankingAndWeightTest()
        {
            var sql            = new SqLiteConnection();
            var pacmans        = sql.GetOneGenerationPacmans(100);
            var gameResult     = new GameResult();
            var rankingPacmans = gameResult.GetRankingAndWeight2(pacmans.ToArray());

            foreach (var p in rankingPacmans)
            {
                Console.WriteLine(p.AveragePoints + ":" + p.Weight);
            }
        }
        public async Task <LastSuccessfulSyncEntity> FindByTableIdAndBackendId(string tableId,
                                                                               string backendId = "default")
        {
            var item = await SqLiteConnection.FindWithQueryAsync <LastSuccessfulSyncEntity>(
                "SELECT lss.* FROM last_successful_sync lss WHERE lss.table_id = ? AND lss.backend_id = ?",
                tableId, backendId
                );

            if (item != default)
            {
                return(item);
            }
            var errorCode = DataErrorCodes.ItemNotFound;

            throw new GrException(errorCode.Message, errorCode: errorCode);
        }
Exemplo n.º 9
0
        public async Task <List <TEntity> > FindAllPendingToSync(DateTimeOffset lastSuccessfulSync, params TId[] newerIds)
        {
            newerIds ??= new TId[0];
            var tableName = await FetchTableName();

            var idColumn = await FetchColumnNameFromAttribute <PrimaryKeyAttribute>();

            var createdAtColumn = await FetchColumnNameFromAttribute <CreatedAtColumnAttribute>();

            var updatedAtColumn = await FetchColumnNameFromAttribute <UpdatedAtColumnAttribute>();

            var strNewerIds = string.Join(", ", newerIds.Select(id => $"'{id}'"));

            return(await SqLiteConnection.QueryAsync <TEntity>(
                       $"SELECT * FROM {tableName} WHERE {createdAtColumn} >= ? " +
                       $"OR ( {updatedAtColumn} >= ? AND {idColumn} not in ({strNewerIds}) )",
                       lastSuccessfulSync, lastSuccessfulSync));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Saves Options locally and popasync
 /// </summary>
 private async Task SaveClickedAsync()
 {
     if (Option != null)
     {
         try {
             SqLiteConnection.Insert(Option);
         } catch (Exception e) {
             if (e.Message == "no such table: Option")
             {
                 SqLiteConnection.CreateTable <Option>();
                 SqLiteConnection.Insert(Option);
             }
         } finally {
             MessagingCenter.Send <NewOptionViewModel, Option>(this, "AddOptionM", Option);
             var page = Application.Current.MainPage as TabbedPage;
             await page.Children[1].Navigation.PopAsync();
         }
     }
 }
Exemplo n.º 11
0
 private void SubscribeAddOptionM()
 {
     MessagingCenter.Subscribe <NewOptionViewModel, Option>(this, "AddOptionM", (sender, args) => {
         foreach (var _criteria in CurrentEvaluation.Criterias)
         {
             if (_criteria.Options != null)
             {
                 _criteria.Options.Add(args);
             }
             else
             {
                 _criteria.Options = new ObservableRangeCollection <Option>().ToList();
                 _criteria.Options.Add(args);
             }
         }
         CurrentEvaluation.Criterias = new List <Criteria>(Criterias.ToList());
         SqLiteConnection.UpdateWithChildren(CurrentEvaluation);
         Options = new ObservableCollection <Option>(CurrentEvaluation.Options);
     });
 }
Exemplo n.º 12
0
 /// <summary>
 /// Save Criteria locally and popAsync
 /// </summary>
 private async Task SaveClickedAsync()
 {
     if (Criteria != null)
     {
         try {
             SqLiteConnection.InsertWithChildren(Criteria);
         } catch (SQLite.SQLiteException e) {
             if (e.Message == "no such table: Criteria")
             {
                 SqLiteConnection.CreateTable <Criteria>();
                 SqLiteConnection.Insert(Criteria);
             }
         } finally {
             SqLiteConnection.InsertWithChildren(Criteria);
             MessagingCenter.Send <NewCriteriaViewModel, Criteria>(this, "AddCriteriaM", Criteria);
             var page = Application.Current.MainPage as TabbedPage;
             await page.Children[2].Navigation.PopAsync();
         }
     }
 }
        /// <inheritdoc/>
        public async Task <TEntity> Save(TEntity entity, bool updateTimestamp = true)
        {
            var now = DateTimeOffset.Now;

            var entityId = entity.GetPropertyValueForAttribute <TId, PrimaryKeyAttribute>();
            var hasId    = entityId != null && !entityId.Equals(default(TId));

            if (updateTimestamp)
            {
                if (!hasId)
                {
                    entity.SetValueForAttribute <CreatedAtColumnAttribute>(now);
                }

                entity.SetValueForAttribute <UpdatedAtColumnAttribute>(now);
            }

            var isUpdate = hasId;

            if (hasId)
            {
                var tableName = await FetchTableName();

                var idColName = await FetchColumnNameFromAttribute <PrimaryKeyAttribute>();

                var oldRecord = await SqLiteConnection.FindWithQueryAsync <TEntity>(
                    $"SELECT * FROM {tableName} WHERE {idColName} = ?", entityId);

                if (oldRecord == default)
                {
                    isUpdate = false;
                }
            }

            var   saveTask = isUpdate ? SqLiteConnection.UpdateAsync(entity) : SqLiteConnection.InsertAsync(entity);
            await saveTask;

            return(entity);
        }
Exemplo n.º 14
0
        private void SubscribeAddOptionM()
        {
            MessagingCenter.Subscribe <NewOptionViewModel, Option>(this, "AddOptionM", (sender, args) => {
                //Add Criterias to new Option
                if (CurrentEvaluation.Criterias != null)
                {
                    args.Criterias = CurrentEvaluation.Criterias;
                }

                //Add new Option to Optionlist
                Options.Add(args);

                // Update CurrentEvaluation object
                CurrentEvaluation.Options = new List <Option>(Options.ToList());

                try {
                    SqLiteConnection.UpdateWithChildren(CurrentEvaluation);
                } catch (Exception e) {
                    throw new NotImplementedException();
                }
            });
        }
Exemplo n.º 15
0
        private void SubscribeAddCriteriaM()
        {
            MessagingCenter.Subscribe <NewCriteriaViewModel, Criteria>(this, "AddCriteriaM", (sender, args) => {
                //Add Options to new Criteria
                args.Options = CurrentEvaluation.Options;

                //Add new Criteria to Collection
                if (Criterias != null)
                {
                    Criterias.Add(args);
                }
                else
                {
                    Criterias = new ObservableRangeCollection <Criteria>();
                    Criterias.Add(args);
                }
                CurrentEvaluation.Criterias = new List <Criteria>(Criterias.ToList());

                //Update full Evaluation
                SqLiteConnection.UpdateWithChildren(CurrentEvaluation);
            });
        }
Exemplo n.º 16
0
        private async Task SaveClickedAsync()
        {
            if (Evaluation != null)
            {
                Evaluation.Criterias = new List <Criteria>();
                Evaluation.Options   = new List <Option>();

                try {
                    SqLiteConnection.Insert(Evaluation);
                } catch (Exception e) {
                    if (e.Message == "no such table: Evaluation")
                    {
                        SqLiteConnection.CreateTable <Evaluation>();
                        SqLiteConnection.Insert(Evaluation);
                    }
                } finally {
                    MessagingCenter.Send <NewEvaluationViewModel>(this, "AddEvaluationM");
                    var            page    = Application.Current.MainPage as TabbedPage;
                    NavigationPage navPage = page.Children[0] as NavigationPage;
                    await navPage.Navigation.PopAsync();
                }
            }
        }
Exemplo n.º 17
0
 public RunAStrategy(RunTheGame runTheGame, SqLiteConnection sqLite)
 {
     _runTheGame = runTheGame;
     _sqLite     = sqLite;
 }