private MappingEntry ParseBlockMappingEntry(out bool success)
        {
            int errorCount = Errors.Count;
            MappingEntry mappingEntry = new MappingEntry();

            while (true)
            {
                int seq_start_position1 = position;
                mappingEntry.Key = ParseBlockExplicitKey(out success);
                if (!success)
                {
                    Error("Failed to parse Key of BlockMappingEntry.");
                    break;
                }

                mappingEntry.Value = ParseBlockExplicitValue(out success);
                if (!success)
                {
                    Error("Failed to parse Value of BlockMappingEntry.");
                    position = seq_start_position1;
                }
                break;
            }
            if (success) { ClearError(errorCount); return mappingEntry; }

            while (true)
            {
                int seq_start_position2 = position;
                mappingEntry.Key = ParseBlockExplicitKey(out success);
                if (!success)
                {
                    Error("Failed to parse Key of BlockMappingEntry.");
                    break;
                }

                mappingEntry.Value = ParseEmptyFlow(out success);
                break;
            }
            if (success) { ClearError(errorCount); return mappingEntry; }

            while (true)
            {
                int seq_start_position3 = position;
                mappingEntry.Key = ParseBlockSimpleKey(out success);
                if (!success)
                {
                    Error("Failed to parse Key of BlockMappingEntry.");
                    break;
                }

                mappingEntry.Value = ParseBlockSimpleValue(out success);
                if (!success)
                {
                    Error("Failed to parse Value of BlockMappingEntry.");
                    position = seq_start_position3;
                }
                break;
            }
            if (success) { ClearError(errorCount); return mappingEntry; }

            while (true)
            {
                int seq_start_position4 = position;
                mappingEntry.Key = ParseBlockSimpleKey(out success);
                if (!success)
                {
                    Error("Failed to parse Key of BlockMappingEntry.");
                    break;
                }

                mappingEntry.Value = ParseEmptyBlock(out success);
                if (!success)
                {
                    Error("Failed to parse Value of BlockMappingEntry.");
                    position = seq_start_position4;
                }
                break;
            }
            if (success) { ClearError(errorCount); return mappingEntry; }

            return mappingEntry;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the yaml.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <param name="sampleYaml">The sample yaml.</param>
        /// <returns></returns>
        public List<MappingEntry> SetYaml(MetaBlog.PostInfo post, List<MappingEntry> sampleYaml)
        {
            FieldInfo[] fields = post.GetType().GetFields();

            foreach(FieldInfo fldInfo in fields)
            {
                string ignoredValues = System.Configuration.ConfigurationSettings.AppSettings["ignored"];
                string []ignoredArray=
                ignoredValues.Split(new char[]{';'});

                // Ignore the ignoredValues
                if(ignoredArray.Contains(fldInfo.Name))
                {
                    continue;
                }

                MappingEntry mappingEntry= sampleYaml.Find(
                    delegate(MappingEntry meEntry)
                        {

                            if (string.Compare(fldInfo.Name, meEntry.Key.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                                return true;

                            return CheckMapping(fldInfo.Name, meEntry.Key.ToString());

                           // return false;
                        }
                    );

                Sequence vals;
                if(mappingEntry!=null)
                {
                    sampleYaml.Remove(mappingEntry);
                    Scalar val = new Scalar {Text = GetValueFromPost(post, fldInfo, out vals)};
                    mappingEntry.Value = val;
                    sampleYaml.Add(mappingEntry);
                }
                else
                {
                    MappingEntry me=new MappingEntry();
                    Scalar key=new Scalar();
                    Scalar val=new Scalar();

                    // Assign Key
                    me.Key = key;
                    key.Text = fldInfo.Name;

                    // Get Value
                    val.Text=GetValueFromPost(post, fldInfo, out vals);

                    // It was a multi valued assignment
                    if(vals!=null)
                    {
                        me.Value = vals;
                    }
                    else
                    {
                        // Don't add if there is no value
                        if (string.IsNullOrEmpty(val.Text))
                            continue;

                        me.Value = val;
                    }

                    sampleYaml.Add(me);
                }

            }

            return sampleYaml;
        }