public async Task BindModelAsync(ModelBindingContext bindingContext) { if (!int.TryParse(bindingContext.ValueProvider.GetValue("id").FirstValue, out int productId)) { throw new Exception("The product id was not provided"); } var editModel = new OpenProductConfigurationEditModel { Features = productRepository.GetProductFeatures(productId) }; for (int i = 0; i < editModel.Features.Count; i++) { BaseFeature feature = editModel.Features[i]; ModelMetadata modelMetadata = modelMetadataProvider.GetMetadataForType(feature.GetType()); IModelBinder modelBinder = modelBinderFactory.CreateBinder(new ModelBinderFactoryContext { Metadata = modelMetadata, CacheToken = modelMetadata }); string modelName = $"{bindingContext.BinderModelName}.Features[{i}]".TrimStart('.'); using (var scope = bindingContext.EnterNestedScope(modelMetadata, modelName, modelName, feature)) { await modelBinder.BindModelAsync(bindingContext); } } bindingContext.Result = ModelBindingResult.Success(editModel); }
/// <summary> /// Verify that there are inputs, show help otherwise /// </summary> /// <param name="inputs">List of inputs</param> /// <param name="feature">Name of the current feature</param> private static void VerifyInputs(List <string> inputs, BaseFeature feature) { if (inputs.Count == 0) { logger.Error("This feature requires at least one input"); _help.OutputIndividualFeature(feature.Name); Environment.Exit(0); } }
public IActionResult Rewind([FromQuery] int height) { try { BaseFeature.SetRewindFlag(this.nodeSettings, height); return(Json("Rewind flag set, please restart the node.")); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public FeatureView EnsureView(BaseFeature feature, ViewStack parent) { var view = parent.Children.OfType <FeatureView>().FirstOrDefault(it => it.Feature == feature); if (view == null) { string viewClass = feature.Metadata.ViewClass; if (viewClass.IsNotBlank()) { var viewType = typeof(FeatureView).Assembly.GetType(viewClass); if (viewType != null) { view = (FeatureView)Activator.CreateInstance(viewType); view.Feature = feature; parent.Children.Add(view); view.OnCreated(); } } } return(view); }
/// <summary> /// Entry class for the RombaSharp application /// </summary> public static void Main(string[] args) { // Perform initial setup and verification LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "romba.log"), true); LoggerImpl.AppendPrefix = true; LoggerImpl.LowestLogLevel = LogLevel.VERBOSE; LoggerImpl.ThrowOnError = false; LoggerImpl.Start(); // Create a new Help object for this program _help = RetrieveHelp(); // Credits take precidence over all if ((new List <string>(args)).Contains("--credits")) { _help.OutputCredits(); LoggerImpl.Close(); return; } // If there's no arguments, show help if (args.Length == 0) { _help.OutputGenericHelp(); LoggerImpl.Close(); return; } // Get the first argument as a feature flag string featureName = args[0]; // Verify that the flag is valid if (!_help.TopLevelFlag(featureName)) { logger.User($"'{featureName}' is not valid feature flag"); _help.OutputIndividualFeature(featureName); LoggerImpl.Close(); return; } // Get the proper name for the feature featureName = _help.GetFeatureName(featureName); // Get the associated feature BaseFeature feature = _help[featureName] as BaseFeature; // If we had the help feature first if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value) { feature.ProcessArgs(args, _help); LoggerImpl.Close(); return; } // Now verify that all other flags are valid if (!feature.ProcessArgs(args, _help)) { LoggerImpl.Close(); return; } // Set the new log level based on settings LoggerImpl.LowestLogLevel = feature.LogLevel; // If output is being redirected or we are in script mode, don't allow clear screens if (!Console.IsOutputRedirected && feature.ScriptMode) { Console.Clear(); Prepare.SetConsoleHeader("SabreTools"); } // Now process the current feature Dictionary <string, Feature> features = _help.GetEnabledFeatures(); bool success = false; switch (featureName) { case DisplayHelpDetailed.Value: case DisplayHelp.Value: // No-op as this should be caught break; // Require input verification case Archive.Value: case Build.Value: case DatStats.Value: case Fixdat.Value: case Import.Value: case Lookup.Value: case Merge.Value: case Miss.Value: case RescanDepots.Value: VerifyInputs(feature.Inputs, featureName); success = feature.ProcessFeatures(features); break; // Requires no input verification case Cancel.Value: case DbStats.Value: case Diffdat.Value: case Dir2Dat.Value: case EDiffdat.Value: case Export.Value: case Memstats.Value: case Progress.Value: case PurgeBackup.Value: case PurgeDelete.Value: case RefreshDats.Value: case Shutdown.Value: case Features.Version.Value: success = feature.ProcessFeatures(features); break; // If nothing is set, show the help default: _help.OutputGenericHelp(); break; } // If the feature failed, output help if (!success) { logger.Error("An error occurred during processing!"); _help.OutputIndividualFeature(featureName); } LoggerImpl.Close(); return; }
/// <summary> /// Entry point for the SabreTools application /// </summary> /// <param name="args">String array representing command line parameters</param> public static void Main(string[] args) { // Perform initial setup and verification LoggerImpl.SetFilename("sabretools.log", true); LoggerImpl.AppendPrefix = true; LoggerImpl.LowestLogLevel = LogLevel.VERBOSE; LoggerImpl.ThrowOnError = false; LoggerImpl.Start(); // Create a new Help object for this program _help = RetrieveHelp(); // Get the location of the script tag, if it exists int scriptLocation = (new List <string>(args)).IndexOf("--script"); // If output is being redirected or we are in script mode, don't allow clear screens if (!Console.IsOutputRedirected && scriptLocation == -1) { Console.Clear(); Prepare.SetConsoleHeader("SabreTools"); } // Now we remove the script tag because it messes things up if (scriptLocation > -1) { List <string> newargs = new List <string>(args); newargs.RemoveAt(scriptLocation); args = newargs.ToArray(); } // Credits take precidence over all if ((new List <string>(args)).Contains("--credits")) { _help.OutputCredits(); LoggerImpl.Close(); return; } // If there's no arguments, show help if (args.Length == 0) { _help.OutputGenericHelp(); LoggerImpl.Close(); return; } // Get the first argument as a feature flag string featureName = args[0]; // Verify that the flag is valid if (!_help.TopLevelFlag(featureName)) { logger.User($"'{featureName}' is not valid feature flag"); _help.OutputIndividualFeature(featureName); LoggerImpl.Close(); return; } // Get the proper name for the feature featureName = _help.GetFeatureName(featureName); // Get the associated feature BaseFeature feature = _help[featureName] as BaseFeature; // If we had the help feature first if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value) { feature.ProcessArgs(args, _help); LoggerImpl.Close(); return; } // Now verify that all other flags are valid if (!feature.ProcessArgs(args, _help)) { LoggerImpl.Close(); return; } // Now process the current feature Dictionary <string, Feature> features = _help.GetEnabledFeatures(); switch (featureName) { // No-op as these should be caught case DisplayHelp.Value: case DisplayHelpDetailed.Value: case Script.Value: break; // Require input verification case Batch.Value: case DatFromDir.Value: case Extract.Value: case Restore.Value: case Split.Value: case Stats.Value: case Update.Value: case Verify.Value: VerifyInputs(feature.Inputs, featureName); feature.ProcessFeatures(features); break; // Requires no input verification case Sort.Value: feature.ProcessFeatures(features); break; // If nothing is set, show the help default: _help.OutputGenericHelp(); break; } LoggerImpl.Close(); return; }
internal override void SetTypeSpecificData(FeatureWrapper feature, IDictionary <string, string> propNameToFieldName, BaseFeature baseFeature) { var data = baseFeature as PolygonFeature; feature.Set(propNameToFieldName[nameof(data.Area)], data.Area); feature.SetPolygonGeo(data.Geometry); }
internal abstract void SetTypeSpecificData(FeatureWrapper feature, IDictionary <string, string> propNameToFieldName, BaseFeature baseFeature);
private void CreateFeatureWrapper(LayerWrapper layer, IDictionary <string, string> propNameToFieldName, BaseFeature data) { FeatureWrapper feature = layer.CreateFeature(); feature.Set(propNameToFieldName[nameof(data.SampleId)], data.SampleId); feature.Set(propNameToFieldName[nameof(data.ValidityTime)], data.ValidityTime.Value); feature.Set(propNameToFieldName[nameof(data.ExtendedData)], data.ExtendedData); feature.Set(propNameToFieldName[nameof(data.UserConf)], data.UserConf); feature.Set(propNameToFieldName[nameof(data.LandCover)], data.LandCover); feature.Set(propNameToFieldName[nameof(data.CropType1)], data.CropType1); feature.Set(propNameToFieldName[nameof(data.CropType2)], data.CropType2); feature.Set(propNameToFieldName[nameof(data.Irrigation1)], data.Irrigation1); feature.Set(propNameToFieldName[nameof(data.Irrigation2)], data.Irrigation2); feature.Set(propNameToFieldName[nameof(data.Irrigation3)], data.Irrigation3); SetTypeSpecificData(feature, propNameToFieldName, data); layer.AddFeatureToLayer(feature); }
/// <summary> /// Entry point for the SabreTools application /// </summary> /// <param name="args">String array representing command line parameters</param> public static void Main(string[] args) { // Perform initial setup and verification LoggerImpl.SetFilename(Path.Combine(PathTool.GetRuntimeDirectory(), "logs", "sabretools.log"), true); LoggerImpl.AppendPrefix = true; LoggerImpl.LowestLogLevel = LogLevel.VERBOSE; LoggerImpl.ThrowOnError = false; LoggerImpl.Start(); // Create a new Help object for this program _help = RetrieveHelp(); // Credits take precidence over all if ((new List <string>(args)).Contains("--credits")) { _help.OutputCredits(); LoggerImpl.Close(); return; } // If there's no arguments, show help if (args.Length == 0) { _help.OutputGenericHelp(); LoggerImpl.Close(); return; } // Get the first argument as a feature flag string featureName = args[0]; // TODO: Remove this block once trimming is no longer needed // TODO: Update wiki documentation ONLY after this reaches stable // TODO: Re-evaluate feature flags with this change in mind featureName = featureName.TrimStart('-'); if (args[0].StartsWith("-")) { logger.User($"Feature flags no longer require leading '-' characters"); } // Verify that the flag is valid if (!_help.TopLevelFlag(featureName)) { logger.User($"'{featureName}' is not valid feature flag"); _help.OutputIndividualFeature(featureName); LoggerImpl.Close(); return; } // Get the proper name for the feature featureName = _help.GetFeatureName(featureName); // Get the associated feature BaseFeature feature = _help[featureName] as BaseFeature; // If we had the help feature first if (featureName == DisplayHelp.Value || featureName == DisplayHelpDetailed.Value) { feature.ProcessArgs(args, _help); LoggerImpl.Close(); return; } // Now verify that all other flags are valid if (!feature.ProcessArgs(args, _help)) { LoggerImpl.Close(); return; } // Set the new log level based on settings LoggerImpl.LowestLogLevel = feature.LogLevel; // If output is being redirected or we are in script mode, don't allow clear screens if (!Console.IsOutputRedirected && feature.ScriptMode) { Console.Clear(); Prepare.SetConsoleHeader("SabreTools"); } // Now process the current feature Dictionary <string, Feature> features = _help.GetEnabledFeatures(); bool success = false; switch (featureName) { // No-op as these should be caught case DisplayHelp.Value: case DisplayHelpDetailed.Value: break; // Require input verification case Batch.Value: case DatFromDir.Value: case Extract.Value: case Restore.Value: case Split.Value: case Stats.Value: case Update.Value: case Verify.Value: VerifyInputs(feature.Inputs, feature); success = feature.ProcessFeatures(features); break; // Requires no input verification case Sort.Value: success = feature.ProcessFeatures(features); break; // If nothing is set, show the help default: _help.OutputGenericHelp(); break; } // If the feature failed, output help if (!success) { logger.Error("An error occurred during processing!"); _help.OutputIndividualFeature(featureName); } LoggerImpl.Close(); return; }