Ejemplo n.º 1
0
 public static string FirstParagraph(HtmlField html)
 {
     V_0 = (new Regex("<p[^>]*>.*?</p>")).Matches(html.get_Value());
     if (V_0.get_Count() <= 0)
     {
         return("");
     }
     return(V_0.get_Item(0).get_Value());
 }
Ejemplo n.º 2
0
        public void SearchHtmlField()
        {
            var field = new HtmlField
            {
                Value = "<p>Lorem ipsum</p>"
            };
            var search = field.GetIndexedContent();

            Assert.Equal(field.Value, search);
        }
        public override SPField EnsureExists(ref SPFieldCollection fields)
        {
            SPField field = null;

            try
            {
                field = fields.TryGetFieldByStaticName(InternalName);
            }
            catch
            {
                // field doesn't exist
            }

            if (field == null || !(field.Group.ToLower().Equals(ParentSchema.GroupName.ToLower())))
            {
                HtmlField htmlField = new HtmlField(fields, "HTML", InternalName);
                InternalName = fields.Add(htmlField);

                field = fields.GetFieldByInternalName(InternalName);
            }

            return(field);
        }
        public Form CreateForm(FormIngestionViewModel model)
        {
            try
            {
                model.ColumnHeadings = GetColumnHeadings(model.DataSheet);
                string lastColName = GetColumnName(model.ColumnHeadings.Count - 1);
                string dataRange   = string.Format("'{0}'!A2:{1}", model.DataSheet, lastColName);

                var request = SheetsService.Spreadsheets.Values.Get(Spreadsheet.SpreadsheetId, dataRange);
                var result  = request.Execute();

                if (string.IsNullOrEmpty(model.ListIdColumn))
                {
                    throw new Exception("Please identify the List ID column");
                }
                int listIdCol = model.ColumnHeadings.IndexOf(model.ListIdColumn);

                if (string.IsNullOrEmpty(model.BlockIdColumn))
                {
                    throw new Exception("Please identify the Block ID column");
                }
                int blockIdCol = model.ColumnHeadings.IndexOf(model.BlockIdColumn);

                List <int> preContextColIndicies = model.PreContextColumns.Select(s => model.ColumnHeadings.IndexOf(s)).ToList();

                if (string.IsNullOrEmpty(model.QuestionColumn))
                {
                    throw new Exception("Please idenfify the Question column");
                }
                int questionCol = model.ColumnHeadings.IndexOf(model.QuestionColumn);

                if (string.IsNullOrEmpty(model.AnswerTypeColumn))
                {
                    throw new Exception("Please idenfify the Answer Type column");
                }
                int answerTypeCol = model.ColumnHeadings.IndexOf(model.AnswerTypeColumn);

                if (string.IsNullOrEmpty(model.AnswerOptionsColumn))
                {
                    throw new Exception("Please idenfify the Answer Options column");
                }
                int answerOptionsCol = model.ColumnHeadings.IndexOf(model.AnswerOptionsColumn);

                if (string.IsNullOrEmpty(model.QuestionIdColumn))
                {
                    throw new Exception("Please idenfify the Question ID column");
                }
                int questionIdCol = model.ColumnHeadings.IndexOf(model.QuestionIdColumn);

                if (string.IsNullOrEmpty(model.IsRequiredIndicatorColumn))
                {
                    throw new Exception("Please idenfify the Required Question Indicator column");
                }
                int isRequiredCol = model.ColumnHeadings.IndexOf(model.IsRequiredIndicatorColumn);

                if (string.IsNullOrEmpty(model.AudioFileColumn))
                {
                    throw new Exception("Please idenfify the Audio File column");
                }
                int audioFileCol = model.ColumnHeadings.IndexOf(model.AudioFileColumn);

                string urlBase = string.IsNullOrEmpty(model.MediaFolderUrl) ? "/media/" : model.MediaFolderUrl.TrimEnd(new char[] { '/' }) + "/";

                //Iterating through all the data and creating numbered lists and list of blocks, list of headers and list of footers
                //The key of each dictionary element represents the list where each block, header or foter belongs to.
                List <CompositeFormField> listFields = new List <CompositeFormField>();
                Dictionary <int, List <CompositeFormField> > blockFieldSets = new Dictionary <int, List <CompositeFormField> >();
                Dictionary <int, CompositeFormField>         headers        = new Dictionary <int, CompositeFormField>();
                Dictionary <int, CompositeFormField>         footers        = new Dictionary <int, CompositeFormField>();

                var uniqueListIds = result.Values.Select(x => x[listIdCol] as string).Distinct().ToList();
                foreach (var listId in uniqueListIds.Where(x => x != "*").Select(x => int.Parse(x)))
                {
                    listFields.Add(new CompositeFormField()
                    {
                        Name = "Page " + listId, Page = listId
                    });
                    blockFieldSets.Add(listId, new List <CompositeFormField>());
                    headers.Add(listId, new CompositeFormField()
                    {
                        Name = "Footer"
                    });
                    footers.Add(listId, new CompositeFormField()
                    {
                        Name = "Header"
                    });
                }

                //Iterating through all the data and creating blocks, headers, footers and questions
                for (int index = 0; index < result.Values.Count; ++index)
                {
                    var           row    = result.Values[index];
                    List <string> values = row.Select(s => s.ToString().Trim()).ToList();

                    //Creating the question
                    List <string> preContexts   = preContextColIndicies.Select(i => values[i]).ToList();
                    string        questionText  = values[questionCol];
                    string        questionId    = values[questionIdCol];
                    string        answerType    = values[answerTypeCol];
                    string        answerOptions = answerOptionsCol < values.Count ? values[answerOptionsCol] : "";

                    if (string.IsNullOrEmpty(answerType))
                    {
                        if (string.IsNullOrEmpty(answerOptions))
                        {
                            answerType = "ShortText";
                        }
                        else
                        {
                            answerType = "RadioButtonSet";
                        }
                    }

                    ///
                    /// Each precontext and question are represented by a composite field inside the selected block.
                    ///
                    CompositeFormField surveyItem = new CompositeFormField()
                    {
                        Name = "Question " + questionId
                    };
                    foreach (string pc in preContexts)
                    {
                        if (!string.IsNullOrEmpty(pc.Trim()))
                        {
                            HtmlField html = new HtmlField()
                            {
                                Name = "Description"
                            };
                            html.SetDescription(pc);
                            surveyItem.InsertChildElement("./fields", html.Data);
                        }
                    }

                    //Adding the question text
                    HtmlField questionTextField = new HtmlField()
                    {
                        Name = "Text"
                    };
                    questionTextField.SetDescription(questionText);
                    surveyItem.InsertChildElement("./fields", questionTextField.Data);

                    //Adding the media file
                    string mediaFile = audioFileCol < values.Count ? values[audioFileCol].TrimStart(new char[] { '/' }) : null;
                    if (!string.IsNullOrEmpty(mediaFile))
                    {
                        ExternalMediaField mf = new ExternalMediaField()
                        {
                            Name       = "Media",
                            Source     = urlBase + mediaFile,
                            MediaType  = Models.Data.CFDataFile.MimeType.Audio,
                            PlayOnce   = true,
                            PlayOnShow = true
                        };
                        surveyItem.InsertChildElement("./fields", mf.Data);
                    }

                    FormField question = null;
                    if (answerType == "ShortText")
                    {
                        question = new TextField();
                    }
                    else if (answerType == "Number")
                    {
                        question = new NumberField();
                    }
                    else if (answerType == "Scale")
                    {
                        List <string> options = answerOptions.Split(new char[] { '|' }).Select(s => s.Trim()).ToList();
                        string[]      begin   = options[0].Split(new char[] { ':' });
                        string[]      end     = options[1].Split(new char[] { ':' });

                        question = new SliderField()
                        {
                            Min      = begin.Length > 0 ? int.Parse(begin[0]) : 0,
                            Max      = end.Length > 0 ? int.Parse(end[0]) : 1,
                            MinLabel = begin.Length > 1 ? begin[1] : "",
                            MaxLabel = end.Length > 1 ? end[1] : ""
                        };
                    }
                    else if (answerType == "RadioButtonSet" || answerType == "DropDown" || answerType == "CheckBoxSet")
                    {
                        List <string> optionStrings = answerOptions.Split(new char[] { '|' }).Select(s => s.Trim()).ToList();
                        List <Option> options       = new List <Option>();
                        foreach (var optVal in optionStrings)
                        {
                            Option opt = new Option();
                            opt.Value = new List <TextValue>()
                            {
                                new TextValue()
                                {
                                    Value = optVal, LanguageCode = "en"
                                }
                            };
                            options.Add(opt);
                        }

                        if (answerType == "RadioButtonSet")
                        {
                            question = new RadioButtonSet()
                            {
                                Options = options
                            }
                        }
                        ;
                        else if (answerType == "CheckBoxSet")
                        {
                            question = new CheckBoxSet()
                            {
                                Options = options
                            }
                        }
                        ;
                        else
                        {
                            question = new DropDownMenu()
                            {
                                Options = options
                            }
                        };
                    }
                    else if (answerType == "TextArea")
                    {
                        question = new TextArea();
                    }
                    else if (answerType == "Attachment")
                    {
                        question = new Attachment();
                    }
                    ////else if(answerType == "DropDown")
                    ////{
                    ////    List<string> optionStrings = answerOptions.Split(new char[] { '|' }).Select(s => s.Trim()).ToList();
                    ////    List<Option> options = new List<Option>();
                    ////    foreach (var optVal in optionStrings)
                    ////    {
                    ////        Option opt = new Option();
                    ////        opt.Value = new List<TextValue>() { new TextValue() { Value = optVal, LanguageCode = "en" } };
                    ////        options.Add(opt);
                    ////    }
                    ////    question = new DropDownMenu() { Options = options };
                    ////}
                    else
                    {
                        throw new Exception(string.Format("Answer type \"{0}\" is not implemented in survey form ingestion.", answerType));
                    }

                    question.Name           = "Answer";
                    question.ReferenceLabel = questionId;
                    question.IsRequired     = values[isRequiredCol] == "1";
                    question.SetAttribute("question-id", values[questionIdCol].ToString());
                    surveyItem.InsertChildElement("./fields", question.Data);

                    //Adding the question to the header, footer or the appropriate block of the
                    //selected list (or all the lists, if list number is *)
                    var    listIdStr       = values[listIdCol];
                    string blockIdStr      = values[blockIdCol].ToUpper();
                    var    applicableLists = listIdStr == "*" ? listFields : listFields.Where(x => x.Page == int.Parse(listIdStr));
                    foreach (var list in applicableLists)
                    {
                        if (blockIdStr == "H")
                        {
                            headers[list.Page].InsertChildElement("./fields", surveyItem.Data);
                        }
                        else if (blockIdStr == "F")
                        {
                            footers[list.Page].InsertChildElement("./fields", surveyItem.Data);
                        }
                        else
                        {
                            var blockSet = blockFieldSets[list.Page];
                            var block    = blockSet.Where(x => x.Page == int.Parse(blockIdStr)).FirstOrDefault();
                            if (block == null)
                            {
                                block = new CompositeFormField()
                                {
                                    Name = "Block " + blockIdStr, Page = int.Parse(blockIdStr)
                                };
                                blockSet.Add(block);
                            }
                            block.InsertChildElement("./fields", surveyItem.Data);
                        }
                    }
                }//END: foreach (var row in result.Values)

                ///
                /// By this point, we have all "lists" in the listFields array and all "blocks" corresponding to
                /// each of those lists in the blockFieldSets dictionary.
                ///

                //Inserting all blocks into each list entry
                foreach (var list in listFields)
                {
                    List <CompositeFormField> blocks = blockFieldSets[list.Page];
                    foreach (var block in blocks)
                    {
                        list.InsertChildElement("./fields", block.Data);
                    }

                    if (headers[list.Page].Fields.Any())
                    {
                        list.InsertChildElement("./header", headers[list.Page].Data);
                    }

                    if (footers[list.Page].Fields.Any())
                    {
                        list.InsertChildElement("./footer", footers[list.Page].Data);
                    }
                }

                Form form = new Form();
                form.SetName(model.FormName);
                form.SetDescription(model.FormDescription);

                foreach (var field in listFields)
                {
                    form.InsertChildElement("./fields", field.Data);
                }

                form.Serialize();
                return(form);



                //////    //If the block number is H or F, the question goes to the header or the footer section of a block.
                //////    if (blockIdCol.HasValue && values[blockIdCol.Value].ToUpper() == "H")
                //////    {
                //////        string lsitNum = listIdCol.HasValue ? values[listIdCol.Value] : "0";
                //////        if (!headers.ContainsKey(lsitNum))
                //////            headers.Add(lsitNum, new List<CompositeFormField>());

                //////    }
                //////    //Otherwise, this is a regular question.


                //////    string listNum = listIdCol.HasValue ? values[listIdCol.Value] : "0";
                //////    string blockNum = blockIdCol.HasValue ? values[blockIdCol.Value] : "0";
                //////    List<string> preContexts = preContextColIndicies.Select(i => values[i]).ToList();
                //////    string questionText = values[questionCol];

                //////    string answerType = answerOptionsCol.HasValue ? values[answerOptionsCol.Value] : "";
                //////    string answerOptions = answerOptionsCol.HasValue ? values[answerOptionsCol.Value] : "";

                //////    if (string.IsNullOrEmpty(answerType))
                //////    {
                //////        if (string.IsNullOrEmpty(answerOptions))
                //////            answerType = "TextField";
                //////        else
                //////            answerType = "RadioButtonSet";
                //////    }

                //////    ///
                //////    /// Each list is represented by a composite field at the top level of the form.
                //////    ///The list number is stored in the "page" property of the field.
                //////    ///Get the composite field representing the given list number, or create a new one if it doesn't exist
                //////    ///
                //////    CompositeFormField list = listFields.Where(field => field.Page == int.Parse(listNum)).FirstOrDefault();
                //////    if(list == null)
                //////    {
                //////        list = new CompositeFormField() { Page = int.Parse(listNum) };
                //////        listFields.Add(list);
                //////        blockFieldSets.Add(listNum, new List<CompositeFormField>()); //Placehoder for blocks of this list.
                //////    }

                //////    ///
                //////    /// Each block is represented by a composite field in the "list".
                //////    ///The block number is stored in the "page" propoerty of this composite field.
                //////    ///Get the composite field representinhg the give block number from the selected list. pr create a new one if it doesn't exist
                //////    ///
                //////    List<CompositeFormField> blocks = blockFieldSets[listNum];
                //////    CompositeFormField block = blocks.Where(field => field.Page == int.Parse(blockNum)).FirstOrDefault();
                //////    if(block == null)
                //////    {
                //////        block = new CompositeFormField() { Page = int.Parse(blockNum) };
                //////        blocks.Add(block);
                //////    }

                //////    ///
                //////    /// Each precontext and question are represented by a composite field inside the selected block.
                //////    ///
                //////    CompositeFormField surveyItem = new CompositeFormField();
                //////    foreach(string pc in preContexts)
                //////    {
                //////        if(!string.IsNullOrEmpty(pc.Trim()))
                //////        {
                //////            HtmlField html = new HtmlField();
                //////            html.SetDescription(pc);
                //////            surveyItem.InsertChildElement("./fields", html.Data);
                //////        }
                //////    }

                //////    FormField question = null;
                //////    if (answerType == "TextField")
                //////        question = new TextField();
                //////    else if (answerOptions == "RadioButtonSet")
                //////    {
                //////        List<string> optionStrings = answerOptions.Split(new char[] { '\n' }).Select(s => s.Trim()).ToList();
                //////        List<Option> options = new List<Option>();
                //////        foreach (var optVal in optionStrings)
                //////        {
                //////            Option opt = new Option();
                //////            opt.Value = new List<TextValue>() { new TextValue() { Value = optVal } };
                //////            options.Add(opt);
                //////        }

                //////        question = new RadioButtonSet()
                //////        {
                //////            Options = options
                //////        };
                //////    }
                //////    else
                //////        throw new Exception(string.Format("Answer type \"{0}\" is not implemented in survey form ingestion."));

                //////    question.SetName(questionText);
                //////    surveyItem.InsertChildElement("./fields", question.Data);

                //////    block.InsertChildElement("./fields", surveyItem.Data);
                //////}

                ////////    ///
                ////////    /// By this point, we have all "lists" in the listFields array and all "blocks" corresponding to
                ////////    /// each of those lists in the blockFieldSets dictionary.
                ////////    ///

                ////////    //Inserting all blocks into each list entry
                ////////    foreach(var list in listFields)
                ////////    {
                ////////        List<CompositeFormField> blocks = blockFieldSets[list.Page.ToString()];
                ////////        foreach (var block in blocks)
                ////////            list.InsertChildElement("./fields", block.Data);
                ////////    }

                ////////    Form form = new Form();
                ////////    form.SetName(model.FormName);
                ////////    form.SetDescription(model.FormDescription);

                ////////    foreach (var field in listFields)
                ////////        form.InsertChildElement("./fields", field.Data);

                ////////    form.Serialize();
                ////////    return form;
            }
            catch (Exception ex)
            {
                model.Error = ex.Message;
            }

            return(null);
        }
Ejemplo n.º 5
0
        protected IStorageHtmlField CreateEmptyHtmlFieldObject(HtmlField field)
        {
            var storageService = service.StorageService;

            return((IStorageHtmlField)storageService.GetObjectFactory().CreateEmptyFieldObject(field.GetType()));
        }
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlProperty"/> class.
 /// </summary>
 /// <param name="field">The field to wrap.</param>
 public HtmlProperty(Field field)
     : base(field)
 {
     _htmlField = field;
 }
 /// <summary>
 /// Tightens the relative image links.
 /// </summary>
 /// <param name="html">The HTML.</param>
 /// <returns>
 /// The relative image links.
 /// </returns>
 /// <contract><requires name="html" condition="not empty"/><ensures condition="not null"/></contract>
 public static string TightenRelativeImageLinks(string html)
 {
     return(HtmlField.TightenRelativeImageLinks(html));
 }
        public void HtmlListSubstitutionTests(string expected, IEnumerable <string> source)
        {
            var field = new HtmlField(source);

            Assert.Equal(expected, field.Html);
        }
        public void HtmlLinkSubstitutionTests(string expected, string source)
        {
            var htmlField = new HtmlField(source);

            Assert.Equal(expected, htmlField.Html);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="HtmlProperty"/> class.
		/// </summary>
		/// <param name="field">The field to wrap.</param>
		public HtmlProperty(Field field)
			: base(field)
		{
			this.htmlField = field;
		}
Ejemplo n.º 11
0
        internal static BaseField CreateField(FieldType type)
        {
            BaseField field = null;

            switch (type)
            {
            case FieldType.ObjectKey:
                field = new ObjectKeyField();
                break;

            case FieldType.BigInt:
                field = new BigIntField();
                break;

            case FieldType.Bool:
                field = new BoolField();
                break;

            case FieldType.Date:
                field = new DateField();
                break;

            case FieldType.DateTime:
                field = new DateTimeField();
                break;

            case FieldType.Decimal:
                field = new DecimalField();
                break;

            case FieldType.Image:
                field = new ImageField();
                break;

            case FieldType.Integer:
                field = new IntegerField();
                break;

            case FieldType.LongText:
                field = new LongTextField();
                break;

            case FieldType.Password:
                field = new PasswordField();
                break;

            case FieldType.MonataryAmount:
                field = new DecimalField();
                break;

            case FieldType.Html:
                field = new HtmlField();
                break;

            case FieldType.Xml:
                field = new XmlField();
                break;

            case FieldType.Json:
                field = new JsonField();
                break;

            case FieldType.Email:
                field = new EmailField();
                break;

            case FieldType.Phone:
                field = new PhoneField();
                break;

            case FieldType.ObjectLink:
                field = new ObjectLinkField();
                break;

            case FieldType.MultiObjectLink:
                field = new MultiObjectLinkField();
                break;

            case FieldType.Select:
                field = new SelectField();
                break;

            case FieldType.MultiSelect:
                field = new MultiSelectField();
                break;

            case FieldType.FilterField:
                field = new FilterField();
                break;

            case FieldType.OneToMany:
                field = new OneToManyField();
                break;

            default:
                field = new StringField();
                break;
            }
            return(field);
        }
Ejemplo n.º 12
0
		protected IStorageHtmlField CreateEmptyHtmlFieldObject(HtmlField field)
		{
			var storageService = service.StorageService;
			return (IStorageHtmlField)storageService.GetObjectFactory().CreateEmptyFieldObject(field.GetType());
		}