Inheritance: DataItem
コード例 #1
0
        private Scalar ParseBlockKey(out bool success)
        {
            int errorCount = Errors.Count;
            Scalar scalar = new Scalar();

            scalar.Text = ParsePlainTextSingleLine(out success);
            if (success) { ClearError(errorCount); return scalar; }

            scalar.Text = ParseDoubleQuotedSingleLine(out success);
            if (success) { ClearError(errorCount); return scalar; }

            scalar.Text = ParseSingleQuotedSingleLine(out success);
            if (success) { ClearError(errorCount); return scalar; }

            return scalar;
        }
コード例 #2
0
        private Scalar ParseBlockScalar(out bool success)
        {
            int errorCount = Errors.Count;
            Scalar scalar = new Scalar();

            scalar.Text = ParseLiteralText(out success);
            if (success) { ClearError(errorCount); return scalar; }

            scalar.Text = ParseFoldedText(out success);
            if (success) { ClearError(errorCount); return scalar; }

            return scalar;
        }
コード例 #3
0
        private Scalar ParseFlowScalarInFlow(out bool success)
        {
            int errorCount = Errors.Count;
            Scalar scalar = new Scalar();

            scalar.Text = ParsePlainTextInFlow(out success);
            if (success) { ClearError(errorCount); return scalar; }

            scalar.Text = ParseSingleQuotedText(out success);
            if (success) { ClearError(errorCount); return scalar; }

            scalar.Text = ParseDoubleQuotedText(out success);
            if (success) { ClearError(errorCount); return scalar; }

            return scalar;
        }
コード例 #4
0
        private DataItem ParseFlowNodeInFlow(out bool success)
        {
            int errorCount = Errors.Count;
            DataItem dataItem = null;

            dataItem = ParseAliasNode(out success);
            if (success) { ClearError(errorCount); return dataItem; }

            dataItem = ParseFlowContentInFlow(out success);
            if (success) { ClearError(errorCount); return dataItem; }

            while (true)
            {
                int seq_start_position1 = position;
                NodeProperty property = ParseNodeProperty(out success);
                if (success) { dataItem = new Scalar(); }
                else
                {
                    Error("Failed to parse property of FlowNodeInFlow.");
                    break;
                }

                while (true)
                {
                    int seq_start_position2 = position;
                    ParseSeparationLinesInFlow(out success);
                    if (!success)
                    {
                        Error("Failed to parse SeparationLinesInFlow of FlowNodeInFlow.");
                        break;
                    }

                    dataItem = ParseFlowContentInFlow(out success);
                    if (!success)
                    {
                        Error("Failed to parse FlowContentInFlow of FlowNodeInFlow.");
                        position = seq_start_position2;
                    }
                    break;
                }
                if (success) { SetDataItemProperty(dataItem, property); }
                success = true;
                break;
            }
            if (success) { ClearError(errorCount); return dataItem; }

            return dataItem;
        }
コード例 #5
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;
        }
コード例 #6
0
        /// <summary>
        /// Gets the value from post.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <param name="fldInfo">The FLD info.</param>
        /// <returns></returns>
        private string GetValueFromPost(PostInfo post, FieldInfo fldInfo, out Sequence vals)
        {
            string value=string.Empty;
            vals = null;
            // vals will be null initially,

              switch(fldInfo.FieldType.Name)
                    {
                        case "DateTime":
                            DateTime d=DateTime.Parse(fldInfo.GetValue(post).ToString());
                            value= d.ToString();
                            break;

                        case "String":
                            value = fldInfo.GetValue(post) as string;
                            break;

                      // vals will be updated in this case
                        case "String[]":
                            string []values = fldInfo.GetValue(post) as string[];
                            if(values==null)
                            {
                                return string.Empty;
                            }

                            vals=new Sequence();

                            foreach(string val in values)
                            {
                                Scalar ss = new Scalar {Text = val};
                                vals.Enties.Add(ss);
                            }

                            break;

                    }

            return value;
        }
コード例 #7
0
 private static TreeNode CreateNodeForScalar(Scalar scalar)
 {
     return new TreeNode(scalar.Text);
 }