Ejemplo n.º 1
0
 /// <summary>
 /// Injectinting ISurveyInfoRepository through Constructor
 /// </summary>
 /// <param name="iSurveyInfoRepository"></param>
 public SurveyFacade(ISurveyInfoRepository iSurveyInfoRepository, ISurveyAnswerRepository iSurveyResponseRepository,
                     Epi.Web.Common.Message.SurveyInfoRequest surveyInfoRequest, Epi.Web.Common.Message.SurveyAnswerRequest surveyResponseRequest,
                     Common.DTO.SurveyAnswerDTO surveyAnswerDTO,
                     SurveyResponseXML surveyResponseXML, UserAuthenticationRequest surveyAuthenticationRequest, Epi.Web.Common.DTO.PassCodeDTO PassCodeDTO, IOrganizationAccountRepository iOrgAccountRepository)
 {
     _iSurveyInfoRepository       = iSurveyInfoRepository;
     _iSurveyAnswerRepository     = iSurveyResponseRepository;
     _surveyInfoRequest           = surveyInfoRequest;
     _surveyAnswerRequest         = surveyResponseRequest;
     _surveyAnswerDTO             = surveyAnswerDTO;
     _surveyResponseXML           = surveyResponseXML;
     _surveyAuthenticationRequest = surveyAuthenticationRequest;
     _PassCodeDTO           = PassCodeDTO;
     _iOrgAccountRepository = iOrgAccountRepository;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initiates an export of the data to the specified file.
        /// </summary>
        public override void Export()
        {
            OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_CONNECTING);

            rowsExported = 0;
            WordBuilder wb = new WordBuilder(SEPARATOR);
            StreamWriter sw = null;

            Epi.Web.Common.Message.SurveyAnswerRequest Request = new Epi.Web.Common.Message.SurveyAnswerRequest();
            Request.Criteria.SurveyId = surveyKey.ToString();
            Request.Criteria.UserPublishKey = secToken;
            Request.Criteria.OrganizationKey = orgKey;
            Request.Criteria.ReturnSizeInfoOnly = true;
            Epi.Web.Common.Message.SurveyAnswerResponse Result = client.GetSurveyAnswer(Request);
            Pages = Result.NumberOfPages;
            PageSize = Result.PageSize;

            Request.Criteria.ReturnSizeInfoOnly = false;

            int count = 0;

            List<SurveyAnswerResponse> Results = new List<SurveyAnswerResponse>();

            OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_BUILDING_COLUMN_HEADINGS);

            for (int i = 1; i <= Pages; i++)
            {
                Request.Criteria.PageNumber = i;
                Request.Criteria.PageSize = PageSize;

                Result = client.GetSurveyAnswer(Request);
                Results.Add(Result);

                foreach (Epi.Web.Common.DTO.SurveyAnswerDTO surveyAnswer in Result.SurveyResponseList)
                {
                    if (surveyAnswer.Status == 3)
                    {
                        count++;
                    }
                }
            }

            if (SetMaxProgressBarValue != null)
            {
                SetMaxProgressBarValue((double)count);
            }

            List<string> columnHeaders = new List<string>();

            foreach (SurveyAnswerResponse R in Results)
            {
                wfList = ParseXML(R);

                foreach (WebFieldData wfData in wfList)
                {
                    if (!columnHeaders.Contains(wfData.FieldName))
                    {
                        columnHeaders.Add(wfData.FieldName);
                    }
                    else
                    {
                        break;
                    }
                }

                break;
            }

            try
            {
                OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORTING);

                sw = File.CreateText(fileName);

                foreach (string s in columnHeaders)
                {
                    wb.Add(s);
                }

                sw.WriteLine(wb.ToString());
                rowsExported = 0;

                foreach (SurveyAnswerResponse R in Results)
                {
                    string currentGUID = string.Empty;
                    string lastGUID = string.Empty;

                    wfList = ParseXML(R);

                    wb = new WordBuilder(SEPARATOR);

                    foreach (WebFieldData wfData in wfList)
                    {
                        currentGUID = wfData.RecordGUID;

                        if (!string.IsNullOrEmpty(currentGUID) && !string.IsNullOrEmpty(lastGUID) && currentGUID != lastGUID)
                        {
                            sw.WriteLine(wb.ToString());
                            wb = new WordBuilder(SEPARATOR);

                            OnSetStatusMessageAndProgressCount("", 1);
                        }

                        string rowValue = wfData.FieldValue.ToString().Replace("\r\n", " ");
                        if (rowValue.Contains(",") || rowValue.Contains("\""))
                        {
                            rowValue = rowValue.Replace("\"", "\"\"");
                            rowValue = Util.InsertIn(rowValue, "\"");
                        }
                        wb.Add(rowValue);

                        lastGUID = wfData.RecordGUID;
                    }

                    sw.WriteLine(wb.ToString());
                }

                OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_COMPLETE);

                if (FinishExport != null)
                {
                    FinishExport();
                }
            }

            catch (Exception ex)
            {
                OnSetStatusMessage(ex.Message);

                if (ExportFailed != null)
                {
                    ExportFailed(ex.Message);
                }
            }
            finally
            {
                // Clean up
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                    sw = null;
                }
            }
        }
        /// <summary>
        /// Initiates an export of the data to the specified file.
        /// </summary>
        public override void Export()
        {
            OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_CONNECTING);

            rowsExported = 0;
            WordBuilder  wb = new WordBuilder(SEPARATOR);
            StreamWriter sw = null;

            Epi.Web.Common.Message.SurveyAnswerRequest Request = new Epi.Web.Common.Message.SurveyAnswerRequest();
            Request.Criteria.SurveyId           = surveyKey.ToString();
            Request.Criteria.UserPublishKey     = secToken;
            Request.Criteria.OrganizationKey    = orgKey;
            Request.Criteria.ReturnSizeInfoOnly = true;
            Epi.Web.Common.Message.SurveyAnswerResponse Result = client.GetSurveyAnswer(Request);
            Pages    = Result.NumberOfPages;
            PageSize = Result.PageSize;

            Request.Criteria.ReturnSizeInfoOnly = false;

            int count = 0;

            List <SurveyAnswerResponse> Results = new List <SurveyAnswerResponse>();

            OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_BUILDING_COLUMN_HEADINGS);

            for (int i = 1; i <= Pages; i++)
            {
                Request.Criteria.PageNumber = i;
                Request.Criteria.PageSize   = PageSize;

                Result = client.GetSurveyAnswer(Request);
                Results.Add(Result);

                foreach (Epi.Web.Common.DTO.SurveyAnswerDTO surveyAnswer in Result.SurveyResponseList)
                {
                    if (surveyAnswer.Status == 3)
                    {
                        count++;
                    }
                }
            }


            if (SetMaxProgressBarValue != null)
            {
                SetMaxProgressBarValue((double)count);
            }

            List <string> columnHeaders = new List <string>();

            foreach (SurveyAnswerResponse R in Results)
            {
                wfList = ParseXML(R);

                foreach (WebFieldData wfData in wfList)
                {
                    if (!columnHeaders.Contains(wfData.FieldName))
                    {
                        columnHeaders.Add(wfData.FieldName);
                    }
                    else
                    {
                        break;
                    }
                }

                break;
            }

            try
            {
                OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORTING);

                sw = File.CreateText(fileName);

                foreach (string s in columnHeaders)
                {
                    wb.Add(s);
                }

                sw.WriteLine(wb.ToString());
                rowsExported = 0;


                foreach (SurveyAnswerResponse R in Results)
                {
                    string currentGUID = string.Empty;
                    string lastGUID    = string.Empty;

                    wfList = ParseXML(R);

                    wb = new WordBuilder(SEPARATOR);

                    foreach (WebFieldData wfData in wfList)
                    {
                        currentGUID = wfData.RecordGUID;

                        if (!string.IsNullOrEmpty(currentGUID) && !string.IsNullOrEmpty(lastGUID) && currentGUID != lastGUID)
                        {
                            sw.WriteLine(wb.ToString());
                            wb = new WordBuilder(SEPARATOR);

                            OnSetStatusMessageAndProgressCount("", 1);
                        }

                        string rowValue = wfData.FieldValue.ToString().Replace("\r\n", " ");
                        if (rowValue.Contains(",") || rowValue.Contains("\""))
                        {
                            rowValue = rowValue.Replace("\"", "\"\"");
                            rowValue = Util.InsertIn(rowValue, "\"");
                        }
                        wb.Add(rowValue);

                        lastGUID = wfData.RecordGUID;
                    }

                    sw.WriteLine(wb.ToString());
                }

                OnSetStatusMessage(ImportExportSharedStrings.WEB_CSV_EXPORT_COMPLETE);

                if (FinishExport != null)
                {
                    FinishExport();
                }
            }

            catch (Exception ex)
            {
                OnSetStatusMessage(ex.Message);

                if (ExportFailed != null)
                {
                    ExportFailed(ex.Message);
                }
            }
            finally
            {
                // Clean up
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                    sw = null;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the DoWorker event for the request worker
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void requestWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                try
                {
                    Epi.Web.Common.Message.SurveyAnswerRequest Request = new Epi.Web.Common.Message.SurveyAnswerRequest();
                    Request.Criteria.SurveyId = SurveyId;
                    Request.Criteria.UserPublishKey = new Guid(PublishKey);
                    Request.Criteria.OrganizationKey = new Guid(OrganizationKey);
                    Request.Criteria.ReturnSizeInfoOnly = true;
                    Epi.Web.Common.Message.SurveyAnswerResponse Result = client.GetSurveyAnswer(Request);
                    Pages = Result.NumberOfPages;
                    PageSize = Result.PageSize;

                    e.Result = Request;
                }
                catch (System.ServiceModel.CommunicationException ex)
                {
                    e.Result = null;
                }
                catch (Exception ex)
                {
                    e.Result = null;
                }
            }
        }