コード例 #1
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            loginProgressBar.Visible = true;
            var  trr = new TestRailReader(serverTxt.Text, loginTxt.Text, passwordTxt.Text);
            bool accessGranted;

            var domain = "@neopost.com";

            if (loginTxt.Text.Substring(loginTxt.Text.Length - domain.Length, domain.Length).Equals(domain))
            {
                accessGranted = trr.TryLogin(domain);
            }
            else
            {
                accessGranted = trr.TryLogin();
            }

            if (accessGranted)
            {
                this.DialogResult = DialogResult.OK;

                var administrator = _dbs.GetAdmin();
                if (administrator != null)
                {
                    administrator.SetProperties(1, serverTxt.Text, loginTxt.Text, administrator.ProjectId);
                }
                else
                {
                    administrator = new Administrator();
                    administrator.SetProperties(1, serverTxt.Text, loginTxt.Text, -1);
                }

                try
                {
                    if (_dbs.DocumentExists(AdminCollectionName, 1))
                    {
                        _dbs.UpdateDocument(administrator);
                    }
                    else
                    {
                        _dbs.InsertDocument(administrator);
                    }
                }
                catch (Exception ex)
                {
                    Program.LogException(ex);
                }
            }
            else
            {
                loginProgressBar.Visible = false;
                MessageBox.Show(@"Cannot login, try again.");
                serverTxt.Focus();
            }
        }
コード例 #2
0
        private void UpdateDatabase()
        {
            SetLoading(true);
            var testCasesCount = 0;

            testCasesCountLbl.Invoke((MethodInvoker) delegate
            {
                testCasesCountLbl.Text = "updating...";
            });
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Parallel.ForEach(SelectedSuites, new ParallelOptions {
                MaxDegreeOfParallelism = Threads
            }, suite =>
            {
                var testCases  = _trr.GetTestCases(ProjectId, Int32.Parse(suite));
                var exceptions = new ConcurrentQueue <Exception>();
                Parallel.ForEach(testCases, new ParallelOptions {
                    MaxDegreeOfParallelism = Threads
                }, testCase =>
                {
                    try
                    {
                        var id = (int)testCase["id"];
                        var customOriginalId       = "";
                        var jTokenCustomOriginalId = testCase["custom_custom_original_id"];
                        if (jTokenCustomOriginalId != null)
                        {
                            if (jTokenCustomOriginalId.Type != JTokenType.Null)
                            {
                                customOriginalId = jTokenCustomOriginalId.ToString();
                            }
                        }
                        var title             = testCase["title"].ToString();
                        var sectionId         = (int)testCase["section_id"];
                        var sectionName       = GetSectionName(sectionId);
                        int milestoneId       = -1;
                        var jTokenMilestoneId = testCase["milestone_id"];
                        if (jTokenMilestoneId != null)
                        {
                            if (jTokenMilestoneId.Type != JTokenType.Null)
                            {
                                milestoneId = (int)jTokenMilestoneId;
                            }
                        }
                        var suiteId                    = (int)testCase["suite_id"];
                        var suiteName                  = GetSuiteName(suiteId);
                        var customCustomStatusId       = -1;
                        var jTokenCustomCustomStatusId = testCase["custom_custom_status"];
                        if (jTokenCustomCustomStatusId != null)
                        {
                            if (jTokenCustomCustomStatusId.Type != JTokenType.Null)
                            {
                                customCustomStatusId = (int)jTokenCustomCustomStatusId;
                            }
                        }
                        var customCustomStatusName              = GetStatusName(customCustomStatusId);
                        List <int> customCustomTestTypeIds      = new List <int>();
                        var jTokenCustomCustomCustomTestTypeIds = testCase["custom_custom_test_type"];
                        if (jTokenCustomCustomCustomTestTypeIds != null)
                        {
                            if (jTokenCustomCustomCustomTestTypeIds.Type != JTokenType.Null)
                            {
                                customCustomTestTypeIds = jTokenCustomCustomCustomTestTypeIds.ToObject <List <int> >();
                            }
                        }
                        var customCustomTestTypeName   = GetTestTypeName(customCustomTestTypeIds);
                        List <int> customCustomTagsIds = new List <int>();
                        var jTokenCustomCustomTagsIds  = testCase["custom_custom_tags"];
                        if (jTokenCustomCustomTagsIds != null)
                        {
                            if (jTokenCustomCustomTagsIds.Type != JTokenType.Null)
                            {
                                customCustomTagsIds = jTokenCustomCustomTagsIds.ToObject <List <int> >();
                            }
                        }
                        var customCustomTagsName = GetTagName(customCustomTagsIds);
                        var customAssigneeId     = -1;
                        var jTokenAssigneeId     = testCase["custom_assignee"];
                        if (jTokenAssigneeId != null)
                        {
                            if (jTokenAssigneeId.Type != JTokenType.Null)
                            {
                                customAssigneeId = (int)jTokenAssigneeId;
                            }
                        }
                        var customAssigneeName = GetAssigneeName(customAssigneeId);
                        var notes       = "";
                        var jTokenNotes = testCase["custom_notes"];
                        if (jTokenNotes != null)
                        {
                            if (jTokenNotes.Type != JTokenType.Null)
                            {
                                notes = jTokenNotes.ToString().ToLower();
                            }
                        }
                        var preconds       = "";
                        var jTokenPreconds = testCase["custom_preconds"];
                        if (jTokenPreconds != null)
                        {
                            if (jTokenPreconds.Type != JTokenType.Null)
                            {
                                preconds = jTokenPreconds.ToString().ToLower();
                            }
                        }
                        var customComments = "";
                        var jTokenComments = testCase["custom_custom_comments"];
                        if (jTokenComments != null)
                        {
                            if (jTokenComments.Type != JTokenType.Null)
                            {
                                customComments = jTokenComments.ToString().ToLower();
                            }
                        }
                        List <string> steps     = new List <string>();
                        List <string> expecteds = new List <string>();
                        var stepsInString       = "";
                        var expectedsInString   = "";
                        var jTokenCustomSteps   = testCase["custom_steps_separated"];
                        if (jTokenCustomSteps != null)
                        {
                            if (jTokenCustomSteps.Type != JTokenType.Null)
                            {
                                foreach (var step in jTokenCustomSteps)
                                {
                                    steps.Add((string)step["content"]);
                                    expecteds.Add((string)step["expected"]);
                                }
                                stepsInString     = String.Join(", ", steps.ToArray()).ToLower();
                                expectedsInString = String.Join(", ", expecteds.ToArray()).ToLower();
                            }
                        }

                        var dbs = new DatabaseServer(DatabaseFilePath, TestCasesCollectionName);

                        // Create your new Test Case instance
                        var testCaseDocument = new TestCase();
                        testCaseDocument.SetProperties(
                            id,
                            customOriginalId,
                            title,
                            sectionId,
                            sectionName,
                            milestoneId,
                            suiteId,
                            suiteName,
                            customCustomStatusId,
                            customCustomStatusName,
                            customCustomTestTypeIds,
                            customCustomTestTypeName,
                            customCustomTagsIds,
                            customCustomTagsName,
                            customAssigneeId,
                            customAssigneeName,
                            notes,
                            preconds,
                            stepsInString,
                            expectedsInString,
                            customComments,
                            (int)testCase["updated_on"]
                            );

                        if (dbs.DocumentExists(TestCasesCollectionName, testCaseDocument.Id))
                        {
                            if (dbs.IsTestCaseUpdatable(testCaseDocument.Id, testCaseDocument.UpdatedOn))
                            {
                                dbs.UpdateDocument(testCaseDocument);
                            }
                        }
                        else
                        {
                            dbs.InsertDocument(testCaseDocument);
                        }

                        testCasesCountLbl.Invoke((MethodInvoker) delegate
                        {
                            testCasesCountLbl.Text = (++testCasesCount).ToString();
                        });
                    }
                    catch (Exception ex)
                    {
                        exceptions.Enqueue(ex);
                    }
                });

                if (exceptions.Count > 0)
                {
                    try
                    {
                        throw new AggregateException(exceptions);
                    }
                    catch (AggregateException exs)
                    {
                        foreach (var ex in exs.InnerExceptions)
                        {
                            Program.LogException(ex);
                        }
                        MessageBox.Show(@"Cannot update DB properly, see log file.");
                    }
                }
            });

            sw.Stop();
            Console.WriteLine(@"Update took: " + sw.Elapsed.ToString("ss") + @"s");

            SetLoading(false);

            try
            {
                Thread threadInput = new Thread(CountTestCases);
                threadInput.Start();
            }
            catch (Exception ex)
            {
                Program.LogException(ex);
            }
        }