public void AddQueryInput(PropertyInfo property) { Accessor accessor = new SingleProperty(property); var input = new RouteParameter(accessor); _queryParameters.Add(input); }
public static string AwesomeDisplay(this IFubuPage page, object model) { var type = model.GetType(); var result = new StringBuilder(); var tags = page.Tags(model); var sl = page.Get<IServiceLocator>(); tags.SetProfile(AwesomeConfiguration.TagProfile); var tr = new HtmlTag("tr"); foreach (var prop in getProperties(type)) { var p = new SingleProperty(prop, type); var elementRequest = new ElementRequest(model, p, sl); var accessRight = page.Get<IFieldAccessService>().RightsFor(elementRequest); HtmlTag display = tags.DisplayFor(elementRequest).Authorized(accessRight.Read); var td = new HtmlTag("td").Append(display); tr.Append(td); } var editLink = new LinkTag("Edit", page.EditUrlFor(model)); tr.Append(new HtmlTag("td").Append(editLink)); var deleteLink = new LinkTag("Delete", page.DeleteUrlFor(model)); tr.Append(new HtmlTag("td").Append(deleteLink)); result.Append(tr.ToString()); return result.ToString(); }
/// <summary> /// Adds a property setter for all primitive properties on T that /// meet the filter /// </summary> /// <param format="filter"></param> /// <returns></returns> public ObjectConstructionExpression <T> SetAllPrimitiveProperties(Func <PropertyInfo, bool> filter) { foreach (PropertyInfo property in typeof(T).GetProperties()) { if (!property.CanWrite) { continue; } if (!property.PropertyType.IsSimple()) { continue; } if (!filter(property)) { continue; } var accessor = new SingleProperty(property); var child = new SetPropertyGrammar(accessor); _grammar.AddGrammar(child); } return(this); }
//returning a string is DUMB public static string AwesomeFields(this IFubuPage page, object model) { var type = model.GetType(); var result = new StringBuilder(); var tags = page.Tags<AwesomeEditModel>(); var sl = page.Get<IServiceLocator>(); tags.SetProfile(AwesomeConfiguration.TagProfile); foreach(var prop in getProperties(type)) { var p = new SingleProperty(prop, type); var elementRequest = new ElementRequest(model, p, sl); var accessRight = page.Get<IFieldAccessService>().RightsFor(elementRequest); var line = new FormLineExpression<AwesomeEditModel>(tags, tags.NewFieldLayout(), elementRequest) .Access(accessRight) .Editable(true); result.Append(line.ToString()); } return result.ToString(); }
public void hash_is_unique_by_rule_model_and_accessor() { var r1 = RemoteFieldRule.For <RequiredFieldRule>(SingleProperty.Build <SomeNamespace.Model>(e => e.Property)); var r2 = RemoteFieldRule.For <RequiredFieldRule>(SingleProperty.Build <OtherNamespace.Model>(e => e.Property)); r1.ToHash().ShouldNotEqual(r2.ToHash()); }
public void singleProperty_can_get_child_accessor() { var expected = ReflectionHelper.GetAccessor <ChildTarget>(c => c.GrandChild.Name); SingleProperty.Build <Target>(t => t.Child.GrandChild). GetChildAccessor <GrandChildTarget>(t => t.Name).ShouldBe(expected); }
public static string AwesomeHeaders(this IFubuPage page, object model) { var type = model.GetType(); var result = new StringBuilder(); var tags = page.Tags(model); var sl = page.Get <IServiceLocator>(); tags.SetProfile(AwesomeConfiguration.TagProfile); var tr = new HtmlTag("tr"); foreach (var prop in getProperties(type)) { var p = new SingleProperty(prop, type); var elementRequest = new ElementRequest(model, p, sl); var accessRight = page.Get <IFieldAccessService>().RightsFor(elementRequest); HtmlTag display = tags.LabelFor(elementRequest).Authorized(accessRight.Read); var td = new HtmlTag("th").Append(display); tr.Append(td); } tr.Append(new HtmlTag("th")); tr.Append(new HtmlTag("th")); result.Append(tr.ToString()); return(result.ToString()); }
public void determine_the_mode_uses_the_last_matching_policy() { var accessor = SingleProperty.Build <ValidationModeTarget>(x => x.Property); var services = new InMemoryServiceLocator(); services.Add(new AccessorRules()); var mode = ValidationMode.Triggered; var p1 = MockRepository.GenerateStub <IValidationModePolicy>(); p1.Stub(x => x.Matches(services, accessor)).Return(true); p1.Stub(x => x.DetermineMode(services, accessor)).Return(ValidationMode.Live); var p2 = MockRepository.GenerateStub <IValidationModePolicy>(); p2.Stub(x => x.Matches(services, accessor)).Return(true); p2.Stub(x => x.DetermineMode(services, accessor)).Return(mode); var node = new ValidationNode(); node.DefaultMode(ValidationMode.Live); node.RegisterPolicy(p1); node.RegisterPolicy(p2); node.As <IValidationNode>().DetermineMode(services, accessor).ShouldEqual(mode); }
private static Uri GetUriForProperty(SingleProperty accessor) { var channelGraph = FubuTransport.DefaultChannelGraph; if (channelGraph != null && accessor.DeclaringType != FubuTransport.DefaultSettings) { // A default graph has been set via SetupForInMemoryTesting, so // sync the URIs for the channels that match. var channel = channelGraph.FirstOrDefault(x => { string channelName = x.Key.Split(':')[1]; return(channelName == accessor.Name); }); if (channel != null) { return(channel.Uri); } } string uri = "{0}://{1}/{2}".ToFormat(InMemoryChannel.Protocol, accessor.OwnerType.Name.Replace("Settings", ""), accessor.Name).ToLower(); return(new Uri(uri)); }
private static ElementRequest GetRequest(PropertyInfo property, object model) { var accessor = new SingleProperty(property); var elementRequest = new ElementRequest(model, accessor, ServiceLocator.Current); elementRequest.ElementId = property.Name; return(elementRequest); }
public void throws_when_targeting_messages_to_an_unknown_accessor() { var rule = FieldEqualityRule.For <FieldEqualityTarget>(x => x.Value1, x => x.Value2); var accessor = SingleProperty.Build <FieldEqualityTarget>(x => x.Other); Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() => rule.ReportMessagesFor(accessor)); }
public void singleProperty_property_names_contains_single_value() { var propertyNames = SingleProperty.Build <Target>(t => t.Child.GrandChild.Name).PropertyNames; propertyNames.Length.ShouldBe(1); propertyNames.ShouldContain("Name"); }
public void CheckProperties(Func <PropertyInfo, bool> filter) { typeof(T).GetProperties().Where(filter).Each(prop => { var accessor = new SingleProperty(prop); addAccessor(accessor); }); }
public void Initialize_SingleProperty() { IBusinessObjectNumericProperty property = new SingleProperty( GetPropertyParameters(GetPropertyInfo(typeof(ClassWithAllDataTypes), "Single"), _businessObjectProvider)); Assert.That(property.Type, Is.SameAs(typeof(Single))); Assert.That(property.AllowNegative, Is.True); }
public AccessRight RightsFor(object target, PropertyInfo property) { if (target == null) throw new ArgumentNullException("target"); var accessor = new SingleProperty(property, _types.ResolveType(target)); var request = new ElementRequest(target, accessor, null); return RightsFor(request); }
public SearchViewModel() { foreach (var p in PropertySearcher.GetSearchProperties(typeof(TEntity))) { SingleProperty property = ContainerManager.RegisterProperty(p); SearchProperties.Add(property); } }
public void GetValueFromSingleProperty() { var target = new Target { Name = "Jeremy" }; var property = SingleProperty.Build <Target>(x => x.Name); property.GetValue(target).ShouldBe("Jeremy"); }
public void build_single_property() { var prop1 = SingleProperty.Build <Target>("Child"); var prop2 = SingleProperty.Build <Target>(x => x.Child); prop1.ShouldBe(prop2); prop1.Name.ShouldBe("Child"); prop1.OwnerType.ShouldBe(typeof(Target)); }
private static DataTable ExtractCertificateInfo(ApplicationUninstallerEntry tag) { var cert = tag.GetCertificate(); if (cert == null) { return(GetError(Localisable.PropertiesWindow_Table_ErrorNoCertificate)); } // Extract required data var lq = from property in typeof(X509Certificate2).GetProperties() select new SingleProperty(property.Name, property.GetValue(cert, new object[] { })); var list = lq.ToList(); // Convert the obtained data to a more human readable form for (var i = 0; i < list.Count; i++) { var item = list[i].Value; var issName = item as X500DistinguishedName; if (issName != null) { list[i] = new SingleProperty(list[i].Key, cert.IssuerName.Format(false)); continue; } var oid = item as Oid; if (oid != null) { list[i] = new SingleProperty(list[i].Key, oid.FriendlyName); continue; } var exts = item as X509ExtensionCollection; if (exts != null) { var result = string.Join(", ", exts.Cast <X509Extension>().Select(x => x.Oid.FriendlyName).ToArray()); list[i] = new SingleProperty(list[i].Key, result); continue; } var key = item as PublicKey; if (key != null) { list[i] = new SingleProperty(list[i].Key, key.Key.SignatureAlgorithm); continue; } var arr = item as byte[]; if (arr != null) { list[i] = new SingleProperty(list[i].Key, arr.ToHexString()); } } // Create and return the table var dt = GetCleanDataTable(); ConvertPropertiesIntoDataTable(list, dt); return(dt); }
public AccessRight RightsFor(object target, PropertyInfo property) { var accessor = new SingleProperty(property, _types.ResolveType(target)); var request = new ElementRequest(accessor){ Model = target }; return RightsFor(request); }
public static void AllChannelsAreInMemory(Type type, object settings) { type.GetProperties().Where(x => x.CanWrite && x.PropertyType == typeof(Uri)).Each(prop => { var accessor = new SingleProperty(prop); var uri = GetUriForProperty(accessor); accessor.SetValue(settings, uri); }); }
public void route_input_should_substitute_method() { SingleProperty accessor = SingleProperty.Build <SampleViewModel>(x => x.InPath); var viewModel = new SampleViewModel { InPath = "5" }; var routeInput = new RouteParameter(accessor); routeInput.Substitute(viewModel, "test/edit/{InPath}").ShouldEqual("test/edit/5"); }
public void SetValueFromSingleProperty() { var target = new Target { Name = "Jeremy" }; var property = SingleProperty.Build <Target>(x => x.Name); property.SetValue(target, "Justin"); target.Name.ShouldBe("Justin"); }
protected SingleProperty NewString(string name, string value = "") { SingleProperty prop = new SingleProperty(name, value); Add(prop); if (prop.Parent == null) { throw new Exception("Another property with same name exists!"); } return(prop); }
public void AddQueryInput(PropertyInfo property) { Accessor accessor = new SingleProperty(property); var input = new RouteParameter(accessor); if (Parent != null) { Parent.Trace("Added '{0}' to query string parameters", input); } _queryParameters.Fill(input); }
public void X() { var type = typeof (object); foreach (var propertyInfo in type.GetProperties()) { if(isEntity(propertyInfo)) { var a = new SingleProperty(propertyInfo); //return some NestedAction? } } }
private IEnumerable<IValidationRule> BuildRulesFor(Type type) { var rules = new List<IValidationRule>(); var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); properties.Each(property => { var accessor = new SingleProperty(property, type); _policies .Where(policy => policy.Matches(accessor)) .Each(policy => rules.AddRange(policy.BuildRules(accessor))); }); return rules; }
public AccessRight RightsFor(object target, PropertyInfo property) { var accessor = new SingleProperty(property, _types.ResolveType(target)); var request = new ElementRequest(accessor) { Model = target, }; attachServices(request); return(RightsFor(request)); }
public static object ToInMemory(Type type) { var settings = Activator.CreateInstance(type); type.GetProperties().Where(x => x.CanWrite && x.PropertyType == typeof(Uri)).Each(prop => { var accessor = new SingleProperty(prop); var uri = GetUriForProperty(accessor); accessor.SetValue(settings, uri); }); return(settings); }
public AccessRight RightsFor(object target, PropertyInfo property) { if (target == null) { throw new ArgumentNullException("target"); } var accessor = new SingleProperty(property, _types.ResolveType(target)); var request = new ElementRequest(target, accessor, _services); return(RightsFor(request)); }
private ClassFieldValidationRules findRules(Type type) { var classRules = new ClassFieldValidationRules(); _typeDescriptors.ForEachProperty(type, property => { var accessor = new SingleProperty(property); var rules = _sources.SelectMany(x => x.RulesFor(property)).Distinct(); classRules.AddRules(accessor, rules); }); return(classRules); }
private bool chainHasValidationContinuedProperties(PropertyChain chain) { if (chain.ValueGetters.Any(x => !(x is PropertyValueGetter))) { return(false); } var propertyValueGetters = chain.ValueGetters.OfType <PropertyValueGetter>().Reverse().Skip(1).Reverse(); return(propertyValueGetters.All(x => { var accessor = new SingleProperty(x.PropertyInfo); return HasRule <ContinuationFieldRule>(accessor.DeclaringType, accessor); })); }
public void equals_for_a_single_property() { var prop1 = SingleProperty.Build <Target>(x => x.Name); var prop2 = SingleProperty.Build <Target>(x => x.Name); var prop3 = SingleProperty.Build <Target>(x => x.Child); prop1.ShouldBe(prop2); prop1.ShouldNotBe(prop3); prop1.Equals(null).ShouldBeFalse(); prop1.Equals(prop1).ShouldBeTrue(); prop1.ShouldBe(prop1); prop1.Equals((object)null).ShouldBeFalse(); prop1.Equals(42).ShouldBeFalse(); }
public ObjectVerificationExpression <T> CheckAllSimpleProperties() { typeof(T).GetTypeInfo() .GetProperties() .Where(x => x.PropertyType.IsSimple()) .Each(prop => { var accessor = new SingleProperty(prop); var child = new CheckPropertyGrammar(accessor); _grammar.AddGrammar(child); }); return(this); }
public FieldValidationExpression Property(Expression <Func <T, object> > property) { var accessor = property.ToAccessor(); if (accessor.DeclaringType.IsInterface) { var myProperty = typeof(T).GetProperty(accessor.Name); if (myProperty != null) { accessor = new SingleProperty(myProperty); } } return(new FieldValidationExpression(this, accessor)); }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var examples = new List <PropertyExample>(); var tagGenerator = _generatorFactory.GeneratorFor(context.ModelType); tagGenerator.SetModel(context.Instance); _populator.PopulateInstance(context.Instance, context.SimpleProperties()); context .SimpleProperties() .Each(prop => { Accessor property; if (context.PropertyChain.Any()) { property = new PropertyChain(context .PropertyChain .Concat <PropertyInfo>(new[] { prop }) .Select(x => new PropertyValueGetter(x)) .ToArray()); } else { property = new SingleProperty(prop); } var propertyExpression = "x => x." + property.PropertyNames.Join("."); var propertySource = _sourceGenerator.SourceFor(prop); var propExamples = new List <Example>(); propExamples.Add(createExample(tagGenerator.LabelFor(tagGenerator.GetRequest(property)), "LabelFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample( tagGenerator.DisplayFor(tagGenerator.GetRequest(property)), "DisplayFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample(tagGenerator.InputFor(tagGenerator.GetRequest(property)), "InputFor({0})".ToFormat(propertyExpression))); var propExample = new PropertyExample { Source = propertySource, Examples = propExamples }; examples.Add(propExample); }); model.Examples = examples; }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var examples = new List<PropertyExample>(); var tagGenerator = _generatorFactory.GeneratorFor(context.ModelType); tagGenerator.SetModel(context.Instance); _populator.PopulateInstance(context.Instance, context.SimpleProperties()); context .SimpleProperties() .Each(prop => { Accessor property; if(context.PropertyChain.Any()) { property = new PropertyChain(context .PropertyChain .Concat<PropertyInfo>(new[] {prop}) .Select(x => new PropertyValueGetter(x)) .ToArray()); } else { property = new SingleProperty(prop); } var propertyExpression = "x => x." + property.PropertyNames.Join("."); var propertySource = _sourceGenerator.SourceFor(prop); var propExamples = new List<Example>(); propExamples.Add(createExample(tagGenerator.LabelFor(tagGenerator.GetRequest(property)), "LabelFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample( tagGenerator.DisplayFor(tagGenerator.GetRequest(property)), "DisplayFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample(tagGenerator.InputFor(tagGenerator.GetRequest(property)), "InputFor({0})".ToFormat(propertyExpression))); var propExample = new PropertyExample { Source = propertySource, Examples = propExamples }; examples.Add(propExample); }); model.Examples = examples; }
public void FillRules(ActionCall call) { var input = call.InputType(); if (input == null) return; _properties.ForEachProperty(input, property => { var accessor = new SingleProperty(property); var rules = _graph .Query() .RulesFor(input, accessor) .Where(rule => _remotes.IsRemote(rule)); rules.Each(rule => _remoteGraph.RegisterRule(accessor, rule)); }); }
public static ValidationOptions For(FormRequest request) { var services = request.Services; var type = services.GetInstance<ITypeResolver>().ResolveType(request.Input); var cache = services.GetInstance<ITypeDescriptorCache>(); var options = new ValidationOptions(); var node = request.Chain.ValidationNode() as IValidationNode; if (node == null) { return options; } // TODO -- Let's query the validation graph and register the rule alias/validation mode pairs here cache.ForEachProperty(type, property => { var accessor = new SingleProperty(property); fillFields(options, node, services, accessor); }); return options; }
public static ValidationOptions For(FormRequest request) { var services = request.Services; var type = services.GetInstance<ITypeResolver>().ResolveType(request.Input); var cache = services.GetInstance<ITypeDescriptorCache>(); var options = new ValidationOptions(); var node = request.Chain.ValidationNode(); if (node == null) { return options; } options._elementTimeout = node.ElementTimeout; cache.ForEachProperty(type, property => { var accessor = new SingleProperty(property); fillFields(options, node, services, accessor); }); return options; }
public static Property Clone(Property target) { Property prop = null; int id = target.PropertyId; PropertyBag bag = target.Owner; switch (target.PropertyType) { case (int)PropertyKind.WispObject: prop = new WispProperty(target.Name, id, ((WispProperty)target).Value, bag); break; case (int)PropertyKind.WispArray: prop = new WispArrayProperty(target.Name, id, ((WispArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int32: prop = new Int32Property(target.Name, id, ((Int32Property)target).Value, bag); break; case (int)PropertyKind.String: prop = new StringProperty(target.Name, id, ((StringProperty)target).Value, bag); break; case (int)PropertyKind.Bool: prop = new BoolProperty(target.Name, id, ((BoolProperty)target).Value, bag); break; case (int)PropertyKind.Guid: prop = new GuidProperty(target.Name, id, ((GuidProperty)target).Value, bag); break; case (int)PropertyKind.Single: prop = new SingleProperty(target.Name, id, ((SingleProperty)target).Value, bag); break; case (int)PropertyKind.Int32Array: prop = new Int32ArrayProperty(target.Name, id, ((Int32ArrayProperty)target).Value, bag); break; case (int)PropertyKind.StringArray: prop = new StringArrayProperty(target.Name, id, ((StringArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTime: prop = new DateTimeProperty(target.Name, id, ((DateTimeProperty)target).Value, bag); break; case (int)PropertyKind.GuidArray: prop = new GuidArrayProperty(target.Name, id, ((GuidArrayProperty)target).Value, bag); break; case (int)PropertyKind.Double: prop = new DoubleProperty(target.Name, id, ((DoubleProperty)target).Value, bag); break; case (int)PropertyKind.Byte: prop = new ByteProperty(target.Name, id, ((ByteProperty)target).Value, bag); break; case (int)PropertyKind.Component: prop = new ComponentProperty(target.Name, id, ((ComponentProperty)target).Value, bag); break; case (int)PropertyKind.SingleArray: prop = new SingleArrayProperty(target.Name, id, ((SingleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int64: prop = new Int64Property(target.Name, id, ((Int64Property)target).Value, bag); break; case (int)PropertyKind.ComponentArray: prop = new ComponentArrayProperty(target.Name, id, ((ComponentArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTimeArray: prop = new DateTimeArrayProperty(target.Name, id, ((DateTimeArrayProperty)target).Value, bag); break; case (int)PropertyKind.ByteArray: prop = new ByteArrayProperty(target.Name, id, ((ByteArrayProperty)target).Value, bag); break; case (int)PropertyKind.DoubleArray: prop = new DoubleArrayProperty(target.Name, id, ((DoubleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16Array: prop = new Int16ArrayProperty(target.Name, id, ((Int16ArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16: prop = new Int16Property(target.Name, id, ((Int16Property)target).Value, bag); break; case (int)PropertyKind.Int64Array: prop = new Int64ArrayProperty(target.Name, id, ((Int64ArrayProperty)target).Value, bag); break; case (int)PropertyKind.BoolArray: prop = new BoolArrayProperty(target.Name, id, ((BoolArrayProperty)target).Value, bag); break; } prop.Name = target.Name; return prop; }
public static bool Item_UpdateFloatProperty(this DB db, Guid ItemId, int propertyId, string propertyName, float newValue) { bool rslt = true; SqlConnection con = DB.GameDataConnection; SqlCommand cmd = DB.GetCommand(con, "Items_UpdateOrInsertFloatProperties", true); cmd.Parameters.Add(new SqlParameter("@itemId", ItemId)); SingleProperty prop = new SingleProperty(propertyName, propertyId, newValue, null); List<SingleProperty> props = new List<SingleProperty>(); props.Add(prop); cmd.Parameters.Add(new SqlParameter("@InputTable", ItemFloatPropertiesToTable(props, ItemId))); try { con.Open(); int code = cmd.ExecuteNonQuery(); } catch (Exception e) { Log1.Logger("Server").Error("[DATABASE ERROR] : " + e.Message); int x = 0; rslt = false; } finally { if (con != null) { con.Close(); } } return rslt; }