Exemplo n.º 1
0
 public TestorTreeItem(int itemId, int?testId, string itemName, TestorItemType itemType, TestorTreeItem[] subItems)
 {
     _itemId       = itemId;
     _itemName     = itemName;
     _itemType     = itemType;
     _testId       = testId;
     _isGroupAdmin = false;
     if (subItems != null)
     {
         _subItems = subItems;
     }
     else
     {
         _subItems = new TestorTreeItem[] { }
     };
 }
Exemplo n.º 2
0
        //Не является операцией сервиса
        private TestorTreeItem[] GetTestTreeItems(ref int i, GetTestTreeByLevelResult[] results, bool isActive)
        {
            List <TestorTreeItem> retValue = new List <TestorTreeItem>();
            int sl = 0;

            if (i != -1)
            {
                GetTestTreeByLevelResult currentItem = results[i];
                sl = currentItem.TreeNode.Split('/').Length;
            }
            for (i++; i < results.Length; i++)
            {
                GetTestTreeByLevelResult value = results[i];
                if (value.TreeNode.Split('/').Length <= sl)
                {
                    i--;
                    break;
                }
                TestorItemType type = (TestorItemType)value.NodeType;
                if (type == TestorItemType.Folder)
                {
                    TestorTreeItem item = new TestorTreeItem(value.NodeId, value.TestId.Value, value.TestName,
                                                             type, GetTestTreeItems(ref i, results, isActive));
                    item.ItemOwner = value.ItemOwner;
                    item.IsActive  = value.TestTreeIsActive;
                    if (!isActive || value.TestTreeIsActive == true)
                    {
                        retValue.Add(item);
                    }
                }
                else if (type == TestorItemType.Test || type == TestorItemType.MasterTest)
                {
                    TestorTreeItem item = new TestorTreeItem(value.NodeId, value.TestId.Value, value.TestName,
                                                             type, GetTestTreeItems(ref i, results, isActive));
                    item.ItemOwner = value.ItemOwner;
                    item.IsActive  = value.TestTreeIsActive;
                    retValue.Add(item);
                }
            }
            return(retValue.ToArray());
        }
Exemplo n.º 3
0
        public TestorTreeItem[] SendTests(byte[] testorData, int folderId, int[] groupIds)
        {
            Debug.Assert(testorData != null);
            Debug.Assert(folderId >= 0);

            Provider.TestRoles(TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                TestorData data = DataCompressor.DecompressData <TestorData>(testorData);

                //data.WriteXml("C:/locator.xml", System.Data.XmlWriteMode.IgnoreSchema);

                Dictionary <int, CoreTest> xTests = new Dictionary <int, CoreTest>();
                foreach (TestorData.CoreTestsRow coreTest in data.CoreTests)
                {
                    CoreTest test = new CoreTest();
                    test.TestKey      = coreTest.TestKey;
                    test.IsMasterTest = coreTest.IsMasterTest;
                    CreateCoreTest(coreTest, test);
                    xTests.Add(coreTest.TestId, test);
                    dataContext.CoreTests.InsertOnSubmit(test);
                    foreach (int groupId in groupIds)
                    {
                        TestGroup group = new TestGroup();
                        group.CoreTest = test;
                        group.GroupId  = groupId;
                        dataContext.TestGroups.InsertOnSubmit(group);
                    }
                    foreach (var coreQuest in coreTest.GetCoreQuestionsRows())
                    {
                        CoreQuestion quest = new CoreQuestion();
                        quest.CoreTest     = test;
                        quest.QuestionType = coreQuest.QuestionType;
                        quest.Question     = coreQuest.Question;
                        quest.QuestionMark = coreQuest.QuestionMark;
                        try
                        {
                            if (!Convert.IsDBNull(coreQuest.QuestionMetadata))
                            {
                                quest.QuestionMetadata = coreQuest.QuestionMetadata;
                            }
                        }
                        catch
                        {
                            quest.QuestionMetadata = null;
                        }
                        dataContext.CoreQuestions.InsertOnSubmit(quest);
                        foreach (var coreAnswer in coreQuest.GetCoreAnswersRows())
                        {
                            CoreAnswer answer = new CoreAnswer();
                            answer.CoreQuestion = quest;
                            answer.Answer       = coreAnswer.Answer;
                            answer.IsTrue       = coreAnswer.IsTrue;
                            try
                            {
                                if (!Convert.IsDBNull(coreAnswer.AnswerMetadata))
                                {
                                    answer.AnswerMetadata = coreAnswer.AnswerMetadata;
                                }
                            }
                            catch
                            {
                                answer.AnswerMetadata = null;
                            }
                            dataContext.CoreAnswers.InsertOnSubmit(answer);
                        }
                        foreach (var coreBlob in coreQuest.GetCoreBLOBsRows())
                        {
                            CoreBLOB blob = new CoreBLOB();
                            blob.CoreQuestion = quest;
                            blob.BLOBId       = coreBlob.BLOBId;
                            blob.BLOBContent  = coreBlob.BLOBContent;
                            dataContext.CoreBLOBs.InsertOnSubmit(blob);
                        }
                    }
                }
                foreach (var masterTest in data.CoreTests.Where(c => c.IsMasterTest == true))
                {
                    var parts = data.CoreMasterParts.Where(c => c.MasterTestId == masterTest.TestId);
                    var test  = xTests.Where(c => c.Value.TestKey == masterTest.TestKey).FirstOrDefault();
                    foreach (var part in parts)
                    {
                        CoreMasterPart masterPart = new CoreMasterPart();
                        masterPart.CoreTest1 = test.Value;
                        masterPart.CoreTest  = xTests.Where(
                            c => c.Key == part.PartTestId).FirstOrDefault().Value;
                        masterPart.QuestionsNumber = part.QuestionsNumber;
                        dataContext.CoreMasterParts.InsertOnSubmit(masterPart);
                    }
                }
                foreach (var coreReq in data.CoreRequirements)
                {
                    CoreRequirement req     = new CoreRequirement();
                    Guid            testKey = data.CoreTests.Where(c => c.TestId == coreReq.TestId).FirstOrDefault().TestKey;
                    Guid            reqKey  = data.CoreTests.Where(c => c.TestId == coreReq.Requirement).FirstOrDefault().TestKey;
                    req.CoreTest  = xTests.Where(c => c.Value.TestKey == testKey).FirstOrDefault().Value;
                    req.CoreTest1 = xTests.Where(c => c.Value.TestKey == reqKey).FirstOrDefault().Value;
                    dataContext.CoreRequirements.InsertOnSubmit(req);
                }
                try
                {
                    dataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                List <TestorTreeItem> retValue = new List <TestorTreeItem>();
                foreach (var test in xTests)
                {
                    CoreTest       coreTest = test.Value;
                    TestorItemType type     = TestorItemType.Test;
                    if (coreTest.IsMasterTest)
                    {
                        type = TestorItemType.MasterTest;
                    }
                    int            result = dataContext.AddTestTreeItem(GetId(folderId), (byte)type, coreTest.TestId, Provider.CurrentUser.UserId);
                    TestorTreeItem item   = new TestorTreeItem(result, coreTest.TestId,
                                                               coreTest.TestName, type, null);
                    retValue.Add(item);
                }
                return(retValue.ToArray());
            }
        }