public override void UpdateSettings() { SurveyType = (SurveyType)Convert.ToInt32(SurveyTypeRadioButtonList.SelectedValue); if (String.IsNullOrEmpty(SurveyClosingDateTextBox.Text)) { SurveyClosingDate = DateTime.MinValue; } else { if (DateTime.TryParse(SurveyClosingDateTextBox.Text, out DateTime result)) { SurveyClosingDate = result; } else { SurveyClosingDate = DateTime.MinValue; } } PrivacyConfirmation = PrivacyConfirmationCheckBox.Checked; ShowClosingDateMessage = ShowClosingDateMessageCheckBox.Checked; UseCaptcha = (UseCaptcha)Convert.ToInt32(UseCaptchaRadioButtonList.SelectedValue); TextQualifier = (TextQualifier)Convert.ToInt32(CSVTextQualifierDropDownList.SelectedValue); Separator = (Separator)Convert.ToInt32(CSVSeparatorDropDownlist.SelectedValue); base.UpdateSettings(); }
/// <summary> /// Qualifies /// </summary> /// <param name="cell"></param> /// <returns></returns> public string TextQualify(string cell) { cell = string.Concat( TextQualifier, cell.Replace(TextQualifier.ToString(), string.Concat(TextQualifier, TextQualifier)), TextQualifier ); return(cell); }
private string EscapeTextQualifier(string textAnswer, TextQualifier textQualifier) { var escapedAnswer = textAnswer; string qualifier = GetTextQualifierCharacter(textQualifier).ToString(); if (textAnswer.Contains(qualifier)) { escapedAnswer = textAnswer.Replace(qualifier, string.Format("{0}{0}", qualifier)); } return(escapedAnswer); }
/// <summary> /// Processes each record. /// </summary> protected override void ProcessRecord() { var testSuite = new TestSuite(); var actions = new List <ICsvProfileAction>(); if (MyInvocation.BoundParameters.ContainsKey("FieldSeparator")) { actions.Add(new FieldSeparatorAction(FieldSeparator.ToCharArray()[0])); } if (MyInvocation.BoundParameters.ContainsKey("TextQualifier")) { actions.Add(new TextQualifierAction(TextQualifier.ToCharArray()[0])); } if (MyInvocation.BoundParameters.ContainsKey("RecordSeparator")) { actions.Add(new RecordSeparatorAction(RecordSeparator)); } if (MyInvocation.BoundParameters.ContainsKey("FirstRowHeader")) { actions.Add(new FirstRowHeaderAction(FirstRowHeader.ToBool())); } if (MyInvocation.BoundParameters.ContainsKey("EmptyCell")) { actions.Add(new EmptyCellAction(EmptyCell)); } if (MyInvocation.BoundParameters.ContainsKey("MissingCell")) { actions.Add(new MissingCellAction(MissingCell)); } foreach (var action in actions) { action.Execute(testSuite); WriteVerbose(action.Display); } WriteObject(testSuite.Settings.CsvProfile); }
private char GetTextQualifierCharacter(TextQualifier textQualifier) { char textQualifierCharacter; switch (textQualifier) { case TextQualifier.None: textQualifierCharacter = '\0'; break; case TextQualifier.DoubleQuote: textQualifierCharacter = '\"'; break; case TextQualifier.SingleQuote: textQualifierCharacter = '\''; break; default: textQualifierCharacter = '\0'; break; } return(textQualifierCharacter); }
/// <summary> /// Writes the indexed <paramref name="column"/> from the <paramref name="record"/> to the line data <see cref="StringBuilder"/>. /// </summary> /// <param name="fcr">The corresponding <see cref="FileColumnReflector"/> configuration.</param> /// <param name="record">The related <see cref="FileRecord"/>.</param> /// <param name="column">The column index.</param> /// <param name="sb">The line data <see cref="StringBuilder"/>.</param> /// <returns><c>true</c> indicates that the column write was successful; otherwise, <c>false</c>.</returns> protected override bool WriteColumnToLineData(FileColumnReflector fcr, FileRecord record, int column, StringBuilder sb) { // Delimit each column. if (column > 0) { sb.Append(Delimiter); } // Get the string value and correct the width if needed. var str = column > record.Columns.Length ? null : record.Columns[column]; // Override if it is the hierarchy column. if (HierarchyColumnIndex.HasValue && HierarchyColumnIndex.Value == column) { str = record.RecordIdentifier; } // Where null this means there is nothing specific to write. if (string.IsNullOrEmpty(str)) { return(true); } // Validate/correct the string value to ensure column width conformance. if (!fcr.StringWidthCorrector(record, ref str)) { return(false); } // Check if the column content contains the delimiter and handle accordingly. var qualify = fcr.PropertyTypeCode == TypeCode.String && TextQualifier != NoCharacter && !TextQualifierOnlyWithDelimiterOnWrite; if (str.IndexOf(Delimiter) >= 0) { if (TextQualifier == NoCharacter) { record.Messages.Add(MessageType.Error, "Text delimiter character found inside column text; no text qualifier has been specified and would result in errant record."); return(false); } else { qualify = true; } } // Double qualify a qualifier inside of the text. if (TextQualifier != NoCharacter) { if (!qualify && str.IndexOf(TextQualifier) >= 0) { qualify = true; } if (qualify) { str = str.Replace(TextQualifier.ToString(), new string(TextQualifier, 2)); } } if (qualify) { sb.Append(TextQualifier); } sb.Append(str); if (qualify) { sb.Append(TextQualifier); } return(true); }
public string CSVExport(int moduleID, string resourceFile, Separator separator, TextQualifier textQualifier) { StringBuilder csvBuilder = new StringBuilder(); csvBuilder.Append(string.Format("{0}SurveyID{0}{1}{0}Question{0}{1}{0}Question Type{0}{1}{0}Statistical{0}{1}{0}Answer{0}{1}{0}Votes{0}{1}{0}Correct Answer{0}{1}{0}UserID{0}{1}{0}IP Address{0}{1}{0}GUID{0}{1}{0}Date{0}\r\n", GetTextQualifierCharacter(textQualifier), GetSeparatorCharacter(separator))); List <SurveysExportInfo> surveys = SurveysExportController.GetAll(moduleID); foreach (SurveysExportInfo survey in surveys) { csvBuilder.Append(string.Format("{0}{2}{0}{1}{0}{3}{0}{1}{0}{4}{0}{1}{0}{5}{0}{1}{0}{6}{0}{1}{0}{7}{0}{1}{0}{8}{0}{1}{0}{9}{0}{1}{0}{10}{0}{1}{0}{11}{0}{1}{0}{12:yyyy-MM-dd hh:mm:ss}{0}\r\n", GetTextQualifierCharacter(textQualifier), GetSeparatorCharacter(separator), survey.SurveyID, survey.Question, Localization.GetString(string.Format("QuestionType.{0}.Text", Enum.GetName(typeof(QuestionType), survey.OptionType), resourceFile)), survey.IsStatistical, (survey.OptionType == QuestionType.Text ? EscapeTextQualifier(survey.TextAnswer, textQualifier) : survey.OptionName), survey.Votes, survey.IsCorrect, survey.UserID, survey.IPAddress, survey.ResultUserID, survey.CreatedDate)); } return(csvBuilder.ToString()); }