public void Process(ConfigurationFile configurationFile) { Dictionary <string, string> aliases = configurationFile.Aliases.ToDictionary(x => x.Alias, x => x.FullClassName); ViewFileReader viewFileReader = new ViewFileReader(aliases); ViewFileProcessor viewFileProcessor = new ViewFileProcessor(); ViewFileWriter viewFileWriter = new ViewFileWriter(); DataTemplateProcessor dataTemplateProcessor = new DataTemplateProcessor(viewFileProcessor, viewFileWriter); List <Resource> globalResources = new List <Resource>(); List <StyleResource> globalStyleResources = new List <StyleResource>(); List <DataTemplateResource> globalDataTemplateResources = new List <DataTemplateResource>(); foreach (string resourceFile in configurationFile.GlobalResourceFiles) { string resourceRelativePath = PathHelper.GetRelativePath(resourceFile); Log.LogMessage(MessageImportance.High, "\t# Preprocessing resource file {0}", resourceRelativePath); List <Resource> resources = viewFileProcessor.ExtractGlobalResources(viewFileReader.Read(resourceFile)); List <StyleResource> styleResources = resources.Where(x => ParsingHelper.IsStyleTag(x.ResourceElement)).Select(x => new StyleResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsStyleTag(x.ResourceElement)); List <DataTemplateResource> dataTemplatesResources = resources.Where(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)).Select(x => new DataTemplateResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)); //assign an id to all data template before processing it (could be loop or just unordered things) string viewName = Path.GetFileNameWithoutExtension(resourceFile); foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplate.ViewId = string.Format("G_{0}_DT_{1}", viewName, dataTemplate.Key); dataTemplate.ViewHolderClassName = NameGeneratorHelper.GetViewHolderName(); } globalResources.AddRange(resources); globalStyleResources.AddRange(styleResources); globalDataTemplateResources.AddRange(dataTemplatesResources); } //process each data template foreach (DataTemplateResource dataTemplate in globalDataTemplateResources) { dataTemplateProcessor.Process(dataTemplate, globalResources, globalStyleResources, globalDataTemplateResources, configurationFile); } foreach (FileBindingDescription fileBindingDescription in configurationFile.FileDescriptions) { string viewInputRelativePath = PathHelper.GetRelativePath(fileBindingDescription.View.InputFile); string viewOutputRelativePath = PathHelper.GetRelativePath(fileBindingDescription.View.OutputFile); Log.LogMessage(MessageImportance.High, "\t# Preprocessing activity {0}.{1} with view {2}", fileBindingDescription.Activity.NamespaceName, fileBindingDescription.Activity.ClassName, viewInputRelativePath); XmlElement rootViewElement = viewFileReader.Read(fileBindingDescription.View.InputFile); //Parse expression, Extract resources and simplify the view file var expressionParsingResult = viewFileProcessor.ExtractExpressions(rootViewElement); List <IdViewObject> viewObjects = expressionParsingResult.Item2; List <XmlAttribute> expressionAttributes = expressionParsingResult.Item1; List <Resource> resources = viewFileProcessor.ExtractResources(rootViewElement); //filter resources for DataTemplate List <DataTemplateResource> dataTemplatesResources = resources.Where(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)).Select(x => new DataTemplateResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)); //filter resources for Style List <StyleResource> styleResources = resources.Where(x => ParsingHelper.IsStyleTag(x.ResourceElement)).Select(x => new StyleResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsStyleTag(x.ResourceElement)); List <StyleResource> totalStyleResources = new List <StyleResource>(styleResources); totalStyleResources.AddRange(globalStyleResources); //Write the view file for Android (axml format) Log.LogMessage(MessageImportance.High, "\t\t Generating view file {0}", viewOutputRelativePath); viewFileWriter.Write(rootViewElement, fileBindingDescription.View.OutputFile, totalStyleResources); ResourceFiles.Add(viewOutputRelativePath); //assign an id to all data template before processing it (could be loop or just unordered things) string viewName = Path.GetFileNameWithoutExtension(fileBindingDescription.View.OutputFile); foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplate.ViewId = string.Format("{0}_DT_{1}", viewName, dataTemplate.Key); dataTemplate.ViewHolderClassName = NameGeneratorHelper.GetViewHolderName(); } List <Resource> totalResources = new List <Resource>(resources); totalResources.AddRange(globalResources); List <DataTemplateResource> totalDataTemplateResources = new List <DataTemplateResource>(dataTemplatesResources); totalDataTemplateResources.AddRange(globalDataTemplateResources); //process each data template foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplateProcessor.Process(dataTemplate, totalResources, totalStyleResources, totalDataTemplateResources, configurationFile); } string classOutputFile = fileBindingDescription.Activity.OutputFile; string classOutputRelativePath = PathHelper.GetRelativePath(classOutputFile); List <Resource> mergedResources = new List <Resource>(totalResources); mergedResources.AddRange(totalDataTemplateResources); AbstractBindingHandlerClassGenerator generator; if (fileBindingDescription.Activity.IsFragment) { Log.LogMessage(MessageImportance.High, "\t\t Generating class file for Fragment to {0}", classOutputRelativePath); generator = new FragmentGenerator { BaseClassType = null, ClassName = fileBindingDescription.Activity.ClassName, Configuration = configurationFile, IsPartialClass = true, NamespaceName = fileBindingDescription.Activity.NamespaceName, }; } else { Log.LogMessage(MessageImportance.High, "\t\t Generating class file for Activity to {0}", classOutputRelativePath); generator = new ActivityGenerator { BaseClassType = null, ClassName = fileBindingDescription.Activity.ClassName, Configuration = configurationFile, IsPartialClass = true, NamespaceName = fileBindingDescription.Activity.NamespaceName, }; } generator.Preprocess(expressionAttributes, mergedResources, viewObjects); generator.Generate(classOutputFile); ClassFiles.Add(classOutputRelativePath); } ClassFiles.AddRange(dataTemplateProcessor.ClassFiles); ResourceFiles.AddRange(dataTemplateProcessor.ResourceFiles); CreateDummyClass(configurationFile); }
public void Process(ConfigurationFile configurationFile) { Dictionary<string, string> aliases = configurationFile.Aliases.ToDictionary(x => x.Alias, x => x.FullClassName); ViewFileReader viewFileReader = new ViewFileReader(aliases); ViewFileProcessor viewFileProcessor = new ViewFileProcessor(); ViewFileWriter viewFileWriter = new ViewFileWriter(); DataTemplateProcessor dataTemplateProcessor = new DataTemplateProcessor(viewFileProcessor, viewFileWriter); List<Resource> globalResources = new List<Resource>(); List<StyleResource> globalStyleResources = new List<StyleResource>(); List<DataTemplateResource> globalDataTemplateResources = new List<DataTemplateResource>(); foreach (string resourceFile in configurationFile.GlobalResourceFiles) { string resourceRelativePath = PathHelper.GetRelativePath(resourceFile); Log.LogMessage(MessageImportance.High, "\t# Preprocessing resource file {0}", resourceRelativePath); List<Resource> resources = viewFileProcessor.ExtractGlobalResources(viewFileReader.Read(resourceFile)); List<StyleResource> styleResources = resources.Where(x => ParsingHelper.IsStyleTag(x.ResourceElement)).Select(x => new StyleResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsStyleTag(x.ResourceElement)); List<DataTemplateResource> dataTemplatesResources = resources.Where(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)).Select(x => new DataTemplateResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)); //assign an id to all data template before processing it (could be loop or just unordered things) string viewName = Path.GetFileNameWithoutExtension(resourceFile); foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplate.ViewId = string.Format("G_{0}_DT_{1}", viewName, dataTemplate.Key); dataTemplate.ViewHolderClassName = NameGeneratorHelper.GetViewHolderName(); } globalResources.AddRange(resources); globalStyleResources.AddRange(styleResources); globalDataTemplateResources.AddRange(dataTemplatesResources); } //process each data template foreach (DataTemplateResource dataTemplate in globalDataTemplateResources) { dataTemplateProcessor.Process(dataTemplate, globalResources, globalStyleResources, globalDataTemplateResources, configurationFile); } foreach (FileBindingDescription fileBindingDescription in configurationFile.FileDescriptions) { string viewInputRelativePath = PathHelper.GetRelativePath(fileBindingDescription.View.InputFile); string viewOutputRelativePath = PathHelper.GetRelativePath(fileBindingDescription.View.OutputFile); Log.LogMessage(MessageImportance.High, "\t# Preprocessing activity {0}.{1} with view {2}", fileBindingDescription.Activity.NamespaceName, fileBindingDescription.Activity.ClassName, viewInputRelativePath); XmlElement rootViewElement = viewFileReader.Read(fileBindingDescription.View.InputFile); //Parse expression, Extract resources and simplify the view file var expressionParsingResult = viewFileProcessor.ExtractExpressions(rootViewElement); List<IdViewObject> viewObjects = expressionParsingResult.Item2; List<XmlAttribute> expressionAttributes = expressionParsingResult.Item1; List<Resource> resources = viewFileProcessor.ExtractResources(rootViewElement); //filter resources for DataTemplate List<DataTemplateResource> dataTemplatesResources = resources.Where(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)).Select(x => new DataTemplateResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)); //filter resources for Style List<StyleResource> styleResources = resources.Where(x => ParsingHelper.IsStyleTag(x.ResourceElement)).Select(x => new StyleResource(x)).ToList(); resources.RemoveAll(x => ParsingHelper.IsStyleTag(x.ResourceElement)); List<StyleResource> totalStyleResources = new List<StyleResource>(styleResources); totalStyleResources.AddRange(globalStyleResources); //Write the view file for Android (axml format) Log.LogMessage(MessageImportance.High, "\t\t Generating view file {0}", viewOutputRelativePath); viewFileWriter.Write(rootViewElement, fileBindingDescription.View.OutputFile, totalStyleResources); ResourceFiles.Add(viewOutputRelativePath); //assign an id to all data template before processing it (could be loop or just unordered things) string viewName = Path.GetFileNameWithoutExtension(fileBindingDescription.View.OutputFile); foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplate.ViewId = string.Format("{0}_DT_{1}", viewName, dataTemplate.Key); dataTemplate.ViewHolderClassName = NameGeneratorHelper.GetViewHolderName(); } List<Resource> totalResources = new List<Resource>(resources); totalResources.AddRange(globalResources); List<DataTemplateResource> totalDataTemplateResources = new List<DataTemplateResource>(dataTemplatesResources); totalDataTemplateResources.AddRange(globalDataTemplateResources); //process each data template foreach (DataTemplateResource dataTemplate in dataTemplatesResources) { dataTemplateProcessor.Process(dataTemplate, totalResources, totalStyleResources, totalDataTemplateResources, configurationFile); } string classOutputFile = fileBindingDescription.Activity.OutputFile; string classOutputRelativePath = PathHelper.GetRelativePath(classOutputFile); List<Resource> mergedResources = new List<Resource>(totalResources); mergedResources.AddRange(totalDataTemplateResources); AbstractBindingHandlerClassGenerator generator; if (fileBindingDescription.Activity.IsFragment) { Log.LogMessage(MessageImportance.High, "\t\t Generating class file for Fragment to {0}", classOutputRelativePath); generator = new FragmentGenerator { BaseClassType = null, ClassName = fileBindingDescription.Activity.ClassName, Configuration = configurationFile, IsPartialClass = true, NamespaceName = fileBindingDescription.Activity.NamespaceName, }; } else { Log.LogMessage(MessageImportance.High, "\t\t Generating class file for Activity to {0}", classOutputRelativePath); generator = new ActivityGenerator { BaseClassType = null, ClassName = fileBindingDescription.Activity.ClassName, Configuration = configurationFile, IsPartialClass = true, NamespaceName = fileBindingDescription.Activity.NamespaceName, }; } generator.Preprocess(expressionAttributes, mergedResources, viewObjects); generator.Generate(classOutputFile); ClassFiles.Add(classOutputRelativePath); } ClassFiles.AddRange(dataTemplateProcessor.ClassFiles); ResourceFiles.AddRange(dataTemplateProcessor.ResourceFiles); CreateDummyClass(configurationFile); }
public void Process(DataTemplateResource dataTemplate, List <Resource> resources, List <StyleResource> styleResources, List <DataTemplateResource> dataTemplatesResources, ConfigurationFile configurationFile) { string viewOutputFile = Path.Combine(configurationFile.ResourceLocation, string.Format("{0}.axml", dataTemplate.ViewId)); string viewOutputRelativePath = PathHelper.GetRelativePath(viewOutputFile); Log.LogMessage(MessageImportance.High, "\t\t Preprocessing DataTemplate {0}", dataTemplate.Key); // Extract informations from xml Tuple <List <XmlAttribute>, List <IdViewObject> > expressionResult = _viewFileProcessor.ExtractExpressions(dataTemplate.ResourceElement); List <XmlAttribute> expressionAttributes = expressionResult.Item1; List <IdViewObject> viewObjects = expressionResult.Item2; List <Resource> localResources = _viewFileProcessor.ExtractResources(dataTemplate.ResourceElement); // filter resources to find any dataTemplate in it List <DataTemplateResource> localDataTemplatesResources = localResources.Where(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)).Select(x => new DataTemplateResource(x)).ToList(); localResources.RemoveAll(x => ParsingHelper.IsDataTemplateTag(x.ResourceElement)); //filter resources for Style List <StyleResource> localStyleResources = resources.Where(x => ParsingHelper.IsStyleTag(x.ResourceElement)).Select(x => new StyleResource(x)).ToList(); localStyleResources.AddRange(styleResources); resources.RemoveAll(x => ParsingHelper.IsStyleTag(x.ResourceElement)); // now write a file for this data template Log.LogMessage(MessageImportance.High, "\t\t\t Generating view file for DataTemplate to {0}", viewOutputRelativePath); _viewFileWriter.Write(dataTemplate.ResourceElement, viewOutputFile, localStyleResources); ResourceFiles.Add(viewOutputRelativePath); // assign an id to all data template before processing it string viewName = dataTemplate.ViewId; foreach (DataTemplateResource localDataTemplate in localDataTemplatesResources) { localDataTemplate.ViewId = string.Format("{0}_DT_{1}", viewName, localDataTemplate.Key); localDataTemplate.ViewHolderClassName = NameGeneratorHelper.GetViewHolderName(); } // process each one List <Resource> mergedResources = new List <Resource>(resources); mergedResources.AddRange(localResources); List <DataTemplateResource> mergedDataTemplatesResources = new List <DataTemplateResource>(dataTemplatesResources); mergedDataTemplatesResources.AddRange(localDataTemplatesResources); foreach (DataTemplateResource localDataTemplate in localDataTemplatesResources) { Process(localDataTemplate, mergedResources, localStyleResources, mergedDataTemplatesResources, configurationFile); } string classOutputFile = Path.Combine(configurationFile.ClassLocation, string.Format("{0}.ui.cs", dataTemplate.ViewHolderClassName)); string classOutputRelativePath = PathHelper.GetRelativePath(classOutputFile); Log.LogMessage(MessageImportance.High, "\t\t\t Generating class file for DataTemplate to {0}", classOutputRelativePath); List <Resource> totalResources = new List <Resource>(mergedResources); totalResources.AddRange(mergedDataTemplatesResources); ViewHolderGenerator generator = new ViewHolderGenerator() { BaseClassType = "Storm.Mvvm.BaseViewHolder", ClassName = dataTemplate.ViewHolderClassName, Configuration = configurationFile, IsPartialClass = false, NamespaceName = configurationFile.GeneratedNamespace, }; generator.Preprocess(expressionAttributes, totalResources, viewObjects); generator.Generate(classOutputFile); ClassFiles.Add(classOutputRelativePath); }