//************************************************************************* //* Private * //************************************************************************* //************************************************************************* //* Protected * //************************************************************************* //************************************************************************* //* Public * //************************************************************************* //*-----------------------------------------------------------------------* //* ParseProject * //*-----------------------------------------------------------------------* /// <summary> /// Parse the project text content into an abstracted definition /// collection. /// </summary> /// <param name="content"> /// JSON string content to be deserialized. /// </param> /// <param name="projectPath"> /// Path to the local working directory. /// </param> /// <param name="configs"> /// Configuration tables loaded in this session. /// </param> /// <param name="components"> /// Metadata component pages loaded in this session. /// </param> /// <param name="templates"> /// Template definitions loaded in this session. /// </param> /// <returns> /// Newly created and resolved JSON Template collection. /// </returns> /// <remarks> /// The project and template files both use generic templates. /// </remarks> public static void Parse(string content, string projectPath, ConfigurationCollection configs, ComponentCollection components, TemplateCollection templates) { ComponentItem iComponent = null; ConfigurationItem iConfig = null; TemplateItem iTemplate = null; JsonTemplateCollection project = JsonConvert. DeserializeObject<JsonTemplateCollection>(content); string typeName = ""; foreach(JsonTemplateItem template in project) { typeName = template.TypeName.ToLower(); switch(typeName) { case "componentpage": iComponent = ComponentItem.Parse(template.Name, template.Definition, projectPath); components.Add(iComponent); break; case "configuration": iConfig = ConfigurationItem.Parse(template.Name, template.Definition, projectPath); configs.Add(iConfig); break; case "template": iTemplate = TemplateItem.Parse(template.Name, template.Definition, projectPath); templates.Add(iTemplate); break; } } }
//*-----------------------------------------------------------------------* //*-----------------------------------------------------------------------* //* Parse * //*-----------------------------------------------------------------------* /// <summary> /// Parse the source content and return a populated object containing /// the deserialized information. /// </summary> /// <param name="name"> /// Name of the new component item. /// </param> /// <param name="lines"> /// Collection of string source lines representing the raw information to /// be parsed. /// </param> /// <param name="projectPath"> /// Current project path. /// </param> /// <returns> /// Newly created component item. /// </returns> public static ComponentItem Parse(string name, StringCollection lines, string projectPath) { AttributeItem attribute = null; //AttributeCollection attributes = null; int eCount = 0; int eIndex = 0; string element = ""; AttributeCatalog elements = null; AttributeCollection entry = null; string filename = ""; int iCount = 0; FileInfo ifile = null; int iIndex = 0; string insert = ""; MatchCollection matches = null; ComponentItem result = new ComponentItem(); string[] sArray = new string[0]; result.mName = name; eCount = lines.Count; for (eIndex = 0; eIndex < eCount; eIndex++) { // Get the current line. element = lines[eIndex]; matches = Regex.Matches(element, @"(?i:\{Include\((?<f>[^\)]+)\)\})"); if (matches.Count > 0) { // Inserts were found. In this version, that means no other entries will // be present on this line. foreach (Match match in matches) { filename = Tools.GetValue(match, "f"); if (Tools.IsRelative(filename)) { filename = Path.Combine(projectPath, filename); } ifile = new FileInfo(filename); if (ifile.Exists) { //attributes = new AttributeCollection(); //result.Attributes.Add(attributes); insert = File.ReadAllText(ifile.FullName); elements = JsonConvert.DeserializeObject <AttributeCatalog>(insert); iCount = elements.Count; for (iIndex = 0; iIndex < iCount; iIndex++) { result.Attributes.Add(elements[iIndex]); } } else { Console.WriteLine( string.Format( "Error could not read file: [{0}]...", ifile.FullName)); } } } else { // No inserts present on the line. element = element.Trim(); if (element.StartsWith("[")) { // Collection of entries. elements = JsonConvert. DeserializeObject <AttributeCatalog>(element); iCount = elements.Count; for (iIndex = 0; iIndex < iCount; iIndex++) { result.Attributes.Add(elements[iIndex]); } } else if (element.StartsWith("{")) { // One element object. entry = JsonConvert.DeserializeObject <AttributeCollection>(element); result.Attributes.Add(entry); } else if (element.IndexOf(":") > -1) { // Name / Value. entry = new AttributeCollection(); sArray = element.Split(new char[] { ':' }); if (sArray.Length > 1) { attribute = new AttributeItem(); entry.Add(attribute); attribute.Name = sArray[0].Replace("\"", "").Trim(); attribute.Value = sArray[1].Replace("\"", "").Trim(); } result.Attributes.Add(entry); } } } return(result); }
//*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -* /// <summary> /// Create a new Instance of the ComponentElementFollower Item. /// </summary> /// <param name="component"> /// A reference to the component being tracked. /// </param> /// <param name="element"> /// A reference to the currently selected attribute collection for the /// component. /// </param> public ComponentElementFollower(ComponentItem component, AttributeCollection element) { mComponent = component; mElement = element; }