public async Task <IActionResult> Create(FeatureAttribute viewModel) { if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { var Id = await _featureAttributeService.Add(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } var features = await _featureService.GetAll(); ViewBag.Features = new SelectList(features.ToList(), "Id", "Title", viewModel.FeatureId); return(View(viewModel)); }
public void FeatureAttribute_Ctr_SetsFeaturePathProperty() { const string feature = "#@#$%^*"; var attribute = new FeatureAttribute(feature, feature); Assert.Equal(feature + feature, attribute.FeaturePath.ConcatAll()); }
private static void InitAuthorizationNameMap() { if (FeaturePropertiesMap == null || FeaturePropertiesMap.Count == 0) { InitFeatureProperties(); } if (AuthorizationMap == null || AuthorizationMap.Count == 0) { AuthorizationMap = DefinitionDao.GetUserAuthorizationMap(); } foreach (var pair in AuthorizationMap) { List <int> ListFeatureId = pair.Value; List <string> ListFeatureName = new List <string>(); foreach (int id in ListFeatureId) { FeatureAttribute attr = ListFeatureAttribute.FirstOrDefault(n => n.Id == id); if (attr == null) { continue; } ListFeatureName.Add((attr.Name + attr.Group).ToKey()); } AuthorizationNameMap[pair.Key] = ListFeatureName; } }
public FeatureInfo(FeatureAttribute feature) { this.Id = feature.Id; this.Name = feature.Name; this.Priority = feature.Priority; this.Description = feature.Description; this.Dependencies = feature.Dependencies; }
public void Features_IsEnabled_ReturnsTrue_WhenPathIsMoreComplexThanFeatureInRegistry() { // test feature a/b/c where value in registry is just a (signifying all features registered) var feature = new Feature("a"); var attribute = new FeatureAttribute("a", "b", "c"); Assert.True(Features.IsEnabled(SetupRegistry(feature), new[] { "a", "b", "c" })); }
public async Task <FeatureAttribute> Add(FeatureAttribute viewModel) { var model = _mapper.Map <FeatureAttributeEntity>(viewModel); _context.FeatureAttributes.Add(model); await _context.SaveChangesAsync(); _mapper.Map(model, viewModel); return(viewModel); }
private bool NeedToCall(FeatureAttribute customAttribute) { if (customAttribute == null) { return(false); } if (!featureNumbers.ContainsKey(customAttribute.FeatureName) || customAttribute.Ignore) { return(false); } return(true); }
public async Task <FeatureAttribute> Update(FeatureAttribute viewModel) { if (viewModel.Id == null) { throw new ArgumentNullException(nameof(viewModel.Id)); } var data = await _context.FeatureAttributes.FirstOrDefaultAsync(c => c.Id == viewModel.Id); _mapper.Map(viewModel, data); _context.Update(data); await _context.SaveChangesAsync(); return(viewModel); }
public void ModifyAttribute(FeatureAttribute attribute) { switch (attribute.Name) { case "name": attribute.Width = 10; break; case "age": attribute.Width = 3; attribute.Precision = 0; break; } }
public static void UpdateAuthorizationNameMap(string type, List <int> listId) { List <string> values = new List <string>(); foreach (int id in listId) { FeatureAttribute attr = ListFeatureAttribute.FirstOrDefault(n => n.Id == id); if (attr == null) { continue; } values.Add((attr.Name + attr.Group).ToKey()); } AuthorizationNameMap[type] = values; }
public async Task <IActionResult> Edit(int Id, FeatureAttribute viewModel) { if (Id == null) { return(NotFound()); } if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { try { await _featureAttributeService.Update(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } catch (DBConcurrencyException) { var exists = await Exists(viewModel.Id); if (!exists) { return(NotFound()); } else { throw; } } } var features = await _featureService.GetAll(); ViewBag.Features = new SelectList(features.ToList(), "Id", "Title", viewModel.FeatureId); return(View(viewModel)); }
public static void Run() { string dataDir = RunExamples.GetDataDir(); //ExStart: SpecifyAttributeValueLength using (VectorLayer layer = VectorLayer.Create(dataDir + "SpecifyAttributeValueLength_out.shp", Drivers.Shapefile)) { // add attributes before adding features FeatureAttribute attribute = new FeatureAttribute("wide", AttributeDataType.String); attribute.Width = 120; layer.Attributes.Add(attribute); Feature feature = layer.ConstructFeature(); feature.SetValue("wide", "this string can be up to 120 characters long now."); layer.Add(feature); } //ExEnd: SpecifyAttributeValueLength }
/// <summary> /// Is the type <paramref name="t"/> included in the model <paramref name="modelName"/>? /// Additionally, if <paramref name="t"/> has one or more [Feature] attributes and /// <paramref name="featureNames"/> is nonnull, does <paramref name="t"/> have a /// [Feature] attribute whose name is found in <paramref name="featureNames"/>? /// </summary> /// <param name="t">The type to be tested</param> /// <param name="modelName">The name of the model</param> /// <param name="featureNames">Null if all features are to be included, or a nonnull set of /// feature names to be included.</param> /// <returns>True if <paramref name="t"/> is part of the model and feature set.</returns> public static bool IsInModel(Type t, string modelName, Set <string> /*?*/ featureNames) { if (!t.Namespace.Equals(modelName)) { // Namespace does not does not match the model name: exclude the class return(false); } else { // Class namespace matches model name and null featureNames: // include the class. (In other words, just ignore any [Feature] attribute; load all.) if (null == featureNames) { return(true); } else { // Check for matching features object /*?*/[] /*?*/ attrs = t.GetCustomAttributes(typeof(FeatureAttribute), true); if (attrs != null && attrs.Length > 0) { foreach (object attrObj in attrs) { FeatureAttribute attr = (FeatureAttribute)attrObj; string name = (string.IsNullOrEmpty(attr.Name) ? t.Name : attr.Name); // Class has a matching [Feature] attribute: the name of the feature must // be in the set of featureNames in order for it to be in the model. if (featureNames.Contains(name)) { return(true); } } // No matching feature attributes found. return(false); } else { // The class does not have any [Feature] attributes: include it. return(true); } } } }
public static void Run() { string dataDir = RunExamples.GetDataDir(); File.Delete(dataDir + "data1_out.json"); File.Delete(dataDir + "data2_out.json"); //ExStart: GetValueOrDefaultOfFeature //You can set default value for a feature of attribute in a layer using (var layer = Drivers.GeoJson.CreateLayer(dataDir + "data1_out.json")) { var attribute = new FeatureAttribute("attribute", AttributeDataType.Integer); attribute.CanBeNull = true; attribute.CanBeUnset = true; layer.Attributes.Add(attribute); Feature feature = layer.ConstructFeature(); int? nullValue = feature.GetValueOrDefault<int?>("attribute"); // value == null var defValue1 = feature.GetValueOrDefault<int?>("attribute", 10); // value == 10 var defValue2 = feature.GetValueOrDefault("attribute", 25); // value == 10 Console.WriteLine($"'{nullValue}' vs '{defValue1}' vs '{defValue2}'"); } //Another example where we set the default value to 100 using (var layer = Drivers.GeoJson.CreateLayer(dataDir + "data2_out.json")) { var attribute = new FeatureAttribute("attribute", AttributeDataType.Double); attribute.CanBeNull = false; attribute.CanBeUnset = false; attribute.DefaultValue = 100; layer.Attributes.Add(attribute); Feature feature = layer.ConstructFeature(); double defValue1 = feature.GetValueOrDefault<double>("attribute"); // value == 100 var defValue2 = feature.GetValueOrDefault("attribute"); // value == 100 feature.SetValue("attribute", 50); var newValue = feature.GetValueOrDefault<double>("attribute"); // value == 50 Console.WriteLine($"'{defValue1}' vs '{defValue2}' vs '{newValue}'"); } //ExEnd: GetValueOrDefaultOfFeature }
public void WhenFeatureSwitchedOff_ThenEmptyResults() { Configuration.FeatureResolver = new DefaultFeatureResolver(); var filterAttribute = new FeatureAttribute("DisabledProperty"); var request = Substitute.For<HttpRequestBase>(); request.ContentType.Returns("application/json"); var httpContext = Substitute.For<HttpContextBase>(); httpContext.Request.Returns(request); var routeData = new RouteData(); routeData.Values.Add("employeeId", "123"); var context = Substitute.For<ActionExecutingContext>(); context.HttpContext.Returns(httpContext); filterAttribute.OnActionExecuting(context); Assert.That(context.Result, Is.Not.Null); }
public void WhenFeatureSwitchedOff_ThenEmptyResults() { Configuration.FeatureResolver = new DefaultFeatureResolver(); var filterAttribute = new FeatureAttribute("DisabledProperty"); var request = Substitute.For <HttpRequestBase>(); request.ContentType.Returns("application/json"); var httpContext = Substitute.For <HttpContextBase>(); httpContext.Request.Returns(request); var routeData = new RouteData(); routeData.Values.Add("employeeId", "123"); var context = Substitute.For <ActionExecutingContext>(); context.HttpContext.Returns(httpContext); filterAttribute.OnActionExecuting(context); Assert.That(context.Result, Is.Not.Null); }
public void ModifyAttribute(FeatureAttribute attribute, AttributesConverterActions actions) { switch (attribute.Name) { case "name": // rename and adjust width attribute.Name = "nickname"; attribute.Width = 10; break; case "age": // change type and adjust width attribute.DataType = AttributeDataType.String; attribute.Width = 3; attribute.Precision = 0; break; case "dob": // exclude attribute from destination file. actions.Exclude = true; break; } }
public FeatureCalculator(FeatureList featureList) { Console.WriteLine("Initializing FeatureCalculator"); var featuresToCalculate = featureList.Features.Where(f => f.QueryDependent == false && f.Ignore == false); featureNumbers = featuresToCalculate.ToDictionary(f => f.FeatureName, f => f.Number); Assembly executingAssembly = Assembly.GetExecutingAssembly(); foreach (Type type in executingAssembly.GetTypes()) { var callData = new List <KeyValuePair <Attribute, MethodInfo> >(); MethodInfo[] methodInfos = type.GetMethods(); object instance = null; foreach (MethodInfo methodInfo in methodInfos) { FeatureAttribute featureAttribute = methodInfo.GetCustomAttributes(typeof(FeatureAttribute), false).OfType <FeatureAttribute>(). FirstOrDefault(); if (NeedToCall(featureAttribute)) { if (instance == null) { instance = (Activator.CreateInstance(type)); } callData.Add(new KeyValuePair <Attribute, MethodInfo>(featureAttribute, methodInfo)); } } if (callData.Any()) { methodsToCall.Add(new MethodToCall { Instance = instance, CallData = callData }); } } }
void Ex11() { FeatureAttribute featureAttribute = default !;
public static Feature SelectFeature(FeatureAttribute attr) { }
public override int GetHashCode() { return(FeatureAttribute.GetHashCode() ^ Coordinates.GetHashCode() ^ LayerName.GetHashCode()); }
public async Task <IActionResult> DeleteConfirmed(int?Id, FeatureAttribute viewModel) { await _featureAttributeService.Remove(Id); return(RedirectToAction(nameof(Index))); }