コード例 #1
0
        public async void RefreshDB(string folderAbsolurePath)
        {
            var fileName   = "db.db";
            var dbFullPath = Path.Combine(folderAbsolurePath, fileName);

            try
            {
                using (var db = new ClientDBContext(dbFullPath))
                {
                    await db.Database.MigrateAsync();

                    bool isInit = await db.UITypes.AnyAsync();

                    if (!isInit)
                    {
                        InitDB();
                        InitTaskList();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
コード例 #2
0
 private void InitDB()
 {
     using (var db = new ClientDBContext())
     {
         UIType uiType;
         uiType = new UIType
         {
             UITypeId = UIType.uiSelect,
             Name     = "Выберите"
         };
         db.Add(uiType);
         uiType = new UIType
         {
             UITypeId = UIType.uiFormula,
             Name     = "Составьте формулу"
         };
         db.Add(uiType);
         uiType = new UIType
         {
             UITypeId = UIType.uiText,
             Name     = "Введите текст"
         };
         db.Add(uiType);
         uiType = new UIType
         {
             UITypeId = UIType.uiMixed,
             Name     = "Заполните"
         };
         db.Add(uiType);
         db.SaveChanges();
     }
 }
コード例 #3
0
 public void SaveTaskInstance(TaskInstance taskInstance)
 {
     using (var db = new ClientDBContext())
     {
         db.TaskInstances.Update(taskInstance);
         db.SaveChanges();
     }
 }
コード例 #4
0
 public IEnumerable <TaskInstance> GetTaskInstancesByTestId(int testId)
 {
     using (var db = new ClientDBContext())
     {
         return(db.TaskInstances.
                Where(x => x.TestId == testId).
                Include(y => y.Task).
                ToList());
     }
 }
コード例 #5
0
 public IEnumerable <TaskItem> GetTaskItemsByTaskId(int taskId)
 {
     using (var db = new ClientDBContext())
     {
         return(db.TaskItems.
                Include(x => x.Children).
                ThenInclude(y => y.UIType).
                Where(x => x.TaskId == taskId).
                ToList());
     }
 }
コード例 #6
0
 public void DeleteTest(Test test)
 {
     try
     {
         using (var db = new ClientDBContext())
         {
             db.Tests.Remove(test);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #7
0
 public IEnumerable <Test> GetTests()
 {
     try
     {
         using (var db = new ClientDBContext())
         {
             return(db.Tests.ToList());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }
コード例 #8
0
 public TaskInstance GetTaskInstance(int taskInstanceId)
 {
     using (var db = new ClientDBContext())
     {
         return(db.TaskInstances.
                Include(y1 => y1.Task).
                ThenInclude(z1 => z1.TaskItems).
                ThenInclude(ti1 => ti1.Children).
                ThenInclude(cti1 => cti1.Children).
                Include(y2 => y2.TaskItems).
                ThenInclude(ti2 => ti2.Children).
                ThenInclude(cti2 => cti2.Children).
                Include(y3 => y3.TaskItems).
                ThenInclude(y => y.UIType).
                First(x => x.TaskInstanceId == taskInstanceId));
     }
 }
コード例 #9
0
        public Test GenerateTest()
        {
            Test result = null;

            using (var db = new ClientDBContext())
            {
                Test test = new Test
                {
                    Date   = DateTime.Now,
                    Header = "Все подряд"
                };
                db.Add(test);

                IEnumerable <Task> tasks = db.Tasks;
                int i = 1;
                foreach (Task task in tasks)
                {
                    TaskInstance taskInstance = new TaskInstance
                    {
                        TestId = test.TestId,
                        TaskId = task.TaskId,
                        SeqNo  = i
                    };
                    db.Add(taskInstance);
                    i++;
                }

                db.SaveChanges();
                result = db.Tests.
                         Include(t1 => t1.TaskInstances).
                         ThenInclude(y1 => y1.Task).
                         ThenInclude(z1 => z1.TaskItems).
                         ThenInclude(ti1 => ti1.Children).
                         ThenInclude(cti1 => cti1.Children).
                         Include(t2 => t2.TaskInstances).
                         ThenInclude(y2 => y2.TaskItems).
                         ThenInclude(ti2 => ti2.Children).
                         Include(t3 => t3.TaskInstances).
                         ThenInclude(y3 => y3.Task).
                         ThenInclude(z3 => z3.TaskItems).
                         ThenInclude(ti3 => ti3.UIType).
                         FirstOrDefault(x => x.TestId == test.TestId);
            }
            return(result);
        }
コード例 #10
0
ファイル: TaskDBController.cs プロジェクト: fafanya/Engame
        private void AddTask_2()
        {
            using (var db = new ClientDBContext())
            {
                Task task = new Task
                {
                    Text = "Вчера в 9 вечера я выполнял домашнее задание."
                };
                db.Add(task);

                TaskItem parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lTense,
                    SeqNo      = 1,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(parentTaskItem);
                TaskItem childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lTense,
                    ValueInt   = VerbTense.vtPast,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(childTaskItem);

                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lAspect,
                    SeqNo      = 2,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lAspect,
                    ValueInt   = VerbAspect.vaContinuous,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(childTaskItem);


                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lSentencePart,
                    SeqNo      = 3,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childTaskItem);

                TaskItem childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spOtherPart,
                    SeqNo      = 1,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);

                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spSubject,
                    SeqNo      = 2,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);

                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = ModalVerb.mvWas,
                    SeqNo      = 3,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);

                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = NotionalVerb.nvVing,
                    SeqNo      = 4,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);

                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spOtherPart,
                    SeqNo      = 5,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);


                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lTranslate,
                    SeqNo      = 4,
                    UITypeId   = UIType.uiText
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId    = parentTaskItem.TaskItemId,
                    LangItemId  = Lib.lTranslate,
                    ValueString = "Yesterday at 9 pm I was doing my homework.",
                    UITypeId    = UIType.uiText
                };
                db.Add(childTaskItem);


                db.SaveChanges();
            }
        }
コード例 #11
0
ファイル: TaskDBController.cs プロジェクト: fafanya/Engame
        private void AddTask_1()
        {
            using (var db = new ClientDBContext())
            {
                Task task = new Task
                {
                    Text = "Мой брат хорошо играет в футбол."
                };
                db.Add(task);

                TaskItem parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lTense,
                    SeqNo      = 1,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(parentTaskItem);
                TaskItem childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lTense,
                    ValueInt   = VerbTense.vtPresent,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(childTaskItem);


                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lAspect,
                    SeqNo      = 2,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lAspect,
                    ValueInt   = VerbAspect.vaSimple,
                    UITypeId   = UIType.uiSelect
                };
                db.Add(childTaskItem);


                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lSentencePart,
                    SeqNo      = 3,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childTaskItem);
                TaskItem childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spOtherPart,
                    SeqNo      = 1,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spSubject,
                    SeqNo      = 2,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = NotionalVerb.nvVs,
                    SeqNo      = 3,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spOtherPart,
                    SeqNo      = 4,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);

                childTaskItem = new TaskItem
                {
                    ParentId   = parentTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spSubject,
                    SeqNo      = 1,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = NotionalVerb.nvVs,
                    SeqNo      = 2,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);
                childChildTaskItem = new TaskItem
                {
                    ParentId   = childTaskItem.TaskItemId,
                    LangItemId = Lib.lSentencePart,
                    ValueInt   = SentencePart.spOtherPart,
                    SeqNo      = 3,
                    UITypeId   = UIType.uiFormula
                };
                db.Add(childChildTaskItem);


                parentTaskItem = new TaskItem
                {
                    TaskId     = task.TaskId,
                    LangItemId = Lib.lTranslate,
                    SeqNo      = 4,
                    UITypeId   = UIType.uiText
                };
                db.Add(parentTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId    = parentTaskItem.TaskItemId,
                    LangItemId  = Lib.lTranslate,
                    ValueString = "My brother plays football well.",
                    UITypeId    = UIType.uiText
                };
                db.Add(childTaskItem);
                childTaskItem = new TaskItem
                {
                    ParentId    = parentTaskItem.TaskItemId,
                    LangItemId  = Lib.lTranslate,
                    ValueString = "My brother plays good football.",
                    UITypeId    = UIType.uiText
                };
                db.Add(childTaskItem);

                db.SaveChanges();
            }
        }