private void GenerateCommandParameterProperties(List <ExpressionContainer> expressionContainers) { foreach (IGrouping <string, ExpressionContainer> expressions in expressionContainers.GroupBy(x => x.TargetObject)) { const string attributeName = "CommandParameter"; Regex commandParameterEventRegex = new Regex("^(?<eventName>[a-zA-Z0-9_]+)\\." + attributeName, RegexOptions.Compiled | RegexOptions.IgnoreCase); List <ExpressionContainer> commandParameterEventExpressions = expressions.Where(x => commandParameterEventRegex.IsMatch(x.TargetField)).ToList(); ExpressionContainer commandParameterExpression = expressions.SingleOrDefault(x => attributeName.Equals(x.TargetField, StringComparison.InvariantCultureIgnoreCase)); commandParameterEventExpressions.ForEach(x => x.IsCommandParameterExpression = true); if (commandParameterExpression != null) { commandParameterExpression.IsCommandParameterExpression = true; } foreach (ExpressionContainer expression in commandParameterEventExpressions) { //find associated event (if exists) string eventName = commandParameterEventRegex.Match(expression.TargetField).Groups["eventName"].Value; ExpressionContainer associatedExpression = expressions.FirstOrDefault(x => eventName.Equals(x.TargetField, StringComparison.InvariantCultureIgnoreCase) && !x.IsCommandParameterExpression); if (associatedExpression != null) { // create proxy property CommandParameterProxy to handle this var result = CodeGeneratorHelper.GenerateProxyProperty(NameGeneratorHelper.GetCommandParameterName(), "CommandParameterProxy"); Properties.Add(result.Item2); Fields.Add(result.Item1); string propertyName = CodeGeneratorHelper.GetPropertyReference(result.Item2).PropertyName; // retarget the binding expression to this new property and to the Value field expression.TargetObject = propertyName; expression.TargetField = "Value"; associatedExpression.CommandParameterTarget = propertyName; } } if (commandParameterExpression != null) { // create proxy property CommandParameterProxy to handle this var result = CodeGeneratorHelper.GenerateProxyProperty(NameGeneratorHelper.GetCommandParameterName(), "CommandParameterProxy"); Properties.Add(result.Item2); Fields.Add(result.Item1); string propertyName = CodeGeneratorHelper.GetPropertyReference(result.Item2).PropertyName; // retarget the binding expression to this new property and to the Value field commandParameterExpression.TargetObject = propertyName; commandParameterExpression.TargetField = "Value"; foreach (ExpressionContainer associatedExpression in expressions.Where(x => string.IsNullOrEmpty(x.CommandParameterTarget) && !x.IsCommandParameterExpression)) { associatedExpression.CommandParameterTarget = propertyName; } } } }
public void CreateDummyClass(ConfigurationFile file) { string className = NameGeneratorHelper.GetDummyClassName(); string namespaceName = file.GeneratedNamespace; EmptyGenerator generator = new EmptyGenerator { ClassName = className, IsPartialClass = false, NamespaceName = namespaceName, BaseClassType = null, Configuration = file, }; string outputFile = Path.Combine(file.ClassLocation, string.Format("{0}.{1}.cs", namespaceName, className)); string outputFileRelativePath = PathHelper.GetRelativePath(outputFile); generator.Generate(outputFile); ClassFiles.Add(outputFileRelativePath); }
private void _ExtractExpressions(XmlElement element, List <XmlAttribute> expressionAttributes, List <IdViewObject> viewsId) { if (ParsingHelper.IsResourceTag(element)) { //will be processed later so do not touch it for now return; } string id = null; bool isFragment = ParsingHelper.IsFragmentTag(element); List <XmlAttribute> bindings = new List <XmlAttribute>(); foreach (XmlAttribute attribute in element.Attributes) { if (ParsingHelper.IsXmlOnlyAttribute(attribute)) { continue; } if (ParsingHelper.IsIdAttribute(attribute)) { if (id != null) { throw new Exception("Multiple id for same element"); } id = attribute.Value; // add @+id/ to use auto declare mechanism in Android attribute.Value = "@+id/" + id; //check isFragment cause we will do a findViewById next and it will not works if (!isFragment) { viewsId.Add(new IdViewObject(element.LocalName, id)); } } else if (ParsingHelper.IsCustomAttribute(attribute)) { bindings.Add(attribute); } else if (ParsingHelper.IsAttributeWithExpression(attribute)) { bindings.Add(attribute); } } if (id == null && bindings.Any()) { XmlAttribute attribute = new XmlAttribute(); id = NameGeneratorHelper.GetViewId(); attribute.Value = "@+id/" + id; attribute.FullName = "android:id"; attribute.NamespaceUri = "http://schemas.android.com/apk/res/android"; element.Attributes.Add(attribute); //check isFragment cause we will do a findViewById next and it will not works if (!isFragment) { viewsId.Add(new IdViewObject(element.LocalName, id)); } } foreach (XmlAttribute attribute in bindings) { attribute.AttachedId = id; element.Attributes.Remove(attribute); } expressionAttributes.AddRange(bindings); foreach (XmlElement child in element.Children) { _ExtractExpressions(child, expressionAttributes, viewsId); } }
private void CreateBindingOverrideMethod(List <ExpressionContainer> bindingExpressions, CodePropertyReferenceExpression localizationServiceReference, Dictionary <string, CodePropertyReferenceExpression> resourceReferences, params CodeMethodReferenceExpression[] preCallMethods) { CodeTypeReference listOfBindingObjectTypeReference = CodeGeneratorHelper.GetTypeReferenceFromName("List<BindingObject>"); CodeTypeReference bindingObjectTypeReference = CodeGeneratorHelper.GetTypeReferenceFromName("BindingObject"); CodeTypeReference bindingExpressionTypeReference = CodeGeneratorHelper.GetTypeReferenceFromName("BindingExpression"); CodeMemberMethod method = new CodeMemberMethod { Attributes = MemberAttributes.Family | MemberAttributes.Override, Name = NameGeneratorHelper.GET_BINDING_METHOD_NAME, ReturnType = listOfBindingObjectTypeReference }; foreach (CodeMethodReferenceExpression preCallMethod in preCallMethods) { method.Statements.Add(new CodeMethodInvokeExpression(preCallMethod)); } var variableCreationResult = CodeGeneratorHelper.CreateVariable(listOfBindingObjectTypeReference, "result"); method.Statements.Add(variableCreationResult.Item1); CodeVariableReferenceExpression resultReference = variableCreationResult.Item2; // group binding expression by target object to simplify foreach (IGrouping <string, ExpressionContainer> groupedExpressions in bindingExpressions.GroupBy(x => x.TargetObject)) { // create a variable for this binding object and build it with the Property of the view element variableCreationResult = CodeGeneratorHelper.CreateVariable(bindingObjectTypeReference, NameGeneratorHelper.GetBindingObjectName(), CodeGeneratorHelper.GetPropertyReference(groupedExpressions.Key)); //viewElementReferences[groupedExpressions.Key]); method.Statements.Add(variableCreationResult.Item1); CodeVariableReferenceExpression objectReference = variableCreationResult.Item2; method.Statements.Add(new CodeMethodInvokeExpression(resultReference, "Add", objectReference)); foreach (ExpressionContainer expressionContainer in groupedExpressions) { Expression expression = expressionContainer.Expression; // create a binding expression for this variableCreationResult = CodeGeneratorHelper.CreateVariable(bindingExpressionTypeReference, NameGeneratorHelper.GetBindingExpressionName(), new CodePrimitiveExpression(expressionContainer.TargetField), new CodePrimitiveExpression(expression.GetValue(BindingExpression.PATH))); method.Statements.Add(variableCreationResult.Item1); CodeVariableReferenceExpression expressionReference = variableCreationResult.Item2; if (expression.Has(BindingExpression.MODE) && expression.Get <ModeExpression>(BindingExpression.MODE).Value != BindingMode.OneWay) { // Expression could only be of type ModeExpression BindingMode mode = expression.Get <ModeExpression>(BindingExpression.MODE).Value; method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "Mode"), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("BindingMode"), mode.ToString()))); } if (expression.Has(BindingExpression.UPDATE_EVENT) && !string.IsNullOrWhiteSpace(expression.GetValue(BindingExpression.UPDATE_EVENT))) { // Expression could only be of type Text string updateEvent = expression.GetValue(BindingExpression.UPDATE_EVENT); method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "UpdateEvent"), new CodePrimitiveExpression(updateEvent))); } if (expression.Has(BindingExpression.CONVERTER)) { // Expression could be type Resource or (Binding : not implemented for now) Expression converterExpression = expression[BindingExpression.CONVERTER]; if (converterExpression.IsOfType(ExpressionType.Binding)) { Log.LogError("Binding expression for converter is not implemented yet"); throw new NotImplementedException("Binding expression for converter is not implemented yet"); } else if (converterExpression.IsOfType(ExpressionType.Resource)) { string resourceKey = converterExpression.GetValue(ResourceExpression.KEY); CodePropertyReferenceExpression resourceReference = resourceReferences[resourceKey]; method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "Converter"), resourceReference)); } } if (expression.Has(BindingExpression.CONVERTER_PARAMETER)) { // Expression could be of type Resource, Translation, Text or (Binding : not implemented for now) Expression converterParameterExpression = expression[BindingExpression.CONVERTER_PARAMETER]; if (converterParameterExpression.IsOfType(ExpressionType.Binding)) { Log.LogError("Binding expression for converter parameter is not implemented yet"); throw new NotImplementedException("Binding expression for converter parameter is not implemented yet"); } else if (converterParameterExpression.IsOfType(ExpressionType.Resource)) { string resourceKey = converterParameterExpression.GetValue(ResourceExpression.KEY); CodePropertyReferenceExpression resourceReference = resourceReferences[resourceKey]; method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), resourceReference)); } else if (converterParameterExpression.IsOfType(ExpressionType.Translation)) { CodeMethodInvokeExpression valueReference = GenerateStatementToGetTranslation(localizationServiceReference, converterParameterExpression); method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), valueReference)); } else if (converterParameterExpression.IsOfType(ExpressionType.Value)) { TextExpression textExpression = converterParameterExpression as TextExpression; if (textExpression != null) { string converterParameterValue = textExpression.Value; method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), new CodePrimitiveExpression(converterParameterValue))); } else { throw new InvalidOperationException("Can't get a textExpression from a ExpressionType.Value expression..."); } } } if (!string.IsNullOrWhiteSpace(expressionContainer.CommandParameterTarget)) { method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "CommandParameter"), CodeGeneratorHelper.GetPropertyReference(expressionContainer.CommandParameterTarget))); } method.Statements.Add(new CodeMethodInvokeExpression(objectReference, "AddExpression", expressionReference)); } } method.Statements.Add(new CodeMethodReturnStatement(resultReference)); Methods.Add(method); }
public void Preprocess(List <XmlAttribute> expressionAttributes, List <Resource> resources, List <IdViewObject> viewElements) { // Create all properties for viewElements foreach (IdViewObject viewElement in viewElements) { Tuple <CodeMemberField, CodeMemberProperty> result = CodeGeneratorHelper.GenerateProxyProperty(viewElement.Id, viewElement.TypeName, new CodeMethodInvokeExpression(GetFindViewByIdReference(viewElement.TypeName), CodeGeneratorHelper.GetAndroidResourceReference(ResourcePart.Id, viewElement.Id))); Fields.Add(result.Item1); Properties.Add(result.Item2); } // Generate property for ILocalizationService LocalizationService CodePropertyReferenceExpression localizationServiceReference = CreateLocalizationServiceProperty(); // Eval all expressions List <ExpressionContainer> expressions = (from attribute in expressionAttributes let expressionResult = EvaluateExpression(attribute.Value) where expressionResult != null select new ExpressionContainer { Expression = expressionResult, TargetObject = attribute.AttachedId, TargetField = attribute.LocalName, IsTargetingResource = false, }).ToList(); // Affect a property name to all resources and check if some has expression as attribute value foreach (Resource res in resources) { res.PropertyName = NameGeneratorHelper.GetResourceName(); foreach (KeyValuePair <string, string> propertyItem in res.Properties.Where(propertyItem => ParsingHelper.IsExpressionValue(propertyItem.Value)).ToList()) { res.Properties.Remove(propertyItem.Key); Expression expr = EvaluateExpression(propertyItem.Value); if (expr != null) { if (CheckCorrectExpressionInResource(expr)) { Log.LogError("Expression {0} is invalid in a resource context (you cannot use binding)", propertyItem.Value); } else { expressions.Add(new ExpressionContainer { Expression = expr, TargetObject = res.PropertyName, TargetField = propertyItem.Key, IsTargetingResource = true, }); } } } } // Check if all resources are declared and filter those we need Dictionary <string, Resource> neededResource = new Dictionary <string, Resource>(); List <string> resourceKeys = expressions.SelectMany(x => GetUsedResources(x.Expression)).Distinct().ToList(); foreach (string key in resourceKeys) { Resource res = resources.FirstOrDefault(x => key.Equals(x.Key, StringComparison.InvariantCultureIgnoreCase)); if (res == null) { Log.LogError("Resource with key {0} does not exists", key); } else { neededResource.Add(key, res); } } // Go through all binding expression and find those where we need to declare implicit resources // Will also remove all Template & TemplateSelector fields in BindingExpression // to only have a fully prepared adapter foreach (Expression bindingExpression in expressions.SelectMany(expression => GetBindingExpressions(expression.Expression)).ToList()) { if (bindingExpression.Has(BindingExpression.TEMPLATE)) { // create a template selector string templateSelectorKey = NameGeneratorHelper.GetResourceKey(); string templateSelectorPropertyName = NameGeneratorHelper.GetResourceName(); neededResource.Add(templateSelectorKey, new Resource(templateSelectorKey) { PropertyName = templateSelectorPropertyName, ResourceElement = null, Type = Configuration.DefaultTemplateSelector }); expressions.Add(new ExpressionContainer { Expression = bindingExpression[BindingExpression.TEMPLATE], TargetField = Configuration.DefaultTemplateSelectorField, TargetObject = templateSelectorPropertyName, IsTargetingResource = true, }); bindingExpression.Remove(BindingExpression.TEMPLATE); ResourceExpression templateSelectorResourceExpression = new ResourceExpression(); templateSelectorResourceExpression.Add(ResourceExpression.KEY, new TextExpression { Value = templateSelectorKey }); bindingExpression.Add(BindingExpression.TEMPLATE_SELECTOR, templateSelectorResourceExpression); } if (bindingExpression.Has(BindingExpression.TEMPLATE_SELECTOR)) { // create an adapter string adapterKey = NameGeneratorHelper.GetResourceKey(); string adapterName = NameGeneratorHelper.GetResourceName(); neededResource.Add(adapterKey, new Resource(adapterKey) { PropertyName = adapterName, ResourceElement = null, Type = Configuration.DefaultAdapter }); expressions.Add(new ExpressionContainer { Expression = bindingExpression[BindingExpression.TEMPLATE_SELECTOR], TargetField = Configuration.DefaultAdapterField, TargetObject = adapterName, IsTargetingResource = true, }); bindingExpression.Remove(BindingExpression.TEMPLATE_SELECTOR); ResourceExpression adapterResourceExpression = new ResourceExpression(); adapterResourceExpression.Add(ResourceExpression.KEY, new TextExpression { Value = adapterKey }); bindingExpression.Add(BindingExpression.ADAPTER, adapterResourceExpression); } } // In order to check if all adapter are not used more than once since we need them to be unique target Dictionary <string, bool> usedAdapter = new Dictionary <string, bool>(); foreach (ExpressionContainer expression in expressions.Where(x => x.Expression.IsOfType(ExpressionType.Binding)).ToList()) { Expression bindingExpression = expression.Expression; if (bindingExpression.Has(BindingExpression.ADAPTER)) { // expression in Adapter could only be Resource (since it's an android platform specific things, a binding expression would not have any sense) Expression resourceExpression = bindingExpression[BindingExpression.ADAPTER]; string adapterKey = resourceExpression.GetValue(ResourceExpression.KEY); Resource adapterResource = neededResource[adapterKey]; if (usedAdapter.ContainsKey(adapterKey)) { Log.LogError("The adapter with key {0} is used more than once which could lead to issue, you need one adapter per use !", adapterKey); } else { usedAdapter.Add(adapterKey, true); } // remove the adapter property bindingExpression.Remove(BindingExpression.ADAPTER); // store old target info string oldTargetField = expression.TargetField; string oldTargetObject = expression.TargetObject; bool oldTargetType = expression.IsTargetingResource; // retarget the binding expression to be targeted to Adapter.Collection expression.TargetField = "Collection"; expression.TargetObject = adapterResource.PropertyName; expression.IsTargetingResource = false; //TODO : false for debug mode only, need to see what we can do about that ? // add a new expression to target the old object/field couple and affect the adapter with the resource expression expressions.Add(new ExpressionContainer { IsTargetingResource = oldTargetType, TargetField = oldTargetField, TargetObject = oldTargetObject, Expression = resourceExpression, }); } } // Create all properties for resources Dictionary <string, CodePropertyReferenceExpression> resourceReferences = CreatePropertiesForResources(neededResource.Values); // Generate all properties to handle CommandParameter and retarget all expressions if needed GenerateCommandParameterProperties(expressions); // Create a setup resources method to initalize resources with all {Resource ...} and {Translation ...} expressions List <ExpressionContainer> translationExpressions = expressions.Where(x => x.Expression.IsOfType(ExpressionType.Translation)).ToList(); List <ExpressionContainer> expressionsTargetingResources = expressions.Where(x => x.IsTargetingResource && x.Expression.IsOfType(ExpressionType.Resource)).ToList(); List <ExpressionContainer> resourceExpressions = expressions.Where(x => !x.IsTargetingResource && x.Expression.IsOfType(ExpressionType.Resource)).ToList(); List <ExpressionContainer> bindingExpressions = expressions.Where(x => !x.IsTargetingResource && x.Expression.IsOfType(ExpressionType.Binding)).ToList(); CodeMethodReferenceExpression assignTranslationMethodReference = CreateAssignTranslationMethod(translationExpressions, localizationServiceReference); CodeMethodReferenceExpression setupResourcesReference = CreateSetupResourcesMethod(expressionsTargetingResources, resourceReferences); CodeMethodReferenceExpression setupResourceForViewElement = CreateSetupResourceForViewElementMethod(resourceExpressions, resourceReferences); CreateBindingOverrideMethod(bindingExpressions, localizationServiceReference, resourceReferences, assignTranslationMethodReference, setupResourcesReference, setupResourceForViewElement); }
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 CreateNPCMarket(string stationGridName, string industryName) { MyCubeGrid stationEntity = null; if (!Utilities.TryGetEntityByNameOrId(stationGridName, out IMyEntity entity)) { Context.Respond($"Unable to find a station by the name of '{stationGridName}'."); return; } stationEntity = entity as MyCubeGrid; if (stationEntity == null || !stationEntity.IsStatic) { Context.Respond($"Unable to find a station by the name of '{stationGridName}'."); return; } if (!Enum.TryParse(industryName, out IndustryTypeEnum industryType)) { var types = string.Join(", ", Enum.GetNames(typeof(IndustryTypeEnum))); Context.Respond($"Unable to find industry type '{industryName}'. Valid industry types are: {types}."); return; } var marketManager = GetManager <MarketManager>(); // Market checks to see if the station is already registered. marketManager.GetMarkets() .Then(markets => { Log.Info("Received markets"); if (markets.Any(m => m.ParentGridId == entity.EntityId)) { Context.Respond("This station is already marked as a market."); return; } var npcManager = EconomyPlugin.GetManager <NPCManager>(); var npcName = NameGeneratorHelper.GetName(); npcManager.CreateNPC(npcName, industryType) .Then(npc => { // NPC is now created.. Need to make them a bank account. var accountsManager = GetManager <AccountsManager>(); accountsManager.CreateAccount((ulong)npc.Id, 0, "default", true) .Then(npcAccount => { // Now they have a bank account.. Time to make a station market. var marketName = NameGeneratorHelper.GetIndustryName(industryType); marketManager.CreateMarket(stationEntity.EntityId, (ulong)npc.Id, marketName, 3000, npcAccount.Id, true, true) .Then(market => { // Market is created.. Now to create buy orders. var simManager = GetManager <MarketSimulationManager>(); simManager.GenerateNPCOrders(npc, market) .Then(() => { stationEntity.DisplayName = market.Name; Context.Respond($"{npc.Name} has founded {market.Name}, specializing in {industryType} trade."); }) .Catch(HandleError); }) .Catch(HandleError); }) .Catch(HandleError); }) .Catch(HandleError); }) .Catch(HandleError); }
public Monstre() : base() { Pv = RandomHelper.GetRandom(5, 50); Nom = NameGeneratorHelper.GetName(); DegatMax = RandomHelper.GetRandom(0, 50); }
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); }