Ejemplo n.º 1
0
 private static ParseResult TryParseYamlMetadataFile(string metadataFileName, out MetadataItem projectMetadata)
 {
     projectMetadata = null;
     try
     {
         using (StreamReader reader = new StreamReader(metadataFileName))
         {
             projectMetadata = YamlUtility.Deserialize <MetadataItem>(reader);
             return(new ParseResult(ResultLevel.Success));
         }
     }
     catch (Exception e)
     {
         return(new ParseResult(ResultLevel.Error, e.Message));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Extract YAML format content from yaml header
        /// </summary>
        /// <param name="content">the whole matched yaml header</param>
        /// <param name="requiredProperties">The properties that should be specified</param>
        /// <param name="properties"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private static bool TryExtractProperties(string content, IEnumerable <string> requiredProperties, out Dictionary <string, object> properties, out string message)
        {
            properties = new Dictionary <string, object>();
            message    = string.Empty;
            if (string.IsNullOrEmpty(content))
            {
                return(false);
            }
            try
            {
                using (StringReader reader = new StringReader(content))
                {
                    properties = YamlUtility.Deserialize <Dictionary <string, object> >(reader);
                    string checkPropertyMessage;
                    bool   checkPropertyStatus = CheckRequiredProperties(properties, requiredProperties, out checkPropertyMessage);
                    if (!checkPropertyStatus)
                    {
                        throw new InvalidDataException(checkPropertyMessage);
                    }

                    if (!string.IsNullOrEmpty(checkPropertyMessage))
                    {
                        message += checkPropertyMessage;
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                message += string.Format(@"yaml header
---
{0}
---
is not in a valid YAML format: {1}.", content, e.Message);
                return(false);
            }
        }