Exemplo n.º 1
0
 private void WriteUserResultInConsul(Result result, OldUser oldUser, Test test, ShellResult shell)
 {
     var dbManager = new ConsulIntegratorManager();
     dbManager.AddShellResult(oldUser, result, test, shell);
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            try
            {
                var consulDBMAnager = new ConsulIntegratorManager();

                // Remove all results from DB
                consulDBMAnager.RemoveResults();

                // Remove all Users from DB
                consulDBMAnager.RemoveUsers();

                #region not Remote

                if (!isRemote)
                {
                    #region OLD
                    //// Get not interpretated profiles
                    //var profiles = _profileRepository.GetProfiles().Where(x => x.Interpretated == false);

                    //foreach (var profile in profiles)
                    //{
                    //    // For each profile create user (if not exist) and result
                    //    var result = _resultRepository.GetResultByResultId(profile.Id);
                    //    var user = _resultRepository.GetUserByResult(profile.Id);
                    //    var test = _resultRepository.GetTestByResult(profile.Id);
                    //    var shellResult = _resultRepository.GetShellResultByResult(profile.Id);

                    //    consulDBMAnager.AddShellResult(user, result, test, shellResult);
                    //}

                    #endregion

                    // Get all SurveyShellResults
                    List<SurveysShellResult> surveysShellResults = SurveysResultRepository.GetAllShellResults();

                    if (surveysShellResults == null)
                    {
                        return;
                    }

                    if (surveysShellResults.Count == 0)
                    {
                        return;
                    }

                    foreach (var surveysShellResult in surveysShellResults)
                    {
                        PersonContent person = ClientRepository.GetPerson(surveysShellResult.PersonId);
                        if (person == null)
                        {
                            continue;
                        }
                        Test test = TestRepository.GetTest(surveysShellResult.MethodsId);
                        String testCodeName = String.Empty;
                        String answerStr = String.Empty;
                        if (test != null)
                        {
                            testCodeName = test.CodeName;
                            switch (testCodeName)
                            {
                                case Constraints.KSondiCodeName:
                                case Constraints.KKettel16ACodeName:
                                case Constraints.KKettel16BCodeName:
                                case Constraints.KShutzCodeName:
                                    answerStr = surveysShellResult.Answer;
                                    break;

                                case Constraints.KKotCodeName:
                                    KotMethod kot = new KotMethod(surveysShellResult.Answer);
                                    kot.CreateProfile();
                                    KotOutput output = new KotOutput();
                                    answerStr = output.FormString(kot);
                                    break;
                                case Constraints.KLusherPairCodeName:
                                    answerStr = LusherPairMethod.GetColorString(surveysShellResult.Answer);
                                    break;

                                case Constraints.KSelfAppraisalCodeName:
                                    answerStr = SelfAppraisalMethod.InvertAnswerString(surveysShellResult.Answer);
                                    break;

                                default:
                                    break;
                            }
                        }

                        consulDBMAnager.AddShellResult(person, surveysShellResult, testCodeName, answerStr);
                    }
                }

                #endregion

                #region Remote

                else
                {

                    label1.Visible = true;

                    // Authorize client
                    RegistrationDataResponse registratedClient = _migrationClient.Authorize();
                    if (registratedClient == null)
                    {
                        throw new UnauthorizedException();
                    }

                    // DateTime To also contains current day
                    DateTimePeriod period = new DateTimePeriod(){From = dateTimePickerFrom.Value, To = dateTimePickerTo.Value.AddDays(1)};

                    // Get migration data from server
                    IntegratorMigrationContent content = _migrationClient.GetMigrationData(registratedClient.Token, period);

                    label1.Visible = false;

                    if (content == null)
                    {
                        MessageBox.Show("Unauthorized");
                        button1.Enabled = true;
                        button2.Enabled = true;
                        return;
                    }

                    if (content.Persons == null || content.SurveysShellResults == null || content.Tests == null)
                    {
                        MessageBox.Show("Unauthorized");
                        button1.Enabled = true;
                        button2.Enabled = true;
                        return;
                    }

                    label2.Visible = true;

                    foreach (var surveysShellResult in content.SurveysShellResults)
                    {
                        WebPerson person = content.Persons.FirstOrDefault(x => x.Id == surveysShellResult.PersonId);
                        if (person == null)
                        {
                            continue;
                        }
                        WebTest test = content.Tests.FirstOrDefault(x => x.Id == surveysShellResult.MethodsId);
                        String testCodeName = String.Empty;
                        String answerStr = String.Empty;
                        if (test != null)
                        {
                            testCodeName = test.CodeName;
                            switch (testCodeName)
                            {
                                case Constraints.KSondiCodeName:
                                case Constraints.KKettel16ACodeName:
                                case Constraints.KKettel16BCodeName:
                                case Constraints.KShutzCodeName:
                                    answerStr = surveysShellResult.Answer;
                                    break;

                                case Constraints.KKotCodeName:
                                    KotMethod kot = new KotMethod(surveysShellResult.Answer);
                                    kot.CreateProfile();
                                    KotOutput output = new KotOutput();
                                    answerStr = output.FormString(kot);
                                    break;
                                case Constraints.KLusherPairCodeName:
                                    answerStr = LusherPairMethod.GetColorString(surveysShellResult.Answer);
                                    break;

                                case Constraints.KSelfAppraisalCodeName:
                                    answerStr = SelfAppraisalMethod.InvertAnswerString(surveysShellResult.Answer);
                                    break;

                                case Constraints.KMmpiCodeName:
                                    // TODO : fix, update method id to 420 on server part
                                    surveysShellResult.ShellMethodId = 420;
                                    String tmpStr = surveysShellResult.Answer;
                                    tmpStr = tmpStr.Replace('2', '0');
                                    answerStr = tmpStr;
                                    break;

                                default:
                                    break;
                            }
                        }

                        consulDBMAnager.AddShellResult(person, surveysShellResult, testCodeName, answerStr);
                    }

                    label2.Visible = false;

                }

                #endregion

                MessageBox.Show("Data was migrated");
            }
            catch (Exception exception)
            {
                label1.Visible = false;
                label2.Visible = false;
                MessageBox.Show(exception.Message);
                button1.Enabled = true;
                button2.Enabled = true;
            }
            button1.Enabled = true;
            button2.Enabled = true;
        }