public void OnGet(PropertyContext context) { var arg0 = (int)context.Arguments[0]; context.Proceed(); if (arg0 == 2) { context.SetReturnValue(new Tuple <int, string, SimpleStruct, SimpleClass, InheritsFromSimpleClass, object>( 3, "c", new SimpleStruct(3), new SimpleClass(3), new InheritsFromSimpleClass(3), new Tuple <int, string, SimpleStruct, SimpleClass, InheritsFromSimpleClass, object>( 4, "d", new SimpleStruct(4), new SimpleClass(4), new InheritsFromSimpleClass(4), null ) )); } }
protected override void DrawPropertyLayout(InspectorProperty property, ContextExampleAttribute attribute, GUIContent label) { // Get two context objects. One for a frame counter, and one for an on/off button. PropertyContext <int> frameCount = property.Context.Get(this, "counter", 0); PropertyContext <bool> toggle = property.Context.Get(this, "toggler", false); // Count the frames. if (Event.current.type == EventType.Layout && toggle.Value) { frameCount.Value++; GUIHelper.RequestRepaint(); } // Draw the current frame count, and a start stop button. SirenixEditorGUI.BeginBox(); { GUILayout.Label("Frame Count: " + frameCount.Value.ToString()); if (GUILayout.Button(toggle.Value ? "Stop" : "Start")) { toggle.Value = !toggle.Value; } } SirenixEditorGUI.EndBox(); // Continue the drawer chain. this.CallNextDrawer(property, label); }
private PropertyContextSurface ChangeProperty(INakedObject nakedObject, string propertyName, ArgumentContext argument) { ValidateConcurrency(nakedObject, argument.Digest); PropertyContext context = CanChangeProperty(nakedObject, propertyName, argument.Value); if (string.IsNullOrEmpty(context.Reason)) { var spec = context.Target.Spec as IObjectSpec; Trace.Assert(spec != null); IEnumerable<PropertyContext> existingValues = spec.Properties.Where(p => p.Id != context.Id). Select(p => new {p, no = p.GetNakedObject(context.Target)}). Select(ao => new PropertyContext { Property = ao.p, ProposedNakedObject = ao.no, ProposedValue = ao.no == null ? null : ao.no.Object, Target = context.Target } ).Union(new[] {context}); var objectContext = new ObjectContext(context.Target) {VisibleProperties = existingValues.ToArray()}; if (ConsentHandler(CrossValidate(objectContext), objectContext, Cause.Other)) { if (!argument.ValidateOnly) { SetProperty(context); } } else { context.Reason = objectContext.Reason; context.ErrorCause = objectContext.ErrorCause; } } context.Mutated = true; // mark as changed even if property not actually changed to stop self rep return context.ToPropertyContextSurface(this, framework); }
/// <summary> /// Validate the property value. /// </summary> /// <param name="context">The <see cref="PropertyContext{TEntity, TProperty}"/>.</param> public override Task ValidateAsync(PropertyContext <TEntity, TProperty> context) { // Do not validate where the compare to property has an error. var ctx = Beef.Check.NotNull(context, nameof(context)); if (ctx.Parent.HasError(_compareTo)) { return(Task.CompletedTask); } // Convert type and compare values. try { var compareToValue = (TProperty)(object)_compareTo.GetValue(context.Parent.Value) !; if (!Compare(ctx.Value !, compareToValue)) { CreateErrorMessage(context, _compareToText ?? _compareTo.Text); } return(Task.CompletedTask); } catch (InvalidCastException icex) { throw new InvalidCastException($"Property '{_compareTo.Name}' and '{ctx.Name}' are incompatible: {icex.Message}", icex); } }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { if (!pipelineContext.Faulted) { switch (pipelineContext.Context) { case CheckboxField checkboxField: pipelineContext.Context = checkboxField.Checked; break; case Field field when string.Equals(field.Type, "Checkbox", StringComparison.InvariantCultureIgnoreCase): pipelineContext.Context = ((CheckboxField)field).Checked; break; default: pipelineContext.Faulted = true; break; } } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
private static void SetSquareRowHeights(PropertyContext <Context> context) { if (context.Value.ColCount > 0 && context.Value.RowCount > 0) { var lastCell = context.Value.Table[context.Value.ColCount - 1, context.Value.RowCount - 1]; if (lastCell != null && Mathf.Abs(lastCell.Rect.height - lastCell.Rect.width) > 0) { for (int y = 0; y < context.Value.RowCount; y++) { int _y = context.Value.Table.RowCount - 1 - y; for (int x = 0; x < context.Value.Table.ColumnCount; x++) { var cell = context.Value.Table[x, _y]; if (cell != null) { cell.Height = lastCell.Rect.width; } } } context.Value.Table.ReCalculateSizes(); GUIHelper.RequestRepaint(); } } }
protected void AddDummyData(DbContextOptions <PropertyContext> contextOptions) { var ctx = new PropertyContext(contextOptions); ctx.Properties.AddRangeAsync(GetDummyDataItems()); ctx.SaveChanges(); }
private List <Attachment> GetAttachments() { var attachments = new List <Attachment>(); if (!HasAttachments) { return(attachments); } var attachmentSet = new HashSet <string>(); foreach (var subNode in SubNodeDataDto) { // fixme start here. this is the node id. If we can figure out that the attachment is embedded // and jump straight to the attachment node id we may have something var nodeType = NID.GetNodeType(subNode.Key); if (nodeType != NID.NodeType.ATTACHMENT_PC) { continue; } var attachmentPC = new PropertyContext(subNode.Value); var attachment = new Attachment(attachmentPC); if (attachmentSet.Contains(attachment.AttachmentLongFileName)) { var smallGuid = Guid.NewGuid().ToString().Substring(0, 5); attachment.AttachmentLongFileName = $"{smallGuid}-{attachment.AttachmentLongFileName}"; } attachmentSet.Add(attachment.AttachmentLongFileName); attachments.Add(attachment); } return(attachments); }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { if (!pipelineContext.Faulted) { if (processorContext.TryGetOption(ConstantOptionKey, out T constantValue)) { pipelineContext.Context = constantValue; } else { pipelineContext.Faulted = true; } } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) { var p = contentItem.Parts.FirstOrDefault(x => x.PartDefinition.Name == part.Name); if (p == null) { return(String.Empty); } var f = p.Fields.FirstOrDefault(x => x.Name == field.Name); if (f == null) { return(String.Empty); } var value = f.Storage.Get <object>(storageName); if (value == null) { return(null); } // call specific formatter rendering return(_propertyFormater.Format(storageType, value, context.State)); }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { switch (pipelineContext.Context) { case ImageField imageField when imageField.MediaItem != null: pipelineContext.Context = imageField.Height; break; default: pipelineContext.Faulted = true; break; } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { if (!pipelineContext.Faulted) { switch (pipelineContext.Context) { case Item item: pipelineContext.Context = item.Name; break; default: pipelineContext.Faulted = true; break; } } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { switch (pipelineContext.Context) { case ImageField imageField when imageField.MediaItem != null: pipelineContext.Context = imageField.MediaItem.DisplayName ?? imageField.MediaItem.Name; break; case MediaItem mediaItem: pipelineContext.Context = mediaItem.DisplayName ?? mediaItem.Name; break; case Item item: pipelineContext.Context = item.DisplayName ?? item.Name; break; default: pipelineContext.Faulted = true; break; } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
public PaymentGatewayRepository( PropertyContext context, ILogger <PaymentGatewayRepository> logger) { _context = context; _logger = logger; }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { if (!pipelineContext.Faulted) { switch (pipelineContext.Context) { case Item mediaItem when mediaItem.Paths.IsMediaItem: pipelineContext.Context = MediaManager.GetMediaUrl(mediaItem); break; case Item contentItem when contentItem.Paths.IsContentItem: pipelineContext.Context = LinkManager.GetItemUrl(contentItem); break; default: pipelineContext.Faulted = true; break; } } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
protected override void Initialize() { var property = this.Property; var attribute = this.Attribute; this.contextMenuInfos = property.Context.GetGlobal("CustomContextMenu", (Dictionary <CustomContextMenuAttribute, ContextMenuInfo>)null); this.populated = property.Context.GetGlobal("CustomContextMenu_Populated", false); if (contextMenuInfos.Value == null) { contextMenuInfos.Value = new Dictionary <CustomContextMenuAttribute, ContextMenuInfo>(); } if (!contextMenuInfos.Value.TryGetValue(attribute, out this.info)) { this.info = new ContextMenuInfo(); var methodInfo = property.ParentType .FindMember() .IsMethod() .IsInstance() .HasNoParameters() .ReturnsVoid() .IsNamed(attribute.MethodName) .GetMember <MethodInfo>(out this.info.ErrorMessage); if (this.info.ErrorMessage == null) { this.info.Name = attribute.MenuItem; this.info.MethodCaller = EmitUtilities.CreateWeakInstanceMethodCaller(methodInfo); } contextMenuInfos.Value[attribute] = this.info; } }
public override ASTN VisitProperty([NotNull] PropertyContext context) { PropertyNode node = new PropertyNode(context) { formal = VisitFormal(context.formal()) as FormalNode }; if (context.expr() != null) { node.expr_body = VisitExpr(context.expr()) as ExprNode; } else if (node.formal.type.Text == "Int") { node.expr_body = new IntNode(context, "0"); } else if (node.formal.type.Text == "String") { node.expr_body = new StringNode(context, ""); } else if (node.formal.type.Text == "Bool") { node.expr_body = new BoolNode(context, "false"); } else { node.expr_body = new VoidNode(context); (node.expr_body as VoidNode).getStaticType = node.formal.type.Text; } return(node); }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { if (!pipelineContext.Faulted) { if (processorContext.TryGetOption(DictionaryKey, out string dictionaryKey)) { if (processorContext.TryGetOption(DefaultValue, out string defaultValue) && defaultValue != default(string)) { pipelineContext.Context = Translate.TextByLanguage(dictionaryKey, Language.Current, defaultValue); } else { pipelineContext.Context = Translate.Text(dictionaryKey); } } else { pipelineContext.Faulted = true; } } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
/// <summary> /// Validate the property value. /// </summary> /// <param name="context">The <see cref="PropertyContext{TEntity, TProperty}"/>.</param> public override async Task ValidateAsync(PropertyContext <TEntity, TProperty> context) { Beef.Check.NotNull(context, nameof(context)); if (_predicate != null) { if (!_predicate.Invoke(context.Parent.Value)) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.ImmutableFormat); } } else if (_immutable != null) { if (!_immutable.Invoke()) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.ImmutableFormat); } } else { if (!(await _immutableAsync !.Invoke().ConfigureAwait(false))) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.ImmutableFormat); } } }
private PropertyContextFacade ChangeCollection(PropertyContext context, Func <NakedObject, NakedObject, Consent> validator, Action <NakedObject, NakedObject> mutator, ArgumentContextFacade args) { ValidateConcurrency(context.Target, args.Digest); var property = (OneToManyAssociation)context.Property; if (ConsentHandler(IsOfCorrectType(property, context), context, Cause.Other)) { if (ConsentHandler(IsCurrentlyImmutable(context.Target), context, Cause.Immutable)) { if (ConsentHandler(property.isAvailable(context.Target), context, Cause.Disabled)) { if (ConsentHandler(validator(context.Target, (NakedObject)context.ProposedNakedObject), context, Cause.Other)) { if (!args.ValidateOnly) { mutator(context.Target, (NakedObject)context.ProposedNakedObject); } } } } } context.Mutated = true; return(context.ToPropertyContextFacade(this)); }
protected List <Attachment> GetAttachments() { var attachments = new List <Attachment>(); if (!HasAttachments) { return(attachments); } var attachmentSet = new HashSet <string>(); foreach (var subNode in SubNodeDataDto) { var nodeType = NID.GetNodeType(subNode.Key); if (nodeType != NID.NodeType.ATTACHMENT_PC) { continue; } var attachmentPC = new PropertyContext(subNode.Value); var attachment = new Attachment(attachmentPC); if (attachmentSet.Contains(attachment.AttachmentLongFileName)) { var smallGuid = Guid.NewGuid().ToString().Substring(0, 5); attachment.AttachmentLongFileName = $"{smallGuid}-{attachment.AttachmentLongFileName}"; } attachmentSet.Add(attachment.AttachmentLongFileName); attachments.Add(attachment); } return(attachments); }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { switch (pipelineContext.Context) { case string stringValue when Enum.TryParse(stringValue, true, out T value): pipelineContext.Context = value; break; case string stringValue when TryMatchByAttribute(stringValue, out T value): pipelineContext.Context = value; break; default: pipelineContext.Faulted = true; break; } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
/// <summary> /// Validate the property value. /// </summary> /// <param name="context">The <see cref="PropertyContext{TEntity, TProperty}"/>.</param> public override void Validate(PropertyContext <TEntity, string> context) { Beef.Check.NotNull(context, nameof(context)); if (string.IsNullOrEmpty(context.Value)) { return; } if (context.Value.Length < MinLength) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.MinLengthFormat, MinLength); return; } if (MaxLength.HasValue && context.Value.Length > MaxLength.Value) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.MaxLengthFormat, MaxLength); return; } if (Regex != null && !Regex.IsMatch(context.Value)) { context.CreateErrorMessage(ErrorText ?? ValidatorStrings.RegexFormat); return; } }
public void Setup() { InitialiseMapping(); _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); var options = new DbContextOptionsBuilder <PropertyContext>() .UseSqlite(_connection) .Options; var inMemoryContext = new PropertyContext(options); inMemoryContext.Properties.AddRange(GenerateFakeProperties()); inMemoryContext.SaveChanges(); // While working with a inMemoryDb there is no need for mocking IPropertyRepository // Instead working to implementation provides implementation test without affecting Db // var service = new Mock<IPropertyRepository>(); // service.Setup(p => p.GetProperties()).Returns(inMemoryContext.Properties); var service = new PropertyRepository(inMemoryContext); Sut = new PropertiesController(service); }
public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext) { try { switch (pipelineContext.Context) { case IEnumerable <Item> items: pipelineContext.Context = items.Select(x => x.ID).ToList(); break; case Item item: pipelineContext.Context = item.ID; break; default: pipelineContext.Faulted = true; break; } } catch { pipelineContext.Faulted = true; throw; } finally { Next(); } }
public LanguageRepository( PropertyContext context, ILogger <LanguageRepository> logger) { _context = context; _logger = logger; }
public void AddProperties(bool unicode, PropertyContext pc) { foreach (var prop in pc.Properties) { SetProperty(unicode, prop.Value); } }
/// <summary> /// Validates an entity given a <see cref="ValidationContext{TEntity}"/>. /// </summary> /// <param name="context">The <see cref="ValidationContext{TEntity}"/>.</param> public void Validate(ValidationContext <TEntity> context) { Check.NotNull(context, nameof(context)); if (context.Value == null) { return; } // Where validating a specific property then make sure the names match. if (context.SelectedPropertyName != null && context.SelectedPropertyName != Name) { return; } // Ensure that the property does not already have an error. if (context.HasError(_property)) { return; } // Get the property value and create the property context. var value = _property.GetValue(context.Value); var ctx = new PropertyContext <TEntity, TProperty>(context, value, this.Name, this.JsonName, this.Text); // Run the rules. Invoke(ctx); }
public void OnSet(PropertyContext context) { var arg0 = (int)context.Arguments[0]; context.Arguments.SetArgument(0, arg0 + 6); context.Proceed(); }
/// <summary> /// Validate the property value. /// </summary> /// <param name="context">The <see cref="PropertyContext{TEntity, TProperty}"/>.</param> public override void Validate(PropertyContext <TEntity, TProperty> context) { // Do not validate where the compare to property has an error. Beef.Check.NotNull(context, nameof(context)); if (context.Parent.HasError(_compareTo)) { return; } // Convert type and compare values. try { var compareToValue = (TProperty)(object)_compareTo.GetValue(context.Parent.Value); #pragma warning disable CA1062 // Validate arguments of public methods; by-design, null check already performed. if (!Compare(context.Value, compareToValue)) { CreateErrorMessage(context, _compareToText ?? _compareTo.Text); } #pragma warning restore CA1062 } catch (InvalidCastException icex) { throw new InvalidCastException($"Property '{_compareTo.Name}' and '{context.Name}' are incompatible: {icex.Message}", icex); } }